*/
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;
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,
}
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;
fdisk_script_write_file(dp, stdout);
fdisk_unref_script(dp);
+ fdisk_deassign_device(sf->cxt, 1);
return 0;
}
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;
}