blob: dcf33dd9f1cb0094c0fbd9d4e9786ef17fdfb727 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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;
};
|