You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "casaroli (via GitHub)" <gi...@apache.org> on 2026/10/18 23:36:04 UTC

[PR] fs/vfs: Let the file system replace the target of rename(). [nuttx]

casaroli opened a new pull request, #20799:
URL: https://github.com/apache/nuttx/pull/20799

   ## Summary
   
   `rename()` on a mounted file system did not replace an existing target in one step. `mountptrename()` removed the target, then called the rename method of the file system. Between the two calls, another task could find no file at the new path: `open()` failed with `ENOENT`. POSIX requires that the new path always refers to the old file or to the new file.
   
   This PR lets the file system replace the target:
   
   - `fs/vfs`: `mountptrename()` calls the rename method first. If it fails and the target exists, it removes the target and calls the rename method again, as before. If the removal fails, `rename()` returns the error of the first call.
   - `fs/tmpfs`: `tmpfs_rename()` replaces an existing file or empty directory in one step (it returned `EEXIST`). An open file that is replaced stays until its last close. A non-empty directory gives `ENOTEMPTY` (before: `EBUSY` from `rmdir`).
   - `fs/mnemofs`, `fs/userfs`: the rename method did not check for an existing target (mnemofs adds a second entry with the same name; a userfs server can do anything). They now return `EEXIST`, so the VFS keeps the old remove-then-rename path for them.
   - A short comment in `include/nuttx/fs/fs.h` states what the VFS expects from the rename method.
   
   v9fs, hostfs, NFS, littlefs and rpmsgfs already replace the target in one step (host `rename()`, NFS RENAME, `lfs_rename()`). (hostfs `rename()` is broken on master for another reason; a separate PR fixes `hostfs_rename()`.) FAT, SMARTFS and SPIFFS return `EEXIST` and keep the old path. The pseudo file system path holds the inode tree lock for the whole operation and does not change.
   
   The first commit fixes white space in `fs_tmpfs.c` that nxstyle reports. These errors are older than this change.
   
   ## Impact
   
   `rename()` over an existing file is atomic on tmpfs, v9fs, hostfs, NFS, littlefs and rpmsgfs. Other file systems behave as before. No new configuration option. No documentation describes the old behaviour, so only the `fs.h` comment changes.
   
   Code size: `lm3s6965-ek:qemu-flat` with `CONFIG_FS_TMPFS`: text +208 bytes.
   
   ## Testing
   
   `renameatomic.c`: a writer thread renames a new file over the target in a loop for 3 s; a reader thread at a higher priority opens the target every tick. Then it checks the replace rules (file over file, directory over empty and non-empty directory, file over directory, directory over file). `qemu-armv8a:knsh` under HVF, tmpfs mounted by the test, v9fs on `/system`.
   
   | | master | this PR |
   |---|---|---|
   | tmpfs: `open()` fails with `ENOENT` (4 runs on master, 3 with this PR) | 150/1511, 124/1384, 51/675, 104/1240 | 0/1399, 0/1500, 0/1389 |
   | v9fs: `open()` fails with `ENOENT` | 414/1470, 287/969, 65/185, 403/1299 | 0/934, 0/932, 0/1117 |
   | tmpfs: directory over non-empty directory | `EBUSY` | `ENOTEMPTY`, both kept |
   | other replace rules (tmpfs, v9fs) | pass | pass |
   
   ostest passes on `qemu-armv8a:knsh` and `qemu-armv8a:nsh`. `lm3s6965-ek:qemu-flat` builds. `sim:mnemofs` and `sim:userfs` compile the changed files without warnings (the sim link fails on macOS in `sim_hostuart.c`, also on master). `tools/checkpatch.sh -c -u -m -g` passes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fs/vfs: Let the file system replace the target of rename(). [nuttx]

Posted by "casaroli (via GitHub)" <gi...@apache.org>.
casaroli commented on PR #20799:
URL: https://github.com/apache/nuttx/pull/20799#issuecomment-6270760642

   This was merged as part of #20800 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fs/vfs: Let the file system replace the target of rename(). [nuttx]

