summaryrefslogtreecommitdiff
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
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@
-rw-r--r--sbin/fdisk/disk.c6
-rw-r--r--sbin/fdisk/misc.c17
-rw-r--r--sbin/fdisk/misc.h5
-rw-r--r--sbin/fdisk/part.c4
4 files changed, 19 insertions, 13 deletions
diff --git a/sbin/fdisk/disk.c b/sbin/fdisk/disk.c
index 10189061528..5bd85cc6bb0 100644
--- a/sbin/fdisk/disk.c
+++ b/sbin/fdisk/disk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disk.c,v 1.22 2004/08/03 09:23:11 deraadt Exp $ */
+/* $OpenBSD: disk.c,v 1.23 2005/11/21 01:59:24 krw Exp $ */
/*
* Copyright (c) 1997, 2001 Tobias Weingartner
@@ -98,6 +98,7 @@ DISK_getlabelmetrics(char *name)
lm->heads = dl.d_ntracks;
lm->sectors = dl.d_nsectors;
lm->size = dl.d_secperunit;
+ unit_types[SECTORS].conversion = dl.d_secsize;
}
DISK_close(fd);
}
@@ -231,7 +232,8 @@ DISK_printmetrics(disk_t *disk, char *units)
int i;
double size;
i = unit_lookup(units);
- size = (double)disk->real->size * DEV_BSIZE / unit_types[i].conversion;
+ size = ((double)disk->real->size * unit_types[SECTORS].conversion) /
+ unit_types[i].conversion;
printf("Disk: %s\t", disk->name);
if (disk->real)
printf("geometry: %d/%d/%d [%.0f %s]\n", disk->real->cylinders,
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;
}
diff --git a/sbin/fdisk/misc.h b/sbin/fdisk/misc.h
index cad3672bcf3..57f2a046445 100644
--- a/sbin/fdisk/misc.h
+++ b/sbin/fdisk/misc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: misc.h,v 1.11 2004/09/30 08:27:50 otto Exp $ */
+/* $OpenBSD: misc.h,v 1.12 2005/11/21 01:59:24 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -39,7 +39,8 @@ struct unit_type {
int conversion;
char *lname;
};
-extern const struct unit_type unit_types[];
+extern struct unit_type unit_types[];
+#define SECTORS 1 /* units are bytes/sectors/kbytes/mbytes/gbytes */
/* Constants */
#define ASK_HEX 0x01
diff --git a/sbin/fdisk/part.c b/sbin/fdisk/part.c
index 6047aba3295..72639e97680 100644
--- a/sbin/fdisk/part.c
+++ b/sbin/fdisk/part.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: part.c,v 1.40 2004/11/10 17:29:41 deraadt Exp $ */
+/* $OpenBSD: part.c,v 1.41 2005/11/21 01:59:24 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -283,7 +283,7 @@ PRT_print(int num, prt_t *partn, char *units)
printf(" #: id C H S - C H S [ start: size ]\n");
printf("------------------------------------------------------------------------\n");
} else {
- size = (double)partn->ns * DEV_BSIZE /
+ size = ((double)partn->ns * unit_types[SECTORS].conversion) /
unit_types[i].conversion;
printf("%c%1d: %.2X %4u %3u %2u - %4u %3u %2u [%12u:%12.0f%s] %s\n",
(partn->flag == 0x80)?'*':' ',