Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 19 Dec 2014, 11:12
All times are UTC - 4
 Forum index » Advanced Topics » Cutting edge
/bin/mount, /bin/umount, /usr/sbin/filemnt
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [3 Posts]  
Author Message
Karl Godt


Joined: 20 Jun 2010
Posts: 3982
Location: Kiel,Germany

PostPosted: Sun 17 Jun 2012, 05:45    Post subject:  /bin/mount, /bin/umount, /usr/sbin/filemnt
Subject description: support for filenames/pathes with spaces
 

Here comes scribble for filemnt :

Version racy-5.3 :

Code:
#!/bin/bash
##############  ROX app.: Click image files to mount & unmount.   by: Terry Becker   aka: SunBurnt
##############   File types = ".2fs, .3fs, .sfs, .iso, & initrd.gz".
#v423 detect wrong squashfs version 3.x or 4.x.
#v424 advise of sfs-version-converter.
#100606 have backported squashfs4 to kernel 2.6.27.47.
#100831 fix KERNELSUBVER for olpc people, have 'uname -r' returning version with '_'.
#101221 yaf-splash fix.
#111016 fix for 3.x kernel.
#111110 handle encrypted save-files.
#111112 small fixes.
#120201 rodin.s: internationalization.
#120220 npierce: improved test and message for already mounted file, also prevent mkdir if file not found, and fix adding pwd prefix
#120220 npierce: add slash to pwd prefix; exit on failed stat. refer: http://murga-linux.com/puppy/viewtopic.php?t=71767&start=450
#120323 replace 'xmessage' with 'pupmessage'.

export TEXTDOMAIN=filemnt
export OUTPUT_CHARSET=UTF-8
. gettext.sh

#v423...
KERNELVER="`uname -r`"
if vercmp $KERNELVER ge 3.0;then #111016
 SFSSTR='squashfs, version 4'
 SFSMAJOR=4
else
 KERNELSUBVER=`echo -n "$KERNELVER" | cut -f 3 -d '.' | cut -f 1 -d '-' | cut -f 1 -d '_'` #100831
 KERNELSUBSUBVER=`echo -n "$KERNELVER" | cut -f 4 -d '.' | cut -f 1 -d '-'`
 SFSSTR='squashfs, version 3'
 SFSMAJOR=3
 if [ $KERNELSUBVER -eq 27 ];then
  if [ $KERNELSUBSUBVER -gt 46 ];then #100606
   SFSSTR='squashfs, version 4'
   SFSMAJOR=4
  fi
 fi
 if [ $KERNELSUBVER -gt 28 ];then
  SFSSTR='squashfs, version 4'
  SFSMAJOR=4
 fi
fi

 imgFile="$1"
 if [ ! -f "$imgFile" ];then echo "No regular file: $imgFile";exit 1;fi #120220
 if [ "`dirname "$imgFile"`" = '.' ] ;then                                #120220
  imgFile="`pwd`/`echo "$imgFile" |sed 's/^\.//'`"                        #120220
 fi
 MntPt='/mnt/'`echo "$imgFile" |sed "s#^\.##g" |sed "s#/#+#g"`


if [ 1 -eq 2 ] ;then   ##############################################   JUMP OVER this SECTION.

 loMnts="`mount |grep '/dev/loop' |awk '{print $1}'`"
 echo "$loMnts" |while read LOOP               ### test if file's mounted
 do
   loFile="`losetup-FULL $LOOP |sed 's/^.*(//' |sed 's/).*$//'`"
   if [ "$loFile" = "$imgFile" ] ;then
    echo -e "\n ### Loop File: $loFile"
    break
   fi
   i=`expr $i + 1`
 done

fi         ##############################################   END of JUMP SECTION.


                     ### file's not mounted, mount it
