casaroli commented on code in PR #19512:
URL: https://github.com/apache/nuttx/pull/19512#discussion_r3648819447


##########
fs/vfs/fs_dir.c:
##########
@@ -564,6 +564,22 @@ static int dir_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
     }
   else if (cmd != BIOC_FLUSH)
     {
+#ifndef CONFIG_DISABLE_MOUNTPOINT
+      /* Not a command the VFS answers for a directory.  If this directory
+       * belongs to a mounted volume whose file system offers volume-wide
+       * commands, it is the one route to them that does not require an
+       * unrelated file to be open.
+       */
+
+      if (INODE_IS_MOUNTPT(dir->fd_root) &&
+          dir->fd_root->u.i_mops != NULL &&
+          dir->fd_root->u.i_mops->ioctldir != NULL)
+        {
+          return dir->fd_root->u.i_mops->ioctldir(dir->fd_root, dir, cmd,

Review Comment:
   Done, `ioctldir` is now tried first and the VFS defaults (`FIOC_FILEPATH`, 
`BIOC_FLUSH`) only run when it answers `-ENOTTY`. Documented that contract in 
`fs.h` and in the filesystem docs, so a file system knows it must return 
`-ENOTTY` for anything it does not recognise.
   
   Verified on sim:nxffs, comparing a clean build of the base commit against 
the patched one. Same sequence of ioctls on a file descriptor, on a descriptor 
for the mountpoint directory, and on a `/dev` directory descriptor:
   
   | | before | after |
   |---|---|---|
   | `FIOC_REFORMAT` via file fd | -1 EBUSY | -1 EBUSY |
   | `FIOC_REFORMAT` via dir fd | -1 ENOTTY | 0 |
   | `FIOC_FILEPATH` via dir fd | 0, `/mnt/nxffs//` | 0, `/mnt/nxffs//` |
   | `BIOC_FLUSH` via dir fd | 0 | 0 |
   | bogus cmd via dir fd | -1 ENOTTY | -1 ENOTTY |
   | `FIOC_FILEPATH` / bogus cmd via `/dev` fd | 0 / -1 ENOTTY | 0 / -1 ENOTTY |
   | file name still present in the raw MTD image | yes | no |
   
   Only the reformat line on the directory descriptor changes, and the raw MTD 
image confirms the volume really was erased. The generic answers survive nxffs 
being consulted ahead of them, because `nxffs_volume_cmd()` forwards what it 
does not recognise to the MTD driver, which returns `-ENOTTY`.



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