From cd25fe0560f746bedad0d16c173deeaa8db6b562 Mon Sep 17 00:00:00 2001 From: "Alejandro W. Sior" Date: Fri, 10 Feb 2023 19:24:23 +0100 Subject: initial commit --- bfs/bootsector.ha | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 bfs/bootsector.ha (limited to 'bfs/bootsector.ha') 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; +}; -- cgit v1.2.3