[Libguestfs] [PATCH] New API: is_whole_device
Matthew Booth
mbooth at redhat.com
Fri Feb 8 14:10:46 UTC 2013
On Fri, 2013-02-08 at 09:42 +0000, Richard W.M. Jones wrote:
> On Thu, Feb 07, 2013 at 02:24:10PM +0000, Matthew Booth wrote:
> > ---
> > daemon/devsparts.c | 27 +++++++++++++++++++++++++++
> > generator/actions.ml | 17 +++++++++++++++++
> > src/MAX_PROC_NR | 2 +-
> > 3 files changed, 45 insertions(+), 1 deletion(-)
> >
> > diff --git a/daemon/devsparts.c b/daemon/devsparts.c
> > index 9a2ce9a..1939f2a 100644
> > --- a/daemon/devsparts.c
> > +++ b/daemon/devsparts.c
> > @@ -245,6 +245,33 @@ do_part_to_partnum (const char *part)
> > }
> >
> > int
> > +do_is_whole_device (const char *device)
> > +{
> > + #define PREFIX "/dev/"
> > +
> > + /* Shouldn't be possible because we already sanity checked our input */
> > + if (!STRPREFIX (device, PREFIX)) return 0;
>
> There's no need for this test.
>
> > + CLEANUP_FREE char *devpath = NULL;
> > + if (asprintf (&devpath, "/sys/block/%s/device",
> > + device + strlen (PREFIX)) == -1)
> > + {
> > + reply_with_perror ("asprintf");
> > + return -1;
> > + }
> > +
> > + struct stat statbuf;
> > + if (stat (devpath, &statbuf) == -1) {
> > + if (errno == ENOENT || errno == ENOTDIR) return 0;
> > +
> > + reply_with_perror ("stat");
> > + return -1;
> > + }
> > +
> > + return 1;
> > +}
>
> This test seems fine. Is it worth adding S_ISDIR (statbuf.st_mode)?
It's actually a symlink. I'll add that and also a comment describing
what it's looking for, then push it.
Matt
More information about the Libguestfs
mailing list