usbfat: 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/rc
  2. # usbfat: [disk [mtpt]] - mount a USB disk's MS FAT file system,
  3. # which might be the only thing on the disk, or might be
  4. # a partition within the disk.
  5. rfork e
  6. disk = ()
  7. mtpt = /n/usb
  8. test -e /dev/usb || bind -a '#u' /dev || {
  9. echo no '#u/usb' >[1=2]
  10. exit nousb
  11. }
  12. test -e /dev/usbdctl || mount -a /srv/usb /dev || {
  13. echo cannot mount /srv/usb >[1=2]
  14. exit nousbd
  15. }
  16. disks=()
  17. mtpt=()
  18. switch ($#*) {
  19. case 0
  20. ;
  21. case 1
  22. disks = $1
  23. case 2
  24. disks = $1
  25. mtpt = $2
  26. case *
  27. echo usage: $0 ' [disk [mtpt]]' >[1=2]
  28. exit usage
  29. }
  30. if(~ `{ls /n/usb >[2]/dev/null | wc -l} 0)
  31. mount /srv/usb /n/usb >[2]/dev/null
  32. if (~ $#disks 0){
  33. disks = /dev/sdU*/data
  34. if(! test -e $disks(1)){
  35. echo no usb disks >[1=2]
  36. exit nodisk
  37. }
  38. disks = (/dev/sdU*/9fat /dev/sdXX/9fat /dev/sdU*/data /dev/sdXX/data)
  39. }
  40. for(d in $disks){
  41. if(! ~ $done yes) {
  42. if(~ $d sdU*.[0-9]* sdXX*)
  43. d=/dev/$d/data
  44. if(test -e $d){
  45. name=`{echo $d | sed 's/.*(sd(XX|U[0-9]+\.[0-9]+)).*/\1/'}
  46. if(~ $#mtpt 0)
  47. mnt=/n/$name
  48. if not
  49. mnt=$mtpt
  50. # don't mount it if it seems to be already mounted.
  51. # if(! test -e $mnt/* && grep -s geometry /dev/$name/ctl)
  52. {
  53. blk = `{disk/fdisk -p $d |
  54. awk '/^part dos / {print $3}'}
  55. if (! ~ $#blk 0 && ~ $blk [0-9]*)
  56. d=$d:$blk
  57. if (mount -c <{dossrv -sf $d >[2]/dev/null} $mnt) {
  58. echo $mnt
  59. done = yes
  60. }
  61. }
  62. }
  63. }
  64. }
  65. exit ''