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


##########
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->volume_ioctl != NULL)
+        {
+          return dir->fd_root->u.i_mops->volume_ioctl(dir->fd_root, cmd,

Review Comment:
   it is because `nxffs_ioctl` take a `struct file` (`*filep`) so it requires 
an open file to operate (`filep->f_priv`). The problem is that on volume 
operations like `FIOC_REFORMAT`, if we keep a file open (to issue the `ioctl`) 
then the file will be pinned and we cannot modify it and the ioctl will return 
`-EBUSY`.
   
   the `volume_ioctl`, in turn, has different semantics: takes a `struct inode` 
(`*mountpt`) which can be a mount point, which does not require an open file or 
a file pointer to work, thus making `FIOC_REFORMAT`, `FIOC_OPTIMIZE` and other 
alike volume operations work.



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