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

   ## Summary
   
   - **fs/userfs: add syncfs and link operations support.**
     `syncfs`, and with `CONFIG_FS_LINKS` `link`, `symlink`, `readlink` and
     `lstat`, were missing from userfs: the VFS returned `EBADF`/`ENOSYS`
     for them and `lstat()` silently used `stat()`. They are now forwarded
     to the daemon over new `USERFS_REQ_SYNCFS/LINK/SYMLINK/READLINK/LSTAT`
     requests and optional `userfs_operations_s` methods of the same name.
     A daemon that leaves a method NULL answers `-ENOSYS`; `lstat` then
     falls back to `stat`, so existing daemons behave as before.
   - **Documentation/userfs: describe the syncfs and link methods.**
   
   ## Impact
   
   - New feature / API change: YES. New optional members at the end of
     `struct userfs_operations_s` and new request/response types in
     `include/nuttx/fs/userfs.h`; existing positional initializers still
     build.
   - Behavior: `syncfs()`/`sync()` now reach the daemon. A userfs mount whose
     daemon has exited without unmounting already blocks every operation on
     it; since `sync()` runs from the reboot notifier, such a stale mount now
     also blocks `poweroff`. Unmount before the daemon exits.
   - Build, hardware, documentation (updated), security, compatibility: NO.
   
   ## Testing
   
   Host: Ubuntu 22.04 x86_64, gcc 13.1.0. Base: master 37709a3995f.
   
   `sim:nsh` with `CONFIG_FS_USERFS`, `CONFIG_FS_LINKS` and the UDP loopback
   network. A test app runs two `userfs_run()` daemons: `/mnt/ufl`
   implements the new methods and counts the calls, `/mnt/ufn` implements
   none of them. It calls `syncfs()`, `link()`, `symlink()`, `readlink()`,
   `lstat()` and `sync()`, then unmounts both.
   
   Testing logs before change:
   
   ```
   userfslink /mnt/ufl: syncfs ret=-1 errno=9
   userfslink /mnt/ufl: link ret=-1 errno=38
   userfslink /mnt/ufl: symlink ret=-1 errno=38
   userfslink /mnt/ufl: readlink ret=-1 errno=38 target=""
   userfslink /mnt/ufl: lstat ret=0 errno=0 type=regular
   userfslink: daemon syncfs=0 link=0 symlink=0 readlink=0 lstat=0 last=""
   userfslink: sync() daemon syncfs=0
   ```
   
   Testing logs after change:
   
   ```
   userfslink /mnt/ufl: syncfs ret=0 errno=0
   userfslink /mnt/ufl: link ret=0 errno=0
   userfslink /mnt/ufl: symlink ret=0 errno=0
   userfslink /mnt/ufl: readlink ret=1 errno=0 target="f"
   userfslink /mnt/ufl: lstat ret=0 errno=0 type=link
   userfslink: daemon syncfs=1 link=1 symlink=1 readlink=1 lstat=1 last="sl->f"
   userfslink /mnt/ufn: syncfs ret=-1 errno=38
   userfslink /mnt/ufn: link ret=-1 errno=38
   userfslink /mnt/ufn: lstat ret=0 errno=0 type=regular
   userfslink: sync() daemon syncfs=1
   userfslink: umount ufl=0 ufn=0
   ```
   
   The daemon without the methods (`/mnt/ufn`) gets `ENOSYS`, and `lstat`
   falls back to `stat`.
   
   - `./tools/checkpatch.sh -g master..HEAD`: all checks pass.
   - Make and CMake builds pass with no warnings in the changed files, with
     `CONFIG_FS_LINKS` on and off; `ostest` exits with status 0.
   - Verified on sim only.
   
   ## PR verification Self-Check
   
   * [x] This PR introduces only one functional change.
   * [x] I have updated all required description fields above.
   * [x] My PR adheres to Contributing Guidelines and Documentation (git commit 
title and message, coding standard, etc).
   * [ ] My PR is still work in progress (not ready for review).
   * [x] My PR is ready for review and can be safely merged into a codebase.
   


-- 
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]

Reply via email to