casaroli opened a new pull request, #22510: URL: https://github.com/apache/nuttx/pull/22510
## Summary Two fixes in tmpfs for open files and directories: - An open file that loses its name (`unlink()`, a `rename()` over it, the unmount) kept its pointer to the directory, but it holds no reference on it, so `rmdir()` can remove that directory while the file is still open. A later `FIOC_FILEPATH` on the file (`F_GETPATH`, `readlink()` of `/proc/PID/fd/N`, and each `close()` with `CONFIG_FS_NOTIFY`) then used the removed directory. The file now forgets its directory when its name goes, as `inode_unlink()` does in the pseudo file system. `FIOC_FILEPATH` on an unlinked file gives `-ENOENT`, as before while the directory was still there. - The reference count of a tmpfs object was 8 bits. 256 open descriptors (open, `dup()`, `opendir()`) on one object made it zero again: `unlink()` then removed a file at once although it was still open, and `rmdir()` removed a directory that was still open. The count is now 32 bits. `tmpfs_mmap()` refused a mapping at 255 references to keep its 8-bit mapping count in range; it now tests the mapping count itself. ## Impact tmpfs only, the same in flat, protected and kernel builds. No API or ABI change (internal tmpfs structures). Each tmpfs object grows by at most 4 bytes on 32-bit targets (the 8-bit count was next to the 8-bit type); no change on 64-bit targets (padding). ## Testing A test program (not in this PR), qemu-armv8a:nsh (flat, HVF), `CONFIG_LIBC_OPEN_MAX=1024`: - `mmap()` of a tmpfs file that is open 255 times: before, `ENOMEM`; after, the mapping works. - `rmdir()` of a tmpfs directory that is open 256 times (`opendir()`): before, `rmdir()` returns 0 and removes the open directory; after, `EBUSY`, as with one open. - open `DIR/f`, `unlink()` it, `rmdir()` `DIR`, make other files and directories, then `F_GETPATH` and `close()`: after the fix, `ENOENT` and 0. ostest passes after the fix. Builds with `-Werror` and `CONFIG_FS_NOTIFY`: qemu-armv8a:nsh and :knsh (Arm GNU 13.2), rv-virt:nsh64, :pnsh64 and :knsh64 (CI image). -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
