summaryrefslogtreecommitdiffstats
path: root/disk-utils
diff options
context:
space:
mode:
authorKarel Zak2014-06-25 13:21:35 +0200
committerKarel Zak2014-06-25 13:31:14 +0200
commite3a4aaa7d3ce308172aa2c0cf2e241d310c762e3 (patch)
tree2b57074a464dac2dbf2e6112389fffa2fd438648 /disk-utils
parentdocs: fix minor things in man-page howto (diff)
downloadkernel-qcow2-util-linux-e3a4aaa7d3ce308172aa2c0cf2e241d310c762e3.tar.gz
kernel-qcow2-util-linux-e3a4aaa7d3ce308172aa2c0cf2e241d310c762e3.tar.xz
kernel-qcow2-util-linux-e3a4aaa7d3ce308172aa2c0cf2e241d310c762e3.zip
fdisk: add long options, cleanup man page and usage()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'disk-utils')
-rw-r--r--disk-utils/fdisk.855
-rw-r--r--disk-utils/fdisk.c94
2 files changed, 88 insertions, 61 deletions
diff --git a/disk-utils/fdisk.8 b/disk-utils/fdisk.8
index 94081efa1..d53d93b30 100644
--- a/disk-utils/fdisk.8
+++ b/disk-utils/fdisk.8
@@ -46,67 +46,66 @@ is not guaranteed. The input (the commands) should always be backward compatibl
.SH OPTIONS
.TP
-.BI "\-b " sectorsize
+\fB\-b\fR, \fB\-\-sector-size\fR \fIsectorsize\fP
Specify the sector size of the disk. Valid values are 512, 1024, 2048, and 4096.
(Recent kernels know the sector size. Use this option only on old kernels or
to override the kernel's ideas.) Since util-linux-2.17, \fBfdisk\fR differentiates
between logical and physical sector size. This option changes both sector sizes to
.IB sectorsize .
.TP
-.BR "\-c"[=\fImode\fR]
+\fB\-c\fR, \fB\-\-compatibility\fR[\fI=mode\fR]
Specify the compatibility mode, 'dos' or 'nondos'. The default is non-DOS
mode. For backward compatibility, it is possible to use the option without
the \fImode\fR argument -- then the default is used. Note that the optional
\fImode\fR argument cannot be separated from the \fB-c\fR option by a space,
-the correct form is for example '-c=dos'. This option is DEPRECATED.
+the correct form is for example '-c=dos'.
.TP
-.BI "\-C " cylinders
-Specify the number of cylinders of the disk.
-I have no idea why anybody would want to do so. This option is DEPRECATED.
-.TP
-.BI "\-H " heads
-Specify the number of heads of the disk. (Not the physical number,
-of course, but the number used for partition tables.)
-Reasonable values are 255 and 16. This option is DEPRECATED.
-.TP
-.BI "\-S " sectors
-Specify the number of sectors per track of the disk.
-(Not the physical number, of course, but the number used for
-partition tables.)
-A reasonable value is 63. This option is DEPRECATED.
-.TP
-.BI \-h
+\fB\-h\fR, \fB\-\-help\fR
Display a help text and exit.
.TP
-.BR "\-L"[=\fIwhen\fR]
+\fB\-L\fR, \fB\-\-color\fR[\fI=when\fR]
Colorize the output in interactive mode. The optional argument \fIwhen\fP can
be \fBauto\fR, \fBnever\fR or \fBalways\fR. The default is \fBauto\fR.
.TP
-.B \-l
+\fB\-l\fR, \fB\-\-list\fR
List the partition tables for the specified devices and then exit.
If no devices are given, those mentioned in
.I /proc/partitions
(if that file exists) are used.
.TP
-.BI "\-s " partition...
-Print the size (in blocks) of each given partition. This option is DEPRECATED
+\fB\-s\fR, \fB\-\-getsz\fR
+Print the size in 512-byte sectors of each given block device. This option is DEPRECATED
in favour of
.BR blockdev (1).
.TP
-.BI "\-t " type
+\fB\-t\fR, \fB\-\-type\fR \fItype\fR
Enable support only for disklabels of the specified \fItype\fP, and disable
support for all other types.
-This is necessary for example to access a protective or hybrid MBR on devices
-with GPT.
.TP
-.BR "\-u"[=\fIunit\fR]
+\fB\-u\fR, \fB\-\-units\fR[\fI=unit\fR]
When listing partition tables, show sizes in 'sectors' or in 'cylinders'. The
default is to show sizes in sectors. For backward compatibility, it is possible
to use the option without the \fIunit\fR argument -- then the default is used.
Note that the optional \fIunit\fR argument cannot be separated from the \fB-u\fR
option by a space, the correct form is for example '-u=cylinders'.
+
+.TP
+\fB\-C\fR, \fB\-\-geom\-cylinders\fR \fInumber\fR
+Specify the number of cylinders of the disk.
+I have no idea why anybody would want to do so.
+.TP
+\fB\-H\fR, \fB\-\-geom\-heads\fR \fInumber\fR
+Specify the number of heads of the disk. (Not the physical number,
+of course, but the number used for partition tables.)
+Reasonable values are 255 and 16.
+.TP
+\fB\-S\fR, \fB\-\-geom\-sectors\fR \fInumber\fR
+Specify the number of sectors per track of the disk.
+(Not the physical number, of course, but the number used for
+partition tables.) A reasonable value is 63.
+
.TP
-.B \-v
+\fB\-V\fR, \fB\-\-version\fR
Display version information and exit.
.SH DEVICES
diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c
index 5da705293..88072810e 100644
--- a/disk-utils/fdisk.c
+++ b/disk-utils/fdisk.c
@@ -45,32 +45,6 @@
# include <linux/blkpg.h>
#endif
-static void __attribute__ ((__noreturn__)) usage(FILE *out)
-{
- fputs(USAGE_HEADER, out);
-
- fprintf(out,
- _(" %1$s [options] <disk> change partition table\n"
- " %1$s [options] -l [<disk>] list partition table(s)\n"),
- program_invocation_short_name);
-
- fputs(USAGE_OPTIONS, out);
- fputs(_(" -b <size> sector size (512, 1024, 2048 or 4096)\n"), out);
- fputs(_(" -c[=<mode>] compatible mode: 'dos' or 'nondos' (default)\n"), out);
- fputs(_(" -h print this help text\n"), out);
- fputs(_(" -c[=<mode>] compatible mode: 'dos' or 'nondos' (default)\n"), out);
- fputs(_(" -L[=<when>] colorize output (auto, always or never)\n"), out);
- fputs(_(" -t <type> force fdisk to recognize specified partition table type only\n"), out);
- fputs(_(" -u[=<unit>] display units: 'cylinders' or 'sectors' (default)\n"), out);
- fputs(_(" -v print program version\n"), out);
- fputs(_(" -C <number> specify the number of cylinders\n"), out);
- fputs(_(" -H <number> specify the number of heads\n"), out);
- fputs(_(" -S <number> specify the number of sectors per track\n"), out);
-
- fprintf(out, USAGE_MAN_TAIL("fdisk(8)"));
- exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
-}
-
int get_user_reply(struct fdisk_context *cxt, const char *prompt,
@@ -764,6 +738,38 @@ static sector_t get_dev_blocks(char *dev)
return size/2;
}
+static void __attribute__ ((__noreturn__)) usage(FILE *out)
+{
+ fputs(USAGE_HEADER, out);
+
+ fprintf(out,
+ _(" %1$s [options] <disk> change partition table\n"
+ " %1$s [options] -l [<disk>] list partition table(s)\n"),
+ program_invocation_short_name);
+
+ fputs(USAGE_OPTIONS, out);
+ fputs(_(" -b, --sector-size <size> physical and logical sector size\n"), out);
+ fputs(_(" -c, --compatibility[=<mode>] mode is 'dos' or 'nondos' (default)\n"), out);
+ fputs(_(" -L, --color[=<when>] colorize output (auto, always or never)\n"), out);
+ fputs(_(" -l, --list display partitions end exit\n"), out);
+ fputs(_(" -t, --type <type> recognize specified partition table type only\n"), out);
+ fputs(_(" -u, --units[=<unit>] display units: 'cylinders' or 'sectors' (default)\n"), out);
+ fputs(_(" -s, --getsz display device size in 512-byte sectors [DEPRECATED]\n"), out);
+
+ fputs(USAGE_SEPARATOR, out);
+ fputs(_(" -C, --geom-cylinders <number> specify the number of cylinders\n"), out);
+ fputs(_(" -H, --geom-heads <number> specify the number of heads\n"), out);
+ fputs(_(" -S, --geom-sectors <number> specify the number of sectors per track\n"), out);
+
+ fputs(USAGE_SEPARATOR, out);
+ fputs(USAGE_HELP, out);
+ fputs(USAGE_VERSION, out);
+
+ fprintf(out, USAGE_MAN_TAIL("fdisk(8)"));
+ exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+}
+
+
enum {
ACT_FDISK = 0, /* default */
ACT_LIST,
@@ -776,6 +782,22 @@ int main(int argc, char **argv)
int colormode = UL_COLORMODE_UNDEF;
struct fdisk_context *cxt;
+ static const struct option longopts[] = {
+ { "color", optional_argument, NULL, 'L' },
+ { "compatibility", optional_argument, NULL, 'c' },
+ { "geom-cylinders", required_argument, NULL, 'C' },
+ { "geom-heads", required_argument, NULL, 'H' },
+ { "geom-sectors", required_argument, NULL, 'S' },
+ { "getsz", no_argument, NULL, 's' },
+ { "help", no_argument, NULL, 'h' },
+ { "list", no_argument, NULL, 'l' },
+ { "sector-size", required_argument, NULL, 'b' },
+ { "type", required_argument, NULL, 't' },
+ { "units", optional_argument, NULL, 'u' },
+ { "version", no_argument, NULL, 'V' },
+ { NULL, 0, NULL, 0 }
+ };
+
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
@@ -788,7 +810,8 @@ int main(int argc, char **argv)
fdisk_context_set_ask(cxt, ask_callback, NULL);
- while ((c = getopt(argc, argv, "b:c::C:hH:lL::sS:t:u::vV")) != -1) {
+ while ((c = getopt_long(argc, argv, "b:c::C:hH:lL::sS:t:u::vV",
+ longopts, NULL)) != -1) {
switch (c) {
case 'b':
{
@@ -808,16 +831,21 @@ int main(int argc, char **argv)
case 'c':
if (optarg) {
/* this setting is independent on the current
- * actively used label */
+ * actively used label
+ */
+ char *p = *optarg == '=' ? optarg + 1 : optarg;
struct fdisk_label *lb = fdisk_context_get_label(cxt, "dos");
+
if (!lb)
err(EXIT_FAILURE, _("not found DOS label driver"));
- if (strcmp(optarg, "=dos") == 0)
+ if (strcmp(p, "dos") == 0)
fdisk_dos_enable_compatible(lb, TRUE);
- else if (strcmp(optarg, "=nondos") == 0)
+ else if (strcmp(p, "nondos") == 0)
fdisk_dos_enable_compatible(lb, FALSE);
- else
+ else {
+ warnx(_("unknown compatibility mode '%s'"), p);
usage(stderr);
+ }
}
/* use default if no optarg specified */
break;
@@ -861,8 +889,8 @@ int main(int argc, char **argv)
if (fdisk_context_set_unit(cxt, optarg) != 0)
usage(stderr);
break;
- case 'V':
- case 'v':
+ case 'V': /* preferred for util-linux */
+ case 'v': /* for backward compatibility only */
printf(UTIL_LINUX_VERSION);
return EXIT_SUCCESS;
case 'h':