fs: procfs add poll support

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
This commit is contained in:
yinshengkai 2023-11-25 20:11:03 +08:00 committed by Xiang Xiao
parent ca99e69c28
commit 9852428953
46 changed files with 82 additions and 5 deletions

View File

@ -114,6 +114,7 @@ const struct procfs_operations cxd56_powermgr_procfs_operations =
cxd56_powermgr_procfs_close, /* close */
cxd56_powermgr_procfs_read, /* read */
NULL, /* write */
NULL, /* poll */
cxd56_powermgr_procfs_dup, /* dup */
cxd56_powermgr_procfs_opendir, /* opendir */
cxd56_powermgr_procfs_closedir, /* closedir */

View File

@ -618,6 +618,7 @@ const struct procfs_operations cxd56_usbdev_operations =
cxd56_usbdev_close, /* close */
cxd56_usbdev_read, /* read */
NULL, /* write */
NULL, /* poll */
cxd56_usbdev_dup, /* dup */
NULL, /* opendir */

View File

@ -91,6 +91,7 @@ static const struct procfs_operations dvfs_procfsoperations =
dvfs_close, /* close */
dvfs_read, /* read */
dvfs_write, /* write */
NULL, /* poll */
dvfs_dup, /* dup */
NULL, /* opendir */
NULL, /* closedir */

View File

@ -102,6 +102,7 @@ const struct procfs_operations arm64_fpu_procfs_operations =
arm64_fpu_procfs_close, /* close */
arm64_fpu_procfs_read, /* read */
NULL, /* write */
NULL, /* poll */
NULL, /* dup */
NULL, /* opendir */
NULL, /* closedir */

View File

@ -94,6 +94,7 @@ const struct procfs_operations s32k1xx_nrstcheck_procfs_ops =
s32k1xx_nrstcheck_procfs_close, /* close */
s32k1xx_nrstcheck_procfs_read, /* read */
NULL, /* write */
NULL, /* poll */
s32k1xx_nrstcheck_procfs_dup, /* dup */
NULL, /* opendir */
NULL, /* closedir */

View File

@ -114,6 +114,7 @@ const struct procfs_operations g_clk_operations =
clk_procfs_close, /* close */
clk_procfs_read, /* read */
NULL, /* write */
NULL, /* poll */
clk_procfs_dup, /* dup */

View File

@ -112,6 +112,7 @@ static const struct procfs_operations g_mmcsd_operations =
mmcsd_close, /* close */
mmcsd_read, /* read */
NULL, /* write */
NULL, /* poll */
mmcsd_dup, /* dup */

View File

@ -155,6 +155,7 @@ const struct procfs_operations g_part_operations =
part_procfs_close, /* close */
part_procfs_read, /* read */
NULL, /* write */
NULL, /* poll */
part_procfs_dup, /* dup */

View File

@ -131,6 +131,7 @@ const struct procfs_operations g_pm_operations =
pm_close, /* close */
pm_read, /* read */
NULL, /* write */
NULL, /* poll */
pm_dup, /* dup */

View File

@ -110,6 +110,7 @@ const struct mountpt_operations g_binfs_operations =
binfs_ioctl, /* ioctl */
NULL, /* mmap */
NULL, /* truncate */
NULL, /* poll */
NULL, /* sync */
binfs_dup, /* dup */

View File

@ -186,6 +186,7 @@ const struct mountpt_operations g_cromfs_operations =
cromfs_ioctl, /* ioctl */
NULL, /* mmap */
NULL, /* truncate */
NULL, /* poll */
NULL, /* sync */
cromfs_dup, /* dup */

View File

@ -127,6 +127,7 @@ const struct mountpt_operations g_fat_operations =
fat_ioctl, /* ioctl */
NULL, /* mmap */
fat_truncate, /* truncate */
NULL, /* poll */
fat_sync, /* sync */
fat_dup, /* dup */
fat_fstat, /* fstat */

