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
--
1.8.3.1