simple /bin/mount

Under development: PCMCIA, wireless, etc.
Post Reply
Message
Author
User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

simple /bin/mount

#1 Post by Karl Godt »

Without words ,
still has to be tested for
Windows filesystems ,
/etc/eventmanager settings ,
removable devices.

Main goal for me is to mount /dev/sdaX using the cli without need for mountpoint or /etc/fstab.

Code: Select all

#!/bin/bash
# Karl Reimer Godt June 2013
# Thanks to L18L for testing and confirming that ntfs-3g could need a patch to
# ignore unused common Linux/GNU mount options

[ "$*" ] || exec busybox mount

ARGS=`set | grep 'BASH_ARG'`
ARGV=`echo "$ARGS" | grep 'ARGV' | grep -o '\[.*"'`
#echo  "$ARGV"
ARGC=`echo "$ARGS" | grep 'ARGC' |cut -f2 -d'"'`
#echo $ARGC
c=$ARGC
while read p
do
P[$c]="${p#*=}"
P[$c]="${P[$c]/#\"}"
P[$c]="${P[$c]/%\"}"
[ "${P[$c]}" = ntfs ] && P[$c]='ntfs-3g'
(( c-- ))
done<<EOI
$(echo "$ARGV" | sed 's%" \[%"\n\[%g' )
EOI
#echo ${P[@]}

[ $# = 1 -a -b "$1" ] &&
{
    mkdir -p /mnt/"${1##*/}"
    mount-FULL "$1" /mnt/"${1##*/}"
    RETVAL=$?
} ||
{
    for sp in ${P[@]}
    do
    case $sp in
    ntfs-3g) NTFSMOUNT=YES;;
    vfat) FATMOUNT=YES;CPAGE=437;IOCSET=iso8859-1
          IFS='.' read KM rest </etc/keymap || KM=us
          case $KM in
          de|be|br|dk|es|fi|fr|it|no|se|pt)         CPAGE=850 ;;
          slovene|croat|hu101|hu|cz-lat2|pl|ro_win) CPAGE=852 ; IOCSET=iso8859-2 ;;
          esac ;;
    esac
    done
}

[ "$RETVAL" ] ||
{
[ "$NTFSMOUNT" ] && {
    mount-FULL ${P[@]} && RETVAL=$? || {
    mount-FULL ${*} && { RETVAL=$? ; NTFSRO=YES ; } || RETVAL=$? ; } ; }

[ "$FATMOUNT" ]  && { mount-FULL ${P[@]} -o shortname=mixed,quiet,codepage=${CPAGE},iocharset=$IOCSET ; RETVAL=$? ; }
[ "$RETVAL" ]    || { mount-FULL ${P[@]} ; RETVAL=$? ; }
}

[ "$DISPLAY" ]    || exit $RETVAL
[ "$RETVAL" = 0 ] || exit $RETVAL
[ "$NTFSRO" ] && xmessage -bg orange "NTFS mount
$0 $*
as
mount-FULL $[P{@]}
failed to mount read-write .
The kernel NTFS driver was used to mount
mount-FULL ${*} at least read-only ." &

. /etc/eventmanager
[ "$ICONDESK" = true ] || exit $RETVAL
[ "$ICONPARTITIONS" = true ] || exit $RETVAL

. /etc/rc.d/functions4puppy4

read device rest <<EOI
$(tail -n1 /proc/mounts)
EOI

DEVNAME=${device##*/}
 case  $DEVNAME in
 fd*)  DRV_CATEGORY=floppy ;;
 mmc*) DEVNAME=${DEVNAME%p*} ; DRV_CATEGORY=card ;;
 esac
[ "$DRV_CATEGORY" ] || DRV_CATEGORY=`probedisk2 | grep -m1 "^${device:0:8}|" |cut -f2 -d'|'`

[ "$DRV_CATEGORY" ] && icon_mounted_func "$DEVNAME" "$DRV_CATEGORY"

[ -L /etc/mtab ] || ln -sf /proc/mounts /etc/mtab
exit $RETVAL
Edit1 : fix for ntfs mount options not understood by ntfs-3g
Edit2 : add support for floppy, fix probably incorrect mmc* devices handling ( have no mmc* device, so can not test )
Edit 3 : use mount-FULL -t ntfs-3g instead of ntfs-3g directly
Edit 4 : typo in "case $DEVNAME in" line ( was DEVAME ) ; fixed removable srX devices ( was grep "^${device//[[:digit:]]/}|" [..] now is grep -m1 "^${device:0:8}|" ) in call for probedisk2 line .
Edit 5 : Added check for "$DRV_CATEGORY" before icon_mounted_func [..] in case device is some pseudo device ( loop, ram )
Last edited by Karl Godt on Mon 10 Jun 2013, 12:12, edited 5 times in total.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Re: simple /bin/mount

#2 Post by L18L »

Karl Godt wrote:Without words ,
still has to be tested for
Windows filesystems ,
/etc/eventmanager settings ,
removable devices.

Main goal for me is to mount /dev/sdaX using the cli wihout need for mountpoint or /etc/fstab.
Tested succesfully on removable device.
Unmounted by click on x at desktop drive icon.
Windoofs not available here. :!:

Code: Select all

# /sbin/mount /dev/sda2
# /bin/mount /dev/sda2
mount: can't find /dev/sda2 in /etc/fstab or /etc/mtab
# /sbin/mount /dev/sdb2
#
(I had it in /sbin/bin thus not overwriting /bin/mount.)

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#3 Post by Karl Godt »

Recognized it also here .

Fix would be to screen out the mount options like

Code: Select all

