struct fdisk_context *cxt; /* libfdisk context */
unsigned int verify : 1, /* call fdisk_verify_disklabel() */
- quiet : 1; /* suppres extra messages */
+ quiet : 1, /* suppres extra messages */
+ noact : 1; /* do not write to device */
};
fdisk_unref_partition(pa);
- if (!listonly)
+ if (sf->noact == 0 && !listonly)
rc = fdisk_write_disklabel(sf->cxt);
if (!rc)
- rc = fdisk_deassign_device(sf->cxt, 1);
+ rc = fdisk_deassign_device(sf->cxt, sf->noact);
return rc;
}
if (!devname)
errx(EXIT_FAILURE, _("no disk device specified"));
- rc = fdisk_assign_device(sf->cxt, devname, 1);
+ rc = fdisk_assign_device(sf->cxt, devname, 1); /* read-only */
if (rc)
err(EXIT_FAILURE, _("cannot open %s"), devname);
fdisk_script_write_file(dp, stdout);
fdisk_unref_script(dp);
- fdisk_deassign_device(sf->cxt, 1);
+ fdisk_deassign_device(sf->cxt, 1); /* no-sync() */
return 0;
}
devname, partno);
fdisk_free_parttype(type);
- if (!rc)
+ if (sf->noact == 0 && !rc)
rc = fdisk_write_disklabel(sf->cxt);
if (!rc)
- rc = fdisk_deassign_device(sf->cxt, 1);
+ rc = fdisk_deassign_device(sf->cxt, 1); /* no-sync */
return rc;
}
int yes = 0;
fdisk_ask_yesno(sf->cxt, _("Do you want to write this to disk?"), &yes);
if (!yes) {
- printf(_("Leaving.\n"));
+ fdisk_info(sf->cxt, _("Leaving."));
rc = 0;
break;
}
}
case SFDISK_DONE_EOF:
case SFDISK_DONE_WRITE:
- rc = fdisk_write_disklabel(sf->cxt);
- if (!rc) {
- fdisk_info(sf->cxt, _("\nThe partition table has been altered."));
- fdisk_reread_partition_table(sf->cxt);
- rc = fdisk_deassign_device(sf->cxt, 0);
+ rc = 0;
+ if (sf->noact)
+ fdisk_info(sf->cxt, _("The partition table unchanged (--no-act)."));
+ else {
+ rc = fdisk_write_disklabel(sf->cxt);
+ if (!rc) {
+ fdisk_info(sf->cxt, _("\nThe partition table has been altered."));
+ fdisk_reread_partition_table(sf->cxt);
+ }
}
+ if (!rc)
+ rc = fdisk_deassign_device(sf->cxt, sf->noact); /* no-sync when no-act */
break;
case SFDISK_DONE_ABORT:
default: /* rc < 0 on error */
fputs(_(" -N, --partno <num> specify partition number\n"), out);
fputs(_(" -X, --label <name> specify label type (dos, gpt, ...)\n"), out);
fputs(_(" -q, --quiet suppress extra info messages\n"), out);
+ fputs(_(" -n, --no-act do everything except write to device\n"), out);
fputs(USAGE_SEPARATOR, out);
fputs(_(" -u, --unit S deprecated, only sector unit is supported\n"), out);
fputs(_(" -L, --Linux deprecated and ignored, only for backward copatibility\n"), out);
{ "label", required_argument, NULL, 'X' },
{ "list", no_argument, NULL, 'l' },
{ "list-types", no_argument, NULL, 'T' },
+ { "no-act", no_argument, NULL, 'n' },
{ "partno", required_argument, NULL, 'N' },
{ "show-size", no_argument, NULL, 's' },
{ "show-geometry", no_argument, NULL, 'g' },
textdomain(PACKAGE);
atexit(close_stdout);
- while ((c = getopt_long(argc, argv, "adhglLN:qsTu:vVX:",
+ while ((c = getopt_long(argc, argv, "adhglLnN:qsTu:vVX:",
longopts, &longidx)) != -1) {
switch(c) {
case 'a':
case 'g':
sf->act = ACT_SHOW_GEOM;
break;
+ case 'n':
+ sf->noact = 1;
+ break;
case 'N':
sf->partno = strtou32_or_err(optarg, _("failed to parse partition number")) - 1;
break;