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

   ## Summary
   
   tmpfs keeps no file times: `stat()` reports `st_atime`, `st_mtime` and
   `st_ctime` as 0, and `utimensat()`/`futimens()` fail with `ENOSYS` unless
   `CONFIG_FS_PERMISSION` is enabled.
   
   - **tmpfs: add configurable timestamp support.** Add the three times to every
     tmpfs object, set them at creation and report them in `stat()`/`fstat()`.
     `read()` updates `st_atime` unless `O_NOATIME` is set; `mmap()` updates
     it too, because tmpfs cannot trap the first access to the mapping. A new
     `msync()` handler marks `st_mtime`/`st_ctime` of a shared mapping.
   - **tmpfs: add timestamp maintenance and chstat.** `write()`, `ftruncate()`
     and `open(O_TRUNC)` update `st_mtime`/`st_ctime`. Creating, removing or
     renaming an entry updates the times of the directories involved, and
     `st_ctime` of a renamed object. `chstat`/`fchstat` now set `st_atime` and
     `st_mtime` and bump `st_ctime` on any metadata change, with or without
     `CONFIG_FS_PERMISSION`.
   - **Documentation/tmpfs: describe timestamp support.**
   
   ## Impact
   
   - New feature: YES, tmpfs files and directories now have real times.
   - User adaptation: NO.
   - Build: NO.
   - Hardware: NO.
   - Documentation: YES, `Documentation/os/filesystem/tmpfs.rst`.
   - Security: NO.
   - Compatibility: `utimensat()`/`futimens()` on tmpfs succeed instead of
     returning `ENOSYS` when `CONFIG_FS_PERMISSION` is disabled. Each tmpfs
     object grows by three `struct timespec`.
   
   ## Testing
   
   I confirm that changes are verified on local setup and works as intended:
   
   - Build Host: Ubuntu 22.04 x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0,
     master `8790ee6868`.
   - Target: `sim:nsh` with `CONFIG_FS_TMPFS`. Verified on sim only, no real
     hardware.
   - `./tools/checkpatch.sh -m -g master..HEAD`: all checks pass.
   - Make and CMake builds pass, `ostest` exits with status 0. Each commit
     builds on its own.
   
   A small test program mounts a tmpfs, runs each step with a 2 second sleep in
   between and compares the times reported by `stat()`:
   
   | step | master | this PR |
   |---|---|---|
   | create a file: times | 0 | set |
   | `read()`: file atime | unchanged | updated |
   | `write()`: file mtime | unchanged | updated |
   | `truncate()`: file ctime | unchanged | updated |
   | `utimensat()`: file mtime / ctime | unchanged | updated |
   | create entry: directory mtime | unchanged | updated |
   | `unlink()`: directory mtime | unchanged | updated |
   | `rename()`: new directory mtime | unchanged | updated |
   
   Testing logs before change:
   
   ```
   create: file times                 atime=0 mtime=0 ctime=0 -> zero
   read(): file atime                 before=0 after=0 -> unchanged
   write(): file mtime                before=0 after=0 -> unchanged
   truncate(): file ctime             before=0 after=0 -> unchanged
   utimensat(): file mtime            before=0 after=0 -> unchanged
   utimensat(): file ctime            before=0 after=0 -> unchanged
   create entry: dir mtime            before=0 after=0 -> unchanged
   unlink(): dir mtime                before=0 after=0 -> unchanged
   rename(): new dir mtime            before=0 after=0 -> unchanged
   fstimes: 9 check(s) failed
   ```
   
   Testing logs after change:
   
   ```
   create: file times                 atime=1794496965 mtime=1794496965 
ctime=1794496965 -> set
   read(): file atime                 before=1794496965 after=1794496967 -> 
updated
   write(): file mtime                before=1794496965 after=1794496969 -> 
updated
   truncate(): file ctime             before=1794496969 after=1794496971 -> 
updated
   utimensat(): file mtime            before=1794496971 after=1794497971 -> 
updated
   utimensat(): file ctime            before=1794496971 after=1794496973 -> 
updated
   create entry: dir mtime            before=1794496965 after=1794496975 -> 
updated
   unlink(): dir mtime                before=1794496975 after=1794496977 -> 
updated
   rename(): new dir mtime            before=1794496965 after=1794496979 -> 
updated
   fstimes: 0 check(s) failed
   ```
   
   ## 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