Getting FreeBSD to recognize my Defy's SD card

When I connect my Motorola Defy phone to my FreeBSD desktop via USB, the usb subsystem checks if there's any mountable media available on the newly connected device. Unfortunately the phone only switches to "Memory card access" mode after it notices the connection, and by this time the media detection from the desktop fails with "NOT READY" error.

Apparently the device will only be rescanned ("retasted") when a write request is issued to the device, so a manual workaround is to issue the following command after the phone has switched to "Memory card access" mode:

dd count=0 if=/dev/null of=/dev/da0

To automate this, I created a small shell script that executes this "fake" write after a short delay, and added a devd rule to invoke this script when the usb device is detected:



( /bin/sleep 3 && /bin/dd count=0 if=/dev/null of=/dev/$1 >/dev/null 2>/dev/null ) &


notify 200 { 
    match "cdev" "da[0-9]+$";
    match "system" "DEVFS";
    match "subsystem" "CDEV";
    match "type" "CREATE";
    action "/opt/DefySD.sh $cdev"; 

After restarting devd, I could auto-mount my SD card from KDE like any other "normal" USB stick.