* My first usb storage automount script :)
@ 2002-12-11 16:22 Wout Mertens
2003-01-03 23:27 ` Eddie Shi
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Wout Mertens @ 2002-12-11 16:22 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1612 bytes --]
Hi there,
I just wanted to share what I hacked up through some frustration. It's a
script that will automatically mount usb devices that are attached.
It ties in to the hotplug architecture as closely as possible, without
changing anything. So then I subscribed to this list to announce it.
Of course, that's when I discovered
http://users.actrix.co.nz/michael/usbmount.html by Michael Hamilton.
So I'll first give a rundown of differences:
My solution:
- only mounts the device that was just inserted (with some luck)
- is called automount_usb, so that, by changing the usb.usermap, it gets
called every time a device is inserted and not just the first time
- creates remover scripts that have /bin/sh as the only dependency
- creates nicely readable names as mount points
- supports devices with multiple partitions
- is really small
But Michael's solution:
- makes KDE icons
- is easier to read
So, please have a look at the attached code, and tell me what you think
about the device detection code. Michael, if you read this, we could
perhaps merge the two efforts and get all the features.
Also, let's start a thread on making a gui.agent script that gets called
by the hotplug scripts. It would notify the user of hotplug events.
I feel that it should be called with the same environment as the other
agents, with an extra HOTPLUG_PATH variable indicating the path on which
the device is available, if applicable.
This could then be used by KDE, Gnome etc to notify the user.
Cheers,
Wout.
PS: /Please/ change usb.agent so that it creates /var/run/usb/ before
pointing remover scripts there...
[-- Attachment #2: Type: TEXT/PLAIN, Size: 2996 bytes --]
#!/bin/sh
# Automount hotplugged usb storage devices. Copyright (c) 2002, Wout Mertens
# This script is released under the GPL.
# The usb devices will be mounted for the console user.
# To work, this needs:
# - kernel support:
# - hotplugging, /proc, usbdevfs and devfs
# - as modules: usb-storage, sd_mod, scsi_mod
# - filesystems that will be mounted, like vfat
# - ls, tr, echo, awk, basename, stat, grep, mount, umount, mkdir, rm, sed
# TODO Fix usb.agent so that /var/run/usb gets created if missing
# TODO Some rigid way of getting this run. Currently, I do
# grep usb-storage /lib/modules/*/modules.usbmap|sed 's/usb-storage/automount_usb/' >> /etc/hotplug/usb.usermap
# TODO Lots of testing
# TODO nice way of setting options
# TODO Also, the error checking should probably be more robust
# TODO Some clean way of handling disconnects while writing.
# TODO Make a generic event system for GUIs that shows that something was
# mounted for the user. Proposal: /etc/hotplug/gui.agent gets
# called with ACTION=add/remove, NAME=nice_name, PATH=new_path, etc.
# Not just for new storage, scanners and so on are useful too...
# Dump debug
mesg () {
#return
/usr/bin/logger -t $0 "$*"
}
# Figure out the device to mount
NUM=`basename $DEVICE|sed 's/^0*//'`
SERIAL=`awk -F= '/^T:.*/{if($0~/Dev#= *'$NUM' /){t=1}else{t=0}}t==1&&/SerialNumber/{print $2;exit}' /proc/bus/usb/devices`
PRODUCT=`awk -F= '/^T:.*/{if($0~/Dev#= *'$NUM' /){t=1}else{t=0}}t==1&&/Product/{print $2;exit}' /proc/bus/usb/devices`
# Use the serial or the product name to find which scsi host was just created
if [ -n "$SERIAL" ]; then
SCSI=`grep -l $SERIAL /proc/scsi/usb-storage-*/*|tail -1`
elif [ -n "$PRODUCT" ]; then
SCSI=`grep -l $PRODUCT /proc/scsi/usb-storage-*/*|tail -1`
fi
mesg Device No. $NUM, serial $SERIAL, name $PRODUCT, path $SCSI
# Mount it
if [ -n "$SCSI" ]; then
# The name of the file is the number of the SCSI host
SCSI=`basename $SCSI`
PARTS=`ls /dev/scsi/host$SCSI/*/*/*/part*`
MOUNTPATH=/mnt/usb/`echo $PRODUCT|tr '[ /?*"]' _`
if [ -e "$MOUNTPATH" ]; then
if mount|grep "$MOUNTPATH">/dev/null; then
# TODO I'm too lazy to write proper collision avoidance code
MOUNTPATH="$MOUNTPATH".$$
fi
fi
# I'm hoping that mount ignores options that don't apply to the fs
# These options should prevent abuse and make it writeable for the
# console user.
MOUNTOPTS='-osync,nosuid'`stat -c',uid=%u,gid=%g' /dev/console`
mesg Mounting $PARTS on $MOUNTPATH, options $MOUNTOPTS
[ `echo $PARTS|wc -w` -eq 1 ] && MOUNTDIRECT=1
REMOVE=
for i in $PARTS; do
if [ -n "$MOUNTDIRECT" ]; then
T=$MOUNTPATH
else
T=$MOUNTPATH/`basename $i`
fi
mkdir -p $T
if mount $MOUNTOPTS $i $T; then
REMOVE="umount $T;$REMOVE;rmdir $T"
else
rmdir $T
fi
done
# Create remover
echo "#!/bin/sh" > $REMOVER
echo $REMOVE | sed 's/;;/;/g' >> $REMOVER
chmod +x $REMOVER
else
exit 1
fi
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: My first usb storage automount script :)
2002-12-11 16:22 My first usb storage automount script :) Wout Mertens
@ 2003-01-03 23:27 ` Eddie Shi
2003-01-07 12:37 ` Wout Mertens
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Eddie Shi @ 2003-01-03 23:27 UTC (permalink / raw)
To: linux-hotplug
Hi,
Does anyone know whether this will work on the following situation:
1. The usb-storage device (ie USB card reader) is alreay plugged in the
system.
2. No CF/MS/SM/SD are plugged in yet.
Given the above assumption , Will the system automount the CF when the CF
card is plugged in ? Or We still need to manually enter " mount -t vfat
/dev/sda1 /cf ".
I guess what I would like to see is to have something like CD's automount
when a CD is inserted.
Thanks
Eddie
----------------------------------------------------------------------------
------------------
Hi there,
I just wanted to share what I hacked up through some frustration. It's a
script that will automatically mount usb devices that are attached.
It ties in to the hotplug architecture as closely as possible, without
changing anything. So then I subscribed to this list to announce it.
Of course, that's when I discovered
http://users.actrix.co.nz/michael/usbmount.html by Michael Hamilton.
So I'll first give a rundown of differences:
My solution:
- only mounts the device that was just inserted (with some luck)
- is called automount_usb, so that, by changing the usb.usermap, it gets
called every time a device is inserted and not just the first time
- creates remover scripts that have /bin/sh as the only dependency
- creates nicely readable names as mount points
- supports devices with multiple partitions
- is really small
But Michael's solution:
- makes KDE icons
- is easier to read
So, please have a look at the attached code, and tell me what you think
about the device detection code. Michael, if you read this, we could
perhaps merge the two efforts and get all the features.
Also, let's start a thread on making a gui.agent script that gets called
by the hotplug scripts. It would notify the user of hotplug events.
I feel that it should be called with the same environment as the other
agents, with an extra HOTPLUG_PATH variable indicating the path on which
the device is available, if applicable.
This could then be used by KDE, Gnome etc to notify the user.
Cheers,
Wout.
PS: /Please/ change usb.agent so that it creates /var/run/usb/ before
pointing remover scripts there...
["automount_usb" (TEXT/PLAIN)]
#!/bin/sh
# Automount hotplugged usb storage devices. Copyright (c) 2002, Wout Mertens
# This script is released under the GPL.
# The usb devices will be mounted for the console user.
# To work, this needs:
# - kernel support:
# - hotplugging, /proc, usbdevfs and devfs
# - as modules: usb-storage, sd_mod, scsi_mod
# - filesystems that will be mounted, like vfat
# - ls, tr, echo, awk, basename, stat, grep, mount, umount, mkdir, rm, sed
# TODO Fix usb.agent so that /var/run/usb gets created if missing
# TODO Some rigid way of getting this run. Currently, I do
# grep usb-storage /lib/modules/*/modules.usbmap|sed
's/usb-storage/automount_usb/' \
>> /etc/hotplug/usb.usermap # TODO Lots of testing
# TODO nice way of setting options
# TODO Also, the error checking should probably be more robust
# TODO Some clean way of handling disconnects while writing.
# TODO Make a generic event system for GUIs that shows that something was
# mounted for the user. Proposal: /etc/hotplug/gui.agent gets
# called with ACTIONd/remove, NAME=nice_name, PATH=new_path, etc.
# Not just for new storage, scanners and so on are useful too...
# Dump debug
mesg () {
#return
/usr/bin/logger -t $0 "$*"
}
# Figure out the device to mount
NUM=`basename $DEVICE|sed 's/^0*//'`
SERIAL=`awk -F= '/^T:.*/{if($0~/Dev#= *'$NUM' \
/){t=1}else{t=0}}t=1&&/SerialNumber/{print $2;exit}' /proc/bus/usb/devices`
\
PRODUCT=`awk -F= '/^T:.*/{if($0~/Dev#= *'$NUM'
/){t=1}else{t=0}}t=1&&/Product/{print \
$2;exit}' /proc/bus/usb/devices` # Use the serial or the product name to
find which \
scsi host was just created if [ -n "$SERIAL" ]; then
SCSI=`grep -l $SERIAL /proc/scsi/usb-storage-*/*|tail -1`
elif [ -n "$PRODUCT" ]; then
SCSI=`grep -l $PRODUCT /proc/scsi/usb-storage-*/*|tail -1`
fi
mesg Device No. $NUM, serial $SERIAL, name $PRODUCT, path $SCSI
# Mount it
if [ -n "$SCSI" ]; then
# The name of the file is the number of the SCSI host
SCSI=`basename $SCSI`
PARTS=`ls /dev/scsi/host$SCSI/*/*/*/part*`
MOUNTPATH=/mnt/usb/`echo $PRODUCT|tr '[ /?*"]' _`
if [ -e "$MOUNTPATH" ]; then
if mount|grep "$MOUNTPATH">/dev/null; then
# TODO I'm too lazy to write proper collision avoidance code
MOUNTPATH="$MOUNTPATH".$$
fi
fi
# I'm hoping that mount ignores options that don't apply to the fs
# These options should prevent abuse and make it writeable for the
# console user.
MOUNTOPTS='-osync,nosuid'`stat -c',uid=%u,gid=%g' /dev/console`
mesg Mounting $PARTS on $MOUNTPATH, options $MOUNTOPTS
[ `echo $PARTS|wc -w` -eq 1 ] && MOUNTDIRECT=1
REMOVE for i in $PARTS; do
if [ -n "$MOUNTDIRECT" ]; then
T=$MOUNTPATH
else
T=$MOUNTPATH/`basename $i`
fi
mkdir -p $T
if mount $MOUNTOPTS $i $T; then
REMOVE="umount $T;$REMOVE;rmdir $T"
else
rmdir $T
fi
done
# Create remover
echo "#!/bin/sh" > $REMOVER
echo $REMOVE | sed 's/;;/;/g' >> $REMOVER
chmod +x $REMOVER
else
exit 1
fi
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: My first usb storage automount script :)
2002-12-11 16:22 My first usb storage automount script :) Wout Mertens
2003-01-03 23:27 ` Eddie Shi
@ 2003-01-07 12:37 ` Wout Mertens
2003-01-07 14:56 ` Tom Clark
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Wout Mertens @ 2003-01-07 12:37 UTC (permalink / raw)
To: linux-hotplug
Hmmm,
Only one way to find out :)
The script is real easy to install, just copy it to /etc/hotplug, and run
the line that registers it (you can find it inside the script).
I think the issue will be if the card reader sends usb plug/unplug events
or not... if it doesn't, I really wouldn't know how to do it.
Actually, there's an easier way to test:
Plug in the reader, have hotplug enabled, and watch /var/log/messages to
see what the kernel thinks is happening. If you see messages every time
you plug/unplug a card, you're lucky, and it will probably work.
Good luck,
Wout.
On Fri, 3 Jan 2003, Eddie Shi wrote:
> Hi,
> Does anyone know whether this will work on the following situation:
>
> 1. The usb-storage device (ie USB card reader) is alreay plugged in the
> system.
>
> 2. No CF/MS/SM/SD are plugged in yet.
>
> Given the above assumption , Will the system automount the CF when the CF
> card is plugged in ? Or We still need to manually enter " mount -t vfat
> /dev/sda1 /cf ".
>
> I guess what I would like to see is to have something like CD's automount
> when a CD is inserted.
>
>
> Thanks
>
>
> Eddie
> ----------------------------------------------------------------------------
> ------------------
> Hi there,
>
> I just wanted to share what I hacked up through some frustration. It's a
> script that will automatically mount usb devices that are attached.
>
> It ties in to the hotplug architecture as closely as possible, without
> changing anything. So then I subscribed to this list to announce it.
>
> Of course, that's when I discovered
> http://users.actrix.co.nz/michael/usbmount.html by Michael Hamilton.
>
> So I'll first give a rundown of differences:
> My solution:
> - only mounts the device that was just inserted (with some luck)
> - is called automount_usb, so that, by changing the usb.usermap, it gets
> called every time a device is inserted and not just the first time
> - creates remover scripts that have /bin/sh as the only dependency
> - creates nicely readable names as mount points
> - supports devices with multiple partitions
> - is really small
>
> But Michael's solution:
> - makes KDE icons
> - is easier to read
>
> So, please have a look at the attached code, and tell me what you think
> about the device detection code. Michael, if you read this, we could
> perhaps merge the two efforts and get all the features.
>
> Also, let's start a thread on making a gui.agent script that gets called
> by the hotplug scripts. It would notify the user of hotplug events.
> I feel that it should be called with the same environment as the other
> agents, with an extra HOTPLUG_PATH variable indicating the path on which
> the device is available, if applicable.
>
> This could then be used by KDE, Gnome etc to notify the user.
>
> Cheers,
>
> Wout.
>
> PS: /Please/ change usb.agent so that it creates /var/run/usb/ before
> pointing remover scripts there...
> ["automount_usb" (TEXT/PLAIN)]
>
> #!/bin/sh
> # Automount hotplugged usb storage devices. Copyright (c) 2002, Wout Mertens
> # This script is released under the GPL.
>
> # The usb devices will be mounted for the console user.
> # To work, this needs:
> # - kernel support:
> # - hotplugging, /proc, usbdevfs and devfs
> # - as modules: usb-storage, sd_mod, scsi_mod
> # - filesystems that will be mounted, like vfat
> # - ls, tr, echo, awk, basename, stat, grep, mount, umount, mkdir, rm, sed
>
> # TODO Fix usb.agent so that /var/run/usb gets created if missing
> # TODO Some rigid way of getting this run. Currently, I do
> # grep usb-storage /lib/modules/*/modules.usbmap|sed
> 's/usb-storage/automount_usb/' \
> >> /etc/hotplug/usb.usermap # TODO Lots of testing
> # TODO nice way of setting options
> # TODO Also, the error checking should probably be more robust
> # TODO Some clean way of handling disconnects while writing.
> # TODO Make a generic event system for GUIs that shows that something was
> # mounted for the user. Proposal: /etc/hotplug/gui.agent gets
> # called with ACTIONd/remove, NAME=nice_name, PATH=new_path, etc.
> # Not just for new storage, scanners and so on are useful too...
>
> # Dump debug
> mesg () {
> #return
> /usr/bin/logger -t $0 "$*"
> }
>
> # Figure out the device to mount
> NUM=`basename $DEVICE|sed 's/^0*//'`
> SERIAL=`awk -F= '/^T:.*/{if($0~/Dev#= *'$NUM' \
> /){t=1}else{t=0}}t=1&&/SerialNumber/{print $2;exit}' /proc/bus/usb/devices`
> \
> PRODUCT=`awk -F= '/^T:.*/{if($0~/Dev#= *'$NUM'
> /){t=1}else{t=0}}t=1&&/Product/{print \
> $2;exit}' /proc/bus/usb/devices` # Use the serial or the product name to
> find which \
> scsi host was just created if [ -n "$SERIAL" ]; then
> SCSI=`grep -l $SERIAL /proc/scsi/usb-storage-*/*|tail -1`
> elif [ -n "$PRODUCT" ]; then
> SCSI=`grep -l $PRODUCT /proc/scsi/usb-storage-*/*|tail -1`
> fi
>
> mesg Device No. $NUM, serial $SERIAL, name $PRODUCT, path $SCSI
>
> # Mount it
> if [ -n "$SCSI" ]; then
> # The name of the file is the number of the SCSI host
> SCSI=`basename $SCSI`
> PARTS=`ls /dev/scsi/host$SCSI/*/*/*/part*`
> MOUNTPATH=/mnt/usb/`echo $PRODUCT|tr '[ /?*"]' _`
> if [ -e "$MOUNTPATH" ]; then
> if mount|grep "$MOUNTPATH">/dev/null; then
> # TODO I'm too lazy to write proper collision avoidance code
> MOUNTPATH="$MOUNTPATH".$$
> fi
> fi
> # I'm hoping that mount ignores options that don't apply to the fs
> # These options should prevent abuse and make it writeable for the
> # console user.
> MOUNTOPTS='-osync,nosuid'`stat -c',uid=%u,gid=%g' /dev/console`
> mesg Mounting $PARTS on $MOUNTPATH, options $MOUNTOPTS
>
> [ `echo $PARTS|wc -w` -eq 1 ] && MOUNTDIRECT=1
> REMOVE> for i in $PARTS; do
> if [ -n "$MOUNTDIRECT" ]; then
> T=$MOUNTPATH
> else
> T=$MOUNTPATH/`basename $i`
> fi
> mkdir -p $T
> if mount $MOUNTOPTS $i $T; then
> REMOVE="umount $T;$REMOVE;rmdir $T"
> else
> rmdir $T
> fi
> done
>
> # Create remover
> echo "#!/bin/sh" > $REMOVER
> echo $REMOVE | sed 's/;;/;/g' >> $REMOVER
> chmod +x $REMOVER
> else
> exit 1
> fi
>
>
>
>
>
>
>
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
> Linux-hotplug-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
>
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: My first usb storage automount script :)
2002-12-11 16:22 My first usb storage automount script :) Wout Mertens
2003-01-03 23:27 ` Eddie Shi
2003-01-07 12:37 ` Wout Mertens
@ 2003-01-07 14:56 ` Tom Clark
2003-01-07 19:13 ` Eddie Shi
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Tom Clark @ 2003-01-07 14:56 UTC (permalink / raw)
To: linux-hotplug
The problem is you need a notification in the first place that a card has
been inserted. Unfortunately, I don't think any card readers on the market
provide this functionality. I've only been able to solve this with a kind
of daemon that periodically tries to mount the card reader's filesystem and
then pings it occasionally to make sure the card hasn't been removed. It's
ugly and wasteful, but what other alternative is there?
-tc
On 1/7/03 4:37 AM, "Wout Mertens" <wmertens@cisco.com> wrote:
> Hmmm,
>
> Only one way to find out :)
>
> The script is real easy to install, just copy it to /etc/hotplug, and run
> the line that registers it (you can find it inside the script).
>
> I think the issue will be if the card reader sends usb plug/unplug events
> or not... if it doesn't, I really wouldn't know how to do it.
>
> Actually, there's an easier way to test:
> Plug in the reader, have hotplug enabled, and watch /var/log/messages to
> see what the kernel thinks is happening. If you see messages every time
> you plug/unplug a card, you're lucky, and it will probably work.
>
> Good luck,
>
> Wout.
>
> On Fri, 3 Jan 2003, Eddie Shi wrote:
>
>> Hi,
>> Does anyone know whether this will work on the following situation:
>>
>> 1. The usb-storage device (ie USB card reader) is alreay plugged in the
>> system.
>>
>> 2. No CF/MS/SM/SD are plugged in yet.
>>
>> Given the above assumption , Will the system automount the CF when the CF
>> card is plugged in ? Or We still need to manually enter " mount -t vfat
>> /dev/sda1 /cf ".
>>
>> I guess what I would like to see is to have something like CD's automount
>> when a CD is inserted.
>>
>>
>> Thanks
>>
>>
>> Eddie
>> ----------------------------------------------------------------------------
>> ------------------
>> Hi there,
>>
>> I just wanted to share what I hacked up through some frustration. It's a
>> script that will automatically mount usb devices that are attached.
>>
>> It ties in to the hotplug architecture as closely as possible, without
>> changing anything. So then I subscribed to this list to announce it.
>>
>> Of course, that's when I discovered
>> http://users.actrix.co.nz/michael/usbmount.html by Michael Hamilton.
>>
>> So I'll first give a rundown of differences:
>> My solution:
>> - only mounts the device that was just inserted (with some luck)
>> - is called automount_usb, so that, by changing the usb.usermap, it gets
>> called every time a device is inserted and not just the first time
>> - creates remover scripts that have /bin/sh as the only dependency
>> - creates nicely readable names as mount points
>> - supports devices with multiple partitions
>> - is really small
>>
>> But Michael's solution:
>> - makes KDE icons
>> - is easier to read
>>
>> So, please have a look at the attached code, and tell me what you think
>> about the device detection code. Michael, if you read this, we could
>> perhaps merge the two efforts and get all the features.
>>
>> Also, let's start a thread on making a gui.agent script that gets called
>> by the hotplug scripts. It would notify the user of hotplug events.
>> I feel that it should be called with the same environment as the other
>> agents, with an extra HOTPLUG_PATH variable indicating the path on which
>> the device is available, if applicable.
>>
>> This could then be used by KDE, Gnome etc to notify the user.
>>
>> Cheers,
>>
>> Wout.
>>
>> PS: /Please/ change usb.agent so that it creates /var/run/usb/ before
>> pointing remover scripts there...
>> ["automount_usb" (TEXT/PLAIN)]
>>
>> #!/bin/sh
>> # Automount hotplugged usb storage devices. Copyright (c) 2002, Wout Mertens
>> # This script is released under the GPL.
>>
>> # The usb devices will be mounted for the console user.
>> # To work, this needs:
>> # - kernel support:
>> # - hotplugging, /proc, usbdevfs and devfs
>> # - as modules: usb-storage, sd_mod, scsi_mod
>> # - filesystems that will be mounted, like vfat
>> # - ls, tr, echo, awk, basename, stat, grep, mount, umount, mkdir, rm, sed
>>
>> # TODO Fix usb.agent so that /var/run/usb gets created if missing
>> # TODO Some rigid way of getting this run. Currently, I do
>> # grep usb-storage /lib/modules/*/modules.usbmap|sed
>> 's/usb-storage/automount_usb/' \
>>>> /etc/hotplug/usb.usermap # TODO Lots of testing
>> # TODO nice way of setting options
>> # TODO Also, the error checking should probably be more robust
>> # TODO Some clean way of handling disconnects while writing.
>> # TODO Make a generic event system for GUIs that shows that something was
>> # mounted for the user. Proposal: /etc/hotplug/gui.agent gets
>> # called with ACTIONd/remove, NAME=nice_name, PATH=new_path, etc.
>> # Not just for new storage, scanners and so on are useful too...
>>
>> # Dump debug
>> mesg () {
>> #return
>> /usr/bin/logger -t $0 "$*"
>> }
>>
>> # Figure out the device to mount
>> NUM=`basename $DEVICE|sed 's/^0*//'`
>> SERIAL=`awk -F= '/^T:.*/{if($0~/Dev#= *'$NUM' \
>> /){t=1}else{t=0}}t=1&&/SerialNumber/{print $2;exit}' /proc/bus/usb/devices`
>> \
>> PRODUCT=`awk -F= '/^T:.*/{if($0~/Dev#= *'$NUM'
>> /){t=1}else{t=0}}t=1&&/Product/{print \
>> $2;exit}' /proc/bus/usb/devices` # Use the serial or the product name to
>> find which \
>> scsi host was just created if [ -n "$SERIAL" ]; then
>> SCSI=`grep -l $SERIAL /proc/scsi/usb-storage-*/*|tail -1`
>> elif [ -n "$PRODUCT" ]; then
>> SCSI=`grep -l $PRODUCT /proc/scsi/usb-storage-*/*|tail -1`
>> fi
>>
>> mesg Device No. $NUM, serial $SERIAL, name $PRODUCT, path $SCSI
>>
>> # Mount it
>> if [ -n "$SCSI" ]; then
>> # The name of the file is the number of the SCSI host
>> SCSI=`basename $SCSI`
>> PARTS=`ls /dev/scsi/host$SCSI/*/*/*/part*`
>> MOUNTPATH=/mnt/usb/`echo $PRODUCT|tr '[ /?*"]' _`
>> if [ -e "$MOUNTPATH" ]; then
>> if mount|grep "$MOUNTPATH">/dev/null; then
>> # TODO I'm too lazy to write proper collision avoidance code
>> MOUNTPATH="$MOUNTPATH".$$
>> fi
>> fi
>> # I'm hoping that mount ignores options that don't apply to the fs
>> # These options should prevent abuse and make it writeable for the
>> # console user.
>> MOUNTOPTS='-osync,nosuid'`stat -c',uid=%u,gid=%g' /dev/console`
>> mesg Mounting $PARTS on $MOUNTPATH, options $MOUNTOPTS
>>
>> [ `echo $PARTS|wc -w` -eq 1 ] && MOUNTDIRECT=1
>> REMOVE>> for i in $PARTS; do
>> if [ -n "$MOUNTDIRECT" ]; then
>> T=$MOUNTPATH
>> else
>> T=$MOUNTPATH/`basename $i`
>> fi
>> mkdir -p $T
>> if mount $MOUNTOPTS $i $T; then
>> REMOVE="umount $T;$REMOVE;rmdir $T"
>> else
>> rmdir $T
>> fi
>> done
>>
>> # Create remover
>> echo "#!/bin/sh" > $REMOVER
>> echo $REMOVE | sed 's/;;/;/g' >> $REMOVER
>> chmod +x $REMOVER
>> else
>> exit 1
>> fi
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> -------------------------------------------------------
>> This sf.net email is sponsored by:ThinkGeek
>> Welcome to geek heaven.
>> http://thinkgeek.com/sf
>> _______________________________________________
>> Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
>> Linux-hotplug-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
>>
>
>
> -------------------------------------------------------
> This SF.NET email is sponsored by:
> SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
> http://www.vasoftware.com
> _______________________________________________
> Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
> Linux-hotplug-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: My first usb storage automount script :)
2002-12-11 16:22 My first usb storage automount script :) Wout Mertens
` (2 preceding siblings ...)
2003-01-07 14:56 ` Tom Clark
@ 2003-01-07 19:13 ` Eddie Shi
2003-01-07 20:37 ` Wout Mertens
2003-01-07 22:07 ` Tom Clark
5 siblings, 0 replies; 7+ messages in thread
From: Eddie Shi @ 2003-01-07 19:13 UTC (permalink / raw)
To: linux-hotplug
That's it, I think Window's must have done the same thing you described.
BTW, when you say "ping it to make sure card is not removed", do you mean
that you try to mount it and check the status return from the mount?
Thanks for the feedback.
Eddie
> -----Original Message-----
> From: Tom Clark [mailto:tclark@mac.com]
> Sent: Tuesday, January 07, 2003 6:56 AM
> To: linux-hotplug-devel@lists.sourceforge.net
> Cc: Eddie Shi; Wout Mertens
> Subject: Re: My first usb storage automount script :)
>
>
> The problem is you need a notification in the first place that a card has
> been inserted. Unfortunately, I don't think any card readers on
> the market
> provide this functionality. I've only been able to solve this with a kind
> of daemon that periodically tries to mount the card reader's
> filesystem and
> then pings it occasionally to make sure the card hasn't been
> removed. It's
> ugly and wasteful, but what other alternative is there?
>
> -tc
>
> On 1/7/03 4:37 AM, "Wout Mertens" <wmertens@cisco.com> wrote:
>
> > Hmmm,
> >
> > Only one way to find out :)
> >
> > The script is real easy to install, just copy it to
> /etc/hotplug, and run
> > the line that registers it (you can find it inside the script).
> >
> > I think the issue will be if the card reader sends usb
> plug/unplug events
> > or not... if it doesn't, I really wouldn't know how to do it.
> >
> > Actually, there's an easier way to test:
> > Plug in the reader, have hotplug enabled, and watch /var/log/messages to
> > see what the kernel thinks is happening. If you see messages every time
> > you plug/unplug a card, you're lucky, and it will probably work.
> >
> > Good luck,
> >
> > Wout.
> >
> > On Fri, 3 Jan 2003, Eddie Shi wrote:
> >
> >> Hi,
> >> Does anyone know whether this will work on the following situation:
> >>
> >> 1. The usb-storage device (ie USB card reader) is alreay
> plugged in the
> >> system.
> >>
> >> 2. No CF/MS/SM/SD are plugged in yet.
> >>
> >> Given the above assumption , Will the system automount the
> CF when the CF
> >> card is plugged in ? Or We still need to manually enter " mount -t vfat
> >> /dev/sda1 /cf ".
> >>
> >> I guess what I would like to see is to have something like
> CD's automount
> >> when a CD is inserted.
> >>
> >>
> >> Thanks
> >>
> >>
> >> Eddie
> >>
> ------------------------------------------------------------------
> ----------
> >> ------------------
> >> Hi there,
> >>
> >> I just wanted to share what I hacked up through some
> frustration. It's a
> >> script that will automatically mount usb devices that are attached.
> >>
> >> It ties in to the hotplug architecture as closely as possible, without
> >> changing anything. So then I subscribed to this list to announce it.
> >>
> >> Of course, that's when I discovered
> >> http://users.actrix.co.nz/michael/usbmount.html by Michael Hamilton.
> >>
> >> So I'll first give a rundown of differences:
> >> My solution:
> >> - only mounts the device that was just inserted (with some luck)
> >> - is called automount_usb, so that, by changing the
> usb.usermap, it gets
> >> called every time a device is inserted and not just the first time
> >> - creates remover scripts that have /bin/sh as the only dependency
> >> - creates nicely readable names as mount points
> >> - supports devices with multiple partitions
> >> - is really small
> >>
> >> But Michael's solution:
> >> - makes KDE icons
> >> - is easier to read
> >>
> >> So, please have a look at the attached code, and tell me what you think
> >> about the device detection code. Michael, if you read this, we could
> >> perhaps merge the two efforts and get all the features.
> >>
> >> Also, let's start a thread on making a gui.agent script that
> gets called
> >> by the hotplug scripts. It would notify the user of hotplug events.
> >> I feel that it should be called with the same environment as the other
> >> agents, with an extra HOTPLUG_PATH variable indicating the
> path on which
> >> the device is available, if applicable.
> >>
> >> This could then be used by KDE, Gnome etc to notify the user.
> >>
> >> Cheers,
> >>
> >> Wout.
> >>
> >> PS: /Please/ change usb.agent so that it creates /var/run/usb/ before
> >> pointing remover scripts there...
> >> ["automount_usb" (TEXT/PLAIN)]
> >>
> >> #!/bin/sh
> >> # Automount hotplugged usb storage devices. Copyright (c)
> 2002, Wout Mertens
> >> # This script is released under the GPL.
> >>
> >> # The usb devices will be mounted for the console user.
> >> # To work, this needs:
> >> # - kernel support:
> >> # - hotplugging, /proc, usbdevfs and devfs
> >> # - as modules: usb-storage, sd_mod, scsi_mod
> >> # - filesystems that will be mounted, like vfat
> >> # - ls, tr, echo, awk, basename, stat, grep, mount, umount,
> mkdir, rm, sed
> >>
> >> # TODO Fix usb.agent so that /var/run/usb gets created if missing
> >> # TODO Some rigid way of getting this run. Currently, I do
> >> # grep usb-storage /lib/modules/*/modules.usbmap|sed
> >> 's/usb-storage/automount_usb/' \
> >>>> /etc/hotplug/usb.usermap # TODO Lots of testing
> >> # TODO nice way of setting options
> >> # TODO Also, the error checking should probably be more robust
> >> # TODO Some clean way of handling disconnects while writing.
> >> # TODO Make a generic event system for GUIs that shows that
> something was
> >> # mounted for the user. Proposal: /etc/hotplug/gui.agent gets
> >> # called with ACTIONd/remove, NAME=nice_name, PATH=new_path, etc.
> >> # Not just for new storage, scanners and so on are useful too...
> >>
> >> # Dump debug
> >> mesg () {
> >> #return
> >> /usr/bin/logger -t $0 "$*"
> >> }
> >>
> >> # Figure out the device to mount
> >> NUM=`basename $DEVICE|sed 's/^0*//'`
> >> SERIAL=`awk -F= '/^T:.*/{if($0~/Dev#= *'$NUM' \
> >> /){t=1}else{t=0}}t=1&&/SerialNumber/{print $2;exit}'
> /proc/bus/usb/devices`
> >> \
> >> PRODUCT=`awk -F= '/^T:.*/{if($0~/Dev#= *'$NUM'
> >> /){t=1}else{t=0}}t=1&&/Product/{print \
> >> $2;exit}' /proc/bus/usb/devices` # Use the serial or the
> product name to
> >> find which \
> >> scsi host was just created if [ -n "$SERIAL" ]; then
> >> SCSI=`grep -l $SERIAL /proc/scsi/usb-storage-*/*|tail -1`
> >> elif [ -n "$PRODUCT" ]; then
> >> SCSI=`grep -l $PRODUCT /proc/scsi/usb-storage-*/*|tail -1`
> >> fi
> >>
> >> mesg Device No. $NUM, serial $SERIAL, name $PRODUCT, path $SCSI
> >>
> >> # Mount it
> >> if [ -n "$SCSI" ]; then
> >> # The name of the file is the number of the SCSI host
> >> SCSI=`basename $SCSI`
> >> PARTS=`ls /dev/scsi/host$SCSI/*/*/*/part*`
> >> MOUNTPATH=/mnt/usb/`echo $PRODUCT|tr '[ /?*"]' _`
> >> if [ -e "$MOUNTPATH" ]; then
> >> if mount|grep "$MOUNTPATH">/dev/null; then
> >> # TODO I'm too lazy to write proper collision avoidance code
> >> MOUNTPATH="$MOUNTPATH".$$
> >> fi
> >> fi
> >> # I'm hoping that mount ignores options that don't apply to the fs
> >> # These options should prevent abuse and make it writeable for the
> >> # console user.
> >> MOUNTOPTS='-osync,nosuid'`stat -c',uid=%u,gid=%g' /dev/console`
> >> mesg Mounting $PARTS on $MOUNTPATH, options $MOUNTOPTS
> >>
> >> [ `echo $PARTS|wc -w` -eq 1 ] && MOUNTDIRECT=1
> >> REMOVE> >> for i in $PARTS; do
> >> if [ -n "$MOUNTDIRECT" ]; then
> >> T=$MOUNTPATH
> >> else
> >> T=$MOUNTPATH/`basename $i`
> >> fi
> >> mkdir -p $T
> >> if mount $MOUNTOPTS $i $T; then
> >> REMOVE="umount $T;$REMOVE;rmdir $T"
> >> else
> >> rmdir $T
> >> fi
> >> done
> >>
> >> # Create remover
> >> echo "#!/bin/sh" > $REMOVER
> >> echo $REMOVE | sed 's/;;/;/g' >> $REMOVER
> >> chmod +x $REMOVER
> >> else
> >> exit 1
> >> fi
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> -------------------------------------------------------
> >> This sf.net email is sponsored by:ThinkGeek
> >> Welcome to geek heaven.
> >> http://thinkgeek.com/sf
> >> _______________________________________________
> >> Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
> >> Linux-hotplug-devel@lists.sourceforge.net
> >> https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
> >>
> >
> >
> > -------------------------------------------------------
> > This SF.NET email is sponsored by:
> > SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
> > http://www.vasoftware.com
> > _______________________________________________
> > Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
> > Linux-hotplug-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
>
>
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: My first usb storage automount script :)
2002-12-11 16:22 My first usb storage automount script :) Wout Mertens
` (3 preceding siblings ...)
2003-01-07 19:13 ` Eddie Shi
@ 2003-01-07 20:37 ` Wout Mertens
2003-01-07 22:07 ` Tom Clark
5 siblings, 0 replies; 7+ messages in thread
From: Wout Mertens @ 2003-01-07 20:37 UTC (permalink / raw)
To: linux-hotplug
Maybe a possible check would be to try to read the first few sectors
(partition table and boot record), and keep an md5 hash. If it changes, do
the sensible thing... Could be faster and less resource intensive than
trying to mount it.
Wout.
On Tue, 7 Jan 2003, Eddie Shi wrote:
> That's it, I think Window's must have done the same thing you described.
> BTW, when you say "ping it to make sure card is not removed", do you mean
> that you try to mount it and check the status return from the mount?
>
> Thanks for the feedback.
>
> Eddie
>
> > -----Original Message-----
> > From: Tom Clark [mailto:tclark@mac.com]
> > Sent: Tuesday, January 07, 2003 6:56 AM
> > To: linux-hotplug-devel@lists.sourceforge.net
> > Cc: Eddie Shi; Wout Mertens
> > Subject: Re: My first usb storage automount script :)
> >
> >
> > The problem is you need a notification in the first place that a card has
> > been inserted. Unfortunately, I don't think any card readers on
> > the market
> > provide this functionality. I've only been able to solve this with a kind
> > of daemon that periodically tries to mount the card reader's
> > filesystem and
> > then pings it occasionally to make sure the card hasn't been
> > removed. It's
> > ugly and wasteful, but what other alternative is there?
> >
> > -tc
> >
> > On 1/7/03 4:37 AM, "Wout Mertens" <wmertens@cisco.com> wrote:
> >
> > > Hmmm,
> > >
> > > Only one way to find out :)
> > >
> > > The script is real easy to install, just copy it to
> > /etc/hotplug, and run
> > > the line that registers it (you can find it inside the script).
> > >
> > > I think the issue will be if the card reader sends usb
> > plug/unplug events
> > > or not... if it doesn't, I really wouldn't know how to do it.
> > >
> > > Actually, there's an easier way to test:
> > > Plug in the reader, have hotplug enabled, and watch /var/log/messages to
> > > see what the kernel thinks is happening. If you see messages every time
> > > you plug/unplug a card, you're lucky, and it will probably work.
> > >
> > > Good luck,
> > >
> > > Wout.
> > >
> > > On Fri, 3 Jan 2003, Eddie Shi wrote:
> > >
> > >> Hi,
> > >> Does anyone know whether this will work on the following situation:
> > >>
> > >> 1. The usb-storage device (ie USB card reader) is alreay
> > plugged in the
> > >> system.
> > >>
> > >> 2. No CF/MS/SM/SD are plugged in yet.
> > >>
> > >> Given the above assumption , Will the system automount the
> > CF when the CF
> > >> card is plugged in ? Or We still need to manually enter " mount -t vfat
> > >> /dev/sda1 /cf ".
> > >>
> > >> I guess what I would like to see is to have something like
> > CD's automount
> > >> when a CD is inserted.
> > >>
> > >>
> > >> Thanks
> > >>
> > >>
> > >> Eddie
> > >>
> > ------------------------------------------------------------------
> > ----------
> > >> ------------------
> > >> Hi there,
> > >>
> > >> I just wanted to share what I hacked up through some
> > frustration. It's a
> > >> script that will automatically mount usb devices that are attached.
> > >>
> > >> It ties in to the hotplug architecture as closely as possible, without
> > >> changing anything. So then I subscribed to this list to announce it.
> > >>
> > >> Of course, that's when I discovered
> > >> http://users.actrix.co.nz/michael/usbmount.html by Michael Hamilton.
> > >>
> > >> So I'll first give a rundown of differences:
> > >> My solution:
> > >> - only mounts the device that was just inserted (with some luck)
> > >> - is called automount_usb, so that, by changing the
> > usb.usermap, it gets
> > >> called every time a device is inserted and not just the first time
> > >> - creates remover scripts that have /bin/sh as the only dependency
> > >> - creates nicely readable names as mount points
> > >> - supports devices with multiple partitions
> > >> - is really small
> > >>
> > >> But Michael's solution:
> > >> - makes KDE icons
> > >> - is easier to read
> > >>
> > >> So, please have a look at the attached code, and tell me what you think
> > >> about the device detection code. Michael, if you read this, we could
> > >> perhaps merge the two efforts and get all the features.
> > >>
> > >> Also, let's start a thread on making a gui.agent script that
> > gets called
> > >> by the hotplug scripts. It would notify the user of hotplug events.
> > >> I feel that it should be called with the same environment as the other
> > >> agents, with an extra HOTPLUG_PATH variable indicating the
> > path on which
> > >> the device is available, if applicable.
> > >>
> > >> This could then be used by KDE, Gnome etc to notify the user.
> > >>
> > >> Cheers,
> > >>
> > >> Wout.
> > >>
> > >> PS: /Please/ change usb.agent so that it creates /var/run/usb/ before
> > >> pointing remover scripts there...
> > >> ["automount_usb" (TEXT/PLAIN)]
> > >>
> > >> #!/bin/sh
> > >> # Automount hotplugged usb storage devices. Copyright (c)
> > 2002, Wout Mertens
> > >> # This script is released under the GPL.
> > >>
> > >> # The usb devices will be mounted for the console user.
> > >> # To work, this needs:
> > >> # - kernel support:
> > >> # - hotplugging, /proc, usbdevfs and devfs
> > >> # - as modules: usb-storage, sd_mod, scsi_mod
> > >> # - filesystems that will be mounted, like vfat
> > >> # - ls, tr, echo, awk, basename, stat, grep, mount, umount,
> > mkdir, rm, sed
> > >>
> > >> # TODO Fix usb.agent so that /var/run/usb gets created if missing
> > >> # TODO Some rigid way of getting this run. Currently, I do
> > >> # grep usb-storage /lib/modules/*/modules.usbmap|sed
> > >> 's/usb-storage/automount_usb/' \
> > >>>> /etc/hotplug/usb.usermap # TODO Lots of testing
> > >> # TODO nice way of setting options
> > >> # TODO Also, the error checking should probably be more robust
> > >> # TODO Some clean way of handling disconnects while writing.
> > >> # TODO Make a generic event system for GUIs that shows that
> > something was
> > >> # mounted for the user. Proposal: /etc/hotplug/gui.agent gets
> > >> # called with ACTIONd/remove, NAME=nice_name, PATH=new_path, etc.
> > >> # Not just for new storage, scanners and so on are useful too...
> > >>
> > >> # Dump debug
> > >> mesg () {
> > >> #return
> > >> /usr/bin/logger -t $0 "$*"
> > >> }
> > >>
> > >> # Figure out the device to mount
> > >> NUM=`basename $DEVICE|sed 's/^0*//'`
> > >> SERIAL=`awk -F= '/^T:.*/{if($0~/Dev#= *'$NUM' \
> > >> /){t=1}else{t=0}}t=1&&/SerialNumber/{print $2;exit}'
> > /proc/bus/usb/devices`
> > >> \
> > >> PRODUCT=`awk -F= '/^T:.*/{if($0~/Dev#= *'$NUM'
> > >> /){t=1}else{t=0}}t=1&&/Product/{print \
> > >> $2;exit}' /proc/bus/usb/devices` # Use the serial or the
> > product name to
> > >> find which \
> > >> scsi host was just created if [ -n "$SERIAL" ]; then
> > >> SCSI=`grep -l $SERIAL /proc/scsi/usb-storage-*/*|tail -1`
> > >> elif [ -n "$PRODUCT" ]; then
> > >> SCSI=`grep -l $PRODUCT /proc/scsi/usb-storage-*/*|tail -1`
> > >> fi
> > >>
> > >> mesg Device No. $NUM, serial $SERIAL, name $PRODUCT, path $SCSI
> > >>
> > >> # Mount it
> > >> if [ -n "$SCSI" ]; then
> > >> # The name of the file is the number of the SCSI host
> > >> SCSI=`basename $SCSI`
> > >> PARTS=`ls /dev/scsi/host$SCSI/*/*/*/part*`
> > >> MOUNTPATH=/mnt/usb/`echo $PRODUCT|tr '[ /?*"]' _`
> > >> if [ -e "$MOUNTPATH" ]; then
> > >> if mount|grep "$MOUNTPATH">/dev/null; then
> > >> # TODO I'm too lazy to write proper collision avoidance code
> > >> MOUNTPATH="$MOUNTPATH".$$
> > >> fi
> > >> fi
> > >> # I'm hoping that mount ignores options that don't apply to the fs
> > >> # These options should prevent abuse and make it writeable for the
> > >> # console user.
> > >> MOUNTOPTS='-osync,nosuid'`stat -c',uid=%u,gid=%g' /dev/console`
> > >> mesg Mounting $PARTS on $MOUNTPATH, options $MOUNTOPTS
> > >>
> > >> [ `echo $PARTS|wc -w` -eq 1 ] && MOUNTDIRECT=1
> > >> REMOVE> > >> for i in $PARTS; do
> > >> if [ -n "$MOUNTDIRECT" ]; then
> > >> T=$MOUNTPATH
> > >> else
> > >> T=$MOUNTPATH/`basename $i`
> > >> fi
> > >> mkdir -p $T
> > >> if mount $MOUNTOPTS $i $T; then
> > >> REMOVE="umount $T;$REMOVE;rmdir $T"
> > >> else
> > >> rmdir $T
> > >> fi
> > >> done
> > >>
> > >> # Create remover
> > >> echo "#!/bin/sh" > $REMOVER
> > >> echo $REMOVE | sed 's/;;/;/g' >> $REMOVER
> > >> chmod +x $REMOVER
> > >> else
> > >> exit 1
> > >> fi
> > >>
> > >>
> > >>
> > >>
> > >>
> > >>
> > >>
> > >>
> > >>
> > >> -------------------------------------------------------
> > >> This sf.net email is sponsored by:ThinkGeek
> > >> Welcome to geek heaven.
> > >> http://thinkgeek.com/sf
> > >> _______________________________________________
> > >> Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
> > >> Linux-hotplug-devel@lists.sourceforge.net
> > >> https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
> > >>
> > >
> > >
> > > -------------------------------------------------------
> > > This SF.NET email is sponsored by:
> > > SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
> > > http://www.vasoftware.com
> > > _______________________________________________
> > > Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
> > > Linux-hotplug-devel@lists.sourceforge.net
> > > https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
> >
> >
>
>
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: My first usb storage automount script :)
2002-12-11 16:22 My first usb storage automount script :) Wout Mertens
` (4 preceding siblings ...)
2003-01-07 20:37 ` Wout Mertens
@ 2003-01-07 22:07 ` Tom Clark
5 siblings, 0 replies; 7+ messages in thread
From: Tom Clark @ 2003-01-07 22:07 UTC (permalink / raw)
To: linux-hotplug
That's pretty much it. The logic is more or less:
On mass storage hotplug, try to mount FS.
If mount fails, start daemon which tries again every N seconds.
If mount succeeds, start daemon which tries to read N sectors every N
seconds.
If read fails, umount the FS and start waiting again.
Keeping a hash is a good idea to bulletproof the whole thing.
-tc
on 1/7/03 12:37 PM, Wout Mertens at wmertens@cisco.com wrote:
> Maybe a possible check would be to try to read the first few sectors
> (partition table and boot record), and keep an md5 hash. If it changes, do
> the sensible thing... Could be faster and less resource intensive than
> trying to mount it.
>
> Wout.
>
> On Tue, 7 Jan 2003, Eddie Shi wrote:
>
>> That's it, I think Window's must have done the same thing you described.
>> BTW, when you say "ping it to make sure card is not removed", do you mean
>> that you try to mount it and check the status return from the mount?
>>
>> Thanks for the feedback.
>>
>> Eddie
>>
>>> -----Original Message-----
>>> From: Tom Clark [mailto:tclark@mac.com]
>>> Sent: Tuesday, January 07, 2003 6:56 AM
>>> To: linux-hotplug-devel@lists.sourceforge.net
>>> Cc: Eddie Shi; Wout Mertens
>>> Subject: Re: My first usb storage automount script :)
>>>
>>>
>>> The problem is you need a notification in the first place that a card has
>>> been inserted. Unfortunately, I don't think any card readers on
>>> the market
>>> provide this functionality. I've only been able to solve this with a kind
>>> of daemon that periodically tries to mount the card reader's
>>> filesystem and
>>> then pings it occasionally to make sure the card hasn't been
>>> removed. It's
>>> ugly and wasteful, but what other alternative is there?
>>>
>>> -tc
>>>
>>> On 1/7/03 4:37 AM, "Wout Mertens" <wmertens@cisco.com> wrote:
>>>
>>>> Hmmm,
>>>>
>>>> Only one way to find out :)
>>>>
>>>> The script is real easy to install, just copy it to
>>> /etc/hotplug, and run
>>>> the line that registers it (you can find it inside the script).
>>>>
>>>> I think the issue will be if the card reader sends usb
>>> plug/unplug events
>>>> or not... if it doesn't, I really wouldn't know how to do it.
>>>>
>>>> Actually, there's an easier way to test:
>>>> Plug in the reader, have hotplug enabled, and watch /var/log/messages to
>>>> see what the kernel thinks is happening. If you see messages every time
>>>> you plug/unplug a card, you're lucky, and it will probably work.
>>>>
>>>> Good luck,
>>>>
>>>> Wout.
>>>>
>>>> On Fri, 3 Jan 2003, Eddie Shi wrote:
>>>>
>>>>> Hi,
>>>>> Does anyone know whether this will work on the following situation:
>>>>>
>>>>> 1. The usb-storage device (ie USB card reader) is alreay
>>> plugged in the
>>>>> system.
>>>>>
>>>>> 2. No CF/MS/SM/SD are plugged in yet.
>>>>>
>>>>> Given the above assumption , Will the system automount the
>>> CF when the CF
>>>>> card is plugged in ? Or We still need to manually enter " mount -t vfat
>>>>> /dev/sda1 /cf ".
>>>>>
>>>>> I guess what I would like to see is to have something like
>>> CD's automount
>>>>> when a CD is inserted.
>>>>>
>>>>>
>>>>> Thanks
>>>>>
>>>>>
>>>>> Eddie
>>>>>
>>> ------------------------------------------------------------------
>>> ----------
>>>>> ------------------
>>>>> Hi there,
>>>>>
>>>>> I just wanted to share what I hacked up through some
>>> frustration. It's a
>>>>> script that will automatically mount usb devices that are attached.
>>>>>
>>>>> It ties in to the hotplug architecture as closely as possible, without
>>>>> changing anything. So then I subscribed to this list to announce it.
>>>>>
>>>>> Of course, that's when I discovered
>>>>> http://users.actrix.co.nz/michael/usbmount.html by Michael Hamilton.
>>>>>
>>>>> So I'll first give a rundown of differences:
>>>>> My solution:
>>>>> - only mounts the device that was just inserted (with some luck)
>>>>> - is called automount_usb, so that, by changing the
>>> usb.usermap, it gets
>>>>> called every time a device is inserted and not just the first time
>>>>> - creates remover scripts that have /bin/sh as the only dependency
>>>>> - creates nicely readable names as mount points
>>>>> - supports devices with multiple partitions
>>>>> - is really small
>>>>>
>>>>> But Michael's solution:
>>>>> - makes KDE icons
>>>>> - is easier to read
>>>>>
>>>>> So, please have a look at the attached code, and tell me what you think
>>>>> about the device detection code. Michael, if you read this, we could
>>>>> perhaps merge the two efforts and get all the features.
>>>>>
>>>>> Also, let's start a thread on making a gui.agent script that
>>> gets called
>>>>> by the hotplug scripts. It would notify the user of hotplug events.
>>>>> I feel that it should be called with the same environment as the other
>>>>> agents, with an extra HOTPLUG_PATH variable indicating the
>>> path on which
>>>>> the device is available, if applicable.
>>>>>
>>>>> This could then be used by KDE, Gnome etc to notify the user.
>>>>>
>>>>> Cheers,
>>>>>
>>>>> Wout.
>>>>>
>>>>> PS: /Please/ change usb.agent so that it creates /var/run/usb/ before
>>>>> pointing remover scripts there...
>>>>> ["automount_usb" (TEXT/PLAIN)]
>>>>>
>>>>> #!/bin/sh
>>>>> # Automount hotplugged usb storage devices. Copyright (c)
>>> 2002, Wout Mertens
>>>>> # This script is released under the GPL.
>>>>>
>>>>> # The usb devices will be mounted for the console user.
>>>>> # To work, this needs:
>>>>> # - kernel support:
>>>>> # - hotplugging, /proc, usbdevfs and devfs
>>>>> # - as modules: usb-storage, sd_mod, scsi_mod
>>>>> # - filesystems that will be mounted, like vfat
>>>>> # - ls, tr, echo, awk, basename, stat, grep, mount, umount,
>>> mkdir, rm, sed
>>>>>
>>>>> # TODO Fix usb.agent so that /var/run/usb gets created if missing
>>>>> # TODO Some rigid way of getting this run. Currently, I do
>>>>> # grep usb-storage /lib/modules/*/modules.usbmap|sed
>>>>> 's/usb-storage/automount_usb/' \
>>>>>>> /etc/hotplug/usb.usermap # TODO Lots of testing
>>>>> # TODO nice way of setting options
>>>>> # TODO Also, the error checking should probably be more robust
>>>>> # TODO Some clean way of handling disconnects while writing.
>>>>> # TODO Make a generic event system for GUIs that shows that
>>> something was
>>>>> # mounted for the user. Proposal: /etc/hotplug/gui.agent gets
>>>>> # called with ACTIONd/remove, NAME=nice_name, PATH=new_path, etc.
>>>>> # Not just for new storage, scanners and so on are useful too...
>>>>>
>>>>> # Dump debug
>>>>> mesg () {
>>>>> #return
>>>>> /usr/bin/logger -t $0 "$*"
>>>>> }
>>>>>
>>>>> # Figure out the device to mount
>>>>> NUM=`basename $DEVICE|sed 's/^0*//'`
>>>>> SERIAL=`awk -F= '/^T:.*/{if($0~/Dev#= *'$NUM' \
>>>>> /){t=1}else{t=0}}t=1&&/SerialNumber/{print $2;exit}'
>>> /proc/bus/usb/devices`
>>>>> \
>>>>> PRODUCT=`awk -F= '/^T:.*/{if($0~/Dev#= *'$NUM'
>>>>> /){t=1}else{t=0}}t=1&&/Product/{print \
>>>>> $2;exit}' /proc/bus/usb/devices` # Use the serial or the
>>> product name to
>>>>> find which \
>>>>> scsi host was just created if [ -n "$SERIAL" ]; then
>>>>> SCSI=`grep -l $SERIAL /proc/scsi/usb-storage-*/*|tail -1`
>>>>> elif [ -n "$PRODUCT" ]; then
>>>>> SCSI=`grep -l $PRODUCT /proc/scsi/usb-storage-*/*|tail -1`
>>>>> fi
>>>>>
>>>>> mesg Device No. $NUM, serial $SERIAL, name $PRODUCT, path $SCSI
>>>>>
>>>>> # Mount it
>>>>> if [ -n "$SCSI" ]; then
>>>>> # The name of the file is the number of the SCSI host
>>>>> SCSI=`basename $SCSI`
>>>>> PARTS=`ls /dev/scsi/host$SCSI/*/*/*/part*`
>>>>> MOUNTPATH=/mnt/usb/`echo $PRODUCT|tr '[ /?*"]' _`
>>>>> if [ -e "$MOUNTPATH" ]; then
>>>>> if mount|grep "$MOUNTPATH">/dev/null; then
>>>>> # TODO I'm too lazy to write proper collision avoidance code
>>>>> MOUNTPATH="$MOUNTPATH".$$
>>>>> fi
>>>>> fi
>>>>> # I'm hoping that mount ignores options that don't apply to the fs
>>>>> # These options should prevent abuse and make it writeable for the
>>>>> # console user.
>>>>> MOUNTOPTS='-osync,nosuid'`stat -c',uid=%u,gid=%g' /dev/console`
>>>>> mesg Mounting $PARTS on $MOUNTPATH, options $MOUNTOPTS
>>>>>
>>>>> [ `echo $PARTS|wc -w` -eq 1 ] && MOUNTDIRECT=1
>>>>> REMOVE>>>>> for i in $PARTS; do
>>>>> if [ -n "$MOUNTDIRECT" ]; then
>>>>> T=$MOUNTPATH
>>>>> else
>>>>> T=$MOUNTPATH/`basename $i`
>>>>> fi
>>>>> mkdir -p $T
>>>>> if mount $MOUNTOPTS $i $T; then
>>>>> REMOVE="umount $T;$REMOVE;rmdir $T"
>>>>> else
>>>>> rmdir $T
>>>>> fi
>>>>> done
>>>>>
>>>>> # Create remover
>>>>> echo "#!/bin/sh" > $REMOVER
>>>>> echo $REMOVE | sed 's/;;/;/g' >> $REMOVER
>>>>> chmod +x $REMOVER
>>>>> else
>>>>> exit 1
>>>>> fi
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> -------------------------------------------------------
>>>>> This sf.net email is sponsored by:ThinkGeek
>>>>> Welcome to geek heaven.
>>>>> http://thinkgeek.com/sf
>>>>> _______________________________________________
>>>>> Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
>>>>> Linux-hotplug-devel@lists.sourceforge.net
>>>>> https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
>>>>>
>>>>
>>>>
>>>> -------------------------------------------------------
>>>> This SF.NET email is sponsored by:
>>>> SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
>>>> http://www.vasoftware.com
>>>> _______________________________________________
>>>> Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
>>>> Linux-hotplug-devel@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
>>>
>>>
>>
>>
>
>
> -------------------------------------------------------
> This SF.NET email is sponsored by:
> SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
> http://www.vasoftware.com
> _______________________________________________
> Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
> Linux-hotplug-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2003-01-07 22:07 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-12-11 16:22 My first usb storage automount script :) Wout Mertens
2003-01-03 23:27 ` Eddie Shi
2003-01-07 12:37 ` Wout Mertens
2003-01-07 14:56 ` Tom Clark
2003-01-07 19:13 ` Eddie Shi
2003-01-07 20:37 ` Wout Mertens
2003-01-07 22:07 ` Tom Clark
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).