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

Sascha Hauer s.hauer at pengutronix.de
Thu Feb 14 16:13:05 EST 2013


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.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list