This is about stupid users (including me) unplugging USB devices whilstHow do you expect writing to a device followed by a forced dismount to work if you aren't using a data journaled file system, and you don't tell it needs to clean its caches? Our lab has been using memory sticks for embedded development for 5 years and we've managed to teach people "don't do that" pretty well (in fact I just taught another person today). It is of course a mistake everyone makes a few times while learning. However the last time I used Windows for this, you had to click on the taskbar to shut down the USB storage device, which is basically the same thing as unmounting. Not doing so often required a reboot.
still mounted, and expecting sane semantics.
This has generally not been the 'Unix' or even 'Linux' way, but people
expect it to work. I also see no clear automated and robust solution from
userspace. "Don't do that then" is a pretty weak answer, especially since we
want to work on the desktop.
The expected behaviour is that on forceably unplugging an USB memory stick,Along with any data that hasen't yet been written to the drive. You're quite likely to corrupt a fragile FS such as FAT.
the created SCSI device should vanish, along with the mounts based on it.
When the user plugs in the device again, people expect to see it get theAutomated mounting with special fixed names can already be done, this has little to do with forced dismounting. Use something like udev for this part.
first available name, and be available for remount, possible automated.
# mount /dev/sda1 /keychainRead-write VFAT without being mounted sync will pretty much never work for forced-dismount if you have written anything.
# grep /keychain /proc/mounts /dev/sda1 /keychain vfat rw,nodiratime,fmask=0033,dmask=0033 0 0
Unmounting and unplugging and replugging saves us.You're likely to have corruption too if you did any writing.
Greg, others, I hope you agree this needs work. I hope we have theThat infrastructure would have to include knowing when to clear caches before the user ever disconnects the device. In other words, not possible, unless you force it to sync constantly which is not very healthy for a flash device (limited number or writes before it dies). Replugging is the only possibility that could ever support writes. The only case that could really be *solved* is the "read-only or no-writes" condition, which is only 50% of the time for something like flash used to transfer files. The only thing would could reasonably expect with writing is to be able to clear the pinned resources somehow.
infrastructure to umount based on USB disconnect events, or, alternatively,
will support 'replugging' which at least does part of what people expect.