Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/distrib/utils/embedded/files Handle arbitrary raw partitions.
details: https://anonhg.NetBSD.org/src/rev/cdb9be804079
branches: trunk
changeset: 373568:cdb9be804079
user: mlelstv <mlelstv%NetBSD.org@localhost>
date: Sat Feb 18 07:58:34 2023 +0000
description:
Handle arbitrary raw partitions.
Fetch geometry from disklabel to be consistent.
Use disktab format instead of the normal human-readable output for parsing
the disklabel.
Avoid overflows in size computation.
diffstat:
distrib/utils/embedded/files/resize_disklabel | 30 ++++++++++++++++++--------
1 files changed, 21 insertions(+), 9 deletions(-)
diffs (88 lines):
diff -r 8ef5330088e0 -r cdb9be804079 distrib/utils/embedded/files/resize_disklabel
--- a/distrib/utils/embedded/files/resize_disklabel Sat Feb 18 07:51:52 2023 +0000
+++ b/distrib/utils/embedded/files/resize_disklabel Sat Feb 18 07:58:34 2023 +0000
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# $NetBSD: resize_disklabel,v 1.3 2018/10/06 09:58:55 jmcneill Exp $
+# $NetBSD: resize_disklabel,v 1.4 2023/02/18 07:58:34 mlelstv Exp $
#
# PROVIDE: resize_disklabel
@@ -16,25 +16,35 @@
get_rawpart()
{
+ local partno
+
partno=$(/sbin/sysctl -n kern.rawpartition)
- test $partno = 2 && echo c || echo d
+ printf "$(printf \\\\%o $((partno + 97)))"
}
get_total_sectors()
{
+ local disk
+
disk=$1
- /sbin/drvctl -p $disk disk-info/geometry/sectors-per-unit
+ /sbin/disklabel -t "$disk" \
+ | sed -ne 's/.*:su#\([0-9]*\):.*/\1/p'
}
get_rawpart_sectors()
{
+ local disk rawpart
+
disk=$1
rawpart=$2
- /sbin/disklabel $disk | grep "^ $rawpart:" | awk '{ print $2; }'
+ /sbin/disklabel -t "$disk" \
+ | sed -ne 's/.*:p'"$rawpart"'#\([0-9]*\):.*/\1/p'
}
grow_mbrpart()
{
+ local disk rawpart ts rs oldsize newsize
+
disk=$1
rawpart=$(get_rawpart)
@@ -44,21 +54,23 @@
return
fi
- ts=$(($(get_total_sectors $disk) - ${PART1START}))
+ ts=$((${DLSIZE} - ${PART1START}))
rs=${PART1SIZE}
if [ "$ts" = "$rs" ]; then
return
fi
- oldsize=$(($rs * 512 / 1024 / 1024))
- newsize=$(($ts * 512 / 1024 / 1024))
+ oldsize=$(($rs / 2048))
+ newsize=$(($ts / 2048))
echo "Growing $disk MBR partition #1 (${oldsize}MB -> ${newsize}MB)"
/sbin/fdisk -f -u -1 -s 169/${PART1START}/${ts} ${disk}
}
grow_disklabel()
{
+ local disk part rawpart ts rs oldsize newsize
+
disk=$1
part=$2
rawpart=$(get_rawpart)
@@ -70,8 +82,8 @@
return
fi
- oldsize=$(($rs * 512 / 1024 / 1024))
- newsize=$(($ts * 512 / 1024 / 1024))
+ oldsize=$(($rs / 2048))
+ newsize=$(($ts / 2048))
echo "Growing $disk disklabel (${oldsize}MB -> ${newsize}MB)"
printf "A\ny\n$part\n\n\n\$\nc\n\n\n\$\nd\n\n\n\$\nW\ny\nQ\n" | \
disklabel -i $disk >/dev/null
Home |
Main Index |
Thread Index |
Old Index