X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=daemon%2Fdevsparts.c;h=c8f0256a351cdb0f69375ddf32f801f120898d12;hp=60e7aa8caa8da8b9f6175fd23f51e1ea04aeaed4;hb=3ed8d5122026f37dd96cc7e8503c4f3ecf0afbb7;hpb=3e70b34eed5a48640e20fbf6dcba774aaace1f3c diff --git a/daemon/devsparts.c b/daemon/devsparts.c index 60e7aa8..c8f0256 100644 --- a/daemon/devsparts.c +++ b/daemon/devsparts.c @@ -26,6 +26,8 @@ #include #include +#include "c-ctype.h" + #include "daemon.h" #include "actions.h" @@ -60,6 +62,10 @@ foreach_block_device (block_dev_func_t func) char dev_path[256]; snprintf (dev_path, sizeof dev_path, "/dev/%s", d->d_name); + /* Ignore the root device. */ + if (is_root_device (dev_path)) + continue; + /* RHBZ#514505: Some versions of qemu <= 0.10 add a * CD-ROM device even though we didn't request it. Try to * detect this by seeing if the device contains media. @@ -99,8 +105,9 @@ foreach_block_device (block_dev_func_t func) return NULL; } - /* Sort the devices */ - sort_strings (r, size); + /* Sort the devices. Note that r might be NULL if there are no devices. */ + if (r != NULL) + sort_strings (r, size); /* NULL terminate the list */ if (add_string (&r, &size, &alloc, NULL) == -1) { @@ -186,3 +193,28 @@ do_list_partitions (void) { return foreach_block_device(add_partitions); } + +char * +do_part_to_dev (const char *part) +{ + int err = 1; + size_t n = strlen (part); + + while (n >= 1 && c_isdigit (part[n-1])) { + err = 0; + n--; + } + + if (err) { + reply_with_error ("device name is not a partition"); + return NULL; + } + + char *r = strndup (part, n); + if (r == NULL) { + reply_with_perror ("strdup"); + return NULL; + } + + return r; +}