# if [ $i -eq 16 ] ;then

 imgFileBASE="`basename "$imgFile"`" #BK
 imgFileDEV_INODE="`stat -L -c "%d_%i" "$imgFile"`" || exit 160 #120220

 if [ ! -d "$MntPt" ] ;then

  DISK_TYPE=`disktype "${imgFile}"`
  Type=`echo "$DISK_TYPE" |grep -m1 -E 'file system|Linux squashfs' |sed 's#^Linux##' |tr -d ',' |awk '{print $1}' |tr '[[:upper:]]' '[[:lower:]]'`
  [ "$Type" ] || { DISK_TYPE=`file -z "$imgFile"`;Type=`echo "$DISK_TYPE" |cut -f 2 -d ':' |grep 'filesystem' |awk '{print $2}' |tr '[[:upper:]]' '[[:lower:]]'`; }
  file -z "$imgFile" |cut -f 2 -d ':'
  [ "$Type" ] || { echo "Warning : disktype and file commands were unable to determine a file system.";[ "$DISPLAY" ] && pupmessage -bg red2 "WARNING:
dsktype and file commands had been unable to fetch the filesystem type for
$imgFile";exit 150; }
  cat /proc/filesystems |grep -w "$Type" || { echo "No Support in kernel $KERNELVER
for filesystem type '$Type' .";[ "$DISPLAY" ] && pupmessage -bg red2 "No Support in kernel $KERNELVER
for filesystem type '$Type' .";exit 151; }

  #BK check if already mounted elsewhere...
  for ONELOOP in `mount | grep '^/dev/loop' | cut -f 1 -d ' ' | tr '\n' ' '`
  do
   MNTDIMG_MNT_PT=`mount | grep "^$ONELOOP " | sed 's#.* on \(.*\) type .*#\1#'`   #120220...
   MNTDIMG=""
   [ "`echo $MNTDIMG_MNT_PT | cut -f 2 -d /`" = "initrd" ] && MNTDIMG="/initrd"
   MNTDIMG="${MNTDIMG}`losetup-FULL $ONELOOP | cut -f 2 -d '(' | cut -f 1 -d ')'`"
   LONG_MNTDIMG=`echo "$MNTDIMG" | sed 's/\*$//'`
   losetup-FULL $ONELOOP
   ls "$LONG_MNTDIMG"*
   MNTDIMG_DEV_INODE=`stat -L -c "%d_%i" "$LONG_MNTDIMG"*`             #120220
   #not perfect, but paths may be symlinks...
   if [ "$MNTDIMG_DEV_INODE" = "$imgFileDEV_INODE" ];then          #120220...
    pupmessage -bg '#FF8080' "Sorry $imgFile is already mounted and in-use by Puppy
on $MNTDIMG_MNT_PT from $MNTDIMG"    #120220
     exit
    fi
  done

  Ext=`echo "$imgFile" |sed 's/^.*\.//'`   # get file type from extention
  if [ "$Ext" = 'fs' ] ;then
   Type=`file -z "$imgFile" |cut -f 2 -d ':' |awk '{print $2}' |tr '[[:upper:]]' '[[:lower:]]'`
     cat /proc/filesystems |grep -w "$Type" || { echo "No Support in kernel $KERNELVER
for filesystem type '$Type' .";[ "$DISPLAY" ] && pupmessage -bg red2 "No Support in kernel $KERNELVER
for filesystem type '$Type' .";exit 151; }
  elif [ "$Ext" = '2fs' ] ;then
   Type='ext2'
  elif [ "$Ext" = '3fs' ] ;then
   Type='ext3'
  elif [ "$Ext" = '4fs' ] ;then #v423 planning for the future!
   Type='ext4'
  elif [ "$Ext" = 'sfs' -o "$Ext" = 'squashfs' -o "$Ext" = 'sqfs' ] ;then
   Type='squashfs'
  elif [ "$Ext" = 'iso' ] ;then
   Type=`echo "$DISK_TYPE" |grep -m1 'file system' |awk '{print $1}' |tr '[[:upper:]]' '[[:lower:]]'`
   [ "$Type" ] || Type='iso9660'
  # BK
  #elif [ "$imgFile" = 'initrd.gz' ] ;then
  # Type='ext2'
  # gunzip $imgFile            # handle gzip image file
  # imgFile="echo "$imgFile" |sed 's/.gz$//'"
  fi

  #v423 detect wrong squashfs version...
  if [ "$Type" = "squashfs" ];then
  #DISK_TYPE=`disktype "${imgFile}"`
   echo "$DISKTYPE"  ##Squashfs filesystem, little endian, version 2.1,
   if [ "`echo "${DISK_TYPE}" | grep 'Linux squashfs, version'`" ];then
       SFS_V_STR=`echo "${DISK_TYPE}" | grep -o 'Linux squashfs, version.*' |awk -F ',' '{print $1" "$2" "$3}'`
       if [ "`echo "${DISK_TYPE}"  |grep "$SFSSTR"`" = "" ];then
       if [ $SFSMAJOR -eq 4 ];then #100606
     pupmessage -center -bg '#FFC0C0' "`gettext \"NOTICE:
 ${SFS_V_STR}, not usable.
All Linux kernels 2.6.29 or later require version 4.x squashfs files
(note, some 2.6.27.47+ kernels have Squashfs4 backported to them).
Note, there is an SFS-version-converter in the Utility menu, run that first.\"`"
      else
     pupmessage -center -bg '#FFC0C0' "`gettext \"NOTICE:
 ${SFS_V_STR}, not usable.
All Linux kernels 2.6.28 or earlier require version 3.x squashfs files
(note, an exception is some 2.6.27.47+ kernels that have Squashfs4 backported).
Note, there is an SFS-version-converter in the Utility menu, run that first.\"`"
      fi
      exit 0
      fi
   else
   pupmessage -center -bg '#FFC0C0' "`gettext \"NOTICE: Could not find a squash filesystem indside
$imgFile. Is the file type extension correct ?\"`"
   fi
  fi
#  echo -e "\nimgFile = $imgFile\t\tExt  = $Ext"
#  echo -e "MntPt   = $MntPt\t\tType = $Type\n"
  echo -e "\n ### Mount: $imgFile\n"
  mkdir -p "$MntPt"

  #111110 handle encrypted save-files...
  CRYPTO=""; Err=0
  DEVLOOP="`losetup-FULL -f`" #next free loop device.
  case $Type in
   ext2|ext3|ext4)
    case $imgFileBASE in
     *_cryptx*) #light encryption.
      CRYPTO='light'
      modprobe cryptoloop
      rxvt -geometry 25x3 -title "$(gettext 'Enter password')" -bg orange -e losetup-FULL -E 1 $DEVLOOP "$imgFile"
      #losetup-FULL -E 1 $DEVLOOP $imgFile
      Err=$?
     ;;
     *_crypt*) #heavy encryption.
      CRYPTO='heavy'
      modprobe cryptoloop
      modprobe aes_generic 2>/dev/null #v407 aes name change.
      modprobe aes 2>/dev/null #for older kernel <2.6.25
      modprobe crypto_blkcipher 2>/dev/null #v407 blkcipher name change.
      modprobe blkcipher 2>/dev/null #old kernel.
      modprobe cbc
      MYPASS="`pupdialog --title "$(gettext 'Password required')" --stdout --inputbox "$(gettext 'Password required to open') ${imgFileBASE}:" 0 0`"
      Err=$?
      if [ $Err -eq 0 ];then
       echo "$MYPASS" | losetup-FULL -p 0 -e aes $DEVLOOP "$imgFile"
       Err=$?
      fi
     ;;
    esac
   ;;
  esac
  if [ "$CRYPTO" ];then
   [ $Err -eq 0 ] && mount -t $Type $DEVLOOP "$MntPt"
   Err=$?
  else #normal, no encryption...
   mount -t $Type -o loop "$imgFile" "$MntPt"
   Err=$?
  fi

  if [ $Err -eq 0 ] ;then
   rox -d "$MntPt" # mount good, run rox filer
