You are not logged in.

#1 2011-09-08 21:15:29

rWarrior
Member
Registered: 2008-12-28
Posts: 26

Disk IO operations return before completion

$ 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.

Offline

#2 2011-09-08 21:17:33

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Disk IO operations return before completion

What filesystem is it? Try

rw,noexec,nosuid,nodev,noatime,shortname=lower,flush,utf8,gid=100

mount options if it's vfat (FAT32).

Last edited by karol (2011-09-08 21:21:19)

Offline

#3 2011-09-08 21:21:47

Gusar
Member
Registered: 2009-08-25
Posts: 3,605

Re: Disk IO operations return before completion

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.

Offline

#4 2011-09-08 21:35:43

rWarrior
Member
Registered: 2008-12-28
Posts: 26

Re: Disk IO operations return before completion

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)

Offline

#5 2011-09-08 21:42:56

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Disk IO operations return before completion

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

Offline

Board footer

Powered by FluxBB