Import sources from 2011-03-30 iso image - sys/lib

This commit is contained in:
Taru Karttunen 2011-03-30 16:53:33 +03:00
parent b41b903422
commit e463eb4036
1144 changed files with 388460 additions and 0 deletions

96
sys/lib/backup/backup Executable file
View file

@ -0,0 +1,96 @@
#!/bin/rc
# backup [-n] [-d dev] [-s set] - backup venti arenas to disc set using dev
# and record that. also print recent fossil dump scores.
rfork ne
cd /sys/lib/backup
. funcs
bind -a . /bin
done=0
while (~ $done 0 && ! ~ $#* 0 && ~ $1 -*) {
switch ($1) {
case -d; rdev=$2; shift
case -n; debug=yes # don't dump; use with -s test
case -s; set=$2 ; shift
case --; done = 1 # no break in rc, alas
case -*
echo usage: $0 '[-n] [-d dev] [-s set]' >[1=2]
exit usage
}
shift
}
fn sigint sighup sigterm {
exit note
}
fn dobackuparenas {
if (~ $debug yes) {
echo pretending to backuparenas $*
shift
for (name)
dumpdone arena0 $name
}
if not
backuparenas $*
}
fn backupdisc {
echo please insert disc $disc of set $set into $rdev and press return to backup
echo -n $"*^': '
if (! ~ $debug yes)
junk=`{read}
if not
echo
dobackuparenas $rdev $*
}
fn backup1 {
progress=no
disc1trks=`{hoc -e $ntracks-$tracks}
disc1arenas=()
if (! ~ $disc1trks 0)
disc1arenas=`{sed $disc1trks^q arenas}
if (! ~ $#disc1arenas 0 && ! ~ $disc1trks 0 && backupdisc $disc1arenas){
tracks = `{hoc -e $tracks+$#disc1arenas}
if (test $tracks -ge $ntracks) {
disc=`{hoc -e $disc+1}
tracks=0
}
updprog
sed 1,$disc1trks^d arenas >morearenas
mv morearenas arenas
arenas=`{cat arenas}
}
}
cd $set
tobackup $set >arenas
quitonfailure $status
arenas=`{cat arenas}
if (~ $#arenas 0) {
echo no sealed arenas not yet on disc exist on $fs
exit ''
}
if (test -s disc)
. disc
if not
updprog
if (! ~ $debug yes && ~ $set set1) {
9fs log
# don't hang in lp
tail -50 /n/$fs/sys/log/fs.archive |
pr -h 'recent fossil dump scores' | lp &
echo fossil dump scores just printed.
}
progress=yes
while (test $#arenas -gt 0 && ~ $progress yes) {
backup1
quitonfailure $status
}
exit ''

33
sys/lib/backup/backuparenas Executable file
View file

@ -0,0 +1,33 @@
#!/bin/rc
# backuparenas dev name ... - dump arena `name' from $fs to blu-ray disc.
# assumes $set is set.
rfork ne
# tunable variables
fs=pie
if (test -e /sys/lib/backup/funcs)
. /sys/lib/backup/funcs
exits=''
fsroot=/n/$fs
if (! test -e $fsroot/!THIS_IS_^`{echo $fs | tr a-z A-Z}^_MAIN) {
import $fs / $fsroot || exit
}
unmount /mnt/cd >[2]/dev/null
cdfs -d $1 || exit
shift
cd $fsroot/dev/fs
for (name) {
grep next /mnt/cd/ctl
if (! {venti/rdarena arena0 $name |
pump -i 65536 -o 1048576 -k 51200 -d 10 >/mnt/cd/wd/$name})
exit
# ls -l /mnt/cd
if (test -e '/env/fn#dumpdone' -a -e '/env/set')
dumpdone arena0 $name
}
echo 'remember to *not* remove /mnt/cd/wd' >[1=2]
# don't remove /mnt/cd/wd, since that would finalize the disc
# and bugger the permanent toc, at least on bd-r.
exit ''

23
sys/lib/backup/dupdisc Executable file
View file

@ -0,0 +1,23 @@
#!/bin/rc
# dupdisc indev outdev - duplicate all blu-ray disc data tracks
rfork ne
if (! ~ $#* 2 || ~ $1 $2 || ~ $1 /dev/* || ~ $2 /dev/*) {
echo usage: $0 indev outdev >[1=2]
exit usage
}
echo copying /dev/$1 tracks to /dev/$2
sleep 2
umount /mnt/cd >[2]/dev/null
cdfs -d /dev/$1 || exit
cdfs -d /dev/$2 -m /n/copy || exit
for (t in `{ls -p /mnt/cd | grep '^d'}) {
echo $t:
grep next /n/copy/ctl
pump -b 1048576 -k 51200 -d 10 </mnt/cd/$t >/n/copy/wd/$t
ls -l /n/copy
}
echo 'remember to *not* rm /mnt/cd/wd' >[1=2]
# don't remove /mnt/cd/wd, since that would finalize the disc
# and bugger the permanent toc, at least on bd-r.

57
sys/lib/backup/funcs Executable file
View file

@ -0,0 +1,57 @@
#!/bin/rc
# funcs - rc functions and definitions common to dump scripts
fn backupinit {
if (! ~ $backupinitdone yes) {
disc=1
tracks=0
# tunable parameters
set=set1
fs=pie
arenas=/dev/sde0/arena0 # on $fs
rdev=/dev/sdE1 # on terminal with bd burner
blocksize=8192
arenasize=1073741824 # twice the venti default, on yoshimi & pie
# trackbytes=$arenasize
# discbytes=`{ls -l $rdev/data | awk '{print $6}'}
# ntracks=`{ hoc -e 'int('$discbytes/$trackbytes')' }
ntracks=45 # for BD dual-layer
backupinitdone=yes
backups=/sys/lib/backup
path=(/bin $backups .)
}
}
# assume we're in $backups/$set
fn updprog {
echo 'disc='$disc 'tracks='$tracks >ndisc && mv ndisc disc
}
# assumes $set is set
fn dumpdone { # arena-part arena-name
@ {
cd $backups/$set
progress=yes
tracks = `{hoc -e $tracks+1}
updprog
if (~ $debug yes)
echo $2 >>fake # pretend these are sealed
echo $2 >>ondisc
}
}
fn quitonfailure { # exit-status
if (! ~ $1 '' 0 '|')
exit $1
}
# caller sets arenabase first
fn arenastart { # arena#
bytes = `{ echo $arenabase' + ('$1' * '$arenasize')' | bc }
blocks = `{ echo $bytes' / '$blocksize | bc }
echo $blocks
}
backupinit

6
sys/lib/backup/mkfile Executable file
View file

@ -0,0 +1,6 @@
clean:V:
rm -f index
setup:V:
mkdir set1
backup:V:
./backup

90
sys/lib/backup/restore Executable file
View file

@ -0,0 +1,90 @@
#!/bin/rc
# restore arena# [dev] - load venti with arenas on dev, stored one per track
# starting with arena#. must have run fmtarenas before restoring
# the first arena in the partition.
# this must be run on the venti server, without venti running on the
# affected arena partition(s).
rfork ne
if (test -e /sys/lib/backup/funcs)
. /sys/lib/backup/funcs
switch ($#*) {
case 1
case 2
rdev=$2
case *
echo usage: $0 arena-num '[dev]' >[1=2]
exit usage
}
starena=$1
if (! ~ $starena [0-9] [0-9][0-9] [0-9][0-9][0-9]) {
echo $0: bad starting arena: $starena >[1=2]
exit bad-arena-num
}
# clear any dregs from a previous run
unmount /mnt/cd >[2]/dev/null
sleep 1
kill cdfs | rc
sleep 1
cdfs -d $rdev || exit
cd /mnt/cd
#for (track in d[0-9]*)
# venti/wrarena $track # slow; takes about 12½ mins. per GB
arena = $starena
# set arenabase for arenastart
arenabase = `{ venti/printarenapart $arenas | sed -e 's/.*arenabase=//' -e 1q }
kill printarenapart | rc # printarenapart leaves a process behind
# echo arenabase $arenabase
skipping=yes
for (track in d[0-9]*) {
if (~ track 'd[0-9]*') {
echo $0: no tracks in /mnt/cd >[1=2]
exit no-tracks
}
if (~ $skipping yes) {
# verify that first track is the expected one
type=`{file $track}
switch ($"type) {
case *': venti arena'
name=`{ venti/printarena $track >[2=1] |
sed -e 's/.*name=([^ =]+).*/\1/' -e 1q }
case *
name=NOT-A-VENTI-ARENA
}
kill printarena | rc # printarena leaves a process behind
echo -n first track is $"name'; is that right? '
switch (`{read}) {
case [yY]*
skipping=no
case skip
skipping=yes
case *
echo aborting, arena is unchanged. >[1=2]
exit 'wrong track'
}
}
if (! ~ $skipping yes) {
# copy each track into its slot in the arena partition
venti/printarena $track >[2=1] | sed 1q | tr -d '\12'
kill printarena | rc # printarena leaves a process behind
off = `{arenastart $arena}
# echo -n writing $track to $arenas at 8K-block offset $off:
sleep 3
echo
# argh! something (cdfs?) appends 60K of *stuff* to each
# arena on optical disc. restrain dd.
count=`{ echo $arenasize/$blocksize | bc }
pump -i 1048576 -o 65536 -d 10 <$track |
dd -quiet 1 -count $count -bs $blocksize -of $arenas \
-oseek $off
arena = `{hoc -e $arena+1}
}
}
# when all done, must run venti/checkarenas, fmtisect, fmtbloom, fmtindex,
# and (the big one) venti/buildindex -b /cfg/pie/venti.conf

47
sys/lib/backup/tobackup Executable file
View file

@ -0,0 +1,47 @@
#!/bin/rc
# tobackup [set] - print names of venti arenas needing to be dumped to disc set
rfork e
cd /sys/lib/backup
. funcs
switch ($#*) {
case 0
case 1
set=$1
case *
echo usage: $0 '[set]' >[1=2]
exit usage
}
if (! test -d $set) {
echo $0: no backup set named $set in $backup >[1=2]
exit 'no backup set'
}
if (! hget -o index http://$fs/index) {
echo $0: 'can''t fetch venti index from' $fs >[1=2]
exit 'no venti index'
}
if (! test -s index) {
echo $0: 'empty venti index from' $fs >[1=2]
exit 'empty index'
}
cd $set
awk '/^arena=/ { name=$1 }
/ disk=sealed/ { print name; name = "" }
' ../index | sed 's/^arena=//' >nsealed
>>sealed
if (! cmp -s sealed nsealed)
cp nsealed sealed
rm -f nsealed
if (! test -s sealed)
exit ''
>>fake
if (test -s ondisc)
comm -23 <{sort -u sealed fake} <{sort -u ondisc}
if not { # first sealed arenas, dump all
cat sealed
chmod +a ondisc >>ondisc
}