summaryrefslogtreecommitdiff
path: root/sbin/fdisk/misc.c
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2005-11-21 01:59:25 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2005-11-21 01:59:25 +0000
commit68dbbb7c0e8800c6b6c72bda3b1528f8e4ad6005 (patch)
tree2a3e4140910032505f16d76ef6f93e150a84a982 /sbin/fdisk/misc.c
parent6a99254c76410c0c0658d8fcbe8b03c48d865d4c (diff)
Replace default DEV_BSIZE sector conversion factor with disklabel's
sector size when possible. Fixes the "[ XX Sectors ]" size display. Pointed out by Robert Szasz while playing with his Sony Hi-MD device. Apply input conversion fixes similar to those recently applied to disklabel(8). Use correct sector size in the conversions. It is still *not* possible to use unusual sector sizes for non-ISO9660 filesystems! ok millert@
Diffstat (limited to 'sbin/fdisk/misc.c')
-rw-r--r--sbin/fdisk/misc.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/sbin/fdisk/misc.c b/sbin/fdisk/misc.c
index 6e59f1d3b78..6aa71e3558d 100644
--- a/sbin/fdisk/misc.c
+++ b/sbin/fdisk/misc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.c,v 1.15 2004/09/18 23:22:05 deraadt Exp $ */
+/* $OpenBSD: misc.c,v 1.16 2005/11/21 01:59:24 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -35,7 +35,7 @@
#include <limits.h>
#include "misc.h"
-const struct unit_type unit_types[] = {
+struct unit_type unit_types[] = {
{"b", 1 , "Bytes"},
{" ", DEV_BSIZE , "Sectors"},
{"K", 1024 , "Kilobytes"},
@@ -194,7 +194,7 @@ getuint(disk_t *disk, char *prompt, char *helpstring, u_int32_t oval,
char buf[BUFSIZ], *endptr, *p, operator = '\0';
u_int32_t rval = oval;
size_t n;
- int mult = 1;
+ int mult = 1, secsize = unit_types[SECTORS].conversion;
double d;
int secpercyl;
@@ -234,22 +234,25 @@ getuint(disk_t *disk, char *prompt, char *helpstring, u_int32_t oval,
buf[--n] = '\0';
break;
case 'b':
- mult = -DEV_BSIZE;
+ mult = -secsize;
buf[--n] = '\0';
break;
case 's':
buf[--n] = '\0';
break;
case 'k':
- mult = 1024 / DEV_BSIZE;
+ if (secsize > 1024)
+ mult = -secsize / 1024;
+ else
+ mult = 1024 / secsize;
buf[--n] = '\0';
break;
case 'm':
- mult = 1048576 / DEV_BSIZE;
+ mult = 1048576 / secsize;
buf[--n] = '\0';
break;
case 'g':
- mult = 1073741824 / DEV_BSIZE;
+ mult = 1073741824 / secsize;
buf[--n] = '\0';
break;
}