fs: Move the default ioctl handle from nx_vioctl to file_vioctl

ensure the behaviour is same in all ioctl function variant

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Ie67cfbc579004c8488ef5004c9be7fb179e77041
This commit is contained in:
Xiang Xiao 2021-07-08 13:53:59 +08:00 committed by Alan Carvalho de Assis
parent d83caef2df
commit 13651cde99
1 changed files with 48 additions and 41 deletions

View File

@ -43,9 +43,13 @@
int file_vioctl(FAR struct file *filep, int req, va_list ap)
{
FAR struct inode *inode;
unsigned long arg;
int ret = -ENOTTY;
DEBUGASSERT(filep != NULL);
arg = va_arg(ap, unsigned long);
/* Is a driver opened? */
inode = filep->f_inode;
@ -56,14 +60,52 @@ int file_vioctl(FAR struct file *filep, int req, va_list ap)
/* Does the driver support the ioctl method? */
if (inode->u.i_ops == NULL || inode->u.i_ops->ioctl == NULL)
if (inode->u.i_ops != NULL && inode->u.i_ops->ioctl != NULL)
{
return -ENOTTY;
}
/* Yes on both accounts. Let the driver perform the ioctl command */
return inode->u.i_ops->ioctl(filep, req, va_arg(ap, unsigned long));
ret = inode->u.i_ops->ioctl(filep, req, arg);
}
/* Check for File system IOCTL commands that can be implemented via
* fcntl()
*/
if (ret != -ENOTTY)
{
return ret;
}
switch (req)
{
case FIONBIO:
{
FAR int *nonblock = (FAR int *)(uintptr_t)arg;
if (nonblock && *nonblock)
{
ret = file_fcntl(filep, F_SETFL,
file_fcntl(filep, F_GETFL) | O_NONBLOCK);
}
else
{
ret = file_fcntl(filep, F_SETFL,
file_fcntl(filep, F_GETFL) & ~O_NONBLOCK);
}
}
break;
case FIOCLEX:
ret = file_fcntl(filep, F_SETFD,
file_fcntl(filep, F_GETFD) | FD_CLOEXEC);
break;
case FIONCLEX:
ret = file_fcntl(filep, F_SETFD,
file_fcntl(filep, F_GETFD) & ~FD_CLOEXEC);
break;
}
return ret;
}
/****************************************************************************
@ -73,7 +115,6 @@ int file_vioctl(FAR struct file *filep, int req, va_list ap)
static int nx_vioctl(int fd, int req, va_list ap)
{
FAR struct file *filep;
FAR int *arg;
int ret;
/* Get the file structure corresponding to the file descriptor. */
@ -84,43 +125,9 @@ static int nx_vioctl(int fd, int req, va_list ap)
return ret;
}
DEBUGASSERT(filep != NULL);
/* Let file_vioctl() do the real work. */
/* Perform the file ioctl. */
ret = file_vioctl(filep, req, ap);
/* Check for File system IOCTL commands that can be implemented via
* fcntl()
*/
if (ret == -ENOTTY)
{
switch (req)
{
case FIONBIO:
arg = va_arg(ap, FAR int *);
if (arg && *arg)
{
ret = nx_fcntl(fd, F_SETFL,
nx_fcntl(fd, F_GETFL) | O_NONBLOCK);
}
else
{
ret = nx_fcntl(fd, F_SETFL,
nx_fcntl(fd, F_GETFL) & ~O_NONBLOCK);
}
break;
case FIOCLEX:
ret = nx_fcntl(fd, F_SETFD, nx_fcntl(fd, F_GETFD) | FD_CLOEXEC);
break;
case FIONCLEX:
ret = nx_fcntl(fd, F_SETFD, nx_fcntl(fd, F_GETFD) & ~FD_CLOEXEC);
break;
}
}
return ret;
return file_vioctl(filep, req, ap);
}
/****************************************************************************