Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8037

Python • Re: [Solved] An equivalent of 'littlefs-python' for FAT ?

$
0
0
I have coded SD Card readers in the past so I will probably favour the DIY route. Hopefully I can recall what I did back then and the re-learning curve will be short. Luckily FAT isn't complicated. At least that way I should be able to create something with the same API as 'littlelfs-python'.
Though it does seem PyFatFS would work with a bit of massaging I took a look at DIY handling of FAT and that proved even easier than I was expecting, though I guess knowing what to expect helped there, and simply reading and walking the file system is a lot simpler than other processing. I even have support for long file names.

By doing it myself I can also better deal with the 'dirty' flag being set. To deal with it using PyFatFS means having to clear the byte and create a temporary file, up to 16MB, which I don't like doing.

My code is focused on handling what MicroPython uses for FAT - FAT16, 4096 bytes per sector, 1 sector per cluster, single File Allocation Table, but should be easily modifiable for FAT12 and FAT32, different sector and cluster sizes, etc. The 4KB sector size was a bit of a surprise given it's normally 512 bytes, but that fits with the minimum Flash erase size being 4KB.

I also discovered something I hadn't previously appreciated, that while FAT file timestamps are notorious for having only 2 second resolution to fit 'hh:mm:ss' into 16-bits. There's another byte in each directory entry (offset 13) which stores 0-199, providing the missing second and increasing resolution to 10ms. It doesn't however seem MicroPython uses that.

Once I have knocked it into shape I will publish what I have.

Statistics: Posted by hippy — Sat Jul 19, 2025 6:32 pm



Viewing all articles
Browse latest Browse all 8037

Trending Articles