To get over some of the limitations of the CH376 chip (like 8.3 file naming and no multiple open files at the same time), and to learn how a filesystem actually works, BRFS (Bart's RAM File System) was created.
Given the state and speed of the FPGC being similar to a home computer of ~1990, only tens of megabytes of persistent storage should be enough for most applications (Fun fact: HDD sizes for the average home user was <100MB until after 1990). SPI NOR Flash provides around the same amount of storage, with very little wear compared to NAND Flash, so no wear leveling is needed. Given that SPI NOR Flash has very fast reads and very slow writes, and that the FPGC already has 64MiB RAM (which is a lot even for 32 bit addressable words), 32MiB of this RAM could easily provide enough space for the entire filesystem with SPI NOR Flash used for persisting the filesystem between reboots/crashes. In contrast to the implementation of CH376, BRFS should be completely managed by BDOS and present via system calls to each application.
16 word superblock:
- (1) total blocks
- (1) bytes per block
- (10) label [1 char per word]
- (1) brfs version
- (3) reserved
8 word dir entries:
- (4) filename.ext [4 chars per word -> 16 chars total]
- (1) modify date [to be implemented when RTC]
- (1) flags [max 32 flags, lsb = is_directory]
- (1) 1st FAT idx of file
- (1) file size [in words, not bytes]
Similar to a linked list, each data block has its own FAT entry (of one word) in the FAT table which points to the next data block of the file, or -1 if it is the last block of the file (or if it is a dir). Each dir entry contains the first FAT index of the file.