-
Notifications
You must be signed in to change notification settings - Fork 33
BareMetal File System
BMFS is a new file system used by BareMetal OS and its related systems. The design is extremely simplified compared to conventional file systems. The system is also geared more toward a small number of very large files (databases, large data files). As all files are contigous we can also implement memory mapped disk IO. BMFS was inspired by the RT11 File System.
- Very simple layout
- All files are contiguous
- Disk is divided into 2 MiB blocks
- Flat organization; no subdirectories/subfolders
Blocks
For simplicity, BMFS acts as an abstraction layer where a number of contiguous sectors are accessed instead of individual sectors. With BMFS, each disk block is 2MiB. The disk driver will handle the optimal way to access the disk (based on if the disk uses 512 byte sectors or supports the new Advanced Format 4096 byte sectors). 2MiB blocks were chosen to match the 2MiB memory page allocation that is used within BareMetal OS.
Free Blocks
The location of free blocks can be calculated from the directory. As all files are contiguous we can extract the location of free blocks by compairing against the blocks that are currently in use. The calculation for locating free blocks only needs to be completed in the file create function.
Disk layout
The first and last disk blocks are reserved for file system usage. All other disk blocks can be used for data.
Block 0:
4KiB - Legacy MBR Boot sector (512B)
- Free space (3584B)
4KiB - Directory (Max 64 files, 64-bytes for each record)
Free space (2040KiB)
Block 1 .. n-1:
Data
Block n (last block on disk):
Copy of Block 0
Directory
BMFS supports a single directory with a maximum of 64 individual files. Each file record is 64 bytes. The directory structure is 4096 bytes and starts at sector 8.
Directory Record structure:
Filename (32 bytes) - Null-terminated ASCII string
Starting Block number (64-bit unsigned int)
Blocks reserved (64-bit unsigned int)
File size (64-bit unsigned int)
Unused (8 bytes)
A filename that starts with 0x00 marks the end of the directory. A filename that starts with 0x01 marks an unused record that should be ignored.
Maximum file size supported is 18,446,744,073,709,551,614 bytes (~18 EiB) with a maximum of 9,223,372,036,854,775,807 allocated blocks.
The following system calls should be available:
- Create (Create and reserve space for a new file)
- Delete (Delete an existing file from the file system)
- Read (Read a file into system memory)
- Write (Write a section of system memory to a file)
- Rename (Change the name of an existing file)
- Directory/List (Prepare and display a list of file)
- Query (Query the existance/details of a file)
The create function accepts two parameters:
Name = A null-terminated string no more that 31 characters
Reserved = The number of blocks to reserve for the file
The delete function accepts one parameter:
Name = The name of the file to delete
The read function accepts two parameters:
Name = The name of the file to read
Destination = The memory address to store the file
The write function accepts three parameters:
Name = The name of the file to write
Source = The memory address of the data
Size = The amount of bytes to write
The rename function accepts two parameters:
Name = The name of the file to rename
NewName = The new name of the file
The dir/ls function accepts no parameters
The query function accepts one parameter:
Name = The name of the file to query
The query function will return the following:
Size = The current size of the file in bytes
Reserved = The amount of blocks reserved for the file (0 if it doesn't exist)