file io - How to write data on USB stick safely - Linux (ARM) - C++ -
I am trying to copy some folders and files to a USB stick and after all is cured , To remove the USB stick. Implementation is something like this:
- Make the related folder structure by using
mkdir
fsync on each USB stick, each file On each file descriptor, copy
fsync
- After copying the file Every directory descriptor
Just after copying the last file, I remove the USB stick (~ 500 MS-1s). But sometimes the entire folder structure disappears. To avoid that file, I used
fsync again on every directory descriptor after copying the previous file. At this time all the files and folders are present on the USB stick but sometimes I have a garbage in the folder structure or the USB stick gets corrupted. USB stick file system vfat is about how to properly save data. Even thoughts?
Unmount it before deleting device. For non-journaled file systems such as VFAT, there is no guarantee that the file system will be in a consistent position on the disk, while it is mounted.
Comments
Post a Comment