#   yaf-splash -timeout 6 -font "8x16" -outline 0 -margin 4 -bg green -text "SUCCESS! Click $imgFileBASE icon again to unmount it" & #BK
#   /usr/X11R7/bin/yaf-splash -timeout 6 -font "8x16" -outline 0 -margin 4 -bg green -text "SUCCESS! Click $imgFileBASE icon again to unmount it" & #BK
   yaf-splash -timeout 6 -bg green -text "`eval_gettext \"SUCCESS! Click \\\$imgFileBASE icon again to unmount it\"`" #BK
  else
   [ -d "$MntPt" ] && { [ "`ls -1A "$MntPt"`" ] || rmdir "$MntPt"; }
  fi

 else                     ### file's mounted, unmount it
  rox -D "$MntPt" #BK
  sync #111112
  umount "$MntPt"
  Err=$?
  #if [ "$imgFileBASE" = 'initrd' ] ;then gzip -9 $imgFile ;fi #111112 bug fix. no, remove.
#  yaf-splash -timeout 3 -font "8x16" -outline 0 -margin 4 -bg orange -text "Unmounting $imgFileBASE" #BK
#  /usr/X11R7/bin/yaf-splash -timeout 3 -font "8x16" -outline 0 -margin 4 -bg orange -text "Unmounting $imgFileBASE" #BK
  yaf-splash -timeout 3 -bg orange -text "$(gettext 'Unmounting') $imgFileBASE" #BK
  #Xdialog --title " Notice..." --no-button \
  #        --infobox "
  #UnMounting: $imgFile
  #" 0 0 2000
  echo -e "\n ### UnMount: $imgFile\n"
  sync #111112
  sleep 2
  [ -d "$MntPt" ] && { [ "`ls -1A "$MntPt"`" ] || rmdir "$MntPt"; }
 fi
 if [ $Err -ne 0 ] ;then         # ERROR: mount/unmount
  #xmessage -title " ERROR..." "  Failed mounting or unmounting.  "
  pupdialog --background red --title "$(gettext 'ERROR')" --msgbox "$(gettext 'Failed mounting or unmounting')" 0 0 &
 fi

