fix(fs): tolerate FatFS VFS limits in atomic dir writes - #324
Open
Love4yzp wants to merge 1 commit into
Open
Conversation
Love4yzp
added a commit
to Love4yzp/pocketjs-d1001
that referenced
this pull request
Aug 22, 2026
Love4yzp
marked this pull request as ready for review
August 22, 2026 13:32
ESP-IDF's FATFS VFS diverges from POSIX in two places that break dir_write's atomic-overwrite path: - O_EXCL opens fail with ENOENT, so the temp-file create_new never succeeds and every atomic write errors out. Fall back to create+truncate: the tmp dir is module-owned and swept, and the monotonic counter keeps the name unique. - FatFS f_rename refuses to overwrite an existing destination (surfaced as EEXIST) where POSIX rename replaces it. Fall back to remove+rename; the atomic-overwrite contract is not representable on FatFS. Both fallback arms are unreachable on POSIX filesystems, so behavior there is unchanged. Verified with cargo test -p pocket-fs (12/12) and on an ESP32-P4 board (ESP-IDF v6.1, FatFS on SD over the VFS) where data.fs writes and rewrites land and persist across reboots.
Love4yzp
force-pushed
the
fix/fs-fatfs-atomic-write
branch
from
August 22, 2026 15:21
4536128 to
1e361c7
Compare
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.
Problem
dir_write's atomic-overwrite path assumes two POSIX behaviors that ESP-IDF's FATFS VFS does not provide, so every atomic write through the fs module fails on ESP32 targets with a FatFS-backed root:create_newcall never succeeds and the write errors out before any payload lands.f_renamerefuses to overwrite an existing destination (FR_EXIST, surfaced as EEXIST) where POSIXrenamereplaces it, so rewriting an existing file fails even after the temp file landed and synced.Fix
Both fallbacks arm only on the exact error kinds where the filesystem is known to diverge from POSIX:
Behavior on POSIX filesystems is unchanged — both fallback arms are unreachable there.
Verification
cargo test -p pocket-fs— 12/12 pass on the host.data.fswrites and rewrites land and persist across reboots. Board-side receipts: pocketjs-d1001 verification doc.