Files
erofs-freebsd-out-tree/docs/pre12-batch-02.md
T
2026-08-18 09:20:44 +02:00

1.6 KiB

Pre12 Batch 02

This batch replaces exactly three potentially unaligned typed loads with the FreeBSD little-endian byte decoders planned for Pre12.

  • xattr.c: hdrbuf contains two raw metadata bytes returned by erofs_xattr_read_backing(..., sizeof(raw_len), ...); le16dec(hdrbuf) decodes the prefix-record length.
  • inode.c: buf contains at least one complete 32-byte compact on-disk inode returned by erofs_read_metadata; its first two bytes are the little-endian i_format field decoded by le16dec(buf).
  • data.c: the non-indexes branch sets entry_size to EROFS_BLOCK_MAP_ENTRY_SIZE == sizeof(__le32) == 4; idx points to those four raw block-map bytes and le32dec(idx) decodes the block address.

For bytes b0..b3, both old expressions and the new helpers produce b0 | b1 << 8 or b0 | b1 << 8 | b2 << 16 | b3 << 24. On a little-endian host the typed load already has that value; on a big-endian host leXXtoh byte-swaps the typed value to that same formula. The helpers preserve this result while avoiding any alignment requirement.

xattr.c and data.c receive the helpers through internal.h to erofs_fs.h to <sys/endian.h>; inode.c also includes <sys/endian.h> directly. Existing le16dec and le32dec consumers confirm the established include convention. Error checks, branches, value ranges, and buffer release ordering are unchanged. No point was skipped and no other endian read was changed.

Validation used exact-expression counts, buffer-source and length inspection, symbolic endian equivalence, source-diff inspection, and git diff --check. No build, QEMU, smoke, feature, or other dynamic test was run.