[Pkg-libvirt-commits] [libguestfs] 181/233: New API: part-get-name (RHBZ#593511).

Hilko Bengen bengen at moszumanska.debian.org
Wed Feb 19 21:12:07 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch experimental
in repository libguestfs.

commit 820b87016794116c783bd224f2e776cfdf65108e
Author: Pino Toscano <ptoscano at redhat.com>
Date:   Tue Feb 4 14:48:14 2014 +0100

    New API: part-get-name (RHBZ#593511).
    
    Counterpart of part-set-name, it uses sgdisk (hence needs the "gdisk"
    feature) to query for the label/name of a partition in a GPT layout.
---
 daemon/parted.c      | 33 +++++++++++++++++++++++++++++++++
 generator/actions.ml | 13 +++++++++++++
 src/MAX_PROC_NR      |  2 +-
 3 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/daemon/parted.c b/daemon/parted.c
index 5282adb..83f2411 100644
--- a/daemon/parted.c
+++ b/daemon/parted.c
@@ -886,9 +886,42 @@ extract_uuid (const char *value)
   return ret;
 }
 
+static char *
+extract_optionally_quoted (const char *value)
+{
+  size_t value_len = strlen (value);
+
+  if (value_len >= 2 &&
+      ((value[0] == '\'' && value[value_len - 1] == '\'') ||
+       (value[0] == '"' && value[value_len - 1] == '"'))) {
+    value_len -= 2;
+    ++value;
+  }
+
+  char *ret = strndup (value, value_len);
+  if (ret == NULL) {
+    reply_with_perror ("strndup");
+    return NULL;
+  }
+
+  return ret;
+}
+
 char *
 do_part_get_gpt_type (const char *device, int partnum)
 {
   return sgdisk_info_extract_field (device, partnum,
                                     "Partition GUID code", extract_uuid);
 }
+
+char *
+do_part_get_name (const char *device, int partnum)
+{
+  char *parttype = do_part_get_parttype (device);
+  if (STREQ (parttype, "gpt"))
+    return sgdisk_info_extract_field (device, partnum,
+                                      "Partition name", extract_optionally_quoted);
+
+  reply_with_error ("cannot get the partition name from '%s' layouts", parttype);
+  return NULL;
+}
diff --git a/generator/actions.ml b/generator/actions.ml
index 176de98..b665149 100644
--- a/generator/actions.ml
+++ b/generator/actions.ml
@@ -11766,6 +11766,19 @@ enables all the other flags, if they are not specified already.
 
 =back" };
 
+  { defaults with
+    name = "part_get_name";
+    style = RString "name", [Device "device"; Int "partnum"], [];
+    proc_nr = Some 416;
+    optional = Some "gdisk";
+    shortdesc = "get partition name";
+    longdesc = "\
+This gets the partition name on partition numbered C<partnum> on
+device C<device>.  Note that partitions are numbered from 1.
+
+The partition name can only be read on certain types of partition
+table.  This works on C<gpt> but not on C<mbr> partitions." };
+
 ]
 
 (* Non-API meta-commands available only in guestfish.
diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR
index 21c8d99..1c105f1 100644
--- a/src/MAX_PROC_NR
+++ b/src/MAX_PROC_NR
@@ -1 +1 @@
-415
+416

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list