diff options
author | Richard Jones <rjones@redhat.com> | 2010-09-15 16:39:36 +0100 |
---|---|---|
committer | Richard Jones <rjones@redhat.com> | 2010-09-15 17:16:51 +0100 |
commit | ffd4820ffe953b0583e3a9357e37d74bed3a2320 (patch) | |
tree | f092d285f9c29c7bec17efdbe2cd16a55d168179 /daemon | |
parent | ff38fea645e69e8f4d84f2691dac3116d9bac1c4 (diff) | |
download | libguestfs-ffd4820ffe953b0583e3a9357e37d74bed3a2320.tar.gz libguestfs-ffd4820ffe953b0583e3a9357e37d74bed3a2320.tar.xz libguestfs-ffd4820ffe953b0583e3a9357e37d74bed3a2320.zip |
New API: part-to-dev: Convert partition name to device name.
This adds a formal API for going from a partition to the containing
device, eg. /dev/sda1 -> /dev/sda
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/devsparts.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/daemon/devsparts.c b/daemon/devsparts.c index 95e4a682..1781def3 100644 --- a/daemon/devsparts.c +++ b/daemon/devsparts.c @@ -26,6 +26,8 @@ #include <dirent.h> #include <sys/stat.h> +#include "c-ctype.h" + #include "daemon.h" #include "actions.h" @@ -190,3 +192,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; +} |