exit $Err
###END###


Whats changed :

Added several ""double quotings .
Added removal of created directory if mount fails .
Removed the & fork from yaf-splash to be less disturbant on urxvt .
Added support for .squash and .sqfs extensions .
Added support for iso check if other then iso9660 ie udf .
Added support for determining and messaging the correct squashfs version ie found one older iso with squashfs-2.x .
Added fallback if disktype fails with file -z command .
Added sanity check if kernel supports the filesystem by checking /proc/filesystem .
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3982
Location: Kiel,Germany

PostPosted: Sun 17 Jun 2012, 06:05    Post subject:  

Here comes umount :

Code:

#!/bin/bash
#Barry Kauler 2006 www.puppylinux.com
#2007 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
#v406 support for old kernel /dev/hd*.
#v407 fix for floppy drive icon.
#v409 gparted create ext3 part. failed, fixed by making /etc/mtab a symlink.
#v423 recent version busybox umount, default for umount is to not free loop device, needs -d.
#120104 a bug if more than 9 partitions in drive, desktop icons may display incorrect mounted status.

#mount-FULL, umount-FULL, losetup-FULL are the full versions.
#The Busybox versions of mount and umount are available but only by:
# # busybox mount ...
# # busybox umount ...
#mount and umount are now scripts.
#if an ntfs partition, puppy uses user-mode ntfs-3g driver.
#the mount and umount scripts allow seamless mounting and unmounting of ntfs f.s.

[ "$1" ] || exec busybox umount
set |grep ARGV |sed 's#BASH_ARGV=(##;s#" \(\[[0-9*]\]="\)#"\n\1#g;s#)$##'
LIST=`set |grep BASH_ARGV |sed 's#BASH_ARGV=(##;s#" \(\[[0-9*]\]="\)#"\n\1#g;s#)$##'`
while read line;do
line="param$line"
eval $line
done <<EOL
$(echo "$LIST")
EOL
sync #paranoid precaution. v2.12 kernel call to modprobe, sync hangs.

. /etc/rc.d/functions4puppy4 #v4.02

#v406 add /dev/hd* support... v407 add fd*...
MOUNTS=`busybox mount`
MNTDDEVS1="`echo "$MOUNTS" | grep '^/dev/[smhfl]' | cut -f 1 -d ' ' | cut -f 3 -d '/'`" #v403 sd, sr, mmc

