Determining disk device and kicking GEOM when doing automatic mounting of umass devices

Darren Pilgrim dmp at bitfreak.org
Fri Jun 10 01:58:53 GMT 2005


I want to have a devd entry that automatically mounts umass devices when
they get attached.  The problem is figuring out which device to mount and
then getting the correct devices created.  For example, the entry for my
thumbdrive:

attach 1000 {
	device-name "umass[0-9]+";
	match "vendor" "0x08ec";
	match "product" "0x0015";
	match "sernum" "0C50935151F0EA20";
	action "$scripts/mount_umass.sh $device-name msdosfs /stickdrive";
};

The mount_umass.sh script is as follows:

---BEGIN FILE---
sleep 10

scsidev="`echo ${1} | sed s/umass/umass-sim/g`"
diskdev="`camcontrol devlist -v | grep -A 1 ${scsidev} | tail -n 1 | \
	awk -F "(" '{ print $2 }' | awk -F "," '{ print $1 }'`"
fstype="${2}"
mountpoint="${3}"

mount -t ${fstype} /dev/${diskdev} ${mountpoint} 2>/dev/null
mount -t ${fstype} /dev/${diskdev}s1 ${mountpoint} 2>/dev/null
----END FILE----

First, the script has to sleep because the device doesn't immediately show
up in the CAM device list.  After waiting long enough to be safe, the script
takes the device name passed by devd and uses it to parse the device name
from the output of `camcontrol devlist`.  GEOM doesn't automatically read
the partition table and create the slice device, so the script forces it to
do so by trying to mount the base device before mounting the actual
partition.

These tricks are ridiculous, IMO.  There has to be a more intelligent means
of going about this.  How do I get the scsi disk device name created for a
umass device as soon as it's created?  How do I inform GEOM that it needs to
add a new MBR to it's configuration and create the appropriate /dev/da?s*
devices?




More information about the freebsd-hackers mailing list