mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
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.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -1 +1 @@
|
||||
415
|
||||
416
|
||||
|
||||
Reference in New Issue
Block a user