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

   ## Summary
   
   open() of a directory gives the file a stand-in inode (dir_allocate()), not 
the inode of the file system of the directory. fstatfs() and fstatvfs() of such 
a descriptor took the stand-in inode as a node of the pseudo file system. For a 
directory on any mounted file system they gave f_type PROC_SUPER_MAGIC, f_bsize 
0 and no sizes, while statfs() of the same path gave the real values.
   
   fstatfs() now uses the inode where the directory starts (fd_root): the mount 
point, or the node of the pseudo file system. dir_fstat() already handles 
fstat() of such a descriptor. A new helper, dir_isdirectory(), tells if a file 
is a directory opened with open(); it compares f_inode with the stand-in inode, 
which is private to fs_dir.c.
   
   ## Impact
   
   fstatfs() and fstatvfs() of a directory descriptor now give the same values 
as statfs() and statvfs() of its path. Descriptors of other files do not 
change. The code is the same in flat, protected and kernel builds, and it has 
no arch code. With CONFIG_DISABLE_DIRECTORY_OPERATIONS, dir_isdirectory() is an 
inline function that returns false. No Kconfig or documentation change.
   
   ## Testing
   
   A test program, fstatfsdir.c, opens each directory with O_RDONLY | 
O_DIRECTORY and with O_RDONLY, then compares fstatfs() and fstatvfs() of the 
descriptor with statfs() and statvfs() of the path. It checks a mount point, a 
directory in it, and a directory of the pseudo file system (/system on v9fs, 
/system/tee, /dev).
   
   - qemu-armv8a:knsh (kernel build, arm64, QEMU HVF): master fails 8 of 12 
(every v9fs case gives f_type 0x9fa0, f_bsize 0, f_namelen 32 instead of 
0x1021997, 65536, 255); this PR passes 12 of 12. ostest: 0 on master and on 
this PR.
   - qemu-armv8a:nsh (flat build, arm64): ostest 0.
   - rv-virt:pnsh64 (protected build, riscv64, gcc 14.3): builds with no new 
warning. The same with CONFIG_DISABLE_DIRECTORY_OPERATIONS=y (the inline stub 
of dir_isdirectory()): builds with no new warning.
   - tools/checkpatch.sh -c -u -m -g: pass.
   


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