diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2008-06-13 04:41:45 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2008-06-13 04:41:45 +0000 |
commit | bf814a395769e2c41b7d86ad0418dcbe8c995116 (patch) | |
tree | 080e68aa26769893bbb376deef381245576628a6 | |
parent | bd224e468c6f0dc1e7fbe1de48f3061dc2e87afc (diff) |
ksh's arithmetic is 32 bit signed so we can no longer rely on
block counts being small enough to do arithmetic on. Manually
process partition block counts into 'human readable' byte sizes
when asking for confirmation of disk configuration.
Install script now properly displays the size of Yottabyte
partitions.
requested by & ok deraadt@
-rw-r--r-- | distrib/miniroot/install.sh | 9 | ||||
-rw-r--r-- | distrib/miniroot/install.sub | 22 |
2 files changed, 25 insertions, 6 deletions
diff --git a/distrib/miniroot/install.sh b/distrib/miniroot/install.sh index 05b04ea60d0..aeb677e95de 100644 --- a/distrib/miniroot/install.sh +++ b/distrib/miniroot/install.sh @@ -1,5 +1,5 @@ #!/bin/ksh -# $OpenBSD: install.sh,v 1.157 2008/06/01 02:45:59 krw Exp $ +# $OpenBSD: install.sh,v 1.158 2008/06/13 04:41:44 krw Exp $ # $NetBSD: install.sh,v 1.5.2.8 1996/08/27 18:15:05 gwr Exp $ # # Copyright (c) 1997-2004 Todd Miller, Theo de Raadt, Ken Westerback @@ -120,7 +120,6 @@ if [ ! -f /etc/fstab ]; then disklabel $DISK 2>&1 | sed -ne '/^ *[a-p]: /p' >/tmp/disklabel.$DISK while read _dev _size _offset _type _rest; do _pp=${DISK}${_dev%:} - _ps=$_size if [[ $_pp == $ROOTDEV ]]; then echo "$ROOTDEV /" >$FILESYSTEMS @@ -133,7 +132,7 @@ if [ ! -f /etc/fstab ]; then fi _partitions[$_i]=$_pp - _psizes[$_i]=$_ps + _psizes[$_i]=$_size # Set _mount_points[$_i]. if [[ -f /tmp/fstab.$DISK ]]; then @@ -165,11 +164,11 @@ if [ ! -f /etc/fstab ]; then _i=0 while :; do _pp=${_partitions[$_i]} - _ps=$(( ${_psizes[$_i]} / 2 )) _mp=${_mount_points[$_i]} + _size=$(stdsize ${_psizes[$_i]}) # Get the mount point from the user - ask "Mount point for ${_pp} (size=${_ps}k)? (or 'none' or 'done')" "$_mp" + ask "Mount point for $_pp ($_size)? (or 'none' or 'done')" "$_mp" case $resp in "") ;; none) _mp= diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub index 41f8771c5f6..77cf954a938 100644 --- a/distrib/miniroot/install.sub +++ b/distrib/miniroot/install.sub @@ -1,4 +1,4 @@ -# $OpenBSD: install.sub,v 1.430 2008/04/17 01:51:44 deraadt Exp $ +# $OpenBSD: install.sub,v 1.431 2008/06/13 04:41:44 krw Exp $ # $NetBSD: install.sub,v 1.5.2.8 1996/09/02 23:25:02 pk Exp $ # # Copyright (c) 1997-2007 Todd Miller, Theo de Raadt, Ken Westerback @@ -229,6 +229,26 @@ mount_mnt2() { mount -o ro,$_opts /dev/$_dev$resp /mnt2 } +# Translate block count into human readable byte count. +# N.B.: Assumes blocks being counted are 512 bytes! +# N.B.: ksh arithmetic is 32 bits so can't just calculate! +stdsize () { + local _p= _s= _sz=$1 + + set -- " " K M G T P E Z Y + + while (( ${#_sz} > 3 )); do + shift + _p=${_sz%[0-9][0-9][0-9]} + _s=${_sz#$_p} + _sz=$_p + done + + (( _s > 500 )) && : $(( _sz = _sz + 1 )) + + echo "$(( _sz * 512 )) ${1}Bytes" +} + # Ask for a password, saving the input in $resp. # Display $1 as the prompt. # *Don't* allow the '!' options that ask does. |