[ "$NTFSMOUNT" ] && {
    for sp in ${P[@]}
    do
    case $sp in
    /*|-o) NTFS3G_OPTS="$NTFS3G_OPTS $sp" ;;
    -*|ntfs) : ;;
    *) NTFS3G_OPTS="$NTFS3G_OPTS $sp" ;;
    esac
    done
    ntfs-3g ${NTFS3G_OPTS} && RETVAL=$? || {
    mount-FULL ${P[@]} && { RETVAL=$? ; NTFSRO=YES ; } || RETVAL=$? ; } ; }
Am adding this to the script above.
Edit : done

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#4 Post by Karl Godt »

Reading the manual page there are two ways to mount ntfs read -write :
[quote="man ntfs-3g"]SYNOPSIS
ntfs

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#5 Post by Karl Godt »

Second style :

Code: Select all

#!/bin/bash
# Karl Reimer Godt June 2013
# Thanks to L18L for testing and confirming that ntfs-3g could need a patch to
# ignore unused common Linux/GNU mount options

[ "$*" ] || exec busybox mount

ARGS=`set | grep 'BASH_ARG'`
ARGV=`echo "$ARGS" | grep 'ARGV' | grep -o '\[.*"'`
ARGC=`echo "$ARGS" | grep 'ARGC' |cut -f2 -d'"'`
c=$ARGC
while read p
do
P[$c]="${p#*=}"
P[$c]="${P[$c]/#\"}"
P[$c]="${P[$c]/%\"}"
[ "${P[$c]}" = ntfs ] && P[$c]='ntfs-3g'
case ${P[$c]} in
 ntfs-3g) NTFSMOUNT=YES;;
 vfat) FATMOUNT=YES;CPAGE=437;IOCSET=iso8859-1
       IFS='.' read KM rest </etc/keymap || KM=us
       case $KM in
       de|be|br|dk|es|fi|fr|it|no|se|pt)         CPAGE=850 ;;
       slovene|croat|hu101|hu|cz-lat2|pl|ro_win) CPAGE=852 ; IOCSET=iso8859-2 ;;
       esac ;;
esac
(( c-- ))
done<<EOI
$(echo "$ARGV" | sed 's%" \[%"\n\[%g' )
EOI

[ $# = 1 -a -b "$1" ] &&
{
    mkdir -p /mnt/"${1##*/}"
    mount-FULL "$1" /mnt/"${1##*/}"
    RETVAL=$?
}

[ "$RETVAL" ] ||
{
 if [ "$NTFSMOUNT" ] ; then {
    mount-FULL ${P[@]} && RETVAL=$? || {
    mount-FULL ${*} && { RETVAL=$? ; NTFSRO=YES ; } || RETVAL=$? ; } ; }
elif [ "$FATMOUNT" ] ; then { mount-FULL ${P[@]} -o shortname=mixed,quiet,codepage=${CPAGE},iocharset=$IOCSET ; RETVAL=$? ; }
else { mount-FULL ${P[@]} ; RETVAL=$? ; }
fi
}

[ "$DISPLAY" -a "$RETVAL" = 0 ] || exit $RETVAL
[ "$NTFSRO" ] && xmessage -bg orange "NTFS mount
$0 $*
as
mount-FULL $[P{@]}
failed to mount read-write .
The kernel NTFS driver was used to mount
mount-FULL ${*} at least read-only ." &

read device rest <<EOI
$(tail -n1 /proc/mounts)
EOI
DEVNAME=${device##*/}
[ -d /root/.pup_event/drive_${DEVNAME} ] || exit $RETVAL

 case $DEVNAME in
 fd*)         DRV_CATEGORY=floppy ;;
 mmc*)     DEVNAME=${DEVNAME%p*} ; DRV_CATEGORY=card ;;
 scd*|sr*) DRV_CATEGORY=optical ;;
 hd*) : ;;  #either drive or optical
 sd*) : ;;  #either drive or usbdrv
 *) exit $RETVAL ;; #loop devices etc.
 esac
#echo "'$DEVNAME' '$DRV_CATEGORY' '$device'"
[ "$DRV_CATEGORY" ] || DRV_CATEGORY=`probedisk2 | grep -m1 "^${device//[[:digit:]]/}|" |cut -f2 -d'|'`

. /etc/rc.d/functions4puppy4
icon_mounted_func "$DEVNAME" "$DRV_CATEGORY"

[ -L /etc/mtab ] || ln -sf /proc/mounts /etc/mtab
exit $RETVAL
Edit1 : forgot and added $RETVAL to one exit: /usr/sbin/filemnt was saying error but mount was successful (debian squeeze pup )
Edit1 : added *) exit [..] to case $DEVNAME in line .

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

/etc/mtab

#6 Post by Karl Godt »

While experimenting with the line
[ -L /etc/mtab ] || ln -sf /proc/mounts /etc/mtab
if that is needed nowadays anymore (/etc/mtab),
it turned out that mount seems not to need it, but /bin/df-FULL .

busybox df does not need /etc/mtab on (slacko-5.3.1).

/bin/df is a wrapper script that does assign
DF="busybox df"
[ "`which df-FULL`" != "" ] && DF="df-FULL"

which could look like

Code: Select all

DF="busybox df"
[ "`which df-FULL`" != "" ] && { DF="df-FULL" ; [ -L /etc/mtab ] || ln -sf /proc/mounts /etc/mtab ; }
But since df is called many times by the (old)pup_event_frontend_d and freememapplet[_tray],
it would add a little to the load average .
IMHO the link /etc/mtab -> /proc/mounts
should be created by /etc/rc.d/rc.sysinit after /proc is mounted ,
so it could be omitted in any userspace scripts .
Risky , probably if something removes /etc/mtab , but I cannot think of anything else but the user, and that could remove also any other important files in /etc .

Post Reply