summaryrefslogtreecommitdiffstats
path: root/disk-utils/sfdisk.c
diff options
context:
space:
mode:
authorKarel Zak2014-09-17 12:56:39 +0200
committerKarel Zak2014-10-07 14:55:32 +0200
commit21ca986d716ebc061cbca9696fdafb3376b526f3 (patch)
tree6412f7be4b5770e6f84805c48c201a6e981eb18c /disk-utils/sfdisk.c
parentlinfdisk: cleanup fsync usage (diff)
downloadkernel-qcow2-util-linux-21ca986d716ebc061cbca9696fdafb3376b526f3.tar.gz
kernel-qcow2-util-linux-21ca986d716ebc061cbca9696fdafb3376b526f3.tar.xz
kernel-qcow2-util-linux-21ca986d716ebc061cbca9696fdafb3376b526f3.zip
sfdisk: cleanup sync() usage, fix --activate
* use sync() only if we change disk layout * don't use sync() when we change details (like partition type) Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils/sfdisk.c')
-rw-r--r--disk-utils/sfdisk.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c
index 18a646bb0..348c9ce93 100644
--- a/disk-utils/sfdisk.c
+++ b/disk-utils/sfdisk.c
@@ -360,24 +360,25 @@ static int command_show_size(struct sfdisk *sf __attribute__((__unused__)),
*/
static int command_activate(struct sfdisk *sf, int argc, char **argv)
{
- int rc, nparts, i;
+ int rc, nparts, i, listonly;
struct fdisk_partition *pa = NULL;
const char *devname = NULL;
- if (argc)
+ if (argc < 1)
errx(EXIT_FAILURE, _("no disk device specified"));
devname = argv[0];
- if (argc > 2)
- errx(EXIT_FAILURE, _("uneexpected arguments"));
+ /* --activate <device> */
+ listonly = argc == 1;
- rc = fdisk_assign_device(sf->cxt, devname, 0);
+ rc = fdisk_assign_device(sf->cxt, devname, listonly);
if (rc)
err(EXIT_FAILURE, _("cannot open %s"), devname);
if (!fdisk_is_label(sf->cxt, DOS))
errx(EXIT_FAILURE, _("toggle boot flags is supported for MBR only"));
+
nparts = fdisk_get_npartitions(sf->cxt);
for (i = 0; i < nparts; i++) {
char *data = NULL;
@@ -388,7 +389,7 @@ static int command_activate(struct sfdisk *sf, int argc, char **argv)
continue;
/* sfdisk --activate list bootable partitions */
- if (argc == 1) {
+ if (listonly) {
if (!fdisk_partition_is_bootable(pa))
continue;
if (fdisk_partition_to_string(pa, sf->cxt,
@@ -414,7 +415,9 @@ static int command_activate(struct sfdisk *sf, int argc, char **argv)
}
fdisk_unref_partition(pa);
- rc = fdisk_write_disklabel(sf->cxt);
+
+ if (!listonly)
+ rc = fdisk_write_disklabel(sf->cxt);
if (!rc)
rc = fdisk_deassign_device(sf->cxt, 1);
return rc;
@@ -449,6 +452,7 @@ static int command_dump(struct sfdisk *sf, int argc, char **argv)
fdisk_script_write_file(dp, stdout);
fdisk_unref_script(dp);
+ fdisk_deassign_device(sf->cxt, 1);
return 0;
}
@@ -528,7 +532,7 @@ static int command_parttype(struct sfdisk *sf, int argc, char **argv)
if (!rc)
rc = fdisk_write_disklabel(sf->cxt);
if (!rc)
- rc = fdisk_deassign_device(sf->cxt, 0);
+ rc = fdisk_deassign_device(sf->cxt, 1);
return rc;
}