fs: Remove all LIBC_IOCTL_VARIADIC related stuff

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2020-05-04 17:00:51 +08:00 committed by patacongo
parent 19cc84ed4a
commit 6604cdb3f2
14 changed files with 103 additions and 272 deletions

View file

@ -8598,11 +8598,7 @@ interface of the same name.
<ul><pre>
#include &lt;sys/ioctl.h&gt;
#ifdef CONFIG_LIBC_IOCTL_VARIADIC
int ioctl(int fd, int req, ...);
#else
int ioctl(int fd, int req, unsigned long arg);
#endif
</pre></ul>
<h4><a name="drvrpollops">2.10.2.4 poll.h</a></h4>

View file

@ -59,7 +59,7 @@
****************************************************************************/
/****************************************************************************
* Name: file_ioctl
* Name: file_ioctl and file_vioctl
*
* Description:
* Perform device specific operations.
@ -67,7 +67,7 @@
* Input Parameters:
* file File structure instance
* req The ioctl command
* arg The argument of the ioctl cmd
* ap The argument of the ioctl cmd
*
* Returned Value:
* Returns a non-negative number on success; A negated errno value is
@ -76,7 +76,7 @@
*
****************************************************************************/
int file_ioctl(FAR struct file *filep, int req, unsigned long arg)
int file_vioctl(FAR struct file *filep, int req, va_list ap)
{
FAR struct inode *inode;
@ -99,11 +99,25 @@ int file_ioctl(FAR struct file *filep, int req, unsigned long arg)
/* Yes on both accounts. Let the driver perform the ioctl command */
return (int)inode->u.i_ops->ioctl(filep, req, arg);
return inode->u.i_ops->ioctl(filep, req, va_arg(ap, unsigned long));
}
int file_ioctl(FAR struct file *filep, int req, ...)
{
va_list ap;
int ret;
/* Let file_vioctl() do the real work. */
va_start(ap, req);
ret = file_vioctl(filep, req, ap);
va_end(ap);
return ret;
}
/****************************************************************************
* Name: nx_ioctl
* Name: nx_ioctl and nx_vioctl
*
* Description:
* nx_ioctl() is similar to the standard 'ioctl' interface except that is
@ -119,9 +133,10 @@ int file_ioctl(FAR struct file *filep, int req, unsigned long arg)
*
****************************************************************************/
int nx_ioctl(int fd, int req, unsigned long arg)
int nx_vioctl(int fd, int req, va_list ap)
{
FAR struct file *filep;
FAR int *arg;
int ret;
/* Did we get a valid file descriptor? */
@ -133,7 +148,7 @@ int nx_ioctl(int fd, int req, unsigned long arg)
#ifdef CONFIG_NET
if (fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS))
{
ret = netdev_ioctl(fd, req, arg);
ret = netdev_vioctl(fd, req, ap);
}
else
#endif
@ -155,7 +170,7 @@ int nx_ioctl(int fd, int req, unsigned long arg)
/* Perform the file ioctl. */
ret = file_ioctl(filep, req, arg);
ret = file_vioctl(filep, req, ap);
}
/* Check for File system IOCTL commands that can be implemented via
@ -167,20 +182,17 @@ int nx_ioctl(int fd, int req, unsigned long arg)
switch (req)
{
case FIONBIO:
{
DEBUGASSERT(arg != 0);
if (*(FAR int *)((uintptr_t)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);
}
}
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;
}
}
@ -188,8 +200,22 @@ int nx_ioctl(int fd, int req, unsigned long arg)
return ret;
}
int nx_ioctl(int fd, int req, ...)
{
va_list ap;
int ret;
/* Let nx_vioctl() do the real work. */
va_start(ap, req);
ret = nx_vioctl(fd, req, ap);
va_end(ap);
return ret;
}
/****************************************************************************
* Name: ioctl/fs_ioctl
* Name: ioctl
*
* Description:
* Perform device specific operations.
@ -197,7 +223,6 @@ int nx_ioctl(int fd, int req, unsigned long arg)
* Input Parameters:
* fd File/socket descriptor of device
* req The ioctl command
* arg The argument of the ioctl cmd
*
* Returned Value:
* >=0 on success (positive non-zero values are cmd-specific)
@ -217,15 +242,17 @@ int nx_ioctl(int fd, int req, unsigned long arg)
*
****************************************************************************/
#ifdef CONFIG_LIBC_IOCTL_VARIADIC
int fs_ioctl(int fd, int req, unsigned long arg)
#else
int ioctl(int fd, int req, unsigned long arg)
#endif
int ioctl(int fd, int req, ...)
{
va_list ap;
int ret;
ret = nx_ioctl(fd, req, arg);
/* Let nx_vioctl() do the real work. */
va_start(ap, req);
ret = nx_vioctl(fd, req, ap);
va_end(ap);
if (ret < 0)
{
set_errno(-ret);

View file

@ -1220,7 +1220,7 @@ int file_truncate(FAR struct file *filep, off_t length);
#endif
/****************************************************************************
* Name: file_ioctl
* Name: file_ioctl and file_vioctl
*
* Description:
* Perform device specific operations.
@ -1228,7 +1228,7 @@ int file_truncate(FAR struct file *filep, off_t length);
* Input Parameters:
* file File structure instance
* req The ioctl command
* arg The argument of the ioctl cmd
* ap The argument of the ioctl cmd
*
* Returned Value:
* Returns a non-negative number on success; A negated errno value is
@ -1237,10 +1237,11 @@ int file_truncate(FAR struct file *filep, off_t length);
*
****************************************************************************/
int file_ioctl(FAR struct file *filep, int req, unsigned long arg);
int file_vioctl(FAR struct file *filep, int req, va_list ap);
int file_ioctl(FAR struct file *filep, int req, ...);
/****************************************************************************
* Name: nx_ioctl
* Name: nx_ioctl and nx_vioctl
*
* Description:
* nx_ioctl() is similar to the standard 'ioctl' interface except that is
@ -1256,40 +1257,8 @@ int file_ioctl(FAR struct file *filep, int req, unsigned long arg);
*
****************************************************************************/
int nx_ioctl(int fd, int req, unsigned long arg);
/****************************************************************************
* Name: fs_ioctl
*
* Description:
* Perform device specific operations.
*
* Input Parameters:
* fd File/socket descriptor of device
* req The ioctl command
* arg The argument of the ioctl cmd
*
* Returned Value:
* >=0 on success (positive non-zero values are cmd-specific)
* -1 on failure with errno set properly:
*
* EBADF
* 'fd' is not a valid descriptor.
* EFAULT
* 'arg' references an inaccessible memory area.
* EINVAL
* 'cmd' or 'arg' is not valid.
* ENOTTY
* 'fd' is not associated with a character special device.
* ENOTTY
* The specified request does not apply to the kind of object that the
* descriptor 'fd' references.
*
****************************************************************************/
#ifdef CONFIG_LIBC_IOCTL_VARIADIC
int fs_ioctl(int fd, int req, unsigned long arg);
#endif
int nx_vioctl(int fd, int req, va_list ap);
int nx_ioctl(int fd, int req, ...);
/****************************************************************************
* Name: file_vfcntl

View file

@ -1228,7 +1228,7 @@ int psock_getpeername(FAR struct socket *psock, FAR struct sockaddr *addr,
FAR socklen_t *addrlen);
/****************************************************************************
* Name: psock_ioctl
* Name: psock_ioctl and psock_vioctl
*
* Description:
* Perform network device specific operations.
@ -1236,7 +1236,7 @@ int psock_getpeername(FAR struct socket *psock, FAR struct sockaddr *addr,
* Input Parameters:
* psock A pointer to a NuttX-specific, internal socket structure
* cmd The ioctl command
* arg The argument of the ioctl cmd
* ap The argument of the ioctl cmd
*
* Returned Value:
* A non-negative value is returned on success; a negated errno value is
@ -1258,10 +1258,11 @@ int psock_getpeername(FAR struct socket *psock, FAR struct sockaddr *addr,
*
****************************************************************************/
int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg);
int psock_vioctl(FAR struct socket *psock, int cmd, va_list ap);
int psock_ioctl(FAR struct socket *psock, int cmd, ...);
/****************************************************************************
* Name: netdev_ioctl
* Name: netdev_vioctl
*
* Description:
* Perform network device specific operations.
@ -1269,7 +1270,7 @@ int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg);
* Input Parameters:
* sockfd Socket descriptor of device
* cmd The ioctl command
* arg The argument of the ioctl cmd
* ap The argument of the ioctl cmd
*
* Returned Value:
* A non-negative value is returned on success; a negated errno value is
@ -1291,7 +1292,7 @@ int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg);
*
****************************************************************************/
int netdev_ioctl(int sockfd, int cmd, unsigned long arg);
int netdev_vioctl(int sockfd, int cmd, va_list ap);
/****************************************************************************
* Name: psock_poll

View file

@ -126,11 +126,7 @@ extern "C"
*
****************************************************************************/
#ifdef CONFIG_LIBC_IOCTL_VARIADIC
int ioctl(int fd, int req, ...);
#else
int ioctl(int fd, int req, unsigned long arg);
#endif
#undef EXTERN
#if defined(__cplusplus)

View file

@ -284,13 +284,7 @@
*/
#define SYS_close (__SYS_descriptors + 0)
#ifdef CONFIG_LIBC_IOCTL_VARIADIC
# define SYS_fs_ioctl (__SYS_descriptors + 1)
#else
# define SYS_ioctl (__SYS_descriptors + 1)
#endif
#define SYS_ioctl (__SYS_descriptors + 1)
#define SYS_read (__SYS_descriptors + 2)
#define SYS_write (__SYS_descriptors + 3)
#define SYS_pread (__SYS_descriptors + 4)

View file

@ -64,7 +64,6 @@
"inet_ntoa","arpa/inet.h","defined(CONFIG_NET_IPv4)","FAR char","struct in_addr"
"inet_ntop","arpa/inet.h","","FAR const char","int","FAR const void *","FAR char *","socklen_t"
"inet_pton","arpa/inet.h","","int","int","FAR const char *","FAR void *"
"ioctl","sys/ioctl.h","defined(CONFIG_LIBC_IOCTL_VARIADIC)","int","int","int","..."
"iswalnum","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t"
"iswalpha","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t"
"iswblank","wctype.h","defined(CONFIG_LIBC_WCHAR)","int","wint_t"

Can't render this file because it has a wrong number of fields in line 3.

View file

@ -3,49 +3,6 @@
# see the file kconfig-language.txt in the NuttX tools repository.
#
config LIBC_IOCTL_VARIADIC
bool "Enable variadic ioctl()"
default y
---help---
By default, NuttX implements the "old style," three-parameter,
ioctl() interface with this function prototype:
int ioctl(int fd, int req, unsigned long arg);
That function is implemented as part of the VFS. If
LIBC_IOCTL_VARIADIC is selected, then an additional compatibility
layer will be provided in the C library. The enabled, then function
prototype will become:
int ioctl(int fd, int req, ...);
The ioctl() is not controlled by any standard so it is really
arbitrary which format you used. You may select the variadic
function prototype with this option. That will slightly increase
code size and ioctl() processing time. It will not support a
variable number of arguments and it still always expects to see a
third argument of type 'unsigned long'. The only benefit of this
alternative function signature is that it may provide greater
compatibility if you are porting code from other platforms that use
the variadic ioctl() function.
WARNING: Use of this option could cause subtle system errors is
the third argument is omitted or if the sizeof the thread argument
is anything other than sizeof (unsigned long). Most small integers
will be promoted to 'int'. The following assertion appears in ioctl():
DEBUGASSERT(sizeof(int) == sizeof(unsigned long) &&
sizeof(FAR void *) == sizeof(unsigned long));
Do not enable this option if the above is not true. 32-bit ARM
should pass this test with all three types having sizeof(type) == 4
bytes. 'float' should also be tested. But 'long long' and 'double'
are out of the question! Don't event try to pass them.
And what will happen if no third argument is passed? In most cases,
this should just result in a garbage value for arg. But you may
discover cases where something worse happens!
config LIB_SENDFILE_BUFSIZE
int "sendfile() buffer size"
default 512

View file

@ -56,10 +56,6 @@ ifneq ($(CONFIG_NFILE_STREAMS),0)
CSRCS += lib_streamsem.c
endif
ifeq ($(CONFIG_LIBC_IOCTL_VARIADIC),y)
CSRCS += lib_ioctl.c
endif
ifeq ($(CONFIG_PIPES),y)
CSRCS += lib_mkfifo.c
endif

View file

@ -1,117 +0,0 @@
/****************************************************************************
* libs/libc/misc/lib_ioctl.c
*
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/ioctl.h>
#include <stdarg.h>
#include <errno.h>
#include <assert.h>
#include <nuttx/fs/fs.h>
#include "libc.h"
#ifdef CONFIG_LIBC_IOCTL_VARIADIC
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: ioctl
*
* Description:
* Perform device specific operations.
*
* Input Parameters:
* fd File/socket descriptor of device
* req The ioctl command
* ... A third argument of type unsigned long is expected
*
* Returned Value:
* >=0 on success (positive non-zero values are cmd-specific)
* -1 on failure with errno set properly:
*
* EBADF
* 'fd' is not a valid descriptor.
* EFAULT
* 'arg' references an inaccessible memory area.
* EINVAL
* 'cmd' or 'arg' is not valid.
* ENOTTY
* 'fd' is not associated with a character special device.
* ENOTTY
* The specified request does not apply to the kind of object that the
* descriptor 'fd' references.
*
****************************************************************************/
int ioctl(int fd, int req, ...)
{
unsigned long arg;
va_list ap;
/* Get the unsigned long argument.
*
* REVISIT: This could be the cause of the crash down the road if the
* actual size of the argument is not sizeof(unsigned long).
* Most small integers will be promoted to 'int'. ARM should pass the
* following test with all three types having sizeof(type) == 4 bytes.
* 'float' should also be tested. But 'long long' and 'double' are out of
* the question! Don't try to pass them.
*
* And what will happen if no third argument is passed? In most cases,
* this should just result in a garbage value for arg. But you may
* discover cases where something worse happens!
*/
DEBUGASSERT(sizeof(int) <= sizeof(unsigned long) &&
sizeof(FAR void *) == sizeof(unsigned long));
va_start(ap, req);
arg = va_arg(ap, unsigned long);
va_end(ap);
/* Then let fs_ioctl() to the real work */
return fs_ioctl(fd, req, arg);
}
#endif /* CONFIG_LIBC_IOCTL_VARIADIC */

View file

@ -1577,7 +1577,7 @@ ssize_t net_ioctl_arglen(int cmd)
#endif
/****************************************************************************
* Name: psock_ioctl
* Name: psock_ioctl and psock_vioctl
*
* Description:
* Perform network device specific operations.
@ -1607,8 +1607,9 @@ ssize_t net_ioctl_arglen(int cmd)
*
****************************************************************************/
int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg)
int psock_vioctl(FAR struct socket *psock, int cmd, va_list ap)
{
unsigned long arg;
int ret;
/* Verify that the psock corresponds to valid, allocated socket */
@ -1618,6 +1619,8 @@ int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg)
return -EBADF;
}
arg = va_arg(ap, unsigned long);
#ifdef CONFIG_NET_USRSOCK
/* Check for a USRSOCK ioctl command */
@ -1702,6 +1705,25 @@ int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg)
return ret;
}
int psock_ioctl(FAR struct socket *psock, int cmd, ...)
{
va_list ap;
int ret;
/* Setup to access the variable argument list */
va_start(ap, cmd);
/* Let psock_vfcntl() do the real work. The errno is not set on
* failures.
*/
ret = psock_vioctl(psock, cmd, ap);
va_end(ap);
return ret;
}
/****************************************************************************
* Name: netdev_ioctl
*
@ -1711,7 +1733,7 @@ int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg)
* Input Parameters:
* sockfd Socket descriptor of device
* cmd The ioctl command
* arg The argument of the ioctl cmd
* ap The argument of the ioctl cmd
*
* Returned Value:
* A non-negative value is returned on success; a negated errno value is
@ -1733,11 +1755,11 @@ int psock_ioctl(FAR struct socket *psock, int cmd, unsigned long arg)
*
****************************************************************************/
int netdev_ioctl(int sockfd, int cmd, unsigned long arg)
int netdev_vioctl(int sockfd, int cmd, va_list ap)
{
FAR struct socket *psock = sockfd_socket(sockfd);
return psock_ioctl(psock, cmd, arg);
return psock_ioctl(psock, cmd, ap);
}
/****************************************************************************

View file

@ -24,7 +24,6 @@
"exit","stdlib.h","","void","int"
"fcntl","fcntl.h","","int","int","int","..."
"fs_fdopen","nuttx/fs/fs.h","CONFIG_NFILE_STREAMS > 0","FAR struct file_struct*","int","int","FAR struct tcb_s*"
"fs_ioctl","nuttx/fs/fs.h","defined(CONFIG_LIBC_IOCTL_VARIADIC)","int","int","int","unsigned long"
"fstat","sys/stat.h","","int","int","FAR struct stat*"
"fstatfs","sys/statfs.h","","int","int","FAR struct statfs*"
"fsync","unistd.h","!defined(CONFIG_DISABLE_MOUNTPOINT)","int","int"
@ -42,7 +41,7 @@
"if_indextoname","net/if.h","defined(CONFIG_NETDEV_IFINDEX)","FAR char *","unsigned int","FAR char *"
"if_nametoindex","net/if.h","defined(CONFIG_NETDEV_IFINDEX)","unsigned int","FAR const char *"
"insmod","nuttx/module.h","defined(CONFIG_MODULE)","FAR void *","FAR const char *","FAR const char *"
"ioctl","sys/ioctl.h","!defined(CONFIG_LIBC_IOCTL_VARIADIC)","int","int","int","unsigned long"
"ioctl","sys/ioctl.h","","int","int","int","..."
"kill","signal.h","","int","pid_t","int"
"link","unistd.h","defined(CONFIG_PSEUDOFS_SOFTLINKS)","int","FAR const char *","FAR const char *"
"listen","sys/socket.h","defined(CONFIG_NET)","int","int","int"

Can't render this file because it has a wrong number of fields in line 2.

View file

@ -197,11 +197,7 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert)
*/
SYSCALL_LOOKUP(close, 1, STUB_close)
#ifdef CONFIG_LIBC_IOCTL_VARIADIC
SYSCALL_LOOKUP(fs_ioctl, 3, STUB_fs_ioctl)
#else
SYSCALL_LOOKUP(ioctl, 3, STUB_ioctl)
#endif
SYSCALL_LOOKUP(ioctl, 6, STUB_ioctl)
SYSCALL_LOOKUP(read, 3, STUB_read)
SYSCALL_LOOKUP(write, 3, STUB_write)
SYSCALL_LOOKUP(pread, 4, STUB_pread)

View file

@ -189,13 +189,9 @@ uintptr_t STUB_nx_vsyslog(int nbr, uintptr_t parm1, uintptr_t parm2,
*/
uintptr_t STUB_close(int nbr, uintptr_t parm1);
#ifdef CONFIG_LIBC_IOCTL_VARIADIC
uintptr_t STUB_fs_ioctl(int nbr, uintptr_t parm1, uintptr_t parm2,
uintptr_t parm3);
#else
uintptr_t STUB_ioctl(int nbr, uintptr_t parm1, uintptr_t parm2,
uintptr_t parm3);
#endif
uintptr_t parm3, uintptr_t parm4, uintptr_t parm5,
uintptr_t parm6);
uintptr_t STUB_read(int nbr, uintptr_t parm1, uintptr_t parm2,
uintptr_t parm3);
uintptr_t STUB_write(int nbr, uintptr_t parm1, uintptr_t parm2,