how to determine filesystem and mount hotplug device
I'm very new to linux programming, and I'm not sure if this is the right forum to post this in, but here goes:
I'm trying to write program that responds to hotplug event messages on the netlink socket when a USB device is plugged in. It should query the device to find out if it is a block device and if so, what (if any) file system is on the device, and then mount the device if it is a block device with a supported file system. If the mount is successful, it should list the root directory of the device on stdout.
So far, I have been able to recognize the events which happen when an SD card is plugged in. Then I watch /etc/mtab for changes that match the device name, and extract the file system from the new entry in mtab.
Not only does this strike me as inelegant and inefficient but, unfortunately, it only works for devices for which udev rules already exist. Even more unfortunately, I have not been able to determine which udev rules are involved in the process.
In any case, I would like to extract the information I need from the hotplug events themselves, so the program will work for any device, whether or not it has ever been seen before.
After much searching, I can't find any books, web pages or forum threads that address this question. I assume that I must be wording the question wrong, due to my lack of familiarity with the Linux Way.
Can anyone help me out with this?