plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

conf.rc (1444B)


      1 #!/usr/local/plan9/bin/rc
      2 
      3 # the venti configuration is stored at the 248kB offset in the first index
      4 # partition and extends for at most 8 kB.
      5 
      6 rfork e
      7 fn usage {
      8 	echo 'usage: venti/conf [-w] /dev/sdC0/v.arenas' >[1=2]
      9 	exit usage
     10 }
     11 
     12 wflag=no
     13 while(! ~ $#* 0 && ~ $1 -* && ! ~ $1 --){
     14 	switch($1){
     15 	case -w
     16 		wflag=yes
     17 	case *
     18 		usage
     19 	}
     20 	shift
     21 }
     22 if(~ $1 --)
     23 	shift
     24 
     25 if(~ $wflag no && ! ~ $#* 1)
     26 	usage
     27 if(~ $wflag yes && ! ~ $#* 1 2)
     28 	usage
     29 
     30 disk=$1
     31 if(! 9 test -f $disk){
     32 	echo 'unknown disk' $1 >[1=2]
     33 	exit nodisk
     34 }
     35 
     36 fn sigexit {
     37 	#rm -f /tmp/venticonf.$pid
     38 }
     39 
     40 if(~ $wflag yes){
     41 	{echo venti config; cat $2} >/tmp/venticonf.$pid || exit oops
     42 	if(! 9 test -s /tmp/venticonf.$pid){
     43 		echo 'config is empty; will not install' >[1=2]
     44 		exit emptyconfig
     45 	}
     46 	if(9 test `{9 ls -l /tmp/venticonf.$pid | awk '{print $6}'} -gt 8192){
     47 		echo 'config is too long; max is a little less than eight kilobytes' >[1=2]
     48 		exit toolong
     49 	}
     50 	9 dd -quiet 1 -bs 1024 -count 8 -if $disk -iseek 248 \
     51 		>/tmp/_venticonf.old || exit backup
     52 	9 dd -quiet 1 -count 2 </dev/zero >> /tmp/venticonf.$pid || exit dd
     53 	9 dd -quiet 1 -bs 1024 -count 8 -if /tmp/venticonf.$pid \
     54 		-of $disk -trunc 0 -oseek 248 || exit dd2
     55 	exit 0
     56 }
     57 
     58 9 dd -quiet 1 -bs 1024 -count 8 -if $disk -iseek 248 |
     59 	zerotrunc >/tmp/venticonf.$pid
     60 
     61 if(! cmp <{sed 1q /tmp/venticonf.$pid} <{echo venti config}){
     62 	echo 'config has bad header' >[1=2]
     63 	exit badconfig
     64 }
     65 
     66 sed 1d /tmp/venticonf.$pid
     67 exit ''