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

   ## Summary
   
   An `open()` with `O_CREAT` of a file that is already there gives inotify the 
event `IN_CREATE` (with `IN_OPEN`). Linux gives only `IN_OPEN` then: `O_CREAT` 
does not tell if the open made the file. `notify_open()` adds `IN_CREATE` for 
each `O_CREAT`, and `file_vopen()` gives it the open flags as they are.
   
   `file_vopen()` now gives `O_CREAT` to `notify_open()` only when the open 
made the file:
   
   - a file in a mounted file system: the stat method of the file system tells, 
before the open, if the file is there (with `O_EXCL` the file is always new; a 
file system without a stat method keeps the old result);
   - the pseudo file system: only `pseudofile_create()` makes a file; a file, 
driver or directory that the lookup finds gives no `IN_CREATE`;
   - a block driver opened through its proxy gives no `IN_CREATE`.
   
   Named limit: two opens that race for a new file can both give `IN_CREATE`.
   
   ## Impact
   
   Only with `CONFIG_FS_NOTIFY`; all the changes are under it. An open with 
`O_CREAT` and without `O_EXCL` of a file in a mounted file system calls the 
stat method of the file system once more. `mq_open()`, `sem_open()`, 
`shm_open()` and the event open do not change. No API or ABI change.
   
   ## Testing
   
   A test program (not in this PR) watches a tmpfs directory with `IN_CREATE | 
IN_OPEN | IN_CLOSE_WRITE` and opens: a new file with `O_CREAT`, the same file 
again with `O_CREAT`, a new file with `O_CREAT | O_EXCL`, and an existing file 
with `O_CREAT | O_TRUNC`. qemu-armv8a:nsh (flat, HVF) with `CONFIG_FS_NOTIFY`: 
before, the two opens of existing files give `IN_CREATE | IN_OPEN`; after, they 
give `IN_OPEN` only, and the two new files still give `IN_CREATE | IN_OPEN`. 
ostest passes.
   
   Builds with `-Werror` and `CONFIG_FS_NOTIFY`, `CONFIG_PSEUDOFS_FILE`: 
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]

Reply via email to