BAOS offers a directory-based filesystem. This filesystem resides in flash, but it should be possible to create another filesystem that resides in the RAM.
All space inside the flash is grouped in blocks. Each block is 64 bytes in length, which makes it able for us to address all blocks with one word (2 bytes). Of these 2 bytes, the first one is the ROM-page, the second one is the blocknumber in this page. All these blocks have the following layout:
Byte | 0 | 1 | 2 | 3 | 4 - 11 | 12 - ... |
---|---|---|---|---|---|---|
Description | Dead / Alive | Blocks in use | Directory | Flags | Filename | Data |
Dead / Alive | This byte belongs to the Flash driver instead of the Filesystem driver. If this byte is $FF, there is no problem, if it is 0 (zero), this block is ignored. This is done because you can only wipe out big parts of flash a time, so the save ereasing cycles, the block is just marked "dead". |
Blocks in Use | This is the number of blocks that are in use by this file. If a file needs more than 64 - 16 = 48 bytes, it goes on on the next block (without a repeating header). This are the number of blocks that this file uses, but there is a little twist. Since this byte also indicates if the block is in use or not, but we can't use a 0 (zero) for "not in use" (since it is flash), this byte is calculated using the equation: "[result] = 255 - [blocks in use by this file]". This means a 0 is the full page is in use and 255 means that this block not in use is at all. By the way, this byte also belongs to the flash driver. |
Directory | The Directory number. The filesystem only emulates directories, but this fact makes no difference to the user. This number gives information on in which directory the file is stored. Every directory has an unique number. 0 (zero) means the root-directory "/" (without quotes, the filesystem is unix-based). |
Flags | Flags is a very special byte. It has multiple purposes. The first bit tells the filesystem if we are talking about a file (0) or a directory (1). The second bit tells if the file (if it is a file, otherwise it is ignored) is executable (1) or not (0). The last 6 bits are together the number of the last byte of the last block (which together tells us the length of the file). |
Filename | Very simple. The name of the file (max. 12 bytes, no trailing zero needed). Old DOS-format can be used (xxxxxxxx.xxx), but is not necessary. ".thisfile" (without quotes) and ".ThisFile" (without quotes) are not the same, but both valid (notice the period at the beginning). |
Data |
The data of the file. When we are talking about a directory, then the first byte is the directory number (this must be the unique number which indicates the directory). This byte is followed by 12 other bytes, which are together the name of the directory. After this the "file" ends. |