NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: how to use amd?



On Mon, 6 Oct 2008, Jeremy C. Reed wrote:
(My real goal is to be able to enter my memory card and have it
automatically mounted and maybe even have a X11 filemanager open to that
directory.)

I want to use amd to mount a directory when I go to it. I will use
/camera. It is my sd0 which is a sdmmc2 memory card (I am using
uncommitted code for this which works fine for me).
[snip]

I won't try to pick your example apart, I'll just take the easy way out and tell you what works for me...

My /etc/amd.conf:
[ global ]
print_pid = no
restart_mounts = yes
search_path = /etc
log_file = /var/log/amd
log_options = all
browsable_dirs = yes
unmount_on_exit = no
dismount_interval = 5
cache_duration = 5
search_path = /etc

[ /mnt ]
map_name = amd.local

My /etc/amd.local (all on one line):

usb type:=program;opts:=utimeout=20;mount:="/etc/devmount devmount mount sd0 
${autodir}/${rhost}/${path}";unmount:="/etc/devmount devmount umount sd0 
${autodir}/${rhost}/${path}"

My /etc/devmount file is just a wrapper that checks the disklabel for a MSDOS partition before mounting. This is because USB drives don't always have fdisk partitions and so you must mount the raw partition:

#!/bin/sh
# $Revision: 1.2 $

dev=$2
dir=$3

do_disklabel()
{
        local ret
        disklabel /dev/r${1}d 2>/dev/null
        ret=$?
        [ $ret -lt 100 -a $ret -gt 0 ] && echo "exit $?"
}

case "$dev" in
sd*)
        part=`do_disklabel $dev | awk 'BEGIN{
                part="d"
        }{
                if($1=="exit") exit($2)
                if($1=="total" && $2=="sectors:" && $3=="2880") {
                        part="d"
                        exit
                }
                if($4=="MSDOS") {
                        sub(":","",$1)
                        part=$1
                        exit
                }
        }
        END{
                print part
        }'`
        [ "$?" != 0 -o -z "$part" ] && exit 1
        ;;
fd*)
        part=a
        ;;
*)
        exit
        ;;
esac

case "$1" in mount)
        mount_msdos -l -M 0777 -m 0666 -o nocoredump,nodev,noexec,nosuid 
/dev/${dev}${part} $dir || exit 1
        ;;
umount)
        umount $dir || exit 1
        ;;
print)
        echo /dev/${dev}${part}
        ;;
*)
        exit 1
        ;;
esac
exit 0

If you don't want any of this you could just use the following /etc/amd.local:

usb type:=pcfs;opts:=utimeout=20,sync,nodev,noexec,nocoredump;dev:=/dev/sd0e

I start amd with command_args:
-l /dev/null -p -a /amd -F /etc/amd.conf >/var/run/amd.pid

In the interests of full disclosure, I'll state that actually I have a custom /etc/rc.d/amd script that generates the amd.local file in the fly with mount points for 4 USB devices, CDROM and floppy (if the latter two are present). It also checks the parents of any existing sd(4) devices and skips them if they are not umass devices (i.e. if they are attached to a real SCSI controller) so that what it exports as the first USB device isn't necessary sd0.

--
Stephen


Home | Main Index | Thread Index | Old Index