AnsweredAssumed Answered

checking usb flash drive presence and receiving its add/remove notifications

Question asked by monsta on Feb 1, 2012
Latest reply on Feb 3, 2012 by monsta

Hello all.

 

One of the programs I work on involves the following simple workflow:

1. Check if a flash drive is plugged into usb port.

2. If it is, mount it and do some work with files.

3. umount it and wait until it's physically removed.

 

So I need some way to manually check flash drive presence and some way to wait for its remove notification.

What I have: BF533-based board with single usb port, uClinux 2009R1-RC6, hotplug and mdev enabled. I plan to move to uClinux 2011R1-RC3 someday.

What isn't there and probably won't be: udev, fresh enough to feature libudev with a stable api ( >= 147 I think).

 

udev seems to be too heavy for uClinux, so the easiest way of both checking the drive status and waiting for notifications isn't available. I tried some other options.

inotify doesn't work with /sys where all the devices' info is stored.

libsysfs works but doesn't have notifications. Also one of the kernel docs named sysfs-rules.txt states that libsysfs is bad and you should parse /sys manually.

Netlink interface is suitable for receiving add/remove notifications, but I see no way to manually check if a drive is plugged.

Finally, there's mdev available for receiving device notifications (via scripts), but not for manual device polling.

 

Can anyone give a hint about the preferred ways of checking flash drive presence and receiving its notifications?

Outcomes