[PLUG] autofs executable map for automount of floppy

karlheg at pdxLinux.org karlheg at pdxLinux.org
Fri Aug 30 11:27:47 UTC 2002


I was trying to use a static automounter map for removable media, and
ran into a snag.  I wanted it to, if the diskette is a Windows disk,
mount it with the "uid=0,gid=25,umask=002" options, so that the
diskette will be writable by GID 25 (floppy).  But if it's a Linux
native file system disk, I want to mount with options appropriate for
that file system.

I was trying to use a static map with "-fstype=auto" and a set of
options that was the union of the option sets for all file system
types that I'd want to mount.  That setup does not work!  It fails to
mount ext2fs diskettes, erroring on unsupported mount options.  I
reported the problem in:

<URL:http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=128616&repeatmerged=yes>

Today I came up with a solution.  Here it is, for all to use and
enjoy...  The "autofs" automounter supports an executable map.  It
runs your script, handing it the "key", and your script prints what
would be the right hand side of the static map.

Now I can put a diskette in the floppy drive, and access it at
"/mnt/rem/floppy".  One second after nothing is using the diskette, it
is umounted.  The "sync" mount option ensures that even if somebody
ejects the diskette before it's truely umounted, the data will still
make it to the diskette before the light winks out.

It sucks that we must use floppy drives that have a physical eject
button on them, rather than one that only _requests_ an eject, like on
a Zip drive or CDROM.  On those, the eject button should not open the
drawer until the disc is really umounted.  (and then we need an easy
(gui) way to discover what is keeping a disc active and thus un
umountable)

8<------------------------------------------------------------>8
#!/bin/sh
#
# autofs executable map for removable media
#
# Karl M. Hegbloom <karlheg at pdxlinux.org>
#
key="$1"

me=$(basename $0)

echo "$me: key is '$key'" >&2

PATH=/usr/sbin:/usr/bin:/sbin:/bin

tmpfile=$(tempfile)

case "$key" in
    floppy)
	dd if=/dev/fd0 of=$tmpfile bs=512 count=4 2>/dev/null
	file_says=$(file $tmpfile)
	rm -f $tmpfile
	if echo $file_says | grep -iq 'x86 boot sector'
	then
	    echo "$me: Diskette contains vfat or msdos filesystem" >&2
	    echo '-fstype=vfat,sync,uid=0,gid=25,umask=002 :/dev/fd0'
	else
	    echo '-fstype=auto,sync,nosuid,nodev :/dev/fd0'
	fi
	;;

    cdrom)
	echo "-fstype=iso9660,nodev,nosuid,ro :/dev/cdrom"
	;;

    *)
	echo "$me: Unknown removable device mountpoint: $key" >&2
	exit 1
	;;
esac
exit 0
8<------------------------------------------------------------>8

-- 
As any limb well and duly exercised, grows stronger,
the nerves of the body are corroborated thereby. --I. Watts.  .''`.
 Debian -- The blue collar Linux distribution.               : :' :
 <URL:http://www.debian.org/social_contract>		     `. `'




More information about the PLUG mailing list