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

   ## Summary
   
   Changing file metadata (mode, owner, group, atime or mtime) is a POSIX status
   change that must update `st_ctime`. Each filesystem implements this rule on
   its own today:
   
   - tmpfs derives it from the chstat flags.
   - littlefs writes `st_ctim` on every `fchstat()`/`chstat()`, so even a
     no-op `utimensat()` (both times `UTIME_OMIT`) bumps `st_ctime`.
   
   This PR adds `CH_STAT_CTIME` and sets it in `file_fchstat()` and `chstat()`
   whenever a metadata field actually changes, after the `UTIME_OMIT` filtering.
   `buf->st_ctim` already holds the current time, so a filesystem only honors 
the
   flag. tmpfs drops its own derivation and littlefs writes `at_ctim` only when
   the flag is set.
   
   hostfs, nfs, v9fs, rpmsgfs, userfs and unionfs test individual `CH_STAT_*`
   bits or forward the flags unchanged, so the new bit does not change their
   behavior.
   
   ## Impact
   
   - New feature: NO.
   - User adaptation: NO.
   - Build: NO.
   - Hardware: NO.
   - Documentation: NO.
   - Security: NO.
   - Compatibility: on littlefs a no-op `utimensat()`/`futimens()` no longer
     updates `st_ctime`. Out-of-tree filesystems see one more bit,
     `CH_STAT_CTIME` `(1 << 5)`, in the chstat flags.
   
   ## 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 `a3b67d70e0`.
   - Target: `sim:nsh` with `CONFIG_FS_TMPFS`, `CONFIG_MTD`, `CONFIG_RAMMTD`
     and `CONFIG_FS_LITTLEFS`. 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.
   
   A small test program mounts littlefs on `/dev/rammtd` and a tmpfs, then on
   each one calls `utimensat()` with both times `UTIME_OMIT`, and then sets
   `mtime`, with a 2 second sleep before each step:
   
   | step | littlefs master | littlefs this PR | tmpfs master | tmpfs this PR |
   |---|---|---|---|---|
   | no-op `utimensat()`: ctime | bumped | unchanged | unchanged | unchanged |
   | set mtime: ctime | bumped | bumped | bumped | bumped |
   
   Testing logs before change:
   
   ```
   littlefs no-op utimensat(): ctime before=1794563573 after=1794563575 -> 
bumped
   littlefs set mtime:          ctime before=1794563575 after=1794563577 -> 
bumped
   tmpfs    no-op utimensat(): ctime before=1794563577 after=1794563577 -> 
unchanged
   tmpfs    set mtime:          ctime before=1794563577 after=1794563581 -> 
bumped
   ```
   
   Testing logs after change:
   
   ```
   littlefs no-op utimensat(): ctime before=1794563483 after=1794563483 -> 
unchanged
   littlefs set mtime:          ctime before=1794563483 after=1794563487 -> 
bumped
   tmpfs    no-op utimensat(): ctime before=1794563487 after=1794563487 -> 
unchanged
   tmpfs    set mtime:          ctime before=1794563487 after=1794563491 -> 
bumped
   ```
   
   ## 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