2

I'm writing a file (let's call it, xyz.bin) to a USB Flash drive... the flash drive mounts under the path: /media/myUsb ...

In order to prevent data loss, I'm doing a sync command like this:

sync -f /media/myUsb

Then, I detach/removed the flashDrive using other commands like this one: safe removal

The Problem: The team that consumes this flashdrive is telling me that sometimes the file comes corrupt... I'm debugging my application to discard anything, but I wornder if the sync commnand is being done correctly or I just misunderstood the sync man page.

EDIT

I bring other details about the process being executed (if that helps)... Using JAVA:

  1. I copy the file to the attached pendrive or flash drive.
  2. I call the OS commnad sync like: sync -f /media/myUsb (using the Process Api
  3. If the command returns OK (I wait for it using: process.waitFor()); then, I execute udisksctl unmount -b <usbMountPoint>...
  4. If the command returns OK (again, I wait for it...) then, I execute udisksctl power-off -b <usbDevice>

  5. If the command returns OK (again, I wait for it...) then, I assume that the writting and detaching was successful! So, I indicate to the operator to remove the pendrive or flashdrive...

  6. Then, another team receives the pendrive and tries to read the file that was written... So times, everything works fine... other times, they said the file comes corrupt and they cannot read the file...

Right now, I'm doing different test to find where is problem... However, my doubt in here is: Are the executed OS commands being executed correctly or I just invoking something that has nosense at all?

  • Related - serverfault.com/questions/115069/… – slm Aug 9 '18 at 1:38
  • The sync command should do a sync of the file system. The question you mention had several answers. What exactly did you do? While a sync is a good idea, it is better to unmount the file system. Some file systems have a flag whether the file system was cleanly unmounted. Unmount will sync anyway, so sync is not necessary. What is important is that you wait for the sync or unmount to finish. This may take a long time depending on the amount of data and the speed of the USB storage. – RalfFriedl Aug 9 '18 at 6:02
  • I would be tempted to do 2 syncs back to back (sync; sync). – slm Aug 9 '18 at 13:50
  • @slm, according to other forums, sync; sync; sync is not necessary... (but in desperated times... XD ) – Carlitos Way Aug 9 '18 at 18:57
  • @RalfFriedl, I just edit my question to bring more details.... – Carlitos Way Aug 9 '18 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.