View File

@ -144,6 +144,7 @@ const struct mountpt_operations g_hostfs_operations =
hostfs_ioctl, /* ioctl */
NULL, /* mmap */
hostfs_ftruncate, /* ftruncate */
NULL, /* poll */
hostfs_sync, /* sync */
hostfs_dup, /* dup */

View File

@ -150,6 +150,7 @@ const struct mountpt_operations g_littlefs_operations =
littlefs_ioctl, /* ioctl */
NULL, /* mmap */
littlefs_truncate, /* truncate */
NULL, /* poll */
littlefs_sync, /* sync */
littlefs_dup, /* dup */

View File

@ -143,7 +143,7 @@ const struct procfs_operations g_mount_operations =
mount_close, /* close */
mount_read, /* read */
NULL, /* write */
NULL, /* poll */
mount_dup, /* dup */
NULL, /* opendir */

View File

@ -202,6 +202,7 @@ const struct mountpt_operations g_nfs_operations =
NULL, /* ioctl */
NULL, /* mmap */
nfs_truncate, /* truncate */
NULL, /* poll */
nfs_sync, /* sync */
nfs_dup, /* dup */

View File

@ -60,6 +60,7 @@ const struct mountpt_operations g_nxffs_operations =
#else
NULL, /* truncate */
#endif
NULL, /* poll */
NULL, /* sync -- No buffered data */
nxffs_dup, /* dup */

View File

@ -218,6 +218,8 @@ static ssize_t procfs_read(FAR struct file *filep, FAR char *buffer,
size_t buflen);
static ssize_t procfs_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen);
static int procfs_poll(FAR struct file *filep, FAR struct pollfd *fds,
bool setup);
static int procfs_ioctl(FAR struct file *filep, int cmd,
unsigned long arg);
@ -270,6 +272,7 @@ const struct mountpt_operations g_procfs_operations =
procfs_ioctl, /* ioctl */
NULL, /* mmap */
NULL, /* truncate */
procfs_poll, /* poll */
NULL, /* sync */
procfs_dup, /* dup */
@ -501,6 +504,28 @@ static ssize_t procfs_write(FAR struct file *filep, FAR const char *buffer,
return 0;
}
static int procfs_poll(FAR struct file *filep, FAR struct pollfd *fds,
bool setup)
{
FAR struct procfs_file_s *handler;
finfo("fds=%p setup=%d\n", fds, setup);
/* Recover our private data from the struct file instance */
handler = (FAR struct procfs_file_s *)filep->f_priv;
DEBUGASSERT(handler);
/* Call the handler's poll routine */
if (handler->procfsentry->ops->poll)
{
return handler->procfsentry->ops->poll(filep, fds, setup);
}
return -ENOSYS;
}
/****************************************************************************
* Name: procfs_ioctl
****************************************************************************/

View File

@ -79,6 +79,7 @@ const struct procfs_operations g_cpuinfo_operations =
cpuinfo_close, /* close */
cpuinfo_read, /* read */
NULL, /* write */
NULL, /* poll */
cpuinfo_dup, /* dup */
NULL, /* opendir */
NULL, /* closedir */

View File

@ -101,6 +101,7 @@ const struct procfs_operations g_cpuload_operations =
cpuload_close, /* close */
cpuload_read, /* read */
NULL, /* write */
NULL, /* poll */
cpuload_dup, /* dup */

View File

@ -99,6 +99,7 @@ const struct procfs_operations g_critmon_operations =
critmon_close, /* close */
critmon_read, /* read */
NULL, /* write */
NULL, /* poll */
critmon_dup, /* dup */

View File

@ -85,6 +85,7 @@ const struct procfs_operations g_fdt_operations =
fdt_close, /* close */
fdt_read, /* read */
NULL, /* write */
NULL, /* poll */
fdt_dup, /* dup */
NULL, /* opendir */
NULL, /* closedir */

