How to detect usb storage arrival and its mount path from C

Hi, I am a newbi to linux,
i wana to write a program in C that can detect arrival of a usb flash memory. I want also to find the actual mount point of new inserted flash disk. can anyone help me?
thanks a lot

This has already been done. Check out the source code for HALD. IIRC, it is written in C.

what is IIRC?

read documentation for /sbin/hotplug and /sys pseudo-filesystem

and also udev(7), udevmonitor(8)

If I Recall Correctly
If I Remember Correctly

Here is the C source code for a demo program written by me which does pretty much what you want to do. I tested it on a vanilla Centos 5.2 box. It uses DBUS to talk to HAL and Glib's g_main_loop_run to handle events. Enjoy!

1 Like