mount 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/bin/sh
  2. #BK 2006 www.puppylinux.com
  3. #2007 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
  4. #v407 fix for floppy drive icon.
  5. #v409 gparted create ext3 part. failed, fixed by making /etc/mtab a symlink.
  6. #120103 shinobar: need 'silent' option for ntfs-3g, avoid err msgs, permissions lost when copy.
  7. #130203 change probedisk2 to probedisk.
  8. #mount-FULL, umount-FULL, losetup-FULL are the full versions.
  9. #The Busybox versions of mount and umount are available but only by:
  10. # # busybox mount ...
  11. # # busybox umount ...
  12. #mount and umount are now scripts.
  13. #if an ntfs partition, puppy uses user-mode ntfs-3g driver.
  14. #the mount and umount scripts allow seamless mounting and unmounting of ntfs f.s.
  15. [ ! $1 ] && exec busybox mount
  16. #i realised this script has to allow reentrancy. So, all temp file now unique,
  17. #using ${$} which is pid of script.
  18. MYPID=${$}
  19. . /etc/rc.d/functions4puppy4 #v4.02
  20. #v2.12 discovered difference between $@ and $*. Replaced all $@ with $* in this script...
  21. #extract all the '-' options, on separate lines... do NOT use $@!!!!...
  22. #v3.93 eliminate ' -- ' and all past it...
  23. DASHOPTS="`echo "$*" | tr '\t' ' ' | sed -e 's/ -- .*//' | tr ' ' '\n' | grep '^\-'`"
  24. #needs an explicit '-t ntfs', does not work with /etc/fstab...
  25. if [ "`echo "$*" | grep 'ntfs'`" = "" ];then
  26. # #busybox mount does not support '--bind'
  27. # #as have mtab file (see below), can now use full mount...
  28. #v409 put in '-n' option as now have /etc/mtab symlink to /proc/mounts...
  29. mount-FULL -n "${@}" #SFR quotes
  30. RETVAL=$?
  31. #fi
  32. else
  33. #screen out all the options...
  34. CMDPRMS="`echo -n "$*" | tr '\t' ' ' | tr -s ' ' | tr ' ' '\n' | grep '^/' | tr '\n' ' '`"
  35. #kirk advised these options so Rox will not complain about file
  36. #permissions when copy a file to a ntfs partition...
  37. [ -f /tmp/ntfsmnterr${MYPID}.txt ] && rm -f /tmp/ntfsmnterr${MYPID}.txt
  38. ntfs-3g $CMDPRMS -o umask=0,no_def_opts,silent 2>/tmp/ntfsmnterr${MYPID}.txt #120103 shinobar: need silent
  39. RETVAL=$?
  40. #v2.16 ntfs-3g v1.417, part. scheduled for check, failed with value 10...
  41. #v4.00 ntfs-3g v1.2412 does not have 4,10, has 15 for dirty f.s., 14 hiberneted...
  42. if [ $RETVAL -eq 4 -o $RETVAL -eq 10 -o $RETVAL -eq 15 -o $RETVAL -eq 14 ];then #try to force it...
  43. if [ $RETVAL -eq 14 ];then
  44. #ntfs-3g $CMDPRMS -o umask=0,no_def_opts,remove_hiberfile 2>/tmp/ntfsmnterr${MYPID}.txt
  45. #RETVAL=$?
  46. echo > /dev/null
  47. else
  48. ntfs-3g $CMDPRMS -o force,umask=0,no_def_opts,silent 2>/tmp/ntfsmnterr${MYPID}.txt #120103 shinobar: need silent.
  49. RETVAL=$?
  50. ERRMSG1="`cat /tmp/ntfsmnterr${MYPID}.txt`"
  51. echo "$ERRMSG1"
  52. if [ $RETVAL -eq 0 ];then
  53. echo "WARNING: NTFS f.s. mounted read/write but corrupted."
  54. [ ! "`pidof X`" = "" ] && nohup gxmessage -bg red -center -title "NTFS WARNING" "The ntfs-3g driver was able to mount the NTFS
  55. partition but returned this error message:
  56. $ERRMSG1
  57. It is mounted read/write, but advice is only write
  58. to it in emergency situation. Recommendation is
  59. boot Windows and fix the filesystem first!!!" &
  60. fi
  61. fi
  62. fi
  63. #ntfs-3g plays very safe and will not mount if thinks anything
  64. #wrong with ntfs f.s. But, we may want to recover files from a
  65. #damaged windows. So, fall back to the kernel ntfs driver...
  66. if [ ! $RETVAL -eq 0 ];then
  67. #mount read-only...
  68. busybox mount -r -t ntfs $CMDPRMS
  69. RETVAL=$?
  70. ERRMSG1="`cat /tmp/ntfsmnterr${MYPID}.txt`"
  71. echo "$ERRMSG1"
  72. if [ $RETVAL -eq 0 ];then
  73. echo "WARNING: NTFS f.s. mounted read-only."
  74. [ ! "`pidof X`" = "" ] && nohup gxmessage -bg red -center -title "NTFS WARNING" "The ntfs-3g driver was unable to mount the NTFS
  75. partition and returned this error message:
  76. $ERRMSG1
  77. So, the inbuilt kernel NTFS driver has been used
  78. to mount the partition read-only." &
  79. fi
  80. fi
  81. fi
  82. #v4.02 if there is a desktop icon (see pup_eventd), then refresh it...
  83. if [ $RETVAL -eq 0 -a "$DISPLAY" != "" ];then
  84. DEVNAME="`busybox mount | tail -n 1 | grep '^/dev/' | cut -f 1 -d ' ' | cut -f 3 -d '/'`"
  85. if [ "$DEVNAME" != "" ];then
  86. DRVNAME="`echo -n "$DEVNAME" | cut -c 1-3`"
  87. #special case, SD card /dev/mmcblk0p1...
  88. [ "$DRVNAME" = "mmc" ] && DRVNAME="`echo -n "$DEVNAME" | sed -e 's/p[0-9]$//'`"
  89. xDRVNAME="$DRVNAME" #v404
  90. [ -d /root/.pup_event/drive_${DEVNAME} ] && DRVNAME="$DEVNAME" #icon for each partition.
  91. if [ -d /root/.pup_event/drive_${DRVNAME} ];then
  92. case $DRVNAME in #v407
  93. fd*)
  94. DRV_CATEGORY="floppy"
  95. ;;
  96. *)
  97. dnPATTERN='/dev/'"${xDRVNAME}"'|'
  98. DRV_CATEGORY="`probedisk | grep "$dnPATTERN" | cut -f 2 -d '|'`"
  99. ;;
  100. esac
  101. icon_mounted_func $DRVNAME $DRV_CATEGORY #see functions4puppy4
  102. fi
  103. fi
  104. fi
  105. #v409, instead just make sure the symlink stays there...
  106. if [ ! -L /etc/mtab ];then
  107. rm -f /etc/mtab
  108. ln -s /proc/mounts /etc/mtab
  109. fi
  110. exit $RETVAL