Skip to contentSkip to conversation

How to detect whether media is present in a reader?

DISCUSSION Michael Hamilton 4 participants 7 messages Jun 9, 2004 – Jun 14, 2004

lore
Share & tools
lore
#0 lore raw

I've attempted to develop a desktop integration script for usb storage devices. ( http://freshmeat.net/projects/usbmount/ )

Before anyone reading this thinks this a trivial problem, you should read the requirements/issues detailed at the bottom of http://users.actrix.co.nz/michael/usbmount.html - many aspects of the USB/SCSI system make this task much harder than it should be. I would recommend anyone working on this area to take a look at my script and see the fun currently involved - and then see if what they're working on will make life easier.

In the mean time, working with what is available on current distributions, I'm looking for a solution to one piece of the puzzle...

I would like to be able to detect whether media is present in a reader or not (eg Compact Flash Card reader). A small piece of C for efficiently obtaining the media state would be good. I would like a solution for both 2.4 and 2.6, but I'll settle for what I can get. Does anyone have some sample code?

From looking at what's available I get the impression that some variant on polling is the only solution for such problems. Is this really the case - even for USB?

I've looked at supermount and submount - I'm not sure they offer a better solution than my own attempts thus far - I don't think they can tackle all of the requirements listed on my webpage.

I was also playing with sginfo from sg3_utils (
http://www.torque.net/sg/u_index.html ). But this can be slow, and, in the absence of media, some of the sg3_utils probes can get stuck in system calls (which requires a reboot).

If I had a simple/efficient way to poll a device's media insertion state, I think my script could then fully automate almost all aspects of desktop integration of usb storage.

Thanks.

-------------------------------------------------------
This SF.Net email is sponsored by: GNOME Foundation
Hackers Unite! GUADEC: The world's #1 Open Source Desktop Event. GNOME Users and Developers European Conference, 28-30th June in Norway
http://2004/guadec.org
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#1 lore raw

I've attempted to develop a desktop integration script for usb storage devices. ( http://freshmeat.net/projects/usbmount/ )

Before anyone reading this thinks this a trivial problem, you should read the requirements/issues detailed at the bottom of http://users.actrix.co.nz/michael/usbmount.html - many aspects of the USB/SCSI system make this task much harder than it should be. I would recommend anyone working on this area to take a look at my script and see the fun currently involved - and then see if what they're working on will make life easier.

In the mean time, working with what is available on current distributions, I'm looking for a solution to one piece of the puzzle...

I would like to be able to detect whether media is present in a reader or not (eg Compact Flash Card reader). A small piece of C for efficiently obtaining the media state would be good. I would like a solution for both 2.4 and 2.6, but I'll settle for what I can get. Does anyone have some sample code?

From looking at what's available I get the impression that some variant on polling is the only solution for such problems. Is this really the case - even for USB?

I've looked at supermount and submount - I'm not sure they offer a better solution than my own attempts thus far - I don't think they can tackle all of the requirements listed on my webpage.

I was also playing with sginfo from sg3_utils (
http://www.torque.net/sg/u_index.html ). But this can be slow, and, in the absence of media, some of the sg3_utils probes can get stuck in system calls (which requires a reboot).

If I had a simple/efficient way to poll a device's media insertion state, I think my script could then fully automate almost all aspects of desktop integration of usb storage.

Thanks.

-------------------------------------------------------
This SF.Net email is sponsored by: GNOME Foundation
Hackers Unite! GUADEC: The world's #1 Open Source Desktop Event. GNOME Users and Developers European Conference, 28-30th June in Norway
http://2004/guadec.org
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#2 lore raw
In reply to Michael Hamilton
Quoted 3 lines · Michael Hamilton

From looking at what's available I get the impression that some variant on polling is the only solution for such problems. Is this really the case - even for USB?

Yup. Problem is that some devices provide no way of reporting if they actually have media in them or not. They also do not tell the host if the media that was in them is now gone. These types of cheap devices are very common :(

Good luck,

greg k-h

-------------------------------------------------------
This SF.Net email is sponsored by: GNOME Foundation
Hackers Unite! GUADEC: The world's #1 Open Source Desktop Event. GNOME Users and Developers European Conference, 28-30th June in Norway
http://2004/guadec.org
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#3 lore raw
In reply to Michael Hamilton
Quoted 37 lines · Michael Hamilton

I've attempted to develop a desktop integration script for usb storage devices. ( http://freshmeat.net/projects/usbmount/ )

Before anyone reading this thinks this a trivial problem, you should read the requirements/issues detailed at the bottom of http://users.actrix.co.nz/michael/usbmount.html - many aspects of the USB/SCSI system make this task much harder than it should be. I would recommend anyone working on this area to take a look at my script and see the fun currently involved - and then see if what they're working on will make life easier.

In the mean time, working with what is available on current distributions, I'm looking for a solution to one piece of the puzzle...

I would like to be able to detect whether media is present in a reader or not (eg Compact Flash Card reader). A small piece of C for efficiently obtaining the media state would be good. I would like a solution for both 2.4 and 2.6, but I'll settle for what I can get. Does anyone have some sample code?

From looking at what's available I get the impression that some variant on polling is the only solution for such problems. Is this really the case - even for USB?

I've looked at supermount and submount - I'm not sure they offer a better solution than my own attempts thus far - I don't think they can tackle all of the requirements listed on my webpage.

I was also playing with sginfo from sg3_utils (
http://www.torque.net/sg/u_index.html ). But this can be slow, and, in the absence of media, some of the sg3_utils probes can get stuck in system calls (which requires a reboot).

Quoted 6 lines

If I had a simple/efficient way to poll a device's media insertion state, I think my script could then fully automate almost all aspects of desktop integration of usb storage.

Thanks.

Hi, have you looked at the HAL project at http://hal.freedesktop.org and gnome-volume-manager which accomplishes this task on Linux 2.6 kernels? (It's so much easier on 2.6 thanks to sysfs). The idea is that it's possible to port this to other kernels which is more or less a requirement for desktop projects link GNOME or KDE. The IPC used to communicate with the desktop session is D-BUS.

Regarding media detection I've found that doing the equivalent of 'blockread --rereadpt /dev/sda' every, say, 2 seconds is a good way of polling for media. In HAL it's straightforward to blacklist or whitelist devices where this causes trouble.

Hope this helps,
David

-------------------------------------------------------
This SF.Net email is sponsored by the new InstallShield X. From Windows to Linux, servers to mobile, InstallShield X is the one installation-authoring solution that does it all. Learn more and evaluate today! http://www.installshield.com/Dev2Dev/0504
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#4 lore raw
In reply to Michael Hamilton

Thanks for the pointers. However it has just occurred to me - and please correct me if I'm wrong - that frequently polling flash media might prematurely wear it out. I guess the media should only be polled when the user tries to access it - something like the approach taken by submount - so I'm probably going to look at virtual file systems (maybe using the fuse library).

Quoted 15 lines · David Zeuthen
Quoted 7 lines

...
If I had a simple/efficient way to poll a device's media insertion state, I think my script could then fully automate almost all aspects of desktop integration of usb storage.

Thanks.

Hi, have you looked at the HAL project at http://hal.freedesktop.org and gnome-volume-manager which accomplishes this task on Linux 2.6 kernels? (It's so much easier on 2.6 thanks to sysfs). The idea is that it's possible to port this to other kernels which is more or less a requirement for desktop projects link GNOME or KDE. The IPC used to communicate with the desktop session is D-BUS.

Quoted 9 lines

Regarding media detection I've found that doing the equivalent of 'blockread --rereadpt /dev/sda' every, say, 2 seconds is a good way of polling for media. In HAL it's straightforward to blacklist or whitelist devices where this causes trouble.

Hope this helps,
David

-------------------------------------------------------
This SF.Net email is sponsored by the new InstallShield X. From Windows to Linux, servers to mobile, InstallShield X is the one installation-authoring solution that does it all. Learn more and evaluate today! http://www.installshield.com/Dev2Dev/0504
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#5 lore raw
In reply to Michael Hamilton
Quoted 3 lines · Michael Hamilton

Thanks for the pointers. However it has just occurred to me - and please correct me if I'm wrong - that frequently polling flash media might prematurely wear it out.

It is my understanding that flash media (NOR and NAND flash) only wears out when doing erase/write operations, think of a lot of embedded devices using flash. But I'm not sure.

Second, all that the polling for media entails is a readonly nonblocking open(2) on the top level block device, e.g. /dev/sda. Whether this means that the device actually accesses the flash memory or it's handled in some logic another place, I'm not sure either.

I think Greg's point was that the cheap devices doesn't give the kernel a signal when media is inserted/removed, not that it was impossible to poll for it - and I guess polling is frowned upon in the kernel. But now I'm just speculating; I don't know really.

Quoted 5 lines

I guess the media should
only be polled when the user tries to access it - something like the approach taken by submount - so I'm probably going to look at virtual file systems (maybe using the fuse library).

There's something called volumagic that goes a step further and mounts/ unmounts devices based on whether the device is accessed - btw, it is all implemented in user space through a NFS server. This solves the problems of user yanking out a USB device and locking of optical drives.

IMHO, It would be good, for desktop Linux at least, if functionality like this was implemented in the kernel without changing the interface that userspace has today, but it doesn't seem like it's going to happy anytime soon. Oh well.

Cheers,
David

-------------------------------------------------------
This SF.Net email is sponsored by the new InstallShield X. From Windows to Linux, servers to mobile, InstallShield X is the one installation-authoring solution that does it all. Learn more and evaluate today! http://www.installshield.com/Dev2Dev/0504
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#6 lore raw
In reply to Michael Hamilton
Quoted 5 lines · David Zeuthen

IMHO, It would be good, for desktop Linux at least, if functionality like this was implemented in the kernel without changing the interface that userspace has today, but it doesn't seem like it's going to happy anytime soon. Oh well.

How would you propose such functionality be added to the kernel?

thanks,

greg k-h

-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel