casaroli opened a new pull request, #20559: URL: https://github.com/apache/nuttx/pull/20559
## Summary `open()` of a directory gives the file a stand-in inode, `g_dir_inode`, with the directory operations. `file_fstat()` did not know it and returned `inode_stat()` of that stand-in: a directory, but with `st_ino` 0 and none of the real directory's attributes, on every file system. Programs that walk directories with `openat()` and `fstat()`, for example with fts, compare `st_dev` and `st_ino` with those from `stat()` to detect loops and changed directories. They failed: a recursive `ls` reported each subdirectory as "already listed", and a recursive `rm` stopped with a traversal error. This PR stats the directory by the path that the open directory keeps (the same path that `F_GETPATH` returns). ## Impact `fstat()` of a file descriptor that `open()` returned for a directory. Other descriptors are unchanged. ## Testing `qemu-armv8a:knsh` with a virtio 9P share mounted at `/mnt`, QEMU 11. The test program was built outside the tree against the export package. A program compares `stat()` of a directory with `fstat()` of the directory opened with `open(path, O_RDONLY | O_DIRECTORY)`: Before: ``` /mnt/d stat: dir=1 ino=170158369 fstat: dir=1 ino=0 /mnt/d/e stat: dir=1 ino=170158371 fstat: dir=1 ino=0 ``` After: ``` /mnt/d stat: dir=1 ino=170158369 fstat: dir=1 ino=170158369 /mnt/d/e stat: dir=1 ino=170158371 fstat: dir=1 ino=170158371 ``` Builds with `-Wno-cpp -Werror`: `qemu-armv8a:knsh`, `lm3s6965-ek:qemu-flat`, `mps2-an500:nsh`, `rv-virt:knsh`, `raspberrypi-pico:nsh`. `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]