#extract all the '-' options, on separate lines...
#v2.12 pathetic bug, need space before $@, see comment /bin/mount... No, use $*...
DASHOPTS="`echo "$*" | tr '\t' ' ' | tr ' ' '\n' | grep '^\-'`"

#v2.12 curses, busybox mount accepts the '-n' option (just ignores it) but umount does not... not true for v1.19.3
if [ ! "`echo " $DASHOPTS" | grep 'n'`" = "" ];then
 FULLCMD=`echo -n " $*" | sed -e 's/ \-n / /g'` #unsatisfactory!
else
 FULLCMD="$*"
fi

# -a param means unmount everything...
#if [ ! "`echo "$@" | grep --extended-regexp '\W-a$|\W-a\W'`" = "" ];then
if [ ! "`echo " $DASHOPTS" | grep 'a'`" = "" ];then
 echo "Option '-a' ..."
 MNTFUSE="`busybox mount | grep 'fuse' | head -n 1 | cut -f 3 -d ' '`"
 [ ! "$MNTFUSE" = "" ] && { echo "Running fusermount for '$MNTFUSE'";fusermount -u "$MNTFUSE"; }
 echo "FULLCMD='$FULLCMD'"
 busybox umount -d $FULLCMD #v423 -d fix.  #pers.mark "$FULLCMD" spits out invalid option -- ' '
 exit $?
fi

#remove everything except the device or mntpt...
echo "$LIST"
LASTPARAM=`echo "$LIST" |sed 's#"$##;s#\[#\\\\[#;s#\]#\\\\]#;s#.*="##' |grep '^/'`
echo "LASTPARAM='$LASTPARAM'"
#thanks to jesse for this...
#for ntfs-3g, find the device and mount point...
#note, '\' essential to prevent 'ps' from reporting this invocation line...
[ "$LASTPARAM" ] && NTFSMNTPT=`ps -eF | grep -o 'ntfs\-3g.*' | grep "${LASTPARAM} " | grep -o '/mnt/.*' |sed 's# -o .*$##'`
echo "NTFSMNTPT='$NTFSMNTPT'"
if [ "$NTFSMNTPT" = "" ];then
 echo "No NTFS"
  if [ "$something" ];then  #TODO ;)
  echo "FULLCMD='$FULLCMD'"
 busybox umount -d "$FULLCMD" #v423 -d fix to free loop device.
 RETVAL=$?
  else
  echo "${param[@]}"
 busybox umount -d "${param[@]}"
 RETVAL=$?
  fi
else
 #fusermount can only unmount by giving the mount-point...
 fusermount -u "$NTFSMNTPT"
 RETVAL=$?
fi
echo "RETVAL='$RETVAL'"
#v403 if there is a desktop icon (see pup_eventd), then refresh it...
if [ $RETVAL -eq 0 ];then
 #find which device has been unmounted... v406 add hd*... v407 add fd*...
 MNTDDEVS2="`busybox mount | grep '^/dev/[smhfl]' | cut -f 1 -d ' ' | cut -f 3 -d '/'`" #v403 sd, sr, mmc
 if [ "$MNTDDEVS2" = "" ];then
  DEVNAME="`echo "$MNTDDEVS1" | head -n 1`" #head is a precaution.
 else
  DEVNAME="`echo "${MNTDDEVS1}
