diff options
Diffstat (limited to 'bfs/bootsector.ha')
| -rw-r--r-- | bfs/bootsector.ha | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/bfs/bootsector.ha b/bfs/bootsector.ha new file mode 100644 index 0000000..dcf33dd --- /dev/null +++ b/bfs/bootsector.ha @@ -0,0 +1,41 @@ +// BFS bootsector, first 512 bytes of a block device +export type bootsector = struct { + // Signature of BFS, 0xCAAA + @offset(446) signature: u16, + + // LBA of lowest yet unallocated + // free block + @offset(448) freeblock: u64, + + // LBA of next block in block + // freelist + @offset(456) nextblock: u64, + @offset(464) lastblock: u64, + + // Inode ID of next free inode block + @offset(472) nextinblk: u64, + @offset(480) lastinblk: u64, + + // Inode ID of root directory + @offset(488) rootinode: u64, + + // Log2 of size of blocks on filesystem + @offset(496) blocksize: u8, +}; + +// Fill a bootsector with everything necessary for it to be valid +export fn bootsector_make(self: *bootsector, rsvdblocks: u64) void = { + self.signature = 0xCAAA; + self.freeblock = rsvdblocks + 1; + self.nextblock = 0; + self.lastblock = 0; + self.nextinblk = 0; + self.lastinblk = 0; + self.rootinode = 0; + self.blocksize = 12; +}; + +// Return whether the bootsector is valid +export fn bootsector_validate(self: *bootsector) bool = { + return self.signature == 0xCAAA; +}; |
