diff options
| author | Alejandro Sior <aho@sior.be> | 2022-06-18 13:54:25 +0200 |
|---|---|---|
| committer | Alejandro Sior <aho@sior.be> | 2022-06-18 13:54:25 +0200 |
| commit | 6117a803ad717fd50003c0bd8fbe393db2dcac6b (patch) | |
| tree | a01ba73f37570b96bebef8c193abaf686ef9f696 /gpt | |
| parent | d6181b5e4f6f2dc72907e9f2e73db9ce0075cddd (diff) | |
add header command
Diffstat (limited to 'gpt')
| -rw-r--r-- | gpt/gpt.ha | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -131,23 +131,25 @@ export fn create(fd: io::file, freeno: size) *gpt = { const mbr_sec = sector::map(fd, 0, 1); const mbr = mbr_sec.buf: *[*]u8: *mbr::bootsector; + *mbr = mbr::bootsector { + magic = 0xaa55, + ... + }; + const prim_header_sec = sector::map(fd, 1, 1); const prim_header = prim_header_sec.buf: *[*]u8: *header; *prim_header = header { signature = 0x5452415020494645, revision = 0x10000, header_size = 92, - header_crc32 = 0, - reserved0 = 0, header_lba = 1, backup_header_lba = bheader_begin, first_lba = free_begin, last_lba = bentries_begin - 1, - disk_guid = [0xCAFEBABE, 0xCAFEBABE], entries_lba = entries_begin, entries_len = 128, entry_size = 128, - entries_crc32 = 0, + ... }; const prim_entries_sec = sector::map(fd, entries_begin, 128*128/512); @@ -286,6 +288,9 @@ export fn mkbackup(self: *gpt) void = { self.backup.header.header_lba = self.backup.header_sec.offs; self.backup.header.backup_header_lba = self.primary.header_sec.offs; self.backup.header.entries_lba = self.backup.entries_sec.offs; + + self.backup.header.entries_crc32 = entries_crc32(self.backup.entries); + self.backup.header.header_crc32 = header_crc32(self.backup.header); }; // Commits changed done on the data structure to the disk @@ -298,7 +303,5 @@ export fn commit(self: *gpt) (void | io::error) = { // Updates the CRC32 checksums of the different blocks export fn chksums(self: *gpt) void = { self.primary.header.entries_crc32 = entries_crc32(self.primary.entries); - self.backup.header.entries_crc32 = entries_crc32(self.backup.entries); self.primary.header.header_crc32 = header_crc32(self.primary.header); - self.backup.header.header_crc32 = header_crc32(self.backup.header); }; |
