From: Alexander Aring <alex.aring@gmail.com>
To: barebox@lists.infradead.org
Subject: [RFC PATCH v2 0/2] fs: add pread and pwrite functions
Date: Sun, 17 Feb 2013 22:04:59 +0100 [thread overview]
Message-ID: <1361135101-994-1-git-send-email-alex.aring@gmail.com> (raw)
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
next reply other threads:[~2013-02-17 21:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-17 21:04 Alexander Aring [this message]
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
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=1361135101-994-1-git-send-email-alex.aring@gmail.com \
--to=alex.aring@gmail.com \
--cc=barebox@lists.infradead.org \
/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