From 864fc0ed2302008ea0d8084f82407dd54168c5a6 Mon Sep 17 00:00:00 2001 From: Jussi Kivilinna Date: Thu, 3 Aug 2017 09:58:20 -0600 Subject: [PATCH] fs/poll: support poll for regular files and block devices cherry-picked 027a446 from nuttx poll: fix poll for regular files and block devices. Open Group documentation tells that poll (and select) support regular files and that 'Regular files shall always poll TRUE for reading and writing'. --- os/fs/vfs/fs_poll.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/os/fs/vfs/fs_poll.c b/os/fs/vfs/fs_poll.c index dd4a903fd2..2c737da225 100644 --- a/os/fs/vfs/fs_poll.c +++ b/os/fs/vfs/fs_poll.c @@ -156,15 +156,28 @@ static int poll_fdsetup(int fd, FAR struct pollfd *fds, bool setup) return ERROR; } - /* Is a driver registered? Does it support the poll method? - * If not, return -ENOSYS - */ - inode = filep->f_inode; - if (inode && inode->u.i_ops && inode->u.i_ops->poll) { - /* Yes, then setup the poll */ - ret = (int)inode->u.i_ops->poll(filep, fds, setup); + if (inode) { + /* Is a driver registered? Does it support the poll method? + * If not, return -ENOSYS + */ + + if (INODE_IS_DRIVER(inode) && inode->u.i_ops && inode->u.i_ops->poll) { + /* Yes, then setup the poll */ + + ret = (int)inode->u.i_ops->poll(filep, fds, setup); + } else if (INODE_IS_MOUNTPT(inode) || INODE_IS_BLOCK(inode)) { + /* Regular files shall always poll TRUE for reading and writing */ + + if (setup) { + fds->revents |= (fds->events & (POLLIN | POLLOUT)); + if (fds->revents != 0) { + sem_post(fds->sem); + } + } + ret = OK; + } } return ret;