1
0

usbeject 773 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/rc
  2. # usbeject - unmount usb disks given as arguments
  3. # unmount all of them if no arguments given
  4. rfork e
  5. disk = ()
  6. mtpt = /n/usb
  7. test -e /dev/fs/ctl || bind -b '#k' /dev >[2]/dev/null
  8. test -e /dev/usb || bind -a '#u' /dev || {
  9. echo $0: no '#u/usb' >[1=2]
  10. exit nousb
  11. }
  12. test -e /dev/usbdctl || mount -a /srv/usb /dev || {
  13. echo $0: cannot mount /srv/usb >[1=2]
  14. exit nousbd
  15. }
  16. disks=()
  17. mtpt=()
  18. switch ($#*) {
  19. case 0
  20. disks=`{ls -pd /n/sdU*}
  21. case *
  22. disks=()
  23. for (a) {
  24. if(~ $a sd??)
  25. disk=`{ls -pd /n/^$*^*}
  26. if not
  27. disk=$a
  28. disks=($disks $disk)
  29. }
  30. }
  31. if (~ $disks '''sdU*''')
  32. exit ''
  33. for (disk in $disks) {
  34. unmount /n/$disk >[2]/dev/null && echo $disk unmounted
  35. if (test -e /dev/fs/ctl)
  36. echo del $disk^parts/^'*' >/dev/fs/ctl >[2]/dev/null
  37. }
  38. exit ''