View File

@ -98,6 +98,7 @@ const struct procfs_operations g_iobinfo_operations =
iobinfo_close, /* close */
iobinfo_read, /* read */
NULL, /* write */
NULL, /* poll */
iobinfo_dup, /* dup */
NULL, /* opendir */
NULL, /* closedir */

View File

@ -123,6 +123,7 @@ const struct procfs_operations g_meminfo_operations =
meminfo_close, /* close */
meminfo_read, /* read */
NULL, /* write */
NULL, /* poll */
meminfo_dup, /* dup */
NULL, /* opendir */
NULL, /* closedir */
@ -138,6 +139,7 @@ const struct procfs_operations g_memdump_operations =
meminfo_close, /* close */
memdump_read, /* read */
memdump_write, /* write */
NULL, /* poll */
meminfo_dup, /* dup */
NULL, /* opendir */
NULL, /* closedir */

View File

@ -250,6 +250,7 @@ const struct procfs_operations g_proc_operations =
proc_close, /* close */
proc_read, /* read */
proc_write, /* write */
NULL, /* poll */
proc_dup, /* dup */

View File

@ -98,6 +98,7 @@ const struct procfs_operations g_tcbinfo_operations =
tcbinfo_close, /* close */
tcbinfo_read, /* read */
NULL, /* write */
NULL, /* poll */
tcbinfo_dup, /* dup */

View File

@ -101,6 +101,7 @@ const struct procfs_operations g_uptime_operations =
uptime_close, /* close */
uptime_read, /* read */
NULL, /* write */
NULL, /* poll */
uptime_dup, /* dup */

View File

@ -101,6 +101,7 @@ const struct procfs_operations g_version_operations =
version_close, /* close */
version_read, /* read */
NULL, /* write */
NULL, /* poll */
version_dup, /* dup */

View File

@ -133,6 +133,7 @@ const struct procfs_operations skel_procfsoperations =
#else
skel_write, /* write */
#endif
NULL, /* poll */
skel_dup, /* dup */

View File

@ -123,6 +123,7 @@ const struct mountpt_operations g_romfs_operations =
romfs_ioctl, /* ioctl */
romfs_mmap, /* mmap */
NULL, /* truncate */
NULL, /* poll */
NULL, /* sync */
romfs_dup, /* dup */

View File

@ -163,6 +163,7 @@ const struct mountpt_operations g_rpmsgfs_operations =
rpmsgfs_ioctl, /* ioctl */
NULL, /* mmap */
rpmsgfs_truncate, /* truncate */
NULL, /* poll */
rpmsgfs_sync, /* sync */
rpmsgfs_dup, /* dup */

View File

@ -177,6 +177,7 @@ const struct procfs_operations g_smartfs_operations =
/* No write supported */
smartfs_write, /* write */
NULL, /* poll */
smartfs_dup, /* dup */

View File

@ -142,6 +142,7 @@ const struct mountpt_operations g_smartfs_operations =
smartfs_ioctl, /* ioctl */
NULL, /* mmap */
smartfs_truncate, /* truncate */
NULL, /* poll */
smartfs_sync, /* sync */
smartfs_dup, /* dup */

View File

@ -143,6 +143,7 @@ const struct mountpt_operations g_spiffs_operations =
spiffs_ioctl, /* ioctl */
NULL, /* mmap */
spiffs_truncate, /* truncate */
NULL, /* poll */
spiffs_sync, /* sync */
spiffs_dup, /* dup */

View File

@ -181,6 +181,7 @@ const struct mountpt_operations g_tmpfs_operations =
NULL, /* ioctl */
tmpfs_mmap, /* mmap */
tmpfs_truncate, /* truncate */
NULL, /* poll */
tmpfs_sync, /* sync */
tmpfs_dup, /* dup */

View File

