Current-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: usb flash drive removal (Re: Desktop NetBSD needs your help)
On Mon, Feb 09, 2009 at 10:51:32AM -0500, Arnaud Lacombe wrote:
> Hi,
>
> On Mon, Feb 9, 2009 at 10:33 AM, Eric Haszlakiewicz
> <erh%nimenees.com@localhost> wrote:
> > I think that there should not _be_ a wrong time to remove a USB drive.
> > Yes, it may be hard to implement it in NetBSD, but it is entirely possible
> > to have a system that doesn't crash, and even does something reasonable.
> > (e.g. like providing an api for prompting the user to reattach the device)
> >
> You cannot ensure that the device is the same state than previously.
> You cannot even ensure that the newly plugged device is the same that
> the old one. The only sane thing to do is to clean-up everything.
No, you're wrong. You CAN ensure, with a reasonably high degree of certainty,
that the device is the same as the old one. Do all of the following:
1) A device is unplugged
a) If there is no unwritten data cached, gracefully unmount the device and
revoke any open file descriptors when the device is unplugged.
b) If there _is_ data cached, keep the mount around in a suspended state,
saving information about the device and in-flight data until later.
b.i) Issue an event that alerts the user that he should plug the device
back in.
2) When a device is reattached
a) If the device has a dependable hardware id of some kind, compare that
with what the previous id was.
b) If not, compare a known written bit of data on the device with a cached
copy. (e.g. perhaps the disklabel, or fdisk partition table, or whatever)
3) Decide on a course of action based on what happpened in steps 1 and 2:
a) If there are no suspended mounts sitting around, nothing special needs
to happen. Attach the device normally.
b) If there _are_ suspended mounts, prompt the user:
b.i) If the id from step 2 is a match, say:
"This appears to be the same device "X" as you previously had atached.
Do you want to recover unwritten data? [Y/n]"
b.ii) If the id from step 2 is not a match, say:
1:"This appears to be a different device than "X", which was previously
attached. Is that correct?
[Y]es, this is a new device
[n]o, try to write the cached data for "X" to this device."
Also, provide a way to throw away the cached data. (e.g. "umount -f")
Getting this right is _both_ a "desktop" issue (due to the need to notify
the user, which includes figuring out which logged in user is the one to
notify) AND a "storage" issue, neither piece of which seems all that easy
to implement.
eric
Home |
Main Index |
Thread Index |
Old Index