${MNTDDEVS2}" | sort | uniq -u | head -n 1`" #head is a precaution.
 fi
 MNTPT=`echo "$MOUNTS" |grep "^/dev/$DEVNAME " |sed 's#.* on \(.*\) type .*#\1#'`
 if [ "$DEVNAME" != "" -a "$DISPLAY" != "" ];then
  DRVNAME="`echo -n "$DEVNAME" | cut -b 1-3`" #ex: DRVNAME=sda
  #special case, SD card /dev/mmcblk0p1...
  [ "$DRVNAME" = "mmc" ] && DRVNAME="`echo -n "$DEVNAME" | sed -e 's/p[0-9]$//'`"
  xDRVNAME="$DRVNAME" #v404
  [ -d /root/.pup_event/drive_${DEVNAME} ] && DRVNAME="$DEVNAME" #icon for each partition. ex: DRVNAME=sda1
  if [ -d /root/.pup_event/drive_${DRVNAME} ];then
   case $DRVNAME in #v407
    fd*)
     DRV_CATEGORY="floppy"
    ;;
    *)
     dnPATTERN='/dev/'"${xDRVNAME}"'|'
     DRV_CATEGORY="`probedisk2 | grep "$dnPATTERN" | cut -f 2 -d '|'`"
    ;;
   esac
   #if any partitions still mounted, leave "MNTD" on icon...
   drvPATTERN='^/dev/'"${DRVNAME}" #important, no space on end.
   #120104 a bug if more than 9 partitions in drive, ex DRVNAME=sda1 xDRVNAME=sda, df test below must ignore sda10 etc...
   [ "$DRVNAME" != "$xDRVNAME" ] && drvPATTERN='^/dev/'"${DRVNAME}"' ' #120104 we do want a space on end.
   #"MNTD" text is intended as a reminder to user that drive needs to be unmounted,
   #   but partitions in use by Puppy cannot be unmounted.
   if [ "`df | tr -s ' ' | cut -f 1,6 -d ' ' | grep "$drvPATTERN" | grep -v ' /initrd/' | grep -v ' /$'`" = "" ];then
    if [ "`df | tr -s ' ' | cut -f 1,6 -d ' ' | grep "$drvPATTERN" | grep -E ' /initrd/| /$'`" != "" ];then
     #only a partition left mntd that is in use by puppy, change green->yellow...
     icon_mounted_func $DRVNAME $DRV_CATEGORY #see functions4puppy4
    else
     #redraw icon without "MNTD" text...
     icon_unmounted_func $DRVNAME $DRV_CATEGORY #see functions4puppy4
    fi
   fi
  fi
 fi
fi

#v409 now have /etc/mtab a symlink to /proc/mounts so this section not needed...
##v2.10 do not update /etc/mtab if '-n' option...
#[ ! "`echo " $DASHOPTS" | grep 'n'`" = "" ] && exit $RETVAL
##busybox does not support /etc/mtab, but some apps (ex: eject
##and the full mount,umount) need it...
#[ $RETVAL -eq 0 ] && busybox mount | sed -e 's/ on / /g' | sed -e 's/ type / /g' | sed -e 's/ (/ /g' | sed -e 's/)$/ 0 0/g' > /etc/mtab
##note, it is a long story here. Busybox can be configured to
##support /etc/mtab, however the information it writes to mtab
##is incomplete, different, and breaks my scripts.

#v409, instead just make sure the symlink stays there...
if [ ! -L /etc/mtab ];then
 rm -f /etc/mtab
 ln -s /proc/mounts /etc/mtab
fi

echo "DEVNAME='$DEVNAME'"
echo "MNTPT='$MNTPT'"
if [ $RETVAL = 0 ];then
if [ "$MNTPT" ];then
 if [ -d "$MNTPT" ];then
 if [ "`echo $DEVNAME |grep '^loop'`" ];then
 [ "$DISPLAY" -a "`pidof ROX-Filer`" ] && rox -D "MNTPT"
 [ "`ls -1A "$MNTPT"`" ] || rmdir  "$MNTPT"
 fi;
 fi
fi;fi
exit $RETVAL


Whats New :

1)
Using bash ARGV to get the parameters, not "$@" .
This means the bang has to point to bash and not ash or any other shell .
Using eval to evaluate the parameters in arrays .

BASH_ARGV presents the parameters in back to begin order, so last parameter shows up as argv[0]="[/path/to/][-]parameter" .

mount and umount as full and as busybox applets seem not to care for the ordering of the -dash-parameters .
This is not usual, since the bash builtin getopts cares: they have to be first of the parameters,
also other binaries may not like "binary /file -v -t -a" -
for them "binary -vta /file" is needed to work correctly .

2)
Added support for removal of the ugly long directory names in /mnt/ if i unmount a loop device by the rxvt cli .