@ -215,6 +215,7 @@ const struct mountpt_operations g_unionfs_operations =
unionfs_ioctl, /* ioctl */
NULL, /* mmap */
unionfs_truncate, /* truncate */
NULL, /* pool */
unionfs_sync, /* sync */
unionfs_dup, /* dup */

View File

@ -162,6 +162,7 @@ const struct mountpt_operations g_userfs_operations =
userfs_ioctl, /* ioctl */
NULL, /* mmap */
userfs_truncate, /* truncate */
NULL, /* poll */
userfs_sync, /* sync */
userfs_dup, /* dup */

View File

@ -313,16 +313,23 @@ int file_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup)
{
/* Yes, it does... Setup the poll */
ret = (int)inode->u.i_ops->poll(filep, fds, setup);
ret = inode->u.i_ops->poll(filep, fds, setup);
}
#ifndef CONFIG_DISABLE_MOUNTPOINT
else if (INODE_IS_MOUNTPT(inode) && inode->u.i_mops != NULL &&
inode->u.i_mops->poll != NULL)
{
ret = inode->u.i_mops->poll(filep, fds, setup);
}
#endif
/* Regular files (and block devices) are always readable and
* writable. Open Group: "Regular files shall always poll TRUE for
* reading and writing."
*/
if (INODE_IS_MOUNTPT(inode) || INODE_IS_BLOCK(inode) ||
INODE_IS_MTD(inode))
else if (INODE_IS_MOUNTPT(inode) || INODE_IS_BLOCK(inode) ||
INODE_IS_MTD(inode))
{
if (setup)
{

View File

@ -134,6 +134,7 @@ const struct mountpt_operations g_zipfs_operations =
NULL, /* ioctl */
NULL, /* mmap */
NULL, /* truncate */
NULL, /* poll */
NULL, /* sync */
zipfs_dup, /* dup */

View File

@ -319,7 +319,8 @@ struct mountpt_operations
CODE int (*mmap)(FAR struct file *filep,
FAR struct mm_map_entry_s *map);
CODE int (*truncate)(FAR struct file *filep, off_t length);
CODE int (*poll)(FAR struct file *filep, FAR struct pollfd *fds,
bool setup);
/* The two structures need not be common after this point. The following
* are extended methods needed to deal with the unique needs of mounted
* file systems.

View File

@ -59,6 +59,8 @@ struct procfs_operations
ssize_t (*write)(FAR struct file *filep,
FAR const char *buffer,
size_t buflen);
int (*poll)(FAR struct file *filep, FAR struct pollfd *fds,
bool setup);
/* The two structures need not be common after this point. The following
* are extended methods needed to deal with the unique needs of mounted

View File

@ -78,6 +78,7 @@ const struct procfs_operations g_mempool_operations =
mempool_close, /* close */
mempool_read, /* read */
NULL, /* write */
NULL, /* poll */
mempool_dup, /* dup */
NULL, /* opendir */
NULL, /* closedir */

View File

@ -168,6 +168,7 @@ const struct procfs_operations g_net_operations =
netprocfs_close, /* close */
netprocfs_read, /* read */
NULL, /* write */
NULL, /* poll */
netprocfs_dup, /* dup */
netprocfs_opendir, /* opendir */

View File

@ -181,6 +181,7 @@ const struct procfs_operations g_netroute_operations =
route_close, /* close */
route_read, /* read */
NULL, /* write */
NULL, /* poll */
route_dup, /* dup */

View File

@ -119,6 +119,7 @@ const struct procfs_operations g_irq_operations =
irq_close, /* close */
irq_read, /* read */
NULL, /* write */
NULL, /* poll */
irq_dup, /* dup */

View File

@ -106,6 +106,7 @@ const struct procfs_operations g_module_operations =
modprocfs_close, /* close */
modprocfs_read, /* read */
NULL, /* write */
NULL, /* poll */
modprocfs_dup, /* dup */
NULL, /* opendir */