casaroli commented on code in PR #19512:
URL: https://github.com/apache/nuttx/pull/19512#discussion_r3644857601
##########
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:
The dir fd does not point to the real inode. `f_inode` is the static
`g_dir_inode`, so the only way to reach the filesystem is `dir->fd_root` (that
is what I use to call volume_ioctl).
The existing ioctl requires `filep->f_priv` to be the filesystem's open-file
struct. forwarding to ioctl means changing its contract and fixing every
filesystem. Even read-only ones like romfs, where a volume ioctl is meaningless
but whose ioctl asserts and dereferences `f_priv` today just so they don't
crash.
To me the optional method is the smaller and safer version of the same idea.
WDYT?
--
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]