diff options
author | Kjell Wooding <kjell@cvs.openbsd.org> | 2002-01-18 08:38:27 +0000 |
---|---|---|
committer | Kjell Wooding <kjell@cvs.openbsd.org> | 2002-01-18 08:38:27 +0000 |
commit | 7598f41630e91a2ab9de9e4ef1f14f7f1e311e40 (patch) | |
tree | cfac9ede494d0071811937f4993f29e30d4a47ac | |
parent | 3e97ac4c2b74886909fff64ecfda1d924d59d547 (diff) |
Allow size values to be displayed in the user's choice of units.
Idea borrowed from disklabel. i.e. Users can now type "print M"
and be rewarded with partition sizes in Megs
-rw-r--r-- | sbin/fdisk/cmd.c | 18 | ||||
-rw-r--r-- | sbin/fdisk/disk.c | 22 | ||||
-rw-r--r-- | sbin/fdisk/disk.h | 4 | ||||
-rw-r--r-- | sbin/fdisk/mbr.c | 11 | ||||
-rw-r--r-- | sbin/fdisk/mbr.h | 4 | ||||
-rw-r--r-- | sbin/fdisk/misc.c | 21 | ||||
-rw-r--r-- | sbin/fdisk/misc.h | 20 | ||||
-rw-r--r-- | sbin/fdisk/part.c | 21 | ||||
-rw-r--r-- | sbin/fdisk/part.h | 4 | ||||
-rw-r--r-- | sbin/fdisk/user.c | 6 |
10 files changed, 93 insertions, 38 deletions
diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c index 2781adbaae9..0cf4afb57a6 100644 --- a/sbin/fdisk/cmd.c +++ b/sbin/fdisk/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.29 2002/01/18 08:33:10 kjell Exp $ */ +/* $OpenBSD: cmd.c,v 1.30 2002/01/18 08:38:26 kjell Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -64,7 +64,7 @@ Xreinit(cmd, disk, mbr, tt, offset) /* Tell em we did something */ printf("In memory copy is initialized to:\n"); printf("Offset: %d\t", offset); - MBR_print(mbr); + MBR_print(mbr, cmd->args); printf("Use 'write' to update disk.\n"); return (CMD_DIRTY); @@ -83,7 +83,7 @@ Xdisk(cmd, disk, mbr, tt, offset) int maxsec = 63; /* Print out disk info */ - DISK_printmetrics(disk); + DISK_printmetrics(disk, cmd->args); #if defined (__powerpc__) || defined (__mips__) maxcyl = 9999999; @@ -133,8 +133,8 @@ Xedit(cmd, disk, mbr, tt, offset) /* Print out current table entry */ pp = &mbr->part[pn]; - PRT_print(0, NULL); - PRT_print(pn, pp); + PRT_print(0, NULL, NULL); + PRT_print(pn, pp, NULL); #define EDIT(p, f, v, n, m, h) \ if ((num = ask_num(p, f, v, n, m, h)) != v) \ @@ -223,8 +223,8 @@ Xsetpid(cmd, disk, mbr, tt, offset) /* Print out current table entry */ pp = &mbr->part[pn]; - PRT_print(0, NULL); - PRT_print(pn, pp); + PRT_print(0, NULL, NULL); + PRT_print(pn, pp, NULL); #define EDIT(p, f, v, n, m, h) \ if ((num = ask_num(p, f, v, n, m, h)) != v) \ @@ -289,9 +289,9 @@ Xprint(cmd, disk, mbr, tt, offset) int offset; { - DISK_printmetrics(disk); + DISK_printmetrics(disk, cmd->args); printf("Offset: %d\t", offset); - MBR_print(mbr); + MBR_print(mbr, cmd->args); return (CMD_CONT); } diff --git a/sbin/fdisk/disk.c b/sbin/fdisk/disk.c index 1f46690589b..b3625774b34 100644 --- a/sbin/fdisk/disk.c +++ b/sbin/fdisk/disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disk.c,v 1.13 2001/06/23 01:54:37 kjell Exp $ */ +/* $OpenBSD: disk.c,v 1.14 2002/01/18 08:38:26 kjell Exp $ */ /* * Copyright (c) 1997, 2001 Tobias Weingartner @@ -48,6 +48,7 @@ #include <machine/biosvar.h> #endif #include "disk.h" +#include "misc.h" int DISK_open(disk, mode) @@ -224,15 +225,24 @@ DISK_getmetrics(disk, user) return (1); } +/* + * Print the disk geometry information. Take an optional modifier + * to indicate the units that should be used for display. + */ int -DISK_printmetrics(disk) +DISK_printmetrics(disk, units) disk_t *disk; -{ - + char *units; +{ + int i; + double size; + i = unit_lookup(units); + size = (double)disk->real->size * DEV_BSIZE / unit_types[i].conversion; printf("Disk: %s\t", disk->name); if (disk->real) - printf("geometry: %d/%d/%d [%d sectors]\n", disk->real->cylinders, - disk->real->heads, disk->real->sectors, disk->real->size); + printf("geometry: %d/%d/%d [%.0f %s]\n", disk->real->cylinders, + disk->real->heads, disk->real->sectors, size, + unit_types[i].lname); else printf("geometry: <none>\n"); diff --git a/sbin/fdisk/disk.h b/sbin/fdisk/disk.h index beb2c7b826b..2889997a9d8 100644 --- a/sbin/fdisk/disk.h +++ b/sbin/fdisk/disk.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disk.h,v 1.4 2001/08/12 12:03:01 heko Exp $ */ +/* $OpenBSD: disk.h,v 1.5 2002/01/18 08:38:26 kjell Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -52,7 +52,7 @@ typedef struct _disk_t { int DISK_open __P((char *, int)); int DISK_close __P((int)); int DISK_getmetrics __P((disk_t *, DISK_metrics *)); -int DISK_printmetrics __P((disk_t *)); +int DISK_printmetrics __P((disk_t *, char *)); #endif /* _DISK_H */ diff --git a/sbin/fdisk/mbr.c b/sbin/fdisk/mbr.c index f116c9051a4..95213315939 100644 --- a/sbin/fdisk/mbr.c +++ b/sbin/fdisk/mbr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.c,v 1.14 2002/01/04 08:35:06 kjell Exp $ */ +/* $OpenBSD: mbr.c,v 1.15 2002/01/18 08:38:26 kjell Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -130,19 +130,20 @@ MBR_make(mbr, mbr_buf) } void -MBR_print(mbr) +MBR_print(mbr, units) mbr_t *mbr; + char *units; { int i; /* Header */ printf("Signature: 0x%X\n", (int)mbr->signature); - PRT_print(0, NULL); + PRT_print(0, NULL, units); /* Entries */ for (i = 0; i < NDOSPART; i++) - PRT_print(i, &mbr->part[i]); + PRT_print(i, &mbr->part[i], units); } int @@ -206,6 +207,6 @@ MBR_pcopy(disk, mbr) PRT_parse(disk, &mbr_disk[MBR_PART_OFF + MBR_PART_SIZE * i], offset, reloff, &mbr->part[i], i); - PRT_print(i, &mbr->part[i]); + PRT_print(i, &mbr->part[i], NULL); } } diff --git a/sbin/fdisk/mbr.h b/sbin/fdisk/mbr.h index 39aab01bec0..306b0be6a36 100644 --- a/sbin/fdisk/mbr.h +++ b/sbin/fdisk/mbr.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.h,v 1.8 2002/01/04 08:35:06 kjell Exp $ */ +/* $OpenBSD: mbr.h,v 1.9 2002/01/18 08:38:26 kjell Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -53,7 +53,7 @@ typedef struct _mbr_t { /* Prototypes */ void MBR_print_disk __P((char *)); -void MBR_print __P((mbr_t *)); +void MBR_print __P((mbr_t *, char *)); void MBR_parse __P((disk_t *, char *, off_t, off_t, mbr_t *)); void MBR_make __P((mbr_t *, char *)); void MBR_init __P((disk_t *, mbr_t *)); diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c index e731194cb3b..997b271c177 100644 --- a/sbin/fdisk/misc.c +++ b/sbin/fdisk/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.7 2002/01/18 08:33:10 kjell Exp $ */ +/* $OpenBSD: misc.c,v 1.8 2002/01/18 08:38:26 kjell Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -40,6 +40,25 @@ #include <machine/limits.h> #include "misc.h" +int +unit_lookup(units) + char *units; +{ + int i = 0; + if (units == NULL) + return (UNIT_TYPE_DEFAULT); + + while (unit_types[i].abbr != NULL) { + if (strncasecmp(unit_types[i].abbr, units, 1) == 0) + break; + i++; + } + /* default */ + if (unit_types[i].abbr == NULL) + return (UNIT_TYPE_DEFAULT); + + return (i); +} int ask_cmd(cmd) diff --git a/sbin/fdisk/misc.h b/sbin/fdisk/misc.h index 92e82e83a42..3a17487321e 100644 --- a/sbin/fdisk/misc.h +++ b/sbin/fdisk/misc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.h,v 1.5 2002/01/18 08:33:10 kjell Exp $ */ +/* $OpenBSD: misc.h,v 1.6 2002/01/18 08:38:26 kjell Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -34,15 +34,33 @@ #define _MISC_H #include <sys/types.h> +#include <machine/param.h> #include "cmd.h" +/* typedefs */ + +static const struct unit_type { + char *abbr; + int conversion; + char *lname; +} unit_types[] = { + {"b", 1 , "Bytes"}, + {" ", DEV_BSIZE , "Sectors"}, + {"K", 1024 , "Kilobytes"}, + {"M", 1024 * 1024 , "Megabytes"}, + {"G", 1024 * 1024 *1024 , "Gigabytes"}, + {NULL, 0 , NULL }, +}; + /* Constants */ #define ASK_HEX 0x01 #define ASK_DEC 0x02 +#define UNIT_TYPE_DEFAULT 1 #define DO_CONVERSIONS 0x00000001 #define DO_ROUNDING 0x00000002 /* Prototypes */ +int unit_lookup __P((char *)); int ask_cmd __P((cmd_t *)); int ask_num __P((const char *, int, int, int, int, void (*help) __P((void)))); int ask_yn __P((const char *)); diff --git a/sbin/fdisk/part.c b/sbin/fdisk/part.c index a69e6257489..c9486637a71 100644 --- a/sbin/fdisk/part.c +++ b/sbin/fdisk/part.c @@ -1,4 +1,4 @@ -/* $OpenBSD: part.c,v 1.27 2002/01/18 08:29:01 kjell Exp $ */ +/* $OpenBSD: part.c,v 1.28 2002/01/18 08:38:26 kjell Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -288,22 +288,29 @@ PRT_make(partn, offset, reloff, prt) } void -PRT_print(num, partn) +PRT_print(num, partn, units) int num; prt_t *partn; + char *units; { + double size; + int i; + i = unit_lookup(units); if (partn == NULL) { - printf(" Starting Ending\n"); - printf(" #: id cyl hd sec - cyl hd sec [ start - size]\n"); + printf(" Starting Ending LBA Info:\n"); + printf(" #: id C H S - C H S [ start: size ]\n"); printf("------------------------------------------------------------------------\n"); } else { - printf("%c%1d: %.2X %4d %3d %3d - %4d %3d %3d [%10d - %10d] %s\n", + size = (double)partn->ns * DEV_BSIZE / + unit_types[i].conversion; + printf("%c%1d: %.2X %4d %3d %2d - %4d %3d %2d [%12d:%12.f%s] %s\n", (partn->flag == 0x80)?'*':' ', num, partn->id, - partn->scyl, partn->shead, partn->ssect, + partn->scyl, partn->shead, partn->ssect, partn->ecyl, partn->ehead, partn->esect, - partn->bs, partn->ns, + partn->bs, size, + unit_types[i].abbr, PRT_ascii_id(partn->id)); } } diff --git a/sbin/fdisk/part.h b/sbin/fdisk/part.h index 164dbf3a2a3..965a6d6d2ce 100644 --- a/sbin/fdisk/part.h +++ b/sbin/fdisk/part.h @@ -1,4 +1,4 @@ -/* $OpenBSD: part.h,v 1.8 2001/08/12 12:03:01 heko Exp $ */ +/* $OpenBSD: part.h,v 1.9 2002/01/18 08:38:26 kjell Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -48,7 +48,7 @@ void PRT_printall __P((void)); const char *PRT_ascii_id __P((int)); void PRT_parse __P((disk_t *, void *, off_t, off_t, prt_t *, int)); void PRT_make __P((prt_t *, off_t, off_t, void *)); -void PRT_print __P((int, prt_t *)); +void PRT_print __P((int, prt_t *, char *)); /* This does CHS -> bs/ns */ void PRT_fix_BN __P((disk_t *, prt_t *, int)); diff --git a/sbin/fdisk/user.c b/sbin/fdisk/user.c index fd5bc2360ad..edd343fd68b 100644 --- a/sbin/fdisk/user.c +++ b/sbin/fdisk/user.c @@ -1,4 +1,4 @@ -/* $OpenBSD: user.c,v 1.17 2001/12/15 02:12:26 kjell Exp $ */ +/* $OpenBSD: user.c,v 1.18 2002/01/18 08:38:26 kjell Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -202,14 +202,14 @@ USER_print_disk(disk) fd = DISK_open(disk->name, O_RDONLY); offset = firstoff = 0; - DISK_printmetrics(disk); + DISK_printmetrics(disk, NULL); do { MBR_read(fd, (off_t)offset, mbr_buf); MBR_parse(disk, mbr_buf, offset, firstoff, &mbr); printf("Offset: %d\t", (int)offset); - MBR_print(&mbr); + MBR_print(&mbr, NULL); /* Print out extended partitions too */ for (offset = i = 0; i < 4; i++) |