Summary
Following the FLUSH CACHE deferral in 7baa16d, add a configurable write-through mode that flushes the drive cache after every write operation. This provides data safety by default while allowing write-back for performance when desired.
Background
The previous commit moved FLUSH CACHE from per-write (write-through) to on-demand (write-back). This is faster but creates a window where data sits in the drive's volatile cache. On power loss, cached data is lost. Write-through eliminates this window.
Proposed Implementation
Add a writeThrough boolean field to IDEDiskDriver, defaulting to true. Read override from system property jnode.ide.writethrough at driver start.
// IDEDiskDriver fields
private boolean writeThrough = true;
// In startDevice(), after existing descriptor reads:
writeThrough = !"false".equals(
VmIOContext.getGlobalProperties().getProperty("jnode.ide.writethrough"));
// In transfer(), after the write loop completes:
if (isWrite && writeThrough) {
flush();
}
Files to Modify
fs/src/driver/org/jnode/driver/block/ide/disk/IDEDiskDriver.java — add field, property read, conditional flush
Testing / Validation
Test 1: Write-through by default
- Build:
sh build.sh cd-x86-lite
- Boot in VirtualBox/QEMU
- Mount a FAT filesystem:
mount /dev/ide0-auto /mnt
- Write a file:
echo test > /mnt/test.txt
- Verify no crash, file persists after reboot
- Verify via serial log that FLUSH CACHE command is issued after write (add debug log in
flush())
Test 2: Write-back via property override
- Add
jnode.ide.writethrough=false to boot command line in GRUB config
- Boot, mount, write file
- Verify file write completes without FLUSH CACHE (faster)
- Verify FLUSH CACHE is only issued on unmount/sync
Test 3: Power loss simulation (write-through)
- Boot with write-through (default)
- Mount FAT, write large file
- Kill VM mid-write (SimulateBox close without save)
- Reboot, mount, verify filesystem consistency (no corruption)
Test 4: Power loss simulation (write-back)
- Boot with
jnode.ide.writethrough=false
- Mount FAT, write large file
- Kill VM mid-write
- Reboot, mount — expect possible partial/corrupted write (acceptable, confirms write-back behavior)
Test 5: Stop device flush
- Unmount filesystem
- Verify FLUSH CACHE is issued during
stopDevice() (already implemented)
Acceptance Criteria
Summary
Following the FLUSH CACHE deferral in 7baa16d, add a configurable write-through mode that flushes the drive cache after every write operation. This provides data safety by default while allowing write-back for performance when desired.
Background
The previous commit moved FLUSH CACHE from per-write (write-through) to on-demand (write-back). This is faster but creates a window where data sits in the drive's volatile cache. On power loss, cached data is lost. Write-through eliminates this window.
Proposed Implementation
Add a
writeThroughboolean field toIDEDiskDriver, defaulting totrue. Read override from system propertyjnode.ide.writethroughat driver start.Files to Modify
fs/src/driver/org/jnode/driver/block/ide/disk/IDEDiskDriver.java— add field, property read, conditional flushTesting / Validation
Test 1: Write-through by default
sh build.sh cd-x86-litemount /dev/ide0-auto /mntecho test > /mnt/test.txtflush())Test 2: Write-back via property override
jnode.ide.writethrough=falseto boot command line in GRUB configTest 3: Power loss simulation (write-through)
Test 4: Power loss simulation (write-back)
jnode.ide.writethrough=falseTest 5: Stop device flush
stopDevice()(already implemented)Acceptance Criteria
jnode.ide.writethrough=falseenables write-back