Skip to content
Browse files

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.
  • Loading branch information...
1 parent 78c21ce commit 820b87016794116c783bd224f2e776cfdf65108e @ptoscano ptoscano committed
Showing with 47 additions and 1 deletion.
  1. +33 −0 daemon/parted.c
  2. +13 −0 generator/actions.ml
  3. +1 −1 src/MAX_PROC_NR
View
33 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;
+}
View
13 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.
View
2 src/MAX_PROC_NR
@@ -1 +1 @@
-415
+416

0 comments on commit 820b870

Please sign in to comment.
Something went wrong with that request. Please try again.