On Sat, Mar 8, 2008 at 4:13 AM, Herbert Graf wrote: > > On Fri, 2008-03-07 at 11:36 -0800, Alex Harford wrote: > > In Linux or in general? I thought this is how Windows does the > > 'Safely Remove Device'. If you have a flash drive in there with an > > LED, the LED goes out, even though it is still plugged in. > > > > There should be a file called state in a subdir like > > /sys/bus/usb/devices/1-0:1.0/power, and: > > echo "2" > /sys/bus/usb/devices/1-0:1.0/power/state > > is supposed to power it off. But on my system (2.6.23) the state file > > does not exist. :( > > That would be perfect! Unfortunately, while the state file exists (it > contains 0) writing 2 to it appears to do nothing. Do you have more > information on this mechanism? This question has repeatedly asked in the Linux USB forum. Every time the response from Alan Stern is a bit different but the essence is that there are no good ways to shut down the port, but you can suspend the port in certain cases to reach the goal. 1. An old example with good explanation http://marc.info/?l=linux-usb-users&m=113250576908315&w=2 Quote: " It seemed likely that Windows was disabling the device's USB port. Linux doesn't do this because there's no reason to. Unless the device is _extremely_ badly designed, the message it displays is nothing more than a warning. The device knows that Windows disables the port when you click the "unplug device" button, so it assumes that if the port isn't disabled then you haven't clicked the button. This heuristic is fine for Windows but it doesn't work with Linux. If you have Power Management and USB selective suspend/resume both configured on in your kernel (CONFIG_PM and CONFIG_USB_SUSPEND), then you can disable the port from the command line. The commands you need to use go like this: echo -n 3 >/sys/block/sdb/device/../../../power/state echo -n 3 >/sys/block/sdb/device/../../../../power/state Vary the name of the block device to suit your setup. Actually these commands suspend the port instead of disabling it; as far as the device is concerned there's no difference. Either way no packets are sent to the device. The first line above tells usb-storage to suspend and the second actually suspends the device." 2. A more recent example: http://marc.info/?l=linux-usb&m=120474399006728&w=2 Quote: "Currently there's no easy way to disable a port in a user program. But it is easy to suspend a port, provided your kernel was built with CONFIG_USB_SUSPEND enabled. All you have to do is: echo suspend >/sys/bus/usb/devices/.../power/level where you fill in the "..." with the pathname for the device you want to suspend." There is a catch though, you may not want to enable CONFIG_USB_SUSPEND with kernels prior to 2.6.23. After 2.6.23, Linux USB developers get more realistic "because in the real world it turns out that USB devices suck when it comes to powermanagement issues :(" and disable USB autosuspend on all devices except for USB hubs by default. There are new set of patches to enable USB autosuspend on some USB devices which do support it. One real example I encountered and my conversations with Alan Stern. http://forum.microchip.com/tm.aspx?m=275422&mpage=2 http://kerneltrap.org/mailarchive/linux-usb-devel/2007/9/22/341937 Regards, Xiaofan -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist