summaryrefslogtreecommitdiffstats
path: root/daemon
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2011-10-25 12:46:05 +0100
committerRichard W.M. Jones <rjones@redhat.com>2011-10-25 12:46:05 +0100
commit47412f137f2b09dbc2b44b78ba84c0b348e3f402 (patch)
tree5bfc088fc2d7099b9b32b8e4529b49f158f527fa /daemon
parent1e891d900714b84a84f9c9e79c6e033aa56c0fcc (diff)
downloadlibguestfs-47412f137f2b09dbc2b44b78ba84c0b348e3f402.tar.gz
libguestfs-47412f137f2b09dbc2b44b78ba84c0b348e3f402.tar.xz
libguestfs-47412f137f2b09dbc2b44b78ba84c0b348e3f402.zip
New API: part-to-partnum
This converts a partition device name (eg. /dev/sda1) to a partition number (eg. 1). This is useful in conjunction with the parted APIs that mostly take a disk device + partnum.
Diffstat (limited to 'daemon')
-rw-r--r--daemon/devsparts.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/daemon/devsparts.c b/daemon/devsparts.c
index 52a6d304..79da41b0 100644
--- a/daemon/devsparts.c
+++ b/daemon/devsparts.c
@@ -220,3 +220,28 @@ do_part_to_dev (const char *part)
return r;
}
+
+int
+do_part_to_partnum (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 -1;
+ }
+
+ int r;
+ if (sscanf (&part[n], "%d", &r) != 1) {
+ reply_with_error ("could not parse number");
+ return -1;
+ }
+
+ return r;
+}