Announcement

Collapse
No announcement yet.

file_Write issue

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • file_Write issue

    I have noticed an interesting problem with file_Write function. I use this function to send files over serial port in chunks of 512 bytes (the last packet may be shorter). For each packet I open the file in append mode, write the 512 bytes and close the file.The whole process runs smoothly and in the end, the file is correctly written, can be normally used and the read-back copy is identical. However, I was looking into the FAT table entries and they do not seem correct to me.

    This is the beggining of the FAT table for a freshly formatted SD:

    F8FF FFFF 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 ...

    This is the beginning of the FAT table after I copy a large (775680 bytes) file. Cluster size is 64 kB, so the file should use 12 clusters. However, the file is actually using 12 correct cluster and it marks additional 12 clusters as used (FFFF value). These additional clusters are not really harmfull, they just steal some space and are not connected anywhere. Also, the file is now fragmented, although I don't think this is a problem in such a simple system.

    F8FF FFFF 0400 FFFF 0600 FFFF 0800 FFFF 0A00 FFFF 0C00 FFFF 0E00 FFFF 1000 FFFF 1200 FFFF 1400 FFFF 1600 FFFF 1800 FFFF FFFF 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 ....


    If I reformat the SD and copy the same file with Windows Explorer, the cluster chain in FAT table looks as expected (without fragmentation and additional clusters):

    F8FF FFFF 0300 0400 0500 0600 0700 0800 0900 0A00 0B00 0C00 0D00 FFFF 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 ...

    Note that files smaller than cluster size are written correctly.

    Regards,
    Valentin

  • #2
    Thanks, for that. We'll have a good look and get to the bottom of it, as you said, it does not look correct
    Mark

    Comment

    Working...
    X