1
votes

I'll try to sum this up briefly. I have an app that can synchronize its data with a USB flash drive connected via an OTG adapter. The problem is this: some files will end up in a folder called LOST.DIR in the root of the flash drive. They are all exactly 4KB large and have random, 3-number names with no file extension. I know they contain data from my app because if I open them in notepad, I can see the data that my app is outputting. This data, however, is sometimes mixed with random symbols. Based on my rudimentary knowledge of file systems, the consistent size of the files and random content makes me think these are blocks of memory marked bad by Android and moved to this folder.

There is one caveat: I am treating the flash drives as if they are hot-swappable, as they would be on a Windows device. I understand that it may not be valid to think of them as this. To get around this, I'm calling running the sync command via su after I finish reading and writing to and from the flash drive. My understanding is that this should sync the in-RAM buffer/cache with the physical flash drive, thereby making it safe to remove. This may be a faulty assumption.

So, my question is two-fold:

  1. What is causing data to randomly disappear and be moved to LOST.DIR?
  2. Is it safe to be treating flash drives as hot swappable? If not, is there a way to make them behave that way?

If my question is not clear enough or you need more information, I can clarify things for you. Thank you.

1

1 Answers

0
votes

What comes to mind is that you are not the only one accessing the flash drive (media scanner, for instance), so sync will flush buffers but something could be ongoing, and sync exits anyway. I think you should also unmount it (and it will fail until it's really safe to remove).