[Libguestfs] [PATCH 4/5] fuse: Fix read for empty files.
Richard W.M. Jones
rjones at redhat.com
Wed Nov 18 09:44:56 UTC 2009
On Wed, Nov 18, 2009 at 08:29:18AM +0100, Jim Meyering wrote:
> Richard W.M. Jones wrote:
> > Subject: [PATCH 4/5] fuse: Fix read for empty files.
> >
> > Error handling for the guestfs_pread call was incorrect, which
> > meant that empty files could produce spurious error messages.
> > ---
> > fuse/guestmount.c | 8 +++++++-
> > 1 files changed, 7 insertions(+), 1 deletions(-)
> >
> > diff --git a/fuse/guestmount.c b/fuse/guestmount.c
> > index 9d16cef..669bf80 100644
> > --- a/fuse/guestmount.c
> > +++ b/fuse/guestmount.c
> > @@ -621,8 +621,14 @@ fg_read (const char *path, char *buf, size_t size, off_t offset,
> > if (size > limit)
> > size = limit;
> >
> > + /* Note the correct error handling here is tricky, because in the
> > + * case where the call returns a zero-length buffer, it might return
> > + * NULL. However it won't adjust rsize along the error path, so we
> > + * can set rsize to something beforehand and use that as a flag.
> > + */
> > + rsize = 1;
> > r = guestfs_pread (g, path, size, offset, &rsize);
> > - if (r == NULL)
> > + if (rsize == 1 && r == NULL)
> > return error ();
>
> That change looks fine.
>
> However, that you (and every guestfs_pread caller) would have to
> endure such contortions suggests that this API is too hard to use.
> Or at least too easy to misuse.
>
> Maybe it will be used so rarely that it doesn't matter...
> But it's still early in the life of libguestfs, so if you
> think you might want to change it, now is better/easier than later.
It certainly needs to be documented ...
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming blog: http://rwmj.wordpress.com
Fedora now supports 80 OCaml packages (the OPEN alternative to F#)
http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
More information about the Libguestfs
mailing list