how to notify an application when a usb flash drive gets connected..
hello everyone,
i am not sure where to start looking for what i want, which is as stated in the title, a way to notify an application that a usb has been connected. so that then the application can mount the file system and do some IO operations.
Any hints and pointers as to what header file is suitable to do that (in linux) as well as any other pointers you have to offer are very welcome.
thank you for your help
nass
Re: how to notify an application when a usb flash drive gets connected..
Sounds like a job for HAL and DBUS.
Re: how to notify an application when a usb flash drive gets connected..
thank you for your fast reply.
hmmm it looks it might be a generally appropriate technique,
however is there some simpler technique of the form
if the kernel (using hotplug or other means) realises that there a usb device has been connected, it should send a singal (SIGUSR1 or some other) which then i can intercept from within the application (and i can do a printf() or smth).
nass
Re: how to notify an application when a usb flash drive gets connected..
Quote:
Originally Posted by
nass
however is there some simpler technique of the form
if the kernel (using hotplug or other means) realises that there a usb device has been connected,
Currently hotplug uses hal to do its job.
Quote:
it should send a singal (SIGUSR1 or some other) which then i can intercept from within the application (and i can do a printf() or smth).
A unix signal is sent to a particular application, so you can't simply "attach" to a signal.
As an alternative you could try to monitor the file system (either /etc/fstab or /mnt/something) if you are sure that the device will be automounted in a particular location but this method might fail, so using HAL is a preffered solution.
Re: how to notify an application when a usb flash drive gets connected..
ok u convinced me:D
i will look into it thoroughly
thank you once again.
nass
Re: how to notify an application when a usb flash drive gets connected..
Quote:
As an alternative you could try to monitor the file system (either /etc/fstab or /mnt/something) if you are sure that the device will be automounted in a particular location but this method might fail, so using HAL is a preffered solution.
How about /proc ?
Re: how to notify an application when a usb flash drive gets connected..
Quote:
Originally Posted by
sunil.thaha
How about /proc ?
What about it?
Re: how to notify an application when a usb flash drive gets connected..
Quote:
Originally Posted by
sunil.thaha
How about /proc ?
Yes, but not every system allows normal users to dig inside it. A similar solution is to use libusb and look from time to time for new devices.
Re: how to notify an application when a usb flash drive gets connected..
Quote:
Originally Posted by
sunil.thaha
How about /proc ?
The problem with /proc is that Linux treats it entirely different than do other Unix and Unix-like systems. Basing an application on Linux's procfs behavior means that it won't work under BSD, Solaris, etc. I would look for a better crossplatform approach.
Re: how to notify an application when a usb flash drive gets connected..
Furthermore /proc under Linux starts to be deprecated in favour of /sys so there is a probability that /proc (or at least most of its functionality) will soon vanish from some Linux distros.
Re: how to notify an application when a usb flash drive gets connected..
Waw!!
Didn't know all of those... Cross platform, Deprecated !!!
Thanks for sharing the info, Guys