Posted by "casaroli (via GitHub)" <gi...@apache.org>.
casaroli closed pull request #20799: fs/vfs: Let the file system replace the target of rename().
URL: https://github.com/apache/nuttx/pull/20799


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fs/vfs: Let the file system replace the target of rename(). [nuttx]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #20799:
URL: https://github.com/apache/nuttx/pull/20799#issuecomment-6256642904

   <!-- membrowse-pr-comment -->
   ## <img src="https://membrowse.com/membrowse-logo.svg" height="24" align="top"> MemBrowse Memory Report &middot; [Explore what changed →](https://membrowse.com/public/apache/nuttx?commit_sha=11a91ff2e6bc8f9f7096f5e04698d3ecb9273c60)
   
   ### [esp32-devkitc](https://membrowse.com/public/apache/nuttx/target/esp32-devkitc/compare?head=11a91ff2e6bc8f9f7096f5e04698d3ecb9273c60&base=ddb09bb4719f045b93cd960387dc485ee7f9069b)
     - **ROM**: .flash.text +36 B (+0.0%, 126,868 B / 4,194,272 B, total: 3% used)
     - **irom0_0_seg**: .flash.text +36 B (+0.0%, 90,884 B / 3,342,304 B, total: 3% used)
   ### [qemu-armv8a](https://membrowse.com/public/apache/nuttx/target/qemu-armv8a/compare?head=11a91ff2e6bc8f9f7096f5e04698d3ecb9273c60&base=ddb09bb4719f045b93cd960387dc485ee7f9069b)
     - **Code**: .text.rename +48 B, .text.tmpfs_rename +248 B (+0.1%, 350,960 B)
   ### [qemu-intel64](https://membrowse.com/public/apache/nuttx/target/qemu-intel64/compare?head=11a91ff2e6bc8f9f7096f5e04698d3ecb9273c60&base=ddb09bb4719f045b93cd960387dc485ee7f9069b)
     - **Code**: .text +69 B (+0.0%, 8,684,965 B)
   ### [rx65n-rsk2mb](https://membrowse.com/public/apache/nuttx/target/rx65n-rsk2mb/compare?head=11a91ff2e6bc8f9f7096f5e04698d3ecb9273c60&base=ddb09bb4719f045b93cd960387dc485ee7f9069b)
     - **ROM**: .text +32 B (+0.0%, 88,364 B / 2,097,152 B, total: 4% used)
   
   *No memory changes detected for:*
   - [arduino-mega2560](https://membrowse.com/public/apache/nuttx/target/arduino-mega2560/compare?head=11a91ff2e6bc8f9f7096f5e04698d3ecb9273c60&base=ddb09bb4719f045b93cd960387dc485ee7f9069b)
   - [hifive1-revb](https://membrowse.com/public/apache/nuttx/target/hifive1-revb/compare?head=11a91ff2e6bc8f9f7096f5e04698d3ecb9273c60&base=ddb09bb4719f045b93cd960387dc485ee7f9069b)
   - [mirtoo](https://membrowse.com/public/apache/nuttx/target/mirtoo/compare?head=11a91ff2e6bc8f9f7096f5e04698d3ecb9273c60&base=ddb09bb4719f045b93cd960387dc485ee7f9069b)
   - [s698pm-dkit](https://membrowse.com/public/apache/nuttx/target/s698pm-dkit/compare?head=11a91ff2e6bc8f9f7096f5e04698d3ecb9273c60&base=ddb09bb4719f045b93cd960387dc485ee7f9069b)
   - [stm32-nucleo-f103rb](https://membrowse.com/public/apache/nuttx/target/stm32-nucleo-f103rb/compare?head=11a91ff2e6bc8f9f7096f5e04698d3ecb9273c60&base=ddb09bb4719f045b93cd960387dc485ee7f9069b)
   
   ---
   <sub>Catch memory regressions in CI with [MemBrowse](https://membrowse.com). Free for open source.</sub>
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fs/vfs: Let the file system replace the target of rename(). [nuttx]

Posted by "casaroli (via GitHub)" <gi...@apache.org>.
casaroli closed pull request #20799: fs/vfs: Let the file system replace the target of rename().
URL: https://github.com/apache/nuttx/pull/20799


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org