From def05ebabb3eac53940af0b375a27eb6d72449ce Mon Sep 17 00:00:00 2001 From: chenrun1 Date: Wed, 15 May 2024 15:34:32 +0800 Subject: [PATCH] hostfs:ioctl should return -ENOTTY when the instruction is incompatible When sending FIOC_XXXLK to hostfs, hostfs will return -1 by default. For ioctl statements, incompatible instructions should be processed as -ENOTTY by default Signed-off-by: chenrun1 --- fs/hostfs/hostfs.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/fs/hostfs/hostfs.c b/fs/hostfs/hostfs.c index c5efb5ae066..d032155eb75 100644 --- a/fs/hostfs/hostfs.c +++ b/fs/hostfs/hostfs.c @@ -604,14 +604,21 @@ static int hostfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg) /* Call our internal routine to perform the ioctl */ ret = host_ioctl(hf->fd, cmd, arg); - - if (ret < 0 && cmd == FIOC_FILEPATH) + if (ret < 0) { - FAR char *path = (FAR char *)(uintptr_t)arg; - ret = inode_getpath(filep->f_inode, path, PATH_MAX); - if (ret >= 0) + switch (cmd) { - strlcat(path, hf->relpath, PATH_MAX); + case FIOC_FILEPATH: + FAR char *path = (FAR char *)(uintptr_t)arg; + ret = inode_getpath(filep->f_inode, path, PATH_MAX); + if (ret >= 0) + { + strlcat(path, hf->relpath, PATH_MAX); + } + + break; + default: + ret = -ENOTTY; } }