mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [RFC PATCH v2 0/2] fs: add pread and pwrite functions
@ 2013-02-17 21:04 Alexander Aring
  2013-02-17 21:05 ` [PATCH 1/2] fs: fix return type of read Alexander Aring
  2013-02-17 21:05 ` [PATCH 2/2] fs: add pread and pwrite functions Alexander Aring
  0 siblings, 2 replies; 7+ messages in thread
From: Alexander Aring @ 2013-02-17 21:04 UTC (permalink / raw)
  To: barebox

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


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-02-19 20:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-17 21:04 [RFC PATCH v2 0/2] fs: add pread and pwrite functions Alexander Aring
2013-02-17 21:05 ` [PATCH 1/2] fs: fix return type of read Alexander Aring
2013-02-17 21:05 ` [PATCH 2/2] fs: add pread and pwrite functions Alexander Aring
2013-02-18 10:17   ` Sascha Hauer
2013-02-18 15:13     ` Alexander Aring
2013-02-19 19:33   ` Sascha Hauer
2013-02-19 20:30     ` Alexander Aring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox