[RFC PATCH v2 0/2] fs: add pread and pwrite functions

Alexander Aring alex.aring at gmail.com
Sun Feb 17 16:04:59 EST 2013


These Patches fixes the return type of read function and add two new functions,
pread and pwrite in fs layer of barebox.

In my opinion this implementation of pread and pwrite could be better if fs
interface has as read callback:
int (*read)(struct device_d *dev, loff_t pos, ... flags, etc...);

not a "FILE *" as parameter.

instead of:
int (*read)(struct device_d *dev, FILE *f, void *buf, size_t size);

I don't want to screw up the interface, it's only a notice. This would be funny
if we change that. :-/

The current implementation of pread and pwrite saves the current file pos and
restore them after do some file manipulation. Could be optimize if a filesystem
driver doesn't read the pos from FILE pointer and I can give the offset over a
parameter. In case of read it would be "f->pos" and pread it would be "offset".

Another thing is:

We could optimize it (pwrite and pread) and (read and write) looks very similar.
The only different between these functions is a "const void *buf" and "void *buf"

I thinking a about a function with a functionpointer as parameter like

static ssize_t __do_read_or_write(int fd, void *buf, size_t count,
			ssize_t func(int fd, void *buf, size_t count))

Which func is for read = __read and for write = __write, but I got trouble because
the function prototype "void *" and "const void*". I can do more parameters and
decide it as runtime, but I don't like to do that, looks very ugly.

Regards
Alex

v2:
	rewritten pread and pwrite functions

Alexander Aring (2):
  fs: fix return type of read
  fs: add pread and pwrite functions

 fs/fs.c      | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++----------
 include/fs.h |  4 ++-
 2 files changed, 78 insertions(+), 15 deletions(-)

-- 
1.8.1.3




More information about the barebox mailing list