plan9fox/rc/bin/diskparts

44 lines
1.1 KiB
Text
Raw Normal View History

#!/bin/rc
2011-05-05 23:49:26 +00:00
rfork e
# note that really big disks (e.g., aoe devices) may have no mbr
# partition table because the mbr partition table can't cope with large
# block numbers, so we may have to examine the data file with prep if
# there's no plan9 file. beware that `disk/prep -p data' on a disk with
# no plan 9 partition table will delete all extant partitions.
2011-08-15 23:50:46 +00:00
fn setup {
if(test -f $1/data && test -f $1/ctl)
{@{disk/edisk -p $1/data
|| disk/fdisk -p $1/data} |
2011-08-15 23:50:46 +00:00
grep -v '^delpart ' >$1/ctl } >[2]/dev/null
if(test -f $1/plan9)
parts=($1/plan9*)
if not
2011-08-15 23:50:46 +00:00
parts=($1/data)
for(part in $parts)
if(test -f $part)
{ disk/prep -p $part |
2011-08-15 23:50:46 +00:00
grep -v '^delpart ' >$1/ctl } >[2]/dev/null
}
2011-08-15 23:50:46 +00:00
if(~ $#* 0){
# set up any disk partitions
if (! test -e /dev/sdctl)
bind -b '#S' /dev
for(disk in /dev/sd*) {
setup $disk
}
sysname=`{cat /dev/sysname}
# set up any fs(3) partitions
if (! test -e /dev/fs/ctl && test -e '#k/fs')
bind -b '#k' /dev
if (~ $#sysname 1 && ! ~ $sysname '' &&
test -r /cfg/$sysname/fsconfig && test -w /dev/fs/ctl)
awk '{print $0; fflush}' /cfg/$sysname/fsconfig >/dev/fs/ctl
}
if not {
for(disk) {
setup $disk
}
}