SD card automount

I'm working on replacing Debian Squeeze with FreeBSD 8.2 for a kiosk machine and one of the last quirks to iron out is FreeBSD's handling of SD cards.

My problem is that upon boot or inserting the card reader (without the SD card) /dev/da0 is created so inserting/pulling out the SD card does not create any events I know of.

Code:
Dec  9 03:52:51 zero kernel: da0 at umass-sim0 bus 0 scbus0 target 0 lun 0
Dec  9 03:52:51 zero kernel: da0: <Generic- Card Reader 1.00> Removable Direct Access SCSI-0 device
Dec  9 03:52:51 zero kernel: da0: 40.000MB/s transfers
Dec  9 03:52:51 zero kernel: da0: Attempt to query device size failed: NOT READY, Medium not present

When inserting the SD card now there is no action but if I do e.g. [cmd=]true > /dev/da0[/cmd] the system works as intended - /dev/da0s1 is created and devd runs my mount script so the SD card is mounted the correct way.

However this is not optimal for a kiosk solution where the user has no keyboard mouse and the system is supposed to unlock/react to the SD card being inserted. This was trivial to set up in Debian via udev but I can't figure out how to get the same functionality in FreeBSD.

Any help would be appreciated - the kiosk boots with the card reader attached and then users inserts/pulls out their SD cards and I need to run a script based upon insertion/pulling out.
 
Miklos said:
This was trivial to set up in Debian via udev but I can't figure out how to get the same functionality in FreeBSD.
The FreeBSD equivalent is devd(8) and devd.conf(5).

Keep in mind that detaching a mounted filesystem may result in a panic.
 
Yes I'm using devd for automounting/calling scripts but I can only get devd to detect on /dev/* create/destroy where as udev is event on the bus.

What I need is a way for da0 not to be created when the card reader is attached but when a card is inserted expose da0 to the system.

Unmounting is another problem as the user of the kiosk might just pull out the sd card and I need to be able to detect that and unmount it immediately.
 
My two-slot card reader always creates da0 and da1 when attached. But loading a card creates da?s1. (If the card has an MBR, like most but not all. Don't know what to do if it just has a plain filesystem.) devd(8) can detect that:
Code:
  match "system" "DEVFS";
  match "type" "CREATE";
  match "cdev" "da[0-9]s1$";

Panic on unexpected detach is not an issue since FreeBSD 8.2 or so. Pending writes will be lost, though.

The freebsd-usb mailing list is more likely to be able to help.
 
Sadly, devd(8) doesn't handle these cases for some reason. What you need to do is poll the device with camcontrol(8), issuing a Test Unit Ready (tur) command to see the media state of the device.

You can take a look at [thread=27233]volman[/thread] if you want to see how I handle it there.
 
Back
Top