8#include "pedigree/kernel/syscallError.h"
10#include "FatFilesystem.h"
12bool FatFilesystem::invalidateFsInfoHints() {
13 if (
m_Type != FAT32 || m_FsInfoInvalidated)
16 const uint32_t sectorBytes = LITTLE_TO_HOST16(
m_Superblock.BPB_BytsPerSec);
17 const uint32_t reservedSectors = LITTLE_TO_HOST16(
m_Superblock.BPB_RsvdSecCnt);
18 const uint32_t primary = LITTLE_TO_HOST16(m_Superblock32.BPB_FsInfo);
19 if (sectorBytes <
sizeof(
FSInfo32) || !primary || primary >= reservedSectors)
22 const uint32_t backupBoot = LITTLE_TO_HOST16(m_Superblock32.BPB_BkBootSec);
23 const uint32_t sectors[] = {primary, primary + backupBoot};
25 backupBoot && backupBoot < reservedSectors && sectors[1] < reservedSectors ? 2 : 1;
26 uint8_t* bytes =
new uint8_t[sectorBytes];
28 SYSCALL_ERROR(OutOfMemory);
31 for (
size_t i = 0; i < copies; ++i) {
32 if (!
readSectorBlock(sectors[i], sectorBytes,
reinterpret_cast<uintptr_t
>(bytes))) {
34 SYSCALL_ERROR(IoError);
39 if (LITTLE_TO_HOST32(info->FSI_LeadSig) != 0x41615252 ||
40 LITTLE_TO_HOST32(info->FSI_StrucSig) != 0x61417272 ||
41 LITTLE_TO_HOST32(info->FSI_TrailSig) != 0xAA550000)
45 info->FSI_Free_Count = HOST_TO_LITTLE32(0xFFFFFFFFU);
46 info->FSI_NxtFree = HOST_TO_LITTLE32(0xFFFFFFFFU);
47 if (!
writeSectorBlock(sectors[i], sectorBytes,
reinterpret_cast<uintptr_t
>(bytes))) {
49 SYSCALL_ERROR(IoError);
54 m_FsInfoInvalidated =
true;
bool writeSectorBlock(uint32_t sec, size_t size, uintptr_t buffer)
bool readSectorBlock(uint32_t sec, size_t size, uintptr_t buffer) const