fs/poll: support poll for regular files and block devices
cherry-picked 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'.
@@ -156,15 +156,28 @@ static int poll_fdsetup(int fd, FAR struct pollfd *fds, bool setup)
return ERROR;
}
+ inode = filep->f_inode;
+
+ if (inode) {
/* 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) {
+ 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;
