$ uname -a Linux mdt3 3.0-ARCH #1 SMP PREEMPT Tue Aug 30 08:53:25 CEST 2011 x86_64 AMD Opteron(tm) Processor 6128 AuthenticAMD GNU/Linux $ cp --version cp (GNU coreutils) 8.12
Last full system update: 2-3 days ago.
When I copy large files from USB keys in a terminal, the command returns (prompt appears again) even though the file copy operation has not completed.
(I have not noticed this problem in the past...)
mount -o umask=0000 /dev/sdg /media/usb cp /media/usb/FILE . # here, cp returns after about 5 seconds, even though the actual operation takes much longer
Error message: none.
Observed behaviour: cp returns after a few seconds. Copied file is of right size, but is corrupt, if USB key is umounted before IO completion.
Expected behaviour: cp returns after tens of minutes. Copied file is not corrupt.
What filesystem is it? Try
mount options if it's vfat (FAT32).
Last edited by karol (2011-09-08 21:21:19)
That's normal. The file is in cache. It'll get written out of the cache if you call sync or when you unmount. For usb sticks, the vfat mount option "flush" was created to mitigate this and write out the file immediately. So whatever means you're using to mount usb stick, tell it to use the flush option. That's assuming your stick is using vfat, but that's the usual fs on these things.
I've seen the same behaviour with both a USB key with VFAT format, and an external hard drive with NTFS format.
I've been transferring large files using the same devices in the past, and I've always thought that the disk operation is complete when the command returns, but I guess I haven't been very observant.
So, I suppose that as long as I wait for umount to complete properly, I should not have corrupt files.
(Edit: by 'unmount' in my initial post, I meant typing the umount command and unplugging after having decided that umount is taking too long.)
Thank you both for your help!
Last edited by rWarrior (2011-09-08 21:40:28)
Wait for the disc activity *whether it's HDD of a pendrive) stops flashing - it's a good indicator.
I've read there's a 'Safeley remove' thingy like the one in Windows https://bbs.archlinux.org/viewtopic.php?id=113869