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

   ## Summary
   
   tmpfs gave `st_ino = 0` to every file and directory, and `d_ino = 0` in 
`readdir()`. POSIX says that `st_dev` and `st_ino` identify a file. With all 
numbers 0, `du` counted only one file of a tmpfs, and `tar` and `cp` took all 
the files for hard links of one file.
   
   This PR gives each new tmpfs object a serial number from a counter that all 
tmpfs mounts share (`atomic_add()`), and returns it in `st_ino` and `d_ino`. 
The number stays when a file grows (only the data is reallocated) and with 
`rename()`.
   
   ## Impact
   
   `stat()`, `fstat()` and `readdir()` of a tmpfs give a serial number from 1 
up, unique among all tmpfs objects. Each tmpfs object header is 4 or 8 bytes 
larger (`ino_t` and alignment). All build modes and architectures with 
`CONFIG_FS_TMPFS`. No API change; no documentation describes the tmpfs serial 
numbers.
   
   ## Testing
   
   Test program `tmpfsino.c` (cases: two files and a directory have different 
`st_ino`, none 0; `fstat()` gives the `st_ino` of `stat()`; `st_ino` stays when 
the file grows; `st_ino` stays with `rename()`; `readdir()` gives `d_ino` = 
`st_ino`), on qemu-armv8a:knsh (kernel build, HVF) with `CONFIG_FS_TMPFS`:
   
   | Case | master aeab6fbf989 | this PR |
   |---|---|---|
   | differ | all 0: FAIL | 3, 4: PASS |
   | fstat | 0 = 0 | 3 = 3: PASS |
   | grow | 0 = 0 | 3 = 3: PASS |
   | rename | 0 = 0 | 3 = 3: PASS |
   | dirent | 0 = 0 | PASS |
   
   On master the last four cases pass only because every number is 0.
   
   ostest exits with status 0 on qemu-armv8a:knsh (kernel) and qemu-armv8a:nsh 
(flat, with `CONFIG_FS_TMPFS`).
   
   Builds with `CONFIG_FS_TMPFS`, each without new warnings: nucleo-f072rb:nsh 
(flat, Cortex-M0, no atomic instructions), stm32f4discovery:nsh (flat, 
Cortex-M4), rv-virt:nsh64 (flat, RISC-V) and rv-virt:pnsh64 (protected, 
RISC-V). (lm3s6965-ek:qemu-protected with `CONFIG_FS_TMPFS` does not fit its 
128 KB kernel flash, so rv-virt:pnsh64 is the protected build.)
   
   `tools/checkpatch.sh -c -u -m -g` passes.
   


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