3)
Support for filenames with spaces ie "/mnt/sda1/USERS/MY ME NAME/Documents/Download/Iso/Ubuntu_x_y-x.iso"
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


Joined: 20 Jun 2010
Posts: 3982
Location: Kiel,Germany

PostPosted: Sun 17 Jun 2012, 06:14    Post subject:  

Now mount :

Code:

#!/bin/sh
#BK 2006 www.puppylinux.com
#2007 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html)
#v407 fix for floppy drive icon.
#v409 gparted create ext3 part. failed, fixed by making /etc/mtab a symlink.
#120103 shinobar: need 'silent' option for ntfs-3g, avoid err msgs, permissions lost when copy.

#mount-FULL, umount-FULL, losetup-FULL are the full versions.
#The Busybox versions of mount and umount are available but only by:
# # busybox mount ...
# # busybox umount ...
#mount and umount are now scripts.
#if an ntfs partition, puppy uses user-mode ntfs-3g driver.
#the mount and umount scripts allow seamless mounting and unmounting of ntfs f.s.

[ ! $1 ] && exec busybox mount

#i realised this script has to allow reentrancy. So, all temp file now unique,
#using ${$} which is pid of script.
MYPID=${$}

. /etc/rc.d/functions4puppy4 #v4.02

#v2.12 discovered difference between $@ and $*. Replaced all $@ with $* in this script...

#extract all the '-' options, on separate lines... do NOT use $@!!!!...
#v3.93 eliminate ' -- ' and all past it...
DASHOPTS="`echo "$*" | tr '\t' ' '  | sed -e 's/ -- .*//' | tr ' ' '\n' | grep '^\-'`"

#needs an explicit '-t ntfs', does not work with /etc/fstab...
if [ "`echo "$*" | grep 'ntfs'`" = "" ];then

 #v3.93 always use full mount, in case of params not understood by bb-mount...
 ##v2.10 hack for T2, scripts have '--bind'...
 #if [ "`echo -n "$*" | grep '\-\-bind'`" = "" ];then
 # busybox mount $@
 # RETVAL=$?
 #else
 # #busybox mount does not support '--bind'
 # #as have mtab file (see below), can now use full mount...
  #v409 put in '-n' option as now have /etc/mtab symlink to /proc/mounts...
  echo "$0:$@"
  mount-FULL -n "${@}"
  RETVAL=$?
 #fi

else
 #screen out all the options...
 CMDPRMS="`echo -n "$*" | tr '\t' ' ' | tr -s ' ' | tr ' ' '\n' | grep '^/' | tr '\n' ' '`"
 #kirk advised these options so Rox will not complain about file
 #permissions when copy a file to a ntfs partition...
 [ -f /tmp/ntfsmnterr${MYPID}.txt ] && rm -f /tmp/ntfsmnterr${MYPID}.txt

 ntfs-3g $CMDPRMS -o umask=0,no_def_opts,silent 2>/tmp/ntfsmnterr${MYPID}.txt #120103 shinobar: need silent
 RETVAL=$?
 #v2.16 ntfs-3g v1.417, part. scheduled for check, failed with value 10...
 #v4.00 ntfs-3g v1.2412 does not have 4,10, has 15 for dirty f.s., 14 hiberneted...
 if [ $RETVAL -eq 4 -o $RETVAL -eq 10 -o $RETVAL -eq 15 -o $RETVAL -eq 14 ];then  #try to force it...
  if [ $RETVAL -eq 14 ];then
   #ntfs-3g $CMDPRMS -o umask=0,no_def_opts,remove_hiberfile 2>/tmp/ntfsmnterr${MYPID}.txt
   #RETVAL=$?
   echo > /dev/null
  else
   ntfs-3g $CMDPRMS -o force,umask=0,no_def_opts,silent 2>/tmp/ntfsmnterr${MYPID}.txt #120103 shinobar: need silent.
   RETVAL=$?
   ERRMSG1="`cat /tmp/ntfsmnterr${MYPID}.txt`"
   echo "$ERRMSG1"
   if [ $RETVAL -eq 0 ];then
    echo "WARNING: NTFS f.s. mounted read/write but corrupted."
    [ ! "`pidof X`" = "" ] && nohup gxmessage -bg red -center -title "NTFS WARNING" "The ntfs-3g driver was able to mount the NTFS
