[Libguestfs] [PATCH 10/27] daemon: Reimplement ‘part_get_mbr_id’ API in OCaml.

Pino Toscano ptoscano at redhat.com
Wed Jul 19 13:18:55 UTC 2017


On Friday, 14 July 2017 15:39:18 CEST Richard W.M. Jones wrote:
> +let part_get_mbr_id device partnum =
> +  if partnum <= 0 then
> +    failwith "partition number must be >= 1";
> +
> +  let param =
> +    if Lazy.force test_sfdisk_has_part_type then
> +      "--part-type"
> +    else
> +      "--print-id" in
> +
> +  udev_settle ();
> +  let out =
> +    command "sfdisk" [param; device; string_of_int partnum] in
> +  udev_settle ();
> +
> +  (* It's printed in hex, possibly with a leading space. *)
> +  sscanf out " %x" identity

I see that the C sscanf discards the leading spaces, so maybe it would
be safer to use String.triml to behave the same, and not break in case
sfdisk changes its output in the future.

-- 
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20170719/67099f01/attachment.sig>


More information about the Libguestfs mailing list