conf.rc 1.4 KB

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