[PATCH 2/4] fs: add pread and pwrite functions

Alexander Aring alex.aring at gmail.com
Thu Feb 14 17:23:06 EST 2013


Hi Sascha,

On Thu, Feb 14, 2013 at 10:13:05PM +0100, Sascha Hauer wrote:
> On Thu, Feb 14, 2013 at 02:08:29PM +0100, Alexander Aring wrote:
> > Add pread and pwrite functions.
> > 
> > These functions setting file pointer to a given
> > offset with lseek and call read or write afterwards.
> > 
> > Signed-off-by: Alexander Aring <alex.aring at gmail.com>
> > ---
> >  fs/fs.c      | 28 ++++++++++++++++++++++++++++
> >  include/fs.h |  2 ++
> >  2 files changed, 30 insertions(+)
> > 
> > diff --git a/fs/fs.c b/fs/fs.c
> > index 48d1c89..fea7e02 100644
> > --- a/fs/fs.c
> > +++ b/fs/fs.c
> > @@ -785,6 +785,20 @@ ssize_t read(int fd, void *buf, size_t count)
> >  }
> >  EXPORT_SYMBOL(read);
> >  
> > +ssize_t pread(int fd, void *buf, size_t count, loff_t offset)
> > +{
> > +	int ret;
> > +
> > +	ret = lseek(fd, offset, SEEK_SET);
> > +	if (ret < 0)
> > +		goto out;
> > +
> > +	ret = read(fd, buf, count);
> > +out:
> > +	return ret;
> > +}
> 
> The man page says that the file offset is not modified by pread/pwrite.
> If we add a standard function with a standard prototype I think it
> should have the same behaviour.
> Maybe this can be implemented similar to the current read() function
> is implemented. read() could then call pread() internally and advances
> the file offset afterwards.

Ok I will change this. Thanks.

Regards
Alex



More information about the barebox mailing list