static umass numbering

Christopher Sean Hilton chris at vindaloo.com
Wed Jan 26 05:59:12 PST 2005


On Tue, 2005-01-18 at 11:36 +0100, Robert Blacquiere wrote:
> Hi folks,
> 
> I have got a couple of usb mass storage devices which work nicely with FreeBSD.
> But they are numbered chronological on insertion. I would like some sort of
> static numbering scheme for easing up for example automounting. 
> Now i use a hand script which take de base da[0-9]+ numbering as var but hate 
> this way of working. 

I'm not sure what you are trying to do but I handled this in 5.3 by
ensuring that the slice and partition layout on all such devices was
uniform. Then I installed a uniformly named script on each drive. The
script can be tailored to provide whatever function the drive supports. 

I use the following layout:

    Slice 1: MSDOS
    Slice 2: FreeBSD
      Partition e: General purpose for automounting
      Partitions a,d,f-h: special purpose

In /etc/amd.map and /etc/fstab I have entries to mount the MSDOS and
FreeBSD partitions from each possible drive:

     /dev/da0s1  --> /amd/msdos0
     /dev/da0s2e --> /amd/da0

     /dev/da1s1  --> /amd/msdos1
     /dev/da1s1e --> /amd/da1

Finally I arrange for devd to run a script from the drive when a new
da[0-9]+ device is attached to the kernel. The devd knows which drive
was attached (da[0-9]+) and can pass that into the script:

     #! /bin/sh

     ...

     device=$1; shift

     ## Use this test to automount the device.

     if test -d /amd/${device}/.; then

         ## Now see if this device has an autorun.sh script for use
         ## on attach.

         if test -f /amd/${device}/autorun.sh; then
             (cd /amd/${device} && sh autorun.sh ${device})
         fi
     fi


Up to here it's basic shell scripting. The problem with all this is that
it all happens as root which I didn't want. So I wrote a daemon and
client which allows the root owned devd process to trigger a user owned
process when a message got passed on a unix domain socket.

-- chris



More information about the freebsd-mobile mailing list