partition but returned this error message:
$ERRMSG1

It is mounted read/write, but advice is only write
to it in emergency situation. Recommendation is
boot Windows and fix the filesystem first!!!" &
   fi
  fi
 fi

 #ntfs-3g plays very safe and will not mount if thinks anything
 #wrong with ntfs f.s. But, we may want to recover files from a
 #damaged windows. So, fall back to the kernel ntfs driver...
 if [ ! $RETVAL -eq 0 ];then
  #mount read-only...
  busybox mount -r -t ntfs $CMDPRMS
  RETVAL=$?
  ERRMSG1="`cat /tmp/ntfsmnterr${MYPID}.txt`"
  echo "$ERRMSG1"
  if [ $RETVAL -eq 0 ];then
   echo "WARNING: NTFS f.s. mounted read-only."
   [ ! "`pidof X`" = "" ] && nohup gxmessage -bg red -center -title "NTFS WARNING" "The ntfs-3g driver was unable to mount the NTFS
partition and returned this error message:
$ERRMSG1

So, the inbuilt kernel NTFS driver has been used
to mount the partition read-only." &
  fi
 fi
fi

#v4.02 if there is a desktop icon (see pup_eventd), then refresh it...
if [ $RETVAL -eq 0 -a "$DISPLAY" != "" ];then
 DEVNAME="`busybox mount | tail -n 1 | grep '^/dev/' | cut -f 1 -d ' ' | cut -f 3 -d '/'`"
 if [ "$DEVNAME" != "" ];then
  DRVNAME="`echo -n "$DEVNAME" | cut -c 1-3`"
  #special case, SD card /dev/mmcblk0p1...
  [ "$DRVNAME" = "mmc" ] && DRVNAME="`echo -n "$DEVNAME" | sed -e 's/p[0-9]$//'`"
  xDRVNAME="$DRVNAME" #v404
  [ -d /root/.pup_event/drive_${DEVNAME} ] && DRVNAME="$DEVNAME" #icon for each partition.
  if [ -d /root/.pup_event/drive_${DRVNAME} ];then
   case $DRVNAME in #v407
    fd*)
     DRV_CATEGORY="floppy"
    ;;
    *)
     dnPATTERN='/dev/'"${xDRVNAME}"'|'
     DRV_CATEGORY="`probedisk2 | grep "$dnPATTERN" | cut -f 2 -d '|'`"
    ;;
   esac
   icon_mounted_func $DRVNAME $DRV_CATEGORY #see functions4puppy4
  fi
 fi
fi

#v409 now have /etc/mtab a symlink to /proc/mounts so this section not needed...
##v2.10 do not update /etc/mtab if '-n' option...
#[ "`echo " $DASHOPTS" | grep '^\-n$'`" != "" ] && exit $RETVAL
##busybox does not support /etc/mtab, but some apps (ex: eject
##and the full mount,umount, mke2fs) need it...
#[ $RETVAL -eq 0 ] && busybox mount | sed -e 's/ on / /g' | sed -e 's/ type / /g' | sed -e 's/ (/ /g' | sed -e 's/)$/ 0 0/g' > /etc/mtab
##note, it is a long story here. Busybox can be configured to
##support /etc/mtab, however the information it writes to mtab
##is incomplete, different, and breaks my scripts.

#v409, instead just make sure the symlink stays there...
if [ ! -L /etc/mtab ];then
 rm -f /etc/mtab
 ln -s /proc/mounts /etc/mtab
fi

exit $RETVAL


Here only one thing is changed :

Double quotes for "$@" . Today it worked for me at racy-5.3 but i remember other installations that casted error messages no such so , which i could not solve that time .

Heres likely the archilles heel of the three scripts .

Note the three scripts are from actual puppy_racy_5.3 with it's fusermount,ntfs-3g and busybox versions .
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 1 [3 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Cutting edge
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1460s ][ Queries: 11 (0.0181s) ][ GZIP on ]