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 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.
I bring other details about the process being executed (if that helps)... Using JAVA:
- I copy the file to the attached pendrive or flash drive.
- I call the OS commnad sync like:
sync -f /media/myUsb(using the Process Api
- If the command returns OK (I wait for it using: process.waitFor()); then, I execute
udisksctl unmount -b <usbMountPoint>...
If the command returns OK (again, I wait for it...) then, I execute
udisksctl power-off -b <usbDevice>
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...
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?