mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
daemon/parted: Assume sfdisk --part-type exists
This "new" parameter was added in 2014: commit 8eab3194ce1737a167812d5e84d83b0dfc253fac Author: Karel Zak <kzak@redhat.com> Date: Mon Sep 15 12:37:52 2014 +0200 sfdisk: add --parttype The patch also makes --{id,change-id,print-id} deprecated in favour of --parttype. The original --id is too generic option name and the --print-id and --change-id are unnecessary and inconsistent with another sfdisk options (e.g. we don't have --change-bootable) Also remove an extraneous / incorrect comment about parted. As history has played out, sfdisk proves to be the better tool and parted is a PITA.
This commit is contained in:
@@ -424,30 +424,6 @@ do_part_get_bootable (const char *device, int partnum)
|
||||
return strstr (boot, "boot") != NULL;
|
||||
}
|
||||
|
||||
/* Test if sfdisk is recent enough to have --part-type, to be used instead
|
||||
* of --print-id and --change-id.
|
||||
*/
|
||||
static int
|
||||
test_sfdisk_has_part_type (void)
|
||||
{
|
||||
static int tested = -1;
|
||||
|
||||
if (tested != -1)
|
||||
return tested;
|
||||
|
||||
int r;
|
||||
CLEANUP_FREE char *out = NULL, *err = NULL;
|
||||
|
||||
r = command (&out, &err, "sfdisk", "--help", NULL);
|
||||
if (r == -1) {
|
||||
reply_with_error ("%s: %s", "sfdisk --help", err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tested = strstr (out, "--part-type") != NULL;
|
||||
return tested;
|
||||
}
|
||||
|
||||
int
|
||||
do_part_set_mbr_id (const char *device, int partnum, int idbyte)
|
||||
{
|
||||
@@ -456,8 +432,6 @@ do_part_set_mbr_id (const char *device, int partnum, int idbyte)
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *param = test_sfdisk_has_part_type () ? "--part-type" : "--change-id";
|
||||
|
||||
char partnum_str[16];
|
||||
snprintf (partnum_str, sizeof partnum_str, "%d", partnum);
|
||||
|
||||
@@ -470,10 +444,10 @@ do_part_set_mbr_id (const char *device, int partnum, int idbyte)
|
||||
|
||||
udev_settle ();
|
||||
|
||||
r = command (NULL, &err, "sfdisk",
|
||||
param, device, partnum_str, idbyte_str, NULL);
|
||||
r = command (NULL, &err, "sfdisk", "--part-type",
|
||||
device, partnum_str, idbyte_str, NULL);
|
||||
if (r == -1) {
|
||||
reply_with_error ("sfdisk %s: %s", param, err);
|
||||
reply_with_error ("sfdisk --part-type: %s", err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,33 +25,13 @@ open Utils
|
||||
|
||||
include Structs
|
||||
|
||||
(* Test if [sfdisk] is recent enough to have [--part-type], to be used
|
||||
* instead of [--print-id] and [--change-id].
|
||||
*)
|
||||
let test_sfdisk_has_part_type = lazy (
|
||||
let out = command "sfdisk" ["--help"] in
|
||||
String.find out "--part-type" >= 0
|
||||
)
|
||||
|
||||
(* Currently we use sfdisk for getting and setting the ID byte. In
|
||||
* future, extend parted to provide this functionality. As a result
|
||||
* of using sfdisk, this won't work for non-MBR-style partitions, but
|
||||
* that limitation is noted in the documentation and we can extend it
|
||||
* later without breaking the ABI.
|
||||
*)
|
||||
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
|
||||
command "sfdisk" ["--part-type"; device; string_of_int partnum] in
|
||||
udev_settle ();
|
||||
|
||||
(* It's printed in hex, possibly with a leading space. *)
|
||||
|
||||
Reference in New Issue
Block a user