From: Karel Zak Date: Tue, 24 Mar 2020 10:17:34 +0000 (+0100) Subject: fdisk: add --noauto-pt X-Git-Tag: v2.36-rc1~169 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f2229320a9f79a414464958c4fb73b83aa20213e;p=thirdparty%2Futil-linux.git fdisk: add --noauto-pt The default partition table depends on system arch, for example on Sparc it's SUN and on x86_64 it's MBR. This option forces fdisk to keep the device empty and allow user to create non-default PT in more elegant way. Addresses: https://github.com/karelzak/util-linux/pull/994 Signed-off-by: Karel Zak --- diff --git a/disk-utils/fdisk.8 b/disk-utils/fdisk.8 index d0ac3bd975..0e0d96324a 100644 --- a/disk-utils/fdisk.8 +++ b/disk-utils/fdisk.8 @@ -83,9 +83,13 @@ If no devices are given, those mentioned in .I /proc/partitions (if that file exists) are used. .TP -\fB\-x\fR, \fB\-\-list-details\fR +\fB\-x\fR, \fB\-\-list\-details\fR Like \fB\-\-list\fR, but provides more details. .TP +\fB\-n\fR, \fB\-\-noauto\-pt\fR +Don't automatically create a default partition table on empty device. The partition table +has to be explicitly created by user (by command like 'o', 'g', etc.). +.TP .BR \-o , " \-\-output " \fIlist\fP Specify which output columns to print. Use .B \-\-help diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c index 17d60b1a94..457509cd34 100644 --- a/disk-utils/fdisk.c +++ b/disk-utils/fdisk.c @@ -867,6 +867,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" -l, --list display partitions and exit\n"), out); fputs(_(" -x, --list-details like --list but with more details\n"), out); + fputs(_(" -n, --noauto-pt don't create default partition table on empty devices\n"), out); fputs(_(" -o, --output output columns\n"), out); fputs(_(" -t, --type recognize specified partition table type only\n"), out); fputs(_(" -u, --units[=] display units: 'cylinders' or 'sectors' (default)\n"), out); @@ -901,7 +902,7 @@ enum { int main(int argc, char **argv) { - int rc, i, c, act = ACT_FDISK; + int rc, i, c, act = ACT_FDISK, noauto_pt = 0; int colormode = UL_COLORMODE_UNDEF; struct fdisk_context *cxt; char *outarg = NULL; @@ -919,6 +920,7 @@ int main(int argc, char **argv) { "help", no_argument, NULL, 'h' }, { "list", no_argument, NULL, 'l' }, { "list-details", no_argument, NULL, 'x' }, + { "noauto-pt", no_argument, NULL, 'n' }, { "sector-size", required_argument, NULL, 'b' }, { "type", required_argument, NULL, 't' }, { "units", optional_argument, NULL, 'u' }, @@ -945,7 +947,7 @@ int main(int argc, char **argv) fdisk_set_ask(cxt, ask_callback, NULL); - while ((c = getopt_long(argc, argv, "b:Bc::C:hH:lL::o:sS:t:u::vVw:W:x", + while ((c = getopt_long(argc, argv, "b:Bc::C:hH:lL::no:sS:t:u::vVw:W:x", longopts, NULL)) != -1) { switch (c) { case 'b': @@ -1008,6 +1010,9 @@ int main(int argc, char **argv) colormode = colormode_or_err(optarg, _("unsupported color mode")); break; + case 'n': + noauto_pt = 1; + break; case 'o': outarg = optarg; break; @@ -1135,7 +1140,8 @@ int main(int argc, char **argv) if (!fdisk_has_label(cxt)) { fdisk_info(cxt, _("Device does not contain a recognized partition table.")); - fdisk_create_disklabel(cxt, NULL); + if (!noauto_pt) + fdisk_create_disklabel(cxt, NULL); } else if (fdisk_is_label(cxt, GPT) && fdisk_gpt_is_hybrid(cxt)) fdisk_warnx(cxt, _(