From e7c97ce7f0a6431bc6bba7b99e6034a1d500ad3d Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Mon, 15 Feb 2021 18:49:34 +0800 Subject: [PATCH] fs: Merge fs_poll into poll_fdsetup to avoid the user misuse the wrong funciton Signed-off-by: Xiang Xiao --- fs/vfs/fs_poll.c | 60 ++++++++++++++----------------------------- include/nuttx/fs/fs.h | 22 +--------------- 2 files changed, 20 insertions(+), 62 deletions(-) diff --git a/fs/vfs/fs_poll.c b/fs/vfs/fs_poll.c index 2f2d64e054..269eb201c3 100644 --- a/fs/vfs/fs_poll.c +++ b/fs/vfs/fs_poll.c @@ -88,8 +88,25 @@ static int poll_fdsetup(int fd, FAR struct pollfd *fds, bool setup) return -EBADF; } } + else + { + FAR struct file *filep; + int ret; - return fs_poll(fd, fds, setup); + /* Get the file pointer corresponding to this file descriptor */ + + ret = fs_getfilep(fd, &filep); + if (ret < 0) + { + return ret; + } + + DEBUGASSERT(filep != NULL); + + /* Let file_poll() do the rest */ + + return file_poll(filep, fds, setup); + } } /**************************************************************************** @@ -283,7 +300,7 @@ static inline int poll_teardown(FAR struct pollfd *fds, nfds_t nfds, * * Description: * Low-level poll operation based on struct file. This is used both to (1) - * support detached file, and also (2) by fs_poll() to perform all + * support detached file, and also (2) by poll_fdsetup() to perform all * normal operations on file descriptors. * * Input Parameters: @@ -343,45 +360,6 @@ int file_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup) return ret; } -/**************************************************************************** - * Name: fs_poll - * - * Description: - * The standard poll() operation redirects operations on file descriptors - * to this function. - * - * Input Parameters: - * fd - The file descriptor of interest - * fds - The structure describing the events to be monitored, OR NULL if - * this is a request to stop monitoring events. - * setup - true: Setup up the poll; false: Teardown the poll - * - * Returned Value: - * Zero (OK) is returned on success; a negated errno value is returned on - * any failure. - * - ****************************************************************************/ - -int fs_poll(int fd, FAR struct pollfd *fds, bool setup) -{ - FAR struct file *filep; - int ret; - - /* Get the file pointer corresponding to this file descriptor */ - - ret = fs_getfilep(fd, &filep); - if (ret < 0) - { - return ret; - } - - DEBUGASSERT(filep != NULL); - - /* Let file_poll() do the rest */ - - return file_poll(filep, fds, setup); -} - /**************************************************************************** * Name: nx_poll * diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index 193699d5be..a8eec37259 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -1232,7 +1232,7 @@ int nx_fcntl(int fd, int cmd, ...); * * Description: * Low-level poll operation based on struct file. This is used both to (1) - * support detached file, and also (2) by fs_poll() to perform all + * support detached file, and also (2) by poll_fdsetup() to perform all * normal operations on file descriptors. * * Input Parameters: @@ -1248,26 +1248,6 @@ int nx_fcntl(int fd, int cmd, ...); int file_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup); -/**************************************************************************** - * Name: fs_poll - * - * Description: - * The standard poll() operation redirects operations on file descriptors - * to this function. - * - * Input Parameters: - * fd - The file descriptor of interest - * fds - The structure describing the events to be monitored, OR NULL if - * this is a request to stop monitoring events. - * setup - true: Setup up the poll; false: Teardown the poll - * - * Returned Value: - * 0: Success; Negated errno on failure - * - ****************************************************************************/ - -int fs_poll(int fd, FAR struct pollfd *fds, bool setup); - /**************************************************************************** * Name: nx_poll *