[Libguestfs] [PATCH] New API: is_whole_device
Richard W.M. Jones
rjones at redhat.com
Fri Feb 8 09:42:58 UTC 2013
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)?
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW
More information about the Libguestfs
mailing list