Skip to content

fix(io): reserve file length without posix_fallocate on macos - #138

Merged
HaoZeke merged 1 commit into
developfrom
fix/macos-fallocate
Dec 3, 2026
Merged

HaoZeke merged 1 commit into
developfrom
fix/macos-fallocate

Conversation

@HaoZeke

@HaoZeke HaoZeke commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

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.


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_len fallback.

Overview
Unifies scratch and CON-bin preallocation behind a shared, pub(crate) allocate_len in writer.rs. CON-bin’s preallocate no longer implements its own Linux fallocate path; it calls that helper (truncating only when len == 0).

Fixes macOS wheel builds by dropping the undeclared posix_fallocate extern that failed linking, and instead reserving space with fcntl(F_PREALLOCATE) plus set_len when the logical size still does not match.

Broadens platform-specific reserve logic: Linux/Android → fallocate, FreeBSD → posix_fallocate, unsupported errno codes → set_len fallback, 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.

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
@HaoZeke
HaoZeke merged commit 2f8ea44 into develop Dec 3, 2026
74 of 79 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant