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 Sat 30 Aug 2014, 08:52
All times are UTC - 4
 Forum index » Advanced Topics » Cutting edge
simple /bin/mount
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [6 Posts]  
Author Message
Karl Godt


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

PostPosted: Fri 07 Jun 2013, 20:07    Post subject:  simple /bin/mount  

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:

#!/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, 08:12; edited 5 times in total
Back to top
View user's profile Send private message Visit poster's website 
L18L

Joined: 19 Jun 2010
Posts: 2505
Location: Burghaslach, Germany somewhere also known as "Hosla"

PostPosted: Sat 08 Jun 2013, 04:33    Post subject: Re: simple /bin/mount
Subject description: test report /sbin/mount
 

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. Exclamation

Code:
# /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.)
Back to top
View user's profile Send private message 
Karl Godt


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

PostPosted: Sat 08 Jun 2013, 06:32    Post subject:  

Recognized it also here .

Fix would be to screen out the mount options like

Code:
[ "$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
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


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

PostPosted: Sat 08 Jun 2013, 09:35    Post subject:  

Reading the manual page there are two ways to mount ntfs read -write :
man ntfs-3g wrote:
SYNOPSIS
ntfs‐3g volume mount_point [‐o option[,...]]
mount −t ntfs‐3g volume mount_point [‐o option[,...]]

The latter works for me too :
First needs to set
[ "${P[$c]}" = ntfs ] && P[$c]='ntfs-3g'
in the ARGV formatting part
and
ntfs-3g) NTFSMOUNT=YES;;
in the case ntfs) vfat) part
and
Code:
[ "$NTFSMOUNT" ] && {
    mount-FULL ${P[@]} && RETVAL=$? || {
    mount-FULL ${*} && { RETVAL=$? ; NTFSRO=YES ; } || RETVAL=$? ; } ; }

and looks better.
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


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

PostPosted: Mon 10 Jun 2013, 07:08    Post subject:  

Second style :
Code:

#!/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 .
Back to top
View user's profile Send private message Visit poster's website 
Karl Godt


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

PostPosted: Tue 11 Jun 2013, 02:17    Post subject: /etc/mtab  

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:
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 .
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 1 [6 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.0779s ][ Queries: 12 (0.0042s) ][ GZIP on ]