[Libguestfs] [PATCH v2 2/3] New APIs: part_set_gpt_attributes and part_get_gpt_attributes
Richard W.M. Jones
rjones at redhat.com
Tue Jan 16 08:48:03 UTC 2018
On Mon, Jan 15, 2018 at 03:14:00PM +0100, Cédric Bosdonnat wrote:
> Allow reading and setting the GPT partition attribute flags.
> ---
> daemon/parted.ml | 23 +++++++++++++++++++++++
> daemon/parted.mli | 3 +++
> generator/actions_core.ml | 37 +++++++++++++++++++++++++++++++++++++
> generator/proc_nr.ml | 2 ++
> lib/MAX_PROC_NR | 2 +-
> 5 files changed, 66 insertions(+), 1 deletion(-)
>
> diff --git a/daemon/parted.ml b/daemon/parted.ml
> index 6fe803613..e3ab823bd 100644
> --- a/daemon/parted.ml
> +++ b/daemon/parted.ml
> @@ -124,10 +124,30 @@ let part_get_parttype device =
> | _ ->
> failwithf "%s: cannot parse the output of parted" device
>
> +let part_set_gpt_attributes device partnum attributes =
> + if partnum <= 0 then failwith "partition number must be >= 1";
> +
> + udev_settle ();
> +
> + let hex = Printf.sprintf "%LX" attributes in
> + let arg = string_of_int partnum ^ ":=:" ^ hex in
You could write these two lines more simply and clearly as:
let arg = sprintf "%d:=:%LX" partnum attributes in
You will also need to add ‘open Printf’ after ‘open Scanf’ at the top
of the file so that all the Printf.* functions are available without
needing to be prefixed.
> diff --git a/daemon/parted.mli b/daemon/parted.mli
> index cbcb7b503..9f57bbac7 100644
> --- a/daemon/parted.mli
> +++ b/daemon/parted.mli
> @@ -30,3 +30,6 @@ val part_get_parttype : string -> string
>
> val part_get_gpt_type : string -> int -> string
> val part_get_gpt_guid : string -> int -> string
> +val part_get_gpt_attributes : string -> int -> int64
> +
> +val part_set_gpt_attributes : string -> int -> int64 -> unit
Unnecessary blank line added here?
> diff --git a/generator/actions_core.ml b/generator/actions_core.ml
> index 02759a6b7..78eee61dd 100644
> --- a/generator/actions_core.ml
> +++ b/generator/actions_core.ml
> @@ -8265,6 +8265,43 @@ Return the type GUID of numbered GPT partition C<partnum>. For MBR partitions,
> return an appropriate GUID corresponding to the MBR type. Behaviour is undefined
> for other partition types." };
>
> + { defaults with
> + name = "part_set_gpt_attributes"; added = (1, 21, 1);
> + style = RErr, [String (Device, "device"); Int "partnum"; Int64 "attributes"], [];
> + impl = OCaml "Parted.part_set_gpt_attributes";
> + optional = Some "gdisk";
> + tests = [
> + InitGPT, Always, TestResult (
> + [["part_set_gpt_attributes"; "/dev/sda"; "1";
> + "4"];
> + ["part_get_gpt_attributes"; "/dev/sda"; "1"]],
> + "4"), [];
> + ];
> + shortdesc = "set the attribute flags of a GPT partition";
> + longdesc = "\
> +Set the attribute flags of numbered GPT partition C<partnum> to C<attributes>. Return an
> +error if the partition table of C<device> isn't GPT.
> +
> +See L<https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_entries>
> +for a useful list of partition attributes." };
So we're implicitly importing the ABI of GPT partition attributes into
the libguestfs ABI, which I think is fine as it seems to be
well-defined.
> + { defaults with
> + name = "part_get_gpt_attributes"; added = (1, 21, 1);
> + style = RInt64 "attributes", [String (Device, "device"); Int "partnum"], [];
> + impl = OCaml "Parted.part_get_gpt_attributes";
> + optional = Some "gdisk";
> + tests = [
> + InitGPT, Always, TestResult (
> + [["part_set_gpt_attributes"; "/dev/sda"; "1";
> + "0"];
> + ["part_get_gpt_attributes"; "/dev/sda"; "1"]],
> + "4"), [];
> + ];
> + shortdesc = "get the attribute flags of a GPT partition";
> + longdesc = "\
> +Return the attribute flags of numbered GPT partition C<partnum> as a hexadecimal bit mask.
It's not actually returning a "hexadecimal bit mask". Just remove
that.
Seems fine apart from the changes noted.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/
More information about the Libguestfs
mailing list