fat32: fix pre-alloc cluster leak; add write-handle ref-count

- Remove FAT_WRITE_PREALLOC_BYTES (redundant at typical cluster sizes)
- Simplify fatPreallocClusterCount to always return MAX_CLUSTERS
- FAT32CloseFile: truncate pre-allocated tail clusters back to ByteSize
  on close, freeing FAT chain entries beyond the file's real size
- Add TFATWriteRef + WriteRefs[32] in TFATVolumeCtx and Registered flag
  on TFATOpenFile to track concurrent write handles per dir entry
- fatRegisterWriteHandle / fatUnregisterWriteHandle: CLI-guarded slot scan
  keyed by (DirLoc.SectorLBA, DirLoc.EntryIdx)
- Register on first FAT chain extension in FAT32EnsureCapacityForWrite
- Truncation in FAT32CloseFile skipped unless this is the last writer
  (prevents RunMap corruption in concurrent-open scenarios)
- Add forward decl for fatFreeClusterChain to fix ordering issue
- app.iotest: update default path to /disk/vol2/IOTEST.BIN
This commit is contained in:
Aaron committed 2026-03-18 21:05:36 +00:00
1 parent 663bfbb0e4
commit 096db148d0
6 files changed
+818 -27

No files matched your search

@@ -69,7 +69,7 @@ function send_read_capacity(device : PAHCI_Device; sectorCount : puint32; blockS
implementation
const
AHCI_ENABLE_NCQ = false;
AHCI_ENABLE_NCQ = true;
function min_u32(a : uint32; b : uint32) : uint32;
begin
@@ -421,15 +421,15 @@ begin
start_port(device^.port);
{ Re-enable port interrupts and bail — device is non-functional. }
device^.port^.int_enable := $40000003;
device^.port^.int_enable := $4000000B;
kfree(buffer);
exit;
end;
{ Re-enable port interrupts now that IDENTIFY polling is done.
$40000003 = bit 0 (D2H Register FIS) | bit 1 (PIO Setup FIS) | bit 30 (Task File Error)
These three bits cover all normal completions and hardware error events. }
device^.port^.int_enable := $40000003;
$4000000B = bit 0 (D2H Register FIS) | bit 1 (PIO Setup FIS) | bit 3 (Set Device Bits / NCQ) | bit 30 (Task File Error)
Bit 3 is required for NCQ completion notifications via SDB FIS. }
device^.port^.int_enable := $4000000B;
b8 := puint16(buffer);
memcpy(uint32(buffer), uint32(@device^.ata_info[0]), 512);