diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2009-06-02 16:23:46 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2009-06-02 16:23:46 +0000 |
commit | b294de3389ef86f3261202c035f47a77b9e18435 (patch) | |
tree | f6d01089269d31ea876b4aa6863711351bfadbac | |
parent | da5b5ff410d49e53c9352edc0f04e3f54516fa23 (diff) |
Add '-h' flag, and '*' as a unit specifier for 'p' Editor command.
Both cause partition sizes to be displayed using a human readable
format with the units automatically chosen by looking at the smallest
partition in the disk label. Remove forceable humanization in 'A'
code and use '-h' in install scripts.
Prodded & ok deraadt@, verbiage tweaks from jmc@
-rw-r--r-- | distrib/alpha/common/install.md | 4 | ||||
-rw-r--r-- | distrib/amd64/common/install.md | 4 | ||||
-rw-r--r-- | distrib/armish/ramdisk/install.md | 4 | ||||
-rw-r--r-- | distrib/hp300/ramdisk/install.md | 4 | ||||
-rw-r--r-- | distrib/hppa/install.md | 4 | ||||
-rw-r--r-- | distrib/i386/common/install.md | 4 | ||||
-rw-r--r-- | distrib/landisk/ramdisk/install.md | 4 | ||||
-rw-r--r-- | distrib/luna88k/ramdisk/install.md | 4 | ||||
-rw-r--r-- | distrib/mac68k/ramdisk/install.md | 4 | ||||
-rw-r--r-- | distrib/macppc/ramdisk/install.md | 4 | ||||
-rw-r--r-- | distrib/mvme68k/ramdisk/install.md | 4 | ||||
-rw-r--r-- | distrib/mvme88k/ramdisk/install.md | 4 | ||||
-rw-r--r-- | distrib/sgi/ramdisk/install.md | 4 | ||||
-rw-r--r-- | distrib/socppc/ramdisk/install.md | 4 | ||||
-rw-r--r-- | distrib/sparc/install.md | 4 | ||||
-rw-r--r-- | distrib/sparc64/common/install.md | 4 | ||||
-rw-r--r-- | distrib/vax/install.md | 4 | ||||
-rw-r--r-- | distrib/zaurus/ramdisk/install.md | 4 | ||||
-rw-r--r-- | sbin/disklabel/disklabel.8 | 14 | ||||
-rw-r--r-- | sbin/disklabel/disklabel.c | 41 | ||||
-rw-r--r-- | sbin/disklabel/editor.c | 17 | ||||
-rw-r--r-- | sbin/disklabel/extern.h | 6 |
22 files changed, 91 insertions, 59 deletions
diff --git a/distrib/alpha/common/install.md b/distrib/alpha/common/install.md index 316e7598e29..ed7b58b2e55 100644 --- a/distrib/alpha/common/install.md +++ b/distrib/alpha/common/install.md @@ -1,4 +1,4 @@ -# $OpenBSD: install.md,v 1.29 2009/05/31 17:49:53 deraadt Exp $ +# $OpenBSD: install.md,v 1.30 2009/06/02 16:23:45 krw Exp $ # # Copyright (c) 1996 The NetBSD Foundation, Inc. # All rights reserved. @@ -55,7 +55,7 @@ md_prep_disklabel() { if [[ $_disk == $ROOTDISK ]]; then while :; do echo "The auto-allocated layout for $_disk is:" - disklabel -A $_disk | egrep "^# |^ [a-p]:" + disklabel -h -A $_disk | egrep "^# |^ [a-p]:" ask "Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout?" a case $resp in a*|A*) _op=-w ; AUTOROOT=y ;; diff --git a/distrib/amd64/common/install.md b/distrib/amd64/common/install.md index df66aca7a94..bf4a367044a 100644 --- a/distrib/amd64/common/install.md +++ b/distrib/amd64/common/install.md @@ -1,4 +1,4 @@ -# $OpenBSD: install.md,v 1.20 2009/05/31 17:49:53 deraadt Exp $ +# $OpenBSD: install.md,v 1.21 2009/06/02 16:23:45 krw Exp $ # # # Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -104,7 +104,7 @@ md_prep_disklabel() { if [[ $_disk == $ROOTDISK ]]; then while :; do echo "The auto-allocated layout for $_disk is:" - disklabel -A $_disk | egrep "^# |^ [a-p]:" + disklabel -h -A $_disk | egrep "^# |^ [a-p]:" ask "Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout?" a case $resp in a*|A*) _op=-w ; AUTOROOT=y ;; diff --git a/distrib/armish/ramdisk/install.md b/distrib/armish/ramdisk/install.md index 0fd079e7b60..278e9c3ce22 100644 --- a/distrib/armish/ramdisk/install.md +++ b/distrib/armish/ramdisk/install.md @@ -1,4 +1,4 @@ -# $OpenBSD: install.md,v 1.10 2009/05/11 17:13:07 deraadt Exp $ +# $OpenBSD: install.md,v 1.11 2009/06/02 16:23:45 krw Exp $ # # # Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -90,7 +90,7 @@ md_prep_disklabel() { if [[ $_disk == $ROOTDISK ]]; then while :; do echo "The auto-allocated layout for $_disk is:" - disklabel -A $_disk | egrep "^# |^ [a-p]:" + disklabel -h -A $_disk | egrep "^# |^ [a-p]:" ask "Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout?" a case $resp in a*|A*) _op=-w ; AUTOROOT=y ;; diff --git a/distrib/hp300/ramdisk/install.md b/distrib/hp300/ramdisk/install.md index a32e9817ba1..78a8846f008 100644 --- a/distrib/hp300/ramdisk/install.md +++ b/distrib/hp300/ramdisk/install.md @@ -1,4 +1,4 @@ -# $OpenBSD: install.md,v 1.52 2009/05/31 17:49:53 deraadt Exp $ +# $OpenBSD: install.md,v 1.53 2009/06/02 16:23:45 krw Exp $ # $NetBSD: install.md,v 1.1.2.4 1996/08/26 15:45:14 gwr Exp $ # # Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -47,7 +47,7 @@ md_prep_disklabel() { if [[ $_disk == $ROOTDISK ]]; then while :; do echo "The auto-allocated layout for $_disk is:" - disklabel -A $_disk | egrep "^# |^ [a-p]:" + disklabel -h -A $_disk | egrep "^# |^ [a-p]:" ask "Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout?" a case $resp in a*|A*) _op=-w ; AUTOROOT=y ;; diff --git a/distrib/hppa/install.md b/distrib/hppa/install.md index 262c9ca9344..df278e0e525 100644 --- a/distrib/hppa/install.md +++ b/distrib/hppa/install.md @@ -1,4 +1,4 @@ -# $OpenBSD: install.md,v 1.13 2009/05/31 17:49:53 deraadt Exp $ +# $OpenBSD: install.md,v 1.14 2009/06/02 16:23:45 krw Exp $ # # machine dependent section of installation/upgrade script. # @@ -18,7 +18,7 @@ md_prep_disklabel() { if [[ $_disk == $ROOTDISK ]]; then while :; do echo "The auto-allocated layout for $_disk is:" - disklabel -A $_disk | egrep "^# |^ [a-p]:" + disklabel -h -A $_disk | egrep "^# |^ [a-p]:" ask "Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout?" a case $resp in a*|A*) _op=-w ; AUTOROOT=y ;; diff --git a/distrib/i386/common/install.md b/distrib/i386/common/install.md index c5e57356031..23298737679 100644 --- a/distrib/i386/common/install.md +++ b/distrib/i386/common/install.md @@ -1,4 +1,4 @@ -# $OpenBSD: install.md,v 1.43 2009/05/31 17:49:53 deraadt Exp $ +# $OpenBSD: install.md,v 1.44 2009/06/02 16:23:45 krw Exp $ # # # Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -106,7 +106,7 @@ md_prep_disklabel() { if [[ $_disk == $ROOTDISK ]]; then while :; do echo "The auto-allocated layout for $_disk is:" - disklabel -A $_disk | egrep "^# |^ [a-p]:" + disklabel -h -A $_disk | egrep "^# |^ [a-p]:" ask "Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout?" a case $resp in a*|A*) _op=-w ; AUTOROOT=y ;; diff --git a/distrib/landisk/ramdisk/install.md b/distrib/landisk/ramdisk/install.md index b55ec02ae08..a770452154e 100644 --- a/distrib/landisk/ramdisk/install.md +++ b/distrib/landisk/ramdisk/install.md @@ -1,4 +1,4 @@ -# $OpenBSD: install.md,v 1.22 2009/05/31 17:49:53 deraadt Exp $ +# $OpenBSD: install.md,v 1.23 2009/06/02 16:23:45 krw Exp $ # # # Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -98,7 +98,7 @@ md_prep_disklabel() { if [[ $_disk == $ROOTDISK ]]; then while :; do echo "The auto-allocated layout for $_disk is:" - disklabel -A $_disk | egrep "^# |^ [a-p]:" + disklabel -h -A $_disk | egrep "^# |^ [a-p]:" ask "Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout?" a case $resp in a*|A*) _op=-w ; AUTOROOT=y ;; diff --git a/distrib/luna88k/ramdisk/install.md b/distrib/luna88k/ramdisk/install.md index b53371c2fda..4877c4503ea 100644 --- a/distrib/luna88k/ramdisk/install.md +++ b/distrib/luna88k/ramdisk/install.md @@ -1,4 +1,4 @@ -# $OpenBSD: install.md,v 1.10 2009/05/11 17:13:07 deraadt Exp $ +# $OpenBSD: install.md,v 1.11 2009/06/02 16:23:45 krw Exp $ # Copyright (c) 1996 The NetBSD Foundation, Inc. # All rights reserved. # @@ -46,7 +46,7 @@ md_prep_disklabel() { if [[ $_disk == $ROOTDISK ]]; then while :; do echo "The auto-allocated layout for $_disk is:" - disklabel -A $_disk | egrep "^# |^ [a-p]:" + disklabel -h -A $_disk | egrep "^# |^ [a-p]:" ask "Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout?" a case $resp in a*|A*) _op=-w ; AUTOROOT=y ;; diff --git a/distrib/mac68k/ramdisk/install.md b/distrib/mac68k/ramdisk/install.md index a83eed0a518..9d220cbfcd7 100644 --- a/distrib/mac68k/ramdisk/install.md +++ b/distrib/mac68k/ramdisk/install.md @@ -1,4 +1,4 @@ -# $OpenBSD: install.md,v 1.34 2009/05/30 22:12:42 krw Exp $ +# $OpenBSD: install.md,v 1.35 2009/06/02 16:23:45 krw Exp $ # # Copyright (c) 2002, Miodrag Vallat. # All rights reserved. @@ -78,7 +78,7 @@ __EOT if [[ $_disk == $ROOTDISK ]]; then while :; do echo "The auto-allocated layout for $_disk is:" - disklabel -A $_disk | egrep "^# |^ [a-p]:" + disklabel -h -A $_disk | egrep "^# |^ [a-p]:" ask "Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout?" a case $resp in a*|A*) _op=-w ; AUTOROOT=y ;; diff --git a/distrib/macppc/ramdisk/install.md b/distrib/macppc/ramdisk/install.md index 90508a5c238..059f1081da7 100644 --- a/distrib/macppc/ramdisk/install.md +++ b/distrib/macppc/ramdisk/install.md @@ -1,4 +1,4 @@ -# $OpenBSD: install.md,v 1.42 2009/05/31 17:49:53 deraadt Exp $ +# $OpenBSD: install.md,v 1.43 2009/06/02 16:23:45 krw Exp $ # # # Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -170,7 +170,7 @@ __EOT if [[ $_disk == $ROOTDISK ]]; then while :; do echo "The auto-allocated layout for $_disk is:" - disklabel -A $_disk | egrep "^# |^ [a-p]:" + disklabel -h -A $_disk | egrep "^# |^ [a-p]:" ask "Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout?" a case $resp in a*|A*) _op=-w ; AUTOROOT=y ;; diff --git a/distrib/mvme68k/ramdisk/install.md b/distrib/mvme68k/ramdisk/install.md index 3e648df4d84..fd8a9b0f2c1 100644 --- a/distrib/mvme68k/ramdisk/install.md +++ b/distrib/mvme68k/ramdisk/install.md @@ -1,4 +1,4 @@ -# $OpenBSD: install.md,v 1.37 2009/05/31 17:49:53 deraadt Exp $ +# $OpenBSD: install.md,v 1.38 2009/06/02 16:23:45 krw Exp $ # Copyright (c) 1996 The NetBSD Foundation, Inc. # All rights reserved. # @@ -47,7 +47,7 @@ md_prep_disklabel() { if [[ $_disk == $ROOTDISK ]]; then while :; do echo "The auto-allocated layout for $_disk is:" - disklabel -A $_disk | egrep "^# |^ [a-p]:" + disklabel -h -A $_disk | egrep "^# |^ [a-p]:" ask "Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout?" a case $resp in a*|A*) _op=-w ; AUTOROOT=y ;; diff --git a/distrib/mvme88k/ramdisk/install.md b/distrib/mvme88k/ramdisk/install.md index bd25c8740b6..96691618553 100644 --- a/distrib/mvme88k/ramdisk/install.md +++ b/distrib/mvme88k/ramdisk/install.md @@ -1,4 +1,4 @@ -# $OpenBSD: install.md,v 1.35 2009/05/31 17:49:53 deraadt Exp $ +# $OpenBSD: install.md,v 1.36 2009/06/02 16:23:45 krw Exp $ # Copyright (c) 1996 The NetBSD Foundation, Inc. # All rights reserved. # @@ -57,7 +57,7 @@ md_prep_disklabel() { if [[ $_disk == $ROOTDISK ]]; then while :; do echo "The auto-allocated layout for $_disk is:" - disklabel -A $_disk | egrep "^# |^ [a-p]:" + disklabel -h -A $_disk | egrep "^# |^ [a-p]:" ask "Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout?" a case $resp in a*|A*) _op=-w ; AUTOROOT=y ;; diff --git a/distrib/sgi/ramdisk/install.md b/distrib/sgi/ramdisk/install.md index 243eba119ed..a1771c78291 100644 --- a/distrib/sgi/ramdisk/install.md +++ b/distrib/sgi/ramdisk/install.md @@ -1,4 +1,4 @@ -# $OpenBSD: install.md,v 1.18 2009/05/30 04:01:29 miod Exp $ +# $OpenBSD: install.md,v 1.19 2009/06/02 16:23:45 krw Exp $ # # # Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -138,7 +138,7 @@ __EOT if [[ $_disk == $ROOTDISK ]]; then while :; do echo "The auto-allocated layout for $_disk is:" - disklabel -A $_disk | egrep "^# |^ [a-p]:" + disklabel -h -A $_disk | egrep "^# |^ [a-p]:" ask "Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout?" a case $resp in a*|A*) _op=-w ; AUTOROOT=y ;; diff --git a/distrib/socppc/ramdisk/install.md b/distrib/socppc/ramdisk/install.md index f17b3786776..e7b69019206 100644 --- a/distrib/socppc/ramdisk/install.md +++ b/distrib/socppc/ramdisk/install.md @@ -1,4 +1,4 @@ -# $OpenBSD: install.md,v 1.8 2009/05/11 17:13:07 deraadt Exp $ +# $OpenBSD: install.md,v 1.9 2009/06/02 16:23:45 krw Exp $ # # # Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -90,7 +90,7 @@ md_prep_disklabel() { if [[ $_disk == $ROOTDISK ]]; then while :; do echo "The auto-allocated layout for $_disk is:" - disklabel -A $_disk | egrep "^# |^ [a-p]:" + disklabel -h -A $_disk | egrep "^# |^ [a-p]:" ask "Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout?" a case $resp in a*|A*) _op=-w ; AUTOROOT=y ;; diff --git a/distrib/sparc/install.md b/distrib/sparc/install.md index aee8a837a4d..48389a6c7a7 100644 --- a/distrib/sparc/install.md +++ b/distrib/sparc/install.md @@ -1,4 +1,4 @@ -# $OpenBSD: install.md,v 1.62 2009/05/31 17:49:53 deraadt Exp $ +# $OpenBSD: install.md,v 1.63 2009/06/02 16:23:45 krw Exp $ # $NetBSD: install.md,v 1.3.2.5 1996/08/26 15:45:28 gwr Exp $ # # @@ -64,7 +64,7 @@ md_prep_disklabel() { if [[ $_disk == $ROOTDISK ]]; then while :; do echo "The auto-allocated layout for $_disk is:" - disklabel -A $_disk | egrep "^# |^ [a-p]:" + disklabel -h -A $_disk | egrep "^# |^ [a-p]:" ask "Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout?" a case $resp in a*|A*) _op=-w ; AUTOROOT=y ;; diff --git a/distrib/sparc64/common/install.md b/distrib/sparc64/common/install.md index 76a7eedbc14..74737b92ac2 100644 --- a/distrib/sparc64/common/install.md +++ b/distrib/sparc64/common/install.md @@ -1,4 +1,4 @@ -# $OpenBSD: install.md,v 1.31 2009/05/31 17:49:53 deraadt Exp $ +# $OpenBSD: install.md,v 1.32 2009/06/02 16:23:45 krw Exp $ # $NetBSD: install.md,v 1.3.2.5 1996/08/26 15:45:28 gwr Exp $ # # @@ -74,7 +74,7 @@ md_prep_disklabel() { if [[ $_disk == $ROOTDISK ]]; then while :; do echo "The auto-allocated layout for $_disk is:" - disklabel -A $_disk | egrep "^# |^ [a-p]:" + disklabel -h -A $_disk | egrep "^# |^ [a-p]:" ask "Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout?" a case $resp in a*|A*) _op=-w ; AUTOROOT=y ;; diff --git a/distrib/vax/install.md b/distrib/vax/install.md index dc1e0f9ceff..3c609c2f631 100644 --- a/distrib/vax/install.md +++ b/distrib/vax/install.md @@ -1,4 +1,4 @@ -# $OpenBSD: install.md,v 1.33 2009/05/11 17:13:07 deraadt Exp $ +# $OpenBSD: install.md,v 1.34 2009/06/02 16:23:45 krw Exp $ # $NetBSD: install.md,v 1.3.2.5 1996/08/26 15:45:28 gwr Exp $ # # @@ -52,7 +52,7 @@ md_prep_disklabel() { if [[ $_disk == $ROOTDISK ]]; then while :; do echo "The auto-allocated layout for $_disk is:" - disklabel -A $_disk | egrep "^# |^ [a-p]:" + disklabel -h -A $_disk | egrep "^# |^ [a-p]:" ask "Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout?" a case $resp in a*|A*) _op=-w ; AUTOROOT=y ;; diff --git a/distrib/zaurus/ramdisk/install.md b/distrib/zaurus/ramdisk/install.md index 1ce074177cc..3a27afa6b63 100644 --- a/distrib/zaurus/ramdisk/install.md +++ b/distrib/zaurus/ramdisk/install.md @@ -1,4 +1,4 @@ -# $OpenBSD: install.md,v 1.21 2009/05/11 17:13:07 deraadt Exp $ +# $OpenBSD: install.md,v 1.22 2009/06/02 16:23:45 krw Exp $ # # # Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -84,7 +84,7 @@ md_prep_disklabel() { if [[ $_disk == $ROOTDISK ]]; then while :; do echo "The auto-allocated layout for $_disk is:" - disklabel -A $_disk | egrep "^# |^ [a-p]:" + disklabel -h -A $_disk | egrep "^# |^ [a-p]:" ask "Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout?" a case $resp in a*|A*) _op=-w ; AUTOROOT=y ;; diff --git a/sbin/disklabel/disklabel.8 b/sbin/disklabel/disklabel.8 index 5bf1fc7e8c0..811444428c0 100644 --- a/sbin/disklabel/disklabel.8 +++ b/sbin/disklabel/disklabel.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: disklabel.8,v 1.84 2009/05/31 00:14:55 krw Exp $ +.\" $OpenBSD: disklabel.8,v 1.85 2009/06/02 16:23:45 krw Exp $ .\" $NetBSD: disklabel.8,v 1.9 1995/03/18 14:54:38 cgd Exp $ .\" .\" Copyright (c) 1987, 1988, 1991, 1993 @@ -33,7 +33,7 @@ .\" .\" @(#)disklabel.8 8.2 (Berkeley) 4/19/94 .\" -.Dd $Mdocdate: May 31 2009 $ +.Dd $Mdocdate: June 2 2009 $ .Dt DISKLABEL 8 .Os .Sh NAME @@ -43,7 +43,7 @@ .Nm disklabel .Op Fl c | d | t .Op Fl Av -.Op Fl p Ar unit +.Op Fl h | p Ar unit .Ar disk .Nm disklabel .Fl w @@ -173,13 +173,15 @@ flag. If .Ar tempfile already exists, it will be overwritten. +.It Fl h +Print partition sizes in human readable format. .It Fl N Disallow writing of the pack label area on the selected disk. .It Fl n Make no permanent changes to the disklabel .Pq useful for debugging purposes . .It Fl p Ar unit -Print partition sizes and offsets in +Print partition sizes in .Ar unit instead of sectors. Valid units are b(ytes), c(ylinders), k(ilobytes), m(egabytes), g(igabytes) @@ -406,6 +408,10 @@ If a .Em unit is given, the size and offsets are displayed in terms of the specified unit. +If the unit is +.Sq * +it is automatically determined by the size of the smallest +partition. .It Cm q Quit the editor. If any changes have been made, the user will be diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c index f19945e268f..adef2b2cd97 100644 --- a/sbin/disklabel/disklabel.c +++ b/sbin/disklabel/disklabel.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.c,v 1.156 2009/05/31 00:05:03 krw Exp $ */ +/* $OpenBSD: disklabel.c,v 1.157 2009/06/02 16:23:45 krw Exp $ */ /* * Copyright (c) 1987, 1993 @@ -39,7 +39,7 @@ static const char copyright[] = #endif /* not lint */ #ifndef lint -static const char rcsid[] = "$OpenBSD: disklabel.c,v 1.156 2009/05/31 00:05:03 krw Exp $"; +static const char rcsid[] = "$OpenBSD: disklabel.c,v 1.157 2009/06/02 16:23:45 krw Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -146,7 +146,7 @@ main(int argc, char *argv[]) FILE *t; char *partname; - while ((ch = getopt(argc, argv, "ABEf:NRWb:cdenp:s:tvw")) != -1) + while ((ch = getopt(argc, argv, "ABEf:hNRWb:cdenp:s:tvw")) != -1) switch (ch) { case 'A': ++aflag; @@ -195,6 +195,9 @@ main(int argc, char *argv[]) case 'f': fstabfile = optarg; break; + case 'h': + print_unit = '*'; + break; case 't': ++tflag; break; @@ -973,13 +976,41 @@ display_partition(FILE *f, struct disklabel *lp, int i, char unit) } } +char +canonical_unit(struct disklabel *lp, char unit) +{ + struct partition *pp; + daddr64_t small; + int i; + + if (unit == '*') { + small = DL_GETDSIZE(lp); + pp = &lp->d_partitions[0]; + for (i = 0; i < lp->d_npartitions; i++, pp++) + if (DL_GETPSIZE(pp) > 0 && DL_GETPSIZE(pp) < small) + small = DL_GETPSIZE(pp); + if (small < DL_BLKTOSEC(lp, MEG(1))) + unit = 'K'; + else if (small < DL_BLKTOSEC(lp, MEG(1024))) + unit = 'M'; + else if (small < DL_BLKTOSEC(lp, GIG(1024))) + unit = 'G'; + else + unit = 'T'; + } + unit = toupper(unit); + + return (unit); +} + void display(FILE *f, struct disklabel *lp, char unit, int all) { int i, j; double d; - unit = toupper(unit); + unit = canonical_unit(lp, unit); + fprintf(f, "# %s:\n", specname); if ((unsigned) lp->d_type < DKMAXTYPES) @@ -1685,7 +1716,7 @@ usage(void) #endif fprintf(stderr, - "usage: disklabel [-c | -d | -t] [-Av] [-p unit] disk\t\t(read)\n"); + "usage: disklabel [-c | -d | -t] [-Av] [-h | -p unit] disk\t(read)\n"); fprintf(stderr, " disklabel -w [-c | -d] [-Anv] disk disktype [packid]\t(write)\n"); fprintf(stderr, diff --git a/sbin/disklabel/editor.c b/sbin/disklabel/editor.c index b8cfb71ed8f..8e1c3f6bdb8 100644 --- a/sbin/disklabel/editor.c +++ b/sbin/disklabel/editor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: editor.c,v 1.214 2009/05/31 19:39:45 krw Exp $ */ +/* $OpenBSD: editor.c,v 1.215 2009/06/02 16:23:45 krw Exp $ */ /* * Copyright (c) 1997-2000 Todd C. Miller <Todd.Miller@courtesan.com> @@ -17,7 +17,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: editor.c,v 1.214 2009/05/31 19:39:45 krw Exp $"; +static char rcsid[] = "$OpenBSD: editor.c,v 1.215 2009/06/02 16:23:45 krw Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -71,9 +71,6 @@ struct space_allocation { char *mp; }; -#define MEG(x) ((x) * 1024LL * (1024 / 512)) -#define GIG(x) (MEG(x) * 1024LL) - /* entries for swap and var are changed by editor_allocspace() */ const struct space_allocation alloc_big[] = { { MEG(80), GIG(1), 5, "/" }, @@ -517,13 +514,6 @@ editor_allocspace(struct disklabel *lp_org) /* How big is the OpenBSD portion of the disk? */ find_bounds(lp_org); - if (print_unit == '\0') { - if (DL_BLKTOSEC(lp_org, MEG(10 * 1024)) > (ending_sector - - starting_sector)) - print_unit = 'm'; - else - print_unit = 'g'; - } cylsecs = lp_org->d_secpercyl; again: @@ -2300,9 +2290,10 @@ psize(daddr64_t sz, char unit, struct disklabel *lp) void display_edit(struct disklabel *lp, char unit, u_int64_t fr) { + struct partition *pp; int i; - unit = toupper(unit); + unit = canonical_unit(lp, unit); printf("OpenBSD area: "); psize(starting_sector, 0, lp); diff --git a/sbin/disklabel/extern.h b/sbin/disklabel/extern.h index 356e15bcd5c..ea86a4c0a39 100644 --- a/sbin/disklabel/extern.h +++ b/sbin/disklabel/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.15 2009/04/18 00:15:46 sthen Exp $ */ +/* $OpenBSD: extern.h,v 1.16 2009/06/02 16:23:45 krw Exp $ */ /* * Copyright (c) 2003 Theo de Raadt <deraadt@openbsd.org> @@ -16,8 +16,12 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#define MEG(x) ((x) * 1024LL * (1024 / 512)) +#define GIG(x) (MEG(x) * 1024LL) + u_short dkcksum(struct disklabel *); int checklabel(struct disklabel *); +char canonical_unit(struct disklabel *, char); double scale(u_int64_t, char, struct disklabel *); void display(FILE *, struct disklabel *, char, int); void display_partition(FILE *, struct disklabel *, int, char); |