[Interest] QFile copy and sync/fsync

Nikos Chantziaras realnc at gmail.com
Thu Jan 3 18:45:21 CET 2013


On 03/01/13 15:51, Duane wrote:
> On 01/02/2013 04:45 PM, Nikos Chantziaras wrote:
>> On 02/01/13 22:49, Duane wrote:
>>> Qt 4.8 on Linux TinyCore or Fedora.
>>>
>>> I have a function to back up some files to a usb stick.  I've had
>>> complaints from users that the files are sometime not copied.  It looks
>>> like they're removing the usb stick before the standard sync cycle.  If
>>> I call sync from my copy routine this works but it hangs the system
>>> waiting for sync to complete.
>>>
>>> If I mount the usb stick with -o sync, this also solves my problem but
>>> it also hangs the system.
>>>  [...]
>>
>> Once QFile::flush() is called, the data is sent to the OS. From there,
>> it's up to the system what to do with the data. Users need to unmount
>> the stick before removing it. If they don't want to do that, then they
>> need to set up their system such that it mounts the USB stick
>> synchronously by default. It's either that or unmount first.
>>  [...]
>
> This device is a "controller" with a touch screen and no access to a
> terminal where the user can enter anything.  I would have to add
> something to the gui to unmount the device but I think this would be
> more or less the same as calling sync when the copying is done.

Keep in mind that if you're not mounting synchronously by default, then 
removing the stick without unmounting it can lead to filesystem 
corruption and inconsistencies.

The fact that it's a USB stick doesn't matter.  The only thing that 
matters is that a non-synchronous filesystem is being removed while it's 
still live.




More information about the Interest mailing list