insajack wrote:
Octacone wrote:Actually the root directory has its cluster number set to 0.
No. Cluster 0 isn't a valid data cluster and, in FAT32, the root directory is just another file.
I am aware of that but:
Root_Directory_Cluster value inside the BPB = 2 (it is actually okay since arrays are zero based, forgot about that, I wasn't talking about FAT[3] but FAT[2])
Root_Directory_Entry itself cluster value = 0 (I think it should be zero actually, no clusters linked = 0 for standard directories (files) and 0 because it entry no.1)
insajack wrote:
Octacone wrote:Looks like mcopy is to blame (kind of), it shouldn't change the starting cluster number when overwriting files. Looks like there isn't a way to fix this, even if I set "FSI_Nxt_Free" to 3 again.
I've already explained why FAT32 would write to unused clusters rather than previously used ones. It makes data recovery more likely. In addition, I would expect that it eases the task of finding a set of contiguous clusters large enough to hold a new file. Once all clusters have been used it will have to start reusing old ones - starting from the beginning again, these will be the clusters for the oldest deleted files.
Just tested this with an actual USB drive. I created an empty FAT 32 partition, put a file inside it, checked the value and it was 3, then I added another file and replaced the first one, 3 became 4 and newly create file had a value of 5. True!
insajack wrote:
If your code assumes nothing, why does this behaviour bother you?
That adds a whole new layer of complexity, like a lot. I guess I can handle the coding but there isn't really much space to do so. (420 bytes (VBR))