1

When a USB device is ejected using the GUI in Finder, what exactly happens at a low level? Are there certain signals sent to the device?

The reason I am asking is because I am trying to emulate manual ejection of a device by adding and removing the file storage module via the console of a device running embedded Linux. Just removing the module works fine on a PC, but a Mac gives me the "not properly ejected" error, and the Linux kernel "panics" and gets a kernel null pointer error.

Here is some extra information:

I am using a USB Gumstix COM device that is running embedded Linux. The device is plugged into a host (Windows or Mac), and I emulate physically removing it by removing the mass storage module in the Linux kernel of the device, thus making the host not see it as a storage device any longer. I accomplish this with modprobe -r g_file_storage.

This works with no problem on Windows. It is not working on a Mac, because I get an error on the Mac host saying the device was not ejected correctly. This causes a null pointer error in the device's Linux kernel, and it panics.

This leads me to believe that there is something the ONLY the Mac does when properly ejecting a USB device that I need to be emulating in my script on the device.

Basically, I want to know if I need to be doing some signal handling or something on the device to properly emulate ejection on Mac hosts.

1
  • 1
    well in windows you are basically telling the PnP manager to eject a mass storage device. For instance in C# you would have the following code snippet to deal with your usb, if ((device.LogicalDrive == null) || (device.LogicalDrive.Length == 0)) continue; device.Eject(true); therefore, i think you just need to find out the PnP manager for your respective host.
    – pneumatics
    Oct 3, 2012 at 16:24

2 Answers 2

2

The user-level 'eject' concept can mean several different things, whereas unmounting always means just unmounting.

For optical media, ejecting causes physical ejection of the disc after unmounting.

For some media, such as removable flash media (USB memory sticks; anything that appears as a white slot-loading drive in the Finder), ejecting unmounts all the device's volumes and then prevents any further interaction with that device until it is physically removed — the device remains in the USB device tree but block devices in /dev are removed and it is no longer listed in Disk Utility or diskutil list.

For other media types, such as removable hard drives (anything that appears as a yellow plastic enclosure in the Finder), ejection will simply unmount the volume and leave it accessible for re-mounting or writing to the block device.

I'm not exactly sure what the criteria are for which behaviour is applied to what kind of device. I tested with a bunch of CoreStorage/FileVault 2-encrypted hard drives and a bunch of USB flash drives. The number of volumes on the device in question appears to make little difference, but the interaction block may be decided by CoreStorage or by the difference in media type.

OS X does not complain if you unplug a device that has not been ejected but has had all its volumes unmounted.

0

When you use GUI tools on Mac and Linux to 'eject' the USB device, the GUI typically checks if the device is busy or not and, if it's not busy, then unmounts the USB device from the file system.

Most Unix/Linux system have a unmount command, which is what the GUI tools do when you 'eject' the USB device. This command should be run before the device is physically removed (however there are options to force it to remove the references to the device, but they dont' always work).

Check out of the manual pages for umount. A copy can be found here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .