Fix GRUB reassessment findings: clean-build gap, validation, robustness

- Add grub package to redbear-full-grub.toml so make all works from
  a clean tree (the installer needs grub.efi before it runs)
- Fix stat -f%z (macOS-only) to stat -c%s (Linux) in GRUB recipe
- Normalize bootloader config value to lowercase in install_inner so
  bootloader = "GRUB" from config files is accepted
- Add bad-cluster marker (0x0FFFFFF7) check in fat_tool.py
  _next_cluster to prevent potential infinite loops on degraded media
- Fix file handle leak in fat_tool.py if _read_bpb raises
- Clean up temp directory in fetch_bootloaders on error
- Update AGENTS.md with GRUB recipe and installer documentation
- Update GRUB plan with clean-build prerequisite note
This commit is contained in:
2026-04-17 22:21:08 +01:00
parent 33d8a4deaa
commit 1b785fea6a
6 changed files with 189 additions and 64 deletions
+10 -3
View File
@@ -47,8 +47,12 @@ class Fat32:
self.f = open(image_path, "r+b")
self.image_size = os.fstat(self.f.fileno()).st_size
self.offset = offset
self._read_bpb()
self._load_fat()
try:
self._read_bpb()
self._load_fat()
except:
self.f.close()
raise
def _read_bpb(self):
self.f.seek(self.offset)
@@ -118,7 +122,10 @@ class Fat32:
if not 2 <= cluster <= self.max_cluster:
raise RuntimeError(f"FAT32: invalid cluster {cluster}")
idx = cluster * 4
return read_le32(self.fat, idx) & 0x0FFFFFFF
val = read_le32(self.fat, idx) & 0x0FFFFFFF
if val == 0x0FFFFFF7:
raise RuntimeError(f"FAT32: bad cluster marker at {cluster}")
return val
def _set_fat(self, cluster, value):
write_le32(self.fat, cluster * 4, value & 0x0FFFFFFF)