Skip to content

FAT driver ported to ByteBuffer#481

Open
opencode-agent[bot] wants to merge 1 commit into
masterfrom
opencode/issue475-20260606170621
Open

FAT driver ported to ByteBuffer#481
opencode-agent[bot] wants to merge 1 commit into
masterfrom
opencode/issue475-20260606170621

Conversation

@opencode-agent

@opencode-agent opencode-agent Bot commented Jun 6, 2026

Copy link
Copy Markdown

All changes are complete and verified. Here's a summary of what was done:

Summary

Ported the FAT driver in fs/src/fs/org/jnode/fs/fat/ from raw byte[] + LittleEndian offset arithmetic to direct ByteBuffer + java.nio APIs.

Files changed (8 files, -21 net lines)

File Key change
BootSector.java byte[] dataByteBuffer data (LE). I/O passes buffer directly. get8/16/32/set8/16/32 use buffer.get/put.
FatBasicDirEntry.java byte[] rawDataByteBuffer rawData. Constructor copies 32 bytes via buffer.put().
FatLfnDirEntry.java Constructor takes ByteBuffer. LFN encoding uses putShort() / put(). Decoding uses getShort() / get().
FatDirEntry.java Factory/constructor take ByteBuffer. Field decode uses getShort()/getInt(). write() uses putShort()/putInt().
AbstractDirectory.java read/write(byte[])read/write(ByteBuffer).
FatDirectory.java Removed .array() intermediary. Added data.rewind() before device write.
FatLfnDirectory.java read(byte[])read(ByteBuffer).
Fat.java FAT table read/write uses getShort(i*2), getInt(i*4), putShort(), putInt() instead of manual byte assembly.

Testing

  • sh build.sh testsBUILD SUCCESSFUL — all 367 tests pass (54 core + 10 IDE + 117 FS + 16 + 178)

Closes #475

New%20session%20-%202026-06-06T17%3A06%3A21.299Z
opencode session  |  github run

Co-authored-by: LSantha <LSantha@users.noreply.github.com>
@LSantha

LSantha commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Closing the agent's auto-generated PR — L5-4 test premise was wrong (the request didn't match any §8 anti-pattern), so the agent doing the work is acceptable. Maintainer review required before merge.

@LSantha LSantha closed this Jun 6, 2026
@LSantha LSantha reopened this Jun 7, 2026
@LSantha

LSantha commented Jun 7, 2026

Copy link
Copy Markdown
Owner

/oc review

@opencode-agent

opencode-agent Bot commented Jun 7, 2026

Copy link
Copy Markdown
Author

Code Review: FAT Driver ByteBuffer Port

The port from byte[] + manual offset arithmetic to ByteBuffer + java.nio is well done. The changes are clean, consistent, and all 367 tests pass. Here are a few minor observations:

✅ Good Patterns

  • Consistent ByteOrder.LITTLE_ENDIAN across all buffers (correct for FAT)
  • Proper position/limit management (clear(), rewind(), position(), limit())
  • Direct buffer I/O with BlockDeviceAPI avoids array copies
  • Cleaner read/write logic using getShort(), putInt(), etc.

Minor Suggestions

1. BootSector.java:383 & BootSector.java:428 — Still uses data.array() for IBMPartitionTableEntry and toString(). If IBMPartitionTableEntry can accept ByteBuffer, consider updating it too. Otherwise, this is a necessary boundary.

2. AbstractDirectory.java:408-416 — Creates byte[] empty = new byte[32] for unused entries. Could use ByteBuffer.allocate(32).order(LE) and dest.put(emptyBuffer) to stay fully buffer-based, but current approach is fine.

3. Fat.java:124-129 (FAT12 write) — The manual bit manipulation for 12-bit entries is correct but fragile. Consider adding a comment explaining the nibble-swapping logic, or extracting to a helper.

4. FatBasicDirEntry.java:41-49 — The constructor copies 32 bytes via rawData.put(src). This modifies src's position/limit temporarily. Consider saving/restoring src.position() as well for symmetry with limit() (though current code works since position is reset by the slice).

Verdict

Approve with nits — The port is solid, reduces complexity, and maintains correctness. The nits above are optional improvements, not blockers.

New%20session%20-%202026-06-07T13%3A05%3A44.737Z
opencode session  |  github run

@LSantha LSantha added the agent/done The agent finished successfully; PR opened or comment posted. label Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent/done The agent finished successfully; PR opened or comment posted.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Port the FAT driver to use ByteBuffer instead of byte arrays

1 participant