You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2026/10/22 12:31:18 UTC
(nuttx) branch master updated: fs/vfs: add CONFIG_DISABLE_DIRECTORY_OPERATIONS
This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 31ab2d6eeb3 fs/vfs: add CONFIG_DISABLE_DIRECTORY_OPERATIONS
31ab2d6eeb3 is described below
commit 31ab2d6eeb3673095eeeacaf4e5bda7824d5bdbc
Author: jingfei <ji...@xiaomi.com>
AuthorDate: Wed Oct 21 15:05:20 2026 +0800
fs/vfs: add CONFIG_DISABLE_DIRECTORY_OPERATIONS
Many small systems never list a directory, yet every image carries the
directory file layer in fs/vfs/fs_dir.c: the pseudo and mountpoint
readdir and seek paths, the stand-in inode and its file operations.
Add DISABLE_DIRECTORY_OPERATIONS, default DEFAULT_SMALL. When set,
fs_dir.c is not built and dir_allocate() returns -ENOSYS, so opendir()
and open() with O_DIRECTORY fail with ENOSYS. dir_fstat() returns
-ENOTTY, so fstat() keeps using the normal inode path.
stm32f103-minimum:nsh: flash -996 bytes.
Signed-off-by: jingfei <ji...@xiaomi.com>
---
fs/Kconfig | 9 +++++++++
fs/inode/inode.h | 16 ++++++++++++++++
fs/vfs/CMakeLists.txt | 5 ++++-
fs/vfs/Make.defs | 6 +++++-
4 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/fs/Kconfig b/fs/Kconfig
index 2ad6dbf4259..bcc9c29556b 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -86,6 +86,15 @@ config DISABLE_PSEUDOFS_OPERATIONS
However, in practical embedded system, they are seldom needed and
you can save a little FLASH space by disabling the capability.
+config DISABLE_DIRECTORY_OPERATIONS
+ bool "Disable directory operations"
+ default DEFAULT_SMALL
+ ---help---
+ Disable opening directories: opendir() and open() with O_DIRECTORY
+ fail with ENOSYS, so readdir(), seekdir() and friends are not
+ available either. Useful for small systems that never list a
+ directory; the directory file layer is not built at all.
+
config PSEUDOFS_ATTRIBUTES
bool "Pseudo-filesystem attributes"
default n
diff --git a/fs/inode/inode.h b/fs/inode/inode.h
index beb3438e830..acc59284f26 100644
--- a/fs/inode/inode.h
+++ b/fs/inode/inode.h
@@ -33,6 +33,7 @@
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
+#include <errno.h>
#include <dirent.h>
#include <sched.h>
@@ -522,7 +523,15 @@ int foreach_inode(foreach_inode_t handler, FAR void *arg);
*
****************************************************************************/
+#ifdef CONFIG_DISABLE_DIRECTORY_OPERATIONS
+static inline int dir_allocate(FAR struct file *filep,
+ FAR const char *relpath)
+{
+ return -ENOSYS;
+}
+#else
int dir_allocate(FAR struct file *filep, FAR const char *relpath);
+#endif
/****************************************************************************
* Name: dir_fstat
@@ -533,7 +542,14 @@ int dir_allocate(FAR struct file *filep, FAR const char *relpath);
*
****************************************************************************/
+#ifdef CONFIG_DISABLE_DIRECTORY_OPERATIONS
+static inline int dir_fstat(FAR struct file *filep, FAR struct stat *buf)
+{
+ return -ENOTTY;
+}
+#else
int dir_fstat(FAR struct file *filep, FAR struct stat *buf);
+#endif
/****************************************************************************
* Name: pseudofile_create
diff --git a/fs/vfs/CMakeLists.txt b/fs/vfs/CMakeLists.txt
index 85a99add6ba..9d1d2127c2a 100644
--- a/fs/vfs/CMakeLists.txt
+++ b/fs/vfs/CMakeLists.txt
@@ -48,12 +48,15 @@ set(SRCS
fs_uio.c
fs_unlink.c
fs_write.c
- fs_dir.c
fs_fsync.c
fs_syncfs.c
fs_truncate.c
fs_link.c)
+if(NOT CONFIG_DISABLE_DIRECTORY_OPERATIONS)
+ list(APPEND SRCS fs_dir.c)
+endif()
+
if(CONFIG_FS_CHROOT)
list(APPEND SRCS fs_chroot.c)
endif()
diff --git a/fs/vfs/Make.defs b/fs/vfs/Make.defs
index 172d779fc95..0b2b02bfcf5 100644
--- a/fs/vfs/Make.defs
+++ b/fs/vfs/Make.defs
@@ -26,9 +26,13 @@ CSRCS += fs_chstat.c fs_close.c fs_dup.c fs_dup2.c fs_dup3.c fs_fcntl.c
CSRCS += fs_epoll.c 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_uio.c fs_unlink.c fs_write.c fs_dir.c fs_fsync.c
+CSRCS += fs_statfs.c fs_uio.c fs_unlink.c fs_write.c fs_fsync.c
CSRCS += fs_syncfs.c fs_truncate.c fs_link.c
+ifneq ($(CONFIG_DISABLE_DIRECTORY_OPERATIONS),y)
+CSRCS += fs_dir.c
+endif
+
ifeq ($(CONFIG_FS_CHROOT),y)
CSRCS += fs_chroot.c
endif