From f8ce0cd4cae0e154faf2c46de93c7613a0571091 Mon Sep 17 00:00:00 2001 From: dongjiuzhu1 Date: Fri, 19 May 2023 23:10:51 +0800 Subject: [PATCH] fs/pseudofile: config pseudofile feature Signed-off-by: dongjiuzhu1 --- fs/Kconfig | 7 +++++++ fs/inode/inode.h | 4 ++++ fs/vfs/Make.defs | 8 +++++++- fs/vfs/fs_open.c | 2 +- fs/vfs/fs_stat.c | 3 +++ include/nuttx/fs/fs.h | 2 ++ 6 files changed, 24 insertions(+), 2 deletions(-) diff --git a/fs/Kconfig b/fs/Kconfig index 2bf53b20f1..c19084b0bf 100644 --- a/fs/Kconfig +++ b/fs/Kconfig @@ -94,6 +94,13 @@ config PSEUDOFS_SOFTLINKS to link a directory in the pseudo-file system, such as /bin, to to a directory in a mounted volume, say /mnt/sdcard/bin. +config PSEUDOFS_FILE + bool "Pseudo file support" + default n + depends on !DISABLE_PSEUDOFS_OPERATIONS + ---help--- + Support to create a file on pseudo filesystem. + config SENDFILE_BUFSIZE int "sendfile() buffer size" default 512 diff --git a/fs/inode/inode.h b/fs/inode/inode.h index 3e79ad1857..6ad3e62475 100644 --- a/fs/inode/inode.h +++ b/fs/inode/inode.h @@ -427,8 +427,10 @@ int dir_allocate(FAR struct file *filep, FAR const char *relpath); * ****************************************************************************/ +#ifdef CONFIG_PSEUDOFS_FILE int pseudofile_create(FAR struct inode **node, FAR const char *path, mode_t mode); +#endif /**************************************************************************** * Name: inode_is_pseudofile @@ -438,7 +440,9 @@ int pseudofile_create(FAR struct inode **node, FAR const char *path, * ****************************************************************************/ +#ifdef CONFIG_PSEUDOFS_FILE bool inode_is_pseudofile(FAR struct inode *inode); +#endif #undef EXTERN #if defined(__cplusplus) diff --git a/fs/vfs/Make.defs b/fs/vfs/Make.defs index 3a2b31efea..4bd008b2c3 100644 --- a/fs/vfs/Make.defs +++ b/fs/vfs/Make.defs @@ -25,7 +25,7 @@ CSRCS += fs_fchstat.c fs_fstat.c fs_fstatfs.c fs_ioctl.c fs_lseek.c CSRCS += fs_mkdir.c fs_open.c fs_poll.c fs_pread.c fs_pwrite.c fs_read.c CSRCS += fs_rename.c fs_rmdir.c fs_select.c fs_sendfile.c fs_stat.c CSRCS += fs_statfs.c fs_unlink.c fs_write.c fs_dir.c fs_fsync.c -CSRCS += fs_truncate.c fs_pseudofile.c +CSRCS += fs_truncate.c # Certain interfaces are not available if there is no mountpoint support @@ -33,6 +33,12 @@ ifneq ($(CONFIG_PSEUDOFS_SOFTLINKS),0) CSRCS += fs_link.c fs_symlink.c fs_readlink.c endif +# Pseudofile support + +ifeq ($(CONFIG_PSEUDOFS_FILE),y) +CSRCS += fs_pseudofile.c +endif + # Stream support ifeq ($(CONFIG_FILE_STREAM),y) diff --git a/fs/vfs/fs_open.c b/fs/vfs/fs_open.c index 966e35e2c3..a8ba7398ac 100644 --- a/fs/vfs/fs_open.c +++ b/fs/vfs/fs_open.c @@ -104,7 +104,7 @@ static int file_vopen(FAR struct file *filep, FAR const char *path, ret = inode_find(&desc); if (ret < 0) { -#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS +#ifdef CONFIG_PSEUDOFS_FILE if ((oflags & O_CREAT) != 0) { ret = pseudofile_create(&desc.node, path, mode); diff --git a/fs/vfs/fs_stat.c b/fs/vfs/fs_stat.c index ad65b98227..f61b181611 100644 --- a/fs/vfs/fs_stat.c +++ b/fs/vfs/fs_stat.c @@ -416,12 +416,15 @@ int inode_stat(FAR struct inode *inode, FAR struct stat *buf, int resolve) { /* What is it if it also has child inodes? */ +#ifdef CONFIG_PSEUDOFS_FILE buf->st_size = inode->i_size; + if (inode_is_pseudofile(inode)) { buf->st_mode |= S_IFREG; } else +#endif { buf->st_mode |= S_IFCHR; } diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index ca965bfba0..6f06f072e3 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -405,7 +405,9 @@ struct inode uint16_t i_flags; /* Flags for inode */ union inode_ops_u u; /* Inode operations */ ino_t i_ino; /* Inode serial number */ +#ifdef CONFIG_PSEUDOFS_FILE size_t i_size; /* The size of per inode driver */ +#endif #ifdef CONFIG_PSEUDOFS_ATTRIBUTES mode_t i_mode; /* Access mode flags */ uid_t i_owner; /* Owner */