usage of usb sticks on the laptops

Ivan Krstić krstic at solarsail.hcs.harvard.edu
Thu Jun 28 05:55:59 EDT 2007


On Jun 28, 2007, at 5:30 AM, Tomeu Vizoso wrote:
> Perhaps we'll need to do the same as is done everywhere and notify  
> when
> a device that needs to be safely unmounted is mounted, and  
> "complain" to
> the user when the stick is removed unsafely.

Normally, complaining is all you can do because the OS provides  
unmediated access to the underlying FS on the USB stick. But hey,  
we're not doing that; we're talking to the datastore on the device  
first. So you have an elegant way of avoiding this whole problem.

When you're about to write a file to the USB device, here's what you do:

1. Start transaction in USB stick datastore.
2. Add a row to the pending_writes table in USB stick datatore  
specifying file name, size, and path of file to be written.
3. End transaction.
4. Copy file to USB stick.
5. Sync.
6. Begin transaction in USB stick datastore.
7. Remove row from pending_writes table.
8. Add row to normal file table.
9. End transaction.

Now, every time when mounting an USB stick, for every row in the  
pending_writes table of the stick's datastore:

1. Does file size on stick match size in pending_writes table? If so,  
go to step 6 above. If not, proceed with next step.
2. Unlink file from stick.
3. Begin transaction in stick datastore.
4. Remove row from pending_writes table.
5. End transaction.

That's it. I had this implemented and working perfectly in Yellow,  
and I was using MD5 instead of file size as the validity check. It  
didn't slow things down because having to even check it is a corner  
case already.

Cheers,

--
Ivan Krstić <krstic at solarsail.hcs.harvard.edu> | GPG: 0x147C722D




More information about the Devel mailing list