From 3b19e88dab4d4e5b969eb63fdf26f642dbb4bdcf Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 15 Feb 2010 10:08:03 +0100 Subject: [PATCH] fdisk: cleanup help, add -h option Signed-off-by: Karel Zak --- fdisk/fdisk.8 | 5 +++++ fdisk/fdisk.c | 55 +++++++++++++++++++++------------------------------ fdisk/fdisk.h | 2 +- 3 files changed, 28 insertions(+), 34 deletions(-) diff --git a/fdisk/fdisk.8 b/fdisk/fdisk.8 index c04972f6..2d93f1f8 100644 --- a/fdisk/fdisk.8 +++ b/fdisk/fdisk.8 @@ -25,6 +25,8 @@ fdisk \- Partition table manipulator for Linux .IR partition ... .sp .B fdisk \-v +.sp +.B fdisk \-h .SH DESCRIPTION Hard disks can be divided into one or more logical disks called .IR partitions . @@ -182,6 +184,9 @@ Specify the sector size of the disk. Valid values are 512, 1024, 2048 or 4096. (Recent kernels know the sector size. Use this only on old kernels or to override the kernel's ideas.) .TP +.BI \-h +Print help and then exit. +.TP .BI "\-C " cyls Specify the number of cylinders of the disk. I have no idea why anybody would want to do so. diff --git a/fdisk/fdisk.c b/fdisk/fdisk.c index affea090..0a402bb4 100644 --- a/fdisk/fdisk.c +++ b/fdisk/fdisk.c @@ -242,6 +242,7 @@ jmp_buf listingbuf; void fatal(enum failure why) { char error[LINE_LENGTH], *message = error; + int rc = EXIT_FAILURE; if (listing) { close(fd); @@ -249,25 +250,22 @@ void fatal(enum failure why) { } switch (why) { + case help: + rc = EXIT_SUCCESS; case usage: message = _( -"Usage: fdisk [-b SSZ] [-u] DISK Change partition table\n" -" fdisk -l [-b SSZ] [-u] DISK List partition table(s)\n" -" fdisk -s PARTITION Give partition size(s) in blocks\n" -" fdisk -v Give fdisk version\n" -"Here DISK is something like /dev/hdb or /dev/sda\n" -"and PARTITION is something like /dev/hda7\n" -"-u: give Start and End in sector (instead of cylinder) units\n" -"-b 2048: (for certain MO disks) use 2048-byte sectors\n"); - break; - case usage2: - /* msg in cases where fdisk used to probe */ - message = _( -"Usage: fdisk [-l] [-b SSZ] [-u] device\n" -"E.g.: fdisk /dev/hda (for the first IDE disk)\n" -" or: fdisk /dev/sdc (for the third SCSI disk)\n" -" or: fdisk /dev/eda (for the first PS/2 ESDI drive)\n" -" or: fdisk /dev/rd/c0d0 or: fdisk /dev/ida/c0d0 (for RAID devices)\n" -" ...\n"); +"Usage:\n" +" fdisk [options] change partition table\n" +" fdisk [options] -l list partition table(s)\n" +" fdisk -s give partition size(s) in blocks\n" +"\nOptions:\n" +" -b sector size (512, 1024, 2048 or 4096)\n" +" -h print help\n" +" -u give sizes in sectors instead of cylinders\n" +" -v print version\n" +" -C specify the number of cylinders\n" +" -H specify the number of heads\n" +" -S specify the number of sectors per track\n" +"\n"); break; case unable_to_open: snprintf(error, sizeof(error), @@ -299,7 +297,7 @@ void fatal(enum failure why) { fputc('\n', stderr); fputs(message, stderr); - exit(1); + exit(rc); } static void @@ -2852,17 +2850,7 @@ main(int argc, char **argv) { bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); - /* - * Calls: - * fdisk -v - * fdisk -l [-b sectorsize] [-u] device ... - * fdisk -s [partition] ... - * fdisk [-b sectorsize] [-u] device - * - * Options -C, -H, -S set the geometry. - * - */ - while ((c = getopt(argc, argv, "b:C:H:lsS:uvV")) != -1) { + while ((c = getopt(argc, argv, "b:C:hH:lsS:uvV")) != -1) { switch (c) { case 'b': /* Ugly: this sector size is really per device, @@ -2879,6 +2867,9 @@ main(int argc, char **argv) { case 'C': user_cylinders = atoi(optarg); break; + case 'h': + fatal(help); + break; case 'H': user_heads = atoi(optarg); if (user_heads <= 0 || user_heads > 256) @@ -2964,10 +2955,8 @@ main(int argc, char **argv) { if (argc-optind == 1) disk_device = argv[optind]; - else if (argc-optind != 0) - fatal(usage); else - fatal(usage2); + fatal(usage); gpt_warning(disk_device); get_boot(fdisk); diff --git a/fdisk/fdisk.h b/fdisk/fdisk.h index 0286ce0a..1a89beb9 100644 --- a/fdisk/fdisk.h +++ b/fdisk/fdisk.h @@ -45,7 +45,7 @@ struct partition { unsigned char size4[4]; /* nr of sectors in partition */ } PACKED; -enum failure {usage, usage2, ioctl_error, +enum failure {help, usage, ioctl_error, unable_to_open, unable_to_read, unable_to_seek, unable_to_write, out_of_memory}; -- 2.39.5