1
0

usbfat: 1.1 KB

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