Repository navigation
fix(storage): fall back when the kernel does not report STATX_DIOALIGN - #10
Merged
Merged
Conversation
queryAlignment() threw when statx came back without STATX_DIOALIGN, so storage could not open a file on a pre-6.1 kernel or a filesystem that does not implement the query (BTRFS, among others). It now falls back to stx_blksize, or the page size when the kernel did not report that either, and warns. The page size is a multiple of every sector size such a filesystem uses, so a buffer aligned to it satisfies any of them. Moving the statx struct and the resolution into linux_statx.h lets linux_alignment_check drive the mask directly, since a modern kernel cannot produce the one this fix is about. Writing that check turned up a division by zero: a filesystem that reports the query but zeroes dio_offset_align (tmpfs) had stx_blksize % stx_dio_offset_align evaluated with a zero divisor whenever stx_blksize was larger. The zero case is now passed through for the caller to reject, as before.
sdiebolt
marked this pull request as ready for review
September 30, 2026 15:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7.
Problem
LinuxFileIO::queryAlignment()threw whenstatx(2)came back withoutSTATX_DIOALIGN:So storage could not open a file on a pre-6.1 kernel, or on a filesystem that does not implement the query — BTRFS among them, which is where this was hit in Effusive when enabling RF/storage saving.
Change
queryAlignment()now falls back instead of throwing: page-sized alignment for both file offset/length and buffer address, with a normal-level warning.dio_offset_align/dio_mem_align(tmpfs) still throws, sinceO_DIRECTis not actually honored there.src/storage/Linux/linux_statx.hasStorage::detail, so the missing-mask path can be tested directly.LinuxFileIO.handStorage/README.mdthat claimed the constructor throws whenever the kernel cannot report a value are updated.Bug found while writing the test
A pre-existing division by zero, unrelated to the missing
STATX_DIOALIGNmask: whendio_offset_alignwas 0 andstx_blksizewas larger,stx_blksize % stx_dio_offset_aligndivided by zero. That is aSIGFPEon tmpfs or any other filesystem that acceptsO_DIRECTwithout enforcing alignment. The zero case is now passed through for the caller to reject, which is what the surrounding code intended.Test
tests/linux_alignment_check.cpp(new, wired into the Storagectestsuite, Linux only, no file I/O) drivesresolveDioAlignment()across: a 512e drive, a block size that is not a multiple of the minimum alignment, a missingSTATX_BASIC_STATS, a tmpfs-style zero report, the no-STATX_DIOALIGNpage fallback with and without a usable block size, and an empty mask.Validation run: