From: Alexander Aring <alex.aring@gmail.com>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] read_file: Make it work on tftp servers which do not pass size
Date: Thu, 20 Jun 2013 09:28:44 +0200 [thread overview]
Message-ID: <20130620072843.GA2086@x61s> (raw)
In-Reply-To: <20130620064217.GN32299@pengutronix.de>
Hi Sascha,
On Thu, Jun 20, 2013 at 08:42:17AM +0200, Sascha Hauer wrote:
> On Wed, Jun 19, 2013 at 11:57:01PM +0200, Alexander Aring wrote:
> > Hi,
> >
> > On Wed, Jun 19, 2013 at 11:32:39PM +0200, Alexander Aring wrote:
> > > Hi Sascha,
> > >
> > > only a very small hint.
> > >
> > > On Wed, Jun 19, 2013 at 10:58:48PM +0200, Sascha Hauer wrote:
> > > > Some tftp servers (for example netkit-tftp) do not pass the filesize.
> > > > Add a workaround for read_file which reads the file into a temporary
> > > > file which then is copied to a buffer.
> > > >
> > > > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > > > ---
> > > > fs/fs.c | 18 ++++++++++++++++++
> > > > fs/tftp.c | 5 ++++-
> > > > include/fs.h | 2 ++
> > > > 3 files changed, 24 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/fs/fs.c b/fs/fs.c
> > > > index dc3a6e3..7046f2c 100644
> > > > --- a/fs/fs.c
> > > > +++ b/fs/fs.c
> > > > @@ -38,10 +38,21 @@ void *read_file(const char *filename, size_t *size)
> > > > int fd;
> > >
> > > ...
> > >
> > > >
> > > > tftp_do_close(priv);
> > > >
> > > > diff --git a/include/fs.h b/include/fs.h
> > > > index 8ff7300..fa6a8da 100644
> > > > --- a/include/fs.h
> > > > +++ b/include/fs.h
> > > > @@ -147,6 +147,8 @@ int protect(int fd, size_t count, unsigned long offset, int prot);
> > > > int protect_file(const char *file, int prot);
> > > > void *memmap(int fd, int flags);
> > > >
> > > > +#define FILESIZE_MAX ((size_t)-1)
> > >
> > > The type of st_size in struct stat is loff_t. I check this and
> > > ((size_t)-1) is different than ((loff_t)-1), so I think we need to cast
> > > to loff_t. Maybe it's better to use a define from limits.h, but we don't
> > > have some header file like this.
> > >
> >
> > ah, I see it now. The fs layer use size_t instead of loff_t. Sorry for
> > the noise.
>
> No no, you were right. This indeed has to be a loff_t. Where did you
> find that the fs layer uses size_t? It should do so only for the length
> arguments of read/write and friends.
>
In function read_file :). The parameter size should be changed to
loff_t instead of size_t, because we make "*size = s.st_size;".
The point is, that a file can be greater than 4GB, but we _can't_
read/write a "block" from a file that is greather than 4GB.
But in this function we do "read(fd, buf, s.st_size) < s.st_size", this
need to be in small (max) 4GB pieces(if necessary). In other words, we
can't use s.st_size here if the file is greater than ((size_t)-1).
I don't think if we need something like this, because we never handle
files which are greater than 4GB.
That's my point of view. This example is only for a 32Bit architecture.
Regards
Alex
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2013-06-20 7:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-19 20:58 Sascha Hauer
2013-06-19 21:32 ` Alexander Aring
2013-06-19 21:57 ` Alexander Aring
2013-06-20 6:42 ` Sascha Hauer
2013-06-20 7:28 ` Alexander Aring [this message]
2013-06-20 8:12 ` Sascha Hauer
2013-06-20 11:15 ` Jan Weitzel
2013-06-20 15:24 ` Sascha Hauer
2013-06-21 7:03 ` Jan Weitzel
2013-06-21 7:10 ` Sascha Hauer
2013-06-21 7:46 ` Jan Weitzel
2013-06-21 8:21 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130620072843.GA2086@x61s \
--to=alex.aring@gmail.com \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox