From: Richard W.M. Jones Date: Thu, 2 Jul 2009 20:50:30 +0000 (+0100) Subject: Add 'sfdiskM' command. X-Git-Tag: 1.0.55~1 X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=commitdiff_plain;h=b2c76a898b9d6fff09af05e4e3bd1d54c8816a95 Add 'sfdiskM' command. This command is a saner interface to partitioning. All partition sizes are specified in megabytes (not cylinders). You don't need to specify the cyls/heads/secs parameters. All the test code has been updated to use this, so it is now CHS-independent (eg. when CHS changes as between IDE and virtio). --- diff --git a/daemon/sfdisk.c b/daemon/sfdisk.c index 5fb30c0..f1726fc 100644 --- a/daemon/sfdisk.c +++ b/daemon/sfdisk.c @@ -31,6 +31,7 @@ static int sfdisk (char *device, int n, int cyls, int heads, int sectors, + const char *extra_flag, char * const* const lines) { FILE *fp; @@ -40,6 +41,7 @@ sfdisk (char *device, int n, int cyls, int heads, int sectors, IS_DEVICE (device, -1); strcpy (buf, "/sbin/sfdisk"); + if (n > 0) sprintf (buf + strlen (buf), " -N %d", n); if (cyls) @@ -48,6 +50,9 @@ sfdisk (char *device, int n, int cyls, int heads, int sectors, sprintf (buf + strlen (buf), " -H %d", heads); if (sectors) sprintf (buf + strlen (buf), " -S %d", sectors); + if (extra_flag) + sprintf (buf + strlen (buf), " %s", extra_flag); + /* Safe because of IS_DEVICE above: */ sprintf (buf + strlen (buf), " %s", device); @@ -82,7 +87,7 @@ int do_sfdisk (char *device, int cyls, int heads, int sectors, char **lines) { - return sfdisk (device, 0, cyls, heads, sectors, lines); + return sfdisk (device, 0, cyls, heads, sectors, NULL, lines); } int @@ -91,7 +96,13 @@ do_sfdisk_N (char *device, int n, int cyls, int heads, int sectors, { const char *lines[2] = { line, NULL }; - return sfdisk (device, n, cyls, heads, sectors, lines); + return sfdisk (device, n, cyls, heads, sectors, NULL, lines); +} + +int +do_sfdiskM (char *device, char **lines) +{ + return sfdisk (device, 0, 0, 0, 0, "-uM", lines); } static char * diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 93e7803..897bdc8 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -138 +139 diff --git a/src/generator.ml b/src/generator.ml index 239f021..ed5810b 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -641,7 +641,7 @@ see L."); let daemon_functions = [ ("mount", (RErr, [String "device"; String "mountpoint"]), 1, [], [InitEmpty, Always, TestOutput ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + [["sfdiskM"; "/dev/sda"; ","]; ["mkfs"; "ext2"; "/dev/sda1"]; ["mount"; "/dev/sda1"; "/"]; ["write_file"; "/new"; "new file contents"; "0"]; @@ -738,7 +738,7 @@ The full block device names are returned, eg. C"); [InitBasicFS, Always, TestOutputListOfDevices ( [["list_partitions"]], ["/dev/sda1"]); InitEmpty, Always, TestOutputListOfDevices ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ",200 ,400 ,"]; + [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"]; ["list_partitions"]], ["/dev/sda1"; "/dev/sda2"; "/dev/sda3"])], "list the partitions", "\ @@ -753,7 +753,7 @@ call C."); [InitBasicFSonLVM, Always, TestOutputListOfDevices ( [["pvs"]], ["/dev/sda1"]); InitEmpty, Always, TestOutputListOfDevices ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ",200 ,400 ,"]; + [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"]; ["pvcreate"; "/dev/sda1"]; ["pvcreate"; "/dev/sda2"]; ["pvcreate"; "/dev/sda3"]; @@ -772,7 +772,7 @@ See also C."); [InitBasicFSonLVM, Always, TestOutputList ( [["vgs"]], ["VG"]); InitEmpty, Always, TestOutputList ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ",200 ,400 ,"]; + [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"]; ["pvcreate"; "/dev/sda1"]; ["pvcreate"; "/dev/sda2"]; ["pvcreate"; "/dev/sda3"]; @@ -793,7 +793,7 @@ See also C."); [InitBasicFSonLVM, Always, TestOutputList ( [["lvs"]], ["/dev/VG/LV"]); InitEmpty, Always, TestOutputList ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ",200 ,400 ,"]; + [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"]; ["pvcreate"; "/dev/sda1"]; ["pvcreate"; "/dev/sda2"]; ["pvcreate"; "/dev/sda3"]; @@ -1146,7 +1146,7 @@ See also C."); ("pvcreate", (RErr, [String "device"]), 39, [], [InitEmpty, Always, TestOutputListOfDevices ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ",200 ,400 ,"]; + [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"]; ["pvcreate"; "/dev/sda1"]; ["pvcreate"; "/dev/sda2"]; ["pvcreate"; "/dev/sda3"]; @@ -1159,7 +1159,7 @@ as C."); ("vgcreate", (RErr, [String "volgroup"; StringList "physvols"]), 40, [], [InitEmpty, Always, TestOutputList ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ",200 ,400 ,"]; + [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"]; ["pvcreate"; "/dev/sda1"]; ["pvcreate"; "/dev/sda2"]; ["pvcreate"; "/dev/sda3"]; @@ -1173,7 +1173,7 @@ from the non-empty list of physical volumes C."); ("lvcreate", (RErr, [String "logvol"; String "volgroup"; Int "mbytes"]), 41, [], [InitEmpty, Always, TestOutputList ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ",200 ,400 ,"]; + [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"]; ["pvcreate"; "/dev/sda1"]; ["pvcreate"; "/dev/sda2"]; ["pvcreate"; "/dev/sda3"]; @@ -1194,7 +1194,7 @@ on the volume group C, with C megabytes."); ("mkfs", (RErr, [String "fstype"; String "device"]), 42, [], [InitEmpty, Always, TestOutput ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + [["sfdiskM"; "/dev/sda"; ","]; ["mkfs"; "ext2"; "/dev/sda1"]; ["mount"; "/dev/sda1"; "/"]; ["write_file"; "/new"; "new file contents"; "0"]; @@ -1269,12 +1269,12 @@ use C."); ("umount", (RErr, [String "pathordevice"]), 45, [FishAlias "unmount"], [InitEmpty, Always, TestOutputListOfDevices ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + [["sfdiskM"; "/dev/sda"; ","]; ["mkfs"; "ext2"; "/dev/sda1"]; ["mount"; "/dev/sda1"; "/"]; ["mounts"]], ["/dev/sda1"]); InitEmpty, Always, TestOutputList ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + [["sfdiskM"; "/dev/sda"; ","]; ["mkfs"; "ext2"; "/dev/sda1"]; ["mount"; "/dev/sda1"; "/"]; ["umount"; "/"]; @@ -1301,7 +1301,7 @@ Some internal mounts are not shown."); ["mounts"]], []); (* check that umount_all can unmount nested mounts correctly: *) InitEmpty, Always, TestOutputList ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ",200 ,400 ,"]; + [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"]; ["mkfs"; "ext2"; "/dev/sda1"]; ["mkfs"; "ext2"; "/dev/sda2"]; ["mkfs"; "ext2"; "/dev/sda3"]; @@ -1825,7 +1825,7 @@ to find out what you can do."); ("lvremove", (RErr, [String "device"]), 77, [], [InitEmpty, Always, TestOutputList ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + [["sfdiskM"; "/dev/sda"; ","]; ["pvcreate"; "/dev/sda1"]; ["vgcreate"; "VG"; "/dev/sda1"]; ["lvcreate"; "LV1"; "VG"; "50"]; @@ -1833,7 +1833,7 @@ to find out what you can do."); ["lvremove"; "/dev/VG/LV1"]; ["lvs"]], ["/dev/VG/LV2"]); InitEmpty, Always, TestOutputList ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + [["sfdiskM"; "/dev/sda"; ","]; ["pvcreate"; "/dev/sda1"]; ["vgcreate"; "VG"; "/dev/sda1"]; ["lvcreate"; "LV1"; "VG"; "50"]; @@ -1841,7 +1841,7 @@ to find out what you can do."); ["lvremove"; "/dev/VG"]; ["lvs"]], []); InitEmpty, Always, TestOutputList ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + [["sfdiskM"; "/dev/sda"; ","]; ["pvcreate"; "/dev/sda1"]; ["vgcreate"; "VG"; "/dev/sda1"]; ["lvcreate"; "LV1"; "VG"; "50"]; @@ -1858,7 +1858,7 @@ the VG name, C."); ("vgremove", (RErr, [String "vgname"]), 78, [], [InitEmpty, Always, TestOutputList ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + [["sfdiskM"; "/dev/sda"; ","]; ["pvcreate"; "/dev/sda1"]; ["vgcreate"; "VG"; "/dev/sda1"]; ["lvcreate"; "LV1"; "VG"; "50"]; @@ -1866,7 +1866,7 @@ the VG name, C."); ["vgremove"; "VG"]; ["lvs"]], []); InitEmpty, Always, TestOutputList ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + [["sfdiskM"; "/dev/sda"; ","]; ["pvcreate"; "/dev/sda1"]; ["vgcreate"; "VG"; "/dev/sda1"]; ["lvcreate"; "LV1"; "VG"; "50"]; @@ -1882,7 +1882,7 @@ group (if any)."); ("pvremove", (RErr, [String "device"]), 79, [], [InitEmpty, Always, TestOutputListOfDevices ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + [["sfdiskM"; "/dev/sda"; ","]; ["pvcreate"; "/dev/sda1"]; ["vgcreate"; "VG"; "/dev/sda1"]; ["lvcreate"; "LV1"; "VG"; "50"]; @@ -1891,7 +1891,7 @@ group (if any)."); ["pvremove"; "/dev/sda1"]; ["lvs"]], []); InitEmpty, Always, TestOutputListOfDevices ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + [["sfdiskM"; "/dev/sda"; ","]; ["pvcreate"; "/dev/sda1"]; ["vgcreate"; "VG"; "/dev/sda1"]; ["lvcreate"; "LV1"; "VG"; "50"]; @@ -1900,7 +1900,7 @@ group (if any)."); ["pvremove"; "/dev/sda1"]; ["vgs"]], []); InitEmpty, Always, TestOutputListOfDevices ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + [["sfdiskM"; "/dev/sda"; ","]; ["pvcreate"; "/dev/sda1"]; ["vgcreate"; "VG"; "/dev/sda1"]; ["lvcreate"; "LV1"; "VG"; "50"]; @@ -2181,7 +2181,7 @@ the human-readable, canonical hex dump of the file."); ("zerofree", (RErr, [String "device"]), 97, [], [InitNone, Always, TestOutput ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + [["sfdiskM"; "/dev/sda"; ","]; ["mkfs"; "ext3"; "/dev/sda1"]; ["mount"; "/dev/sda1"; "/"]; ["write_file"; "/new"; "test file"; "0"]; @@ -2279,7 +2279,7 @@ are activated or deactivated."); ("lvresize", (RErr, [String "device"; Int "mbytes"]), 105, [], [InitNone, Always, TestOutput ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + [["sfdiskM"; "/dev/sda"; ","]; ["pvcreate"; "/dev/sda1"]; ["vgcreate"; "VG"; "/dev/sda1"]; ["lvcreate"; "LV"; "VG"; "10"]; @@ -2370,11 +2370,11 @@ Sleep for C seconds."); ("ntfs_3g_probe", (RInt "status", [Bool "rw"; String "device"]), 110, [], [InitNone, Always, TestOutputInt ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + [["sfdiskM"; "/dev/sda"; ","]; ["mkfs"; "ntfs"; "/dev/sda1"]; ["ntfs_3g_probe"; "true"; "/dev/sda1"]], 0); InitNone, Always, TestOutputInt ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + [["sfdiskM"; "/dev/sda"; ","]; ["mkfs"; "ext2"; "/dev/sda1"]; ["ntfs_3g_probe"; "true"; "/dev/sda1"]], 12)], "probe NTFS volume", @@ -2661,7 +2661,7 @@ the command C."); ("mkswap", (RErr, [String "device"]), 130, [], [InitEmpty, Always, TestRun ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + [["sfdiskM"; "/dev/sda"; ","]; ["mkswap"; "/dev/sda1"]])], "create a swap partition", "\ @@ -2669,7 +2669,7 @@ Create a swap partition on C."); ("mkswap_L", (RErr, [String "label"; String "device"]), 131, [], [InitEmpty, Always, TestRun ( - [["sfdisk"; "/dev/sda"; "0"; "0"; "0"; ","]; + [["sfdiskM"; "/dev/sda"; ","]; ["mkswap_L"; "hello"; "/dev/sda1"]])], "create a swap partition with a label", "\ @@ -2677,7 +2677,7 @@ Create a swap partition on C with label C