From: Karel Zak Date: Thu, 18 Sep 2014 08:21:35 +0000 (+0200) Subject: sfdisk: add --unit and --show-geometry, update deprecated.txt X-Git-Tag: v2.26-rc1~367 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d420a7f9f68b3ede82df572ae398d6eb3b8424da;p=thirdparty%2Futil-linux.git sfdisk: add --unit and --show-geometry, update deprecated.txt Signed-off-by: Karel Zak --- diff --git a/Documentation/deprecated.txt b/Documentation/deprecated.txt index 9ca5c2f856..1757d5cca4 100644 --- a/Documentation/deprecated.txt +++ b/Documentation/deprecated.txt @@ -3,11 +3,23 @@ deprecated utils are in maintenance mode and we keep them in source tree for backward compatibility only. -what: "swapon --summary" output format -why: does not provide control on output data formatting. The recommended solution - is to use --show= in all scripts. +what: sfdisk --show-size +why: this does not belong to fdisk, use "blockdev --getsz" -what: "pid" as binary name for "kill --pid" +-------------------------- + +what: sfdisk --unit +why: unnecessary option, only 'S'ector unit is supported + +-------------------------- + +what: "swapon --summary" output format +why: does not provide control on output data formatting. The recommended solution + is to use --show= in all scripts. + +-------------------------- + +what: "pid" as binary name for "kill --pid" why: too ugly, too obscure -------------------------- diff --git a/disk-utils/sfdisk.c b/disk-utils/sfdisk.c index 348c9ce93d..44a99233f6 100644 --- a/disk-utils/sfdisk.c +++ b/disk-utils/sfdisk.c @@ -66,6 +66,7 @@ enum { ACT_LIST, ACT_LIST_TYPES, ACT_SHOW_SIZE, + ACT_SHOW_GEOM, ACT_VERIFY, ACT_PARTTYPE, }; @@ -355,6 +356,52 @@ static int command_show_size(struct sfdisk *sf __attribute__((__unused__)), return 0; } +static int print_geom(struct sfdisk *sf, const char *devname) +{ + fdisk_enable_listonly(sf->cxt, 1); + + if (fdisk_assign_device(sf->cxt, devname, 1)) { + warn(_("cannot open: %s"), devname); + return 1; + } + + fdisk_info(sf->cxt, "%s: %ju cylinders, %ju heads, %ju sectors/track", + devname, + (uintmax_t) fdisk_get_geom_cylinders(sf->cxt), + (uintmax_t) fdisk_get_geom_heads(sf->cxt), + (uintmax_t) fdisk_get_geom_sectors(sf->cxt)); + + fdisk_deassign_device(sf->cxt, 1); + return 0; +} + +/* + * sfdisk --show-geometry [ [ ...] */ @@ -842,22 +889,25 @@ static void __attribute__ ((__noreturn__)) usage(FILE *out) " %1$s [options] \n"), program_invocation_short_name); fputs(_("\nCommands:\n"), out); - fputs(_(" -d, --dump dump partition table (usable for later input)\n"), out); - fputs(_(" -l, --list [ ...] list partitions of each device\n"), out); fputs(_(" -a, --activate [ ...] list or set bootable MBR partitions\n"), out); fputs(_(" -c, --type [] print or change partition type\n"), out); + fputs(_(" -d, --dump dump partition table (usable for later input)\n"), out); + fputs(_(" -g, --show-geometry [ ...] list geometry of all or specified devices\n"), out); + fputs(_(" -l, --list [ ...] list partitions of each device\n"), out); fputs(_(" -s, --show-size [ ...] list sizes of all or specified devices\n"), out); fputs(_(" -T, --list-types print the recognized types (see -X)\n"), out); fputs(_(" -V, --verify test whether partitions seem correct\n"), out); + fputs(USAGE_SEPARATOR, out); fputs(_(" device (usually disk) path\n"), out); fputs(_(" partition number\n"), out); - fputs(_(" partition type, GUUID for GPT, hex for MBR\n"), out); + fputs(_(" partition type, GUID for GPT, hex for MBR\n"), out); fputs(USAGE_OPTIONS, out); fputs(_(" -N, --partno specify partition number\n"), out); fputs(_(" -X, --label specify label type (dos, gpt, ...)\n"), out); + fputs(_(" -u, --unit S deprecated, all input and output is in sectors only\n"), out); fputs(USAGE_SEPARATOR, out); fputs(USAGE_HELP, out); @@ -891,8 +941,10 @@ int main(int argc, char *argv[]) { "list-types", no_argument, NULL, 'T' }, { "partno", required_argument, NULL, 'N' }, { "show-size", no_argument, NULL, 's' }, + { "show-geometry", no_argument, NULL, 'g' }, { "verify", no_argument, NULL, 'V' }, { "version", no_argument, NULL, 'v' }, + { "unit", required_argument, NULL, 'u' }, /* deprecated */ { "type",no_argument, NULL, 'c' }, /* wanted */ { "change-id",no_argument, NULL, OPT_CHANGE_ID }, /* deprecated */ @@ -907,7 +959,7 @@ int main(int argc, char *argv[]) textdomain(PACKAGE); atexit(close_stdout); - while ((c = getopt_long(argc, argv, "adhlN:sTvVX:", + while ((c = getopt_long(argc, argv, "adhglN:sTu:vVX:", longopts, &longidx)) != -1) { switch(c) { case 'a': @@ -931,6 +983,9 @@ int main(int argc, char *argv[]) case 'd': sf->act = ACT_DUMP; break; + case 'g': + sf->act = ACT_SHOW_GEOM; + break; case 'N': sf->partno = strtou32_or_err(optarg, _("failed to parse partition number")) - 1; break; @@ -943,6 +998,12 @@ int main(int argc, char *argv[]) case 'T': sf->act = ACT_LIST_TYPES; break; + case 'u': + /* deprecated */ + warnx(_("--unit option is deprecated, only sectors are supported")); + if (*optarg != 'S') + errx(EXIT_FAILURE, _("unssupported unit '%c'"), *optarg); + break; case 'v': printf(_("%s from %s\n"), program_invocation_short_name, PACKAGE_STRING); @@ -951,7 +1012,6 @@ int main(int argc, char *argv[]) sf->verify = 1; break; default: - warnx(_("unsupported option '%c'"), c); usage(stderr); } } @@ -988,6 +1048,10 @@ int main(int argc, char *argv[]) rc = command_show_size(sf, argc - optind, argv + optind); break; + case ACT_SHOW_GEOM: + rc = command_show_geometry(sf, argc - optind, argv + optind); + break; + case ACT_VERIFY: rc = command_verify(sf, argc - optind, argv + optind); break;