Detect Removing / Unmounting USB Mass Storage on Linux

I use a gadget g_file_storageon Linux to export a partition as a removable USB storage device to host a PC (Windows, Linux, MAC).

All these host OSs (can) automatically mount the removable disk and get access to it without problems, and I'm looking for a way to detect that the host is pushing / disconnecting the disk.

The only way I've found so far is limited to Windows XP. When users select Safely Remove Hardware, XP puts the USB device in suspend mode, which can be detected at the remote end. For some reason this does not work in Vista.

+3
source share
4 answers

I also got into this problem.

My built-in read-only USB drive monitors SCSI commands from the host. On Mac OS X (10.5): On the plug-in, the OS X driver speaks very well to the device to prevent media removal (SCSI PREVENT / ALLOW MEDIUM REMOVAL command). My device accepts this command. Later, when the user signals that the device should be selected, OS X, again, is not bad, sends PREVENT / ALLOW REMOVAL again with the ALLOW icon, and then sends a SCSI START / STOP indicating a stop (or release, I can’t remember). Beautiful.

Windows XP SCSI TEST UNIT READY. ; " " SCSI, , TEST UNIT READY , . Windows .

A TEST UNIT READY Timeout Windows, . OS X, OS X , Windows; .

15 2009

.

, SCSI "" USB Mass-Storage-Class "" "".

, , Windows XP "" , , , , . , , . USB suspend , 1/4 " " USB suspend. , . , , , WINDOWS XP , , "", TEST UNIT READY, , .

OS X (10.6) - . , . SCSI START/STOP, , , . , STOP - , , OS X , . , OS X ALLOW REMOVAL STOP ( EJECT ?), , .

. NON , Windows XP USB- (OS X ). .

, .

+4

, , , .

, .

  • Mer (maemo opensource fork) (afaik) / . USB-, , usb. - . #mer irc.freenode.net.
  • USB, - USB, , ? libusb gadget usb apis ...
+1

, - - . Eject , .

0

EDIT: , , Windows, Linux...

dmesg :

[31027.944083] usb 2-2: USB , 2

-1

Source: https://habr.com/ru/post/1716289/


All Articles