Repository navigation
fix(io): reserve file length without posix_fallocate on macos - #138
Merged
Merged
Conversation
macOS libSystem has no `posix_fallocate`, and the declared extern failed to link the gpridge wheels. `libc::fallocate` is the Linux and Android binding. `libc::posix_fallocate` is the FreeBSD binding. macOS reserves the gap with `fcntl(F_PREALLOCATE)` and `File::set_len` sets the logical size, because `F_PREALLOCATE` does not. Both of those calls set `F_ALLOCATEALL`. `fcntl(2)` allows `F_ALLOCATECONTIG` alone to succeed after a short allocation, and returns `ENOSPC` for a shortfall only when `F_ALLOCATEALL` is set. Windows and every other host use `File::set_len`. A filesystem that returns `EOPNOTSUPP`, `ENOTSUP`, `ENOSYS`, or `EINVAL` still extends that way. `ENOSPC` and any other error are returned, and the file ends at the requested length. CON-bin uses the same helper. Kitline-Change: ksrqwnpsuvlqpmozvwnmsurzrskyupzn
This was referenced Dec 3, 2026
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.
macOS libSystem has no
posix_fallocate, and the declared extern failedto link the gpridge wheels.
libc::fallocateis the Linux and Androidbinding.
libc::posix_fallocateis the FreeBSD binding. macOS reservesthe gap with
fcntl(F_PREALLOCATE)andFile::set_lensets the logicalsize, because
F_PREALLOCATEdoes not. Both of those calls setF_ALLOCATEALL.fcntl(2)allowsF_ALLOCATECONTIGalone to succeedafter a short allocation, and returns
ENOSPCfor a shortfall only whenF_ALLOCATEALLis set. Windows and every other host useFile::set_len.A filesystem that returns
EOPNOTSUPP,ENOTSUP,ENOSYS, orEINVALstill extends that way.
ENOSPCand any other error are returned, andthe file ends at the requested length. CON-bin uses the same helper.
Note
Medium Risk
Touches low-level file allocation on every platform and is on the CON-bin write path; behavior changes on macOS and error handling for ENOSPC is stricter than silent
set_lenfallback.Overview
Unifies scratch and CON-bin preallocation behind a shared,
pub(crate)allocate_leninwriter.rs. CON-bin’spreallocateno longer implements its own Linuxfallocatepath; it calls that helper (truncating only whenlen == 0).Fixes macOS wheel builds by dropping the undeclared
posix_fallocateextern that failed linking, and instead reserving space withfcntl(F_PREALLOCATE)plusset_lenwhen the logical size still does not match.Broadens platform-specific reserve logic: Linux/Android →
fallocate, FreeBSD →posix_fallocate, unsupported errno codes →set_lenfallback, with Miri skipping syscalls. Grow/shrink is handled by comparing current file length before reserve.Adds a unit test that temp files end at the requested length after allocate/shrink.
Reviewed by Cursor Bugbot for commit 2f8ea44. Bugbot is set up for automated code reviews on this repo. Configure here.