This is an automated email from the ASF dual-hosted git repository.

GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 47772365c5d4e9719dad4eb275547edce3fa1408
Author: jingfei <[email protected]>
AuthorDate: Tue Jul 28 17:23:26 2026 +0800

    fs/driver: decouple block/MTD inode helpers from DISABLE_MOUNTPOINT
    
    Split the block and MTD driver inode helpers out of the
    CONFIG_DISABLE_MOUNTPOINT build guard so they can be compiled
    independently of mountpoint support.
    
    Introduce CONFIG_FS_BLOCK_DRIVER to gate the block driver inode
    helpers, the block_operations vtable and ftl.c.  It is always enabled
    with mount points and can be selected with DISABLE_MOUNTPOINT, so
    configurations with mount points build the same objects as before.
    The MTD driver inode helpers are gated by CONFIG_MTD, since they do not
    call any block function; find_mtddriver() and close_mtddriver() keep
    their -ENODEV stubs for builds with mount points but without MTD.
    
    fs_mtdproxy.c opens the auto-created FTL block device through
    open_blockdriver() and then unlinks it, so FS_MTD_PROXY now also
    depends on FS_BLOCK_DRIVER and on nx_unlink() being built, and the
    block-inode branch of nx_unlink() follows CONFIG_FS_BLOCK_DRIVER.
    
    Use the build layer (Make.defs/CMakeLists.txt) as the single cropping
    point for the block/MTD inode helper sources and drop the redundant
    in-file whole-file #ifdef guards.
    
    Signed-off-by: cuiziwei <[email protected]>
    Signed-off-by: jingfei <[email protected]>
---
 drivers/mtd/CMakeLists.txt         | 10 +++++++-
 drivers/mtd/Make.defs              |  6 +++++
 fs/Kconfig                         | 13 ++++++++++-
 fs/driver/CMakeLists.txt           | 47 ++++++++++++++++++++------------------
 fs/driver/Make.defs                | 29 +++++++++++++----------
 fs/driver/driver.h                 |  7 +++---
 fs/driver/fs_blockproxy.c          |  5 ----
 fs/driver/fs_registerblockdriver.c |  4 ----
 fs/driver/fs_registermtddriver.c   |  4 ----
 fs/vfs/fs_open.c                   |  3 +--
 fs/vfs/fs_stat.c                   |  2 +-
 fs/vfs/fs_unlink.c                 |  2 +-
 include/nuttx/fs/fs.h              | 24 +++++++++++++++----
 13 files changed, 95 insertions(+), 61 deletions(-)

diff --git a/drivers/mtd/CMakeLists.txt b/drivers/mtd/CMakeLists.txt
index 116c53e3b5d..382880059e7 100644
--- a/drivers/mtd/CMakeLists.txt
+++ b/drivers/mtd/CMakeLists.txt
@@ -21,7 +21,15 @@
 # 
##############################################################################
 
 if(CONFIG_MTD)
-  set(SRCS ftl.c)
+  set(SRCS)
+
+  # ftl.c turns an MTD device into a block driver via register_blockdriver() 
and
+  # the block_operations vtable, so it additionally requires the block driver
+  # inode helpers.
+
+  if(CONFIG_FS_BLOCK_DRIVER)
+    list(APPEND SRCS ftl.c)
+  endif()
 
   if(CONFIG_MTD_CONFIG_NVS)
     list(APPEND SRCS mtd_config_nvs.c)
diff --git a/drivers/mtd/Make.defs b/drivers/mtd/Make.defs
index 528210aa6eb..2eb29cee4a9 100644
--- a/drivers/mtd/Make.defs
+++ b/drivers/mtd/Make.defs
@@ -29,7 +29,13 @@
 
 ifeq ($(CONFIG_MTD),y)
 
+# ftl.c turns an MTD device into a block driver via register_blockdriver()
+# and the block_operations vtable, so it additionally requires the block
+# driver inode helpers.
+
+ifeq ($(CONFIG_FS_BLOCK_DRIVER),y)
 CSRCS += ftl.c
+endif
 
 ifeq ($(CONFIG_MTD_CONFIG_NVS),y)
 CSRCS += mtd_config_nvs.c
diff --git a/fs/Kconfig b/fs/Kconfig
index 07af9f4c8f1..0d9519e51ed 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -41,6 +41,16 @@ config DISABLE_MOUNTPOINT
 config FS_UIO
        bool
 
+config FS_BLOCK_DRIVER
+       bool "Block driver support without mount points" if DISABLE_MOUNTPOINT
+       default !DISABLE_MOUNTPOINT
+       ---help---
+               Build the block driver inode helpers (register_blockdriver(),
+               open_blockdriver(), ...) and the FTL layer over MTD.  Always
+               enabled with mount points.  With DISABLE_MOUNTPOINT, enable this
+               to use block drivers (e.g. an FTL over MTD) for raw access
+               without mounting them.
+
 config FS_LARGEFILE
        bool "Large File Support"
        default n
@@ -227,7 +237,8 @@ config FS_HEAPBUF_SECTION
 config FS_MTD_PROXY
        bool "Auto-create FTL block device when mounting MTD"
        default y
-       depends on MTD
+       depends on MTD && FS_BLOCK_DRIVER
+       depends on !DISABLE_MOUNTPOINT || !DISABLE_PSEUDOFS_OPERATIONS
        ---help---
                When enabled, mount() and open_blockdriver() will automatically
                create a temporary FTL block device for an MTD device that is
diff --git a/fs/driver/CMakeLists.txt b/fs/driver/CMakeLists.txt
index 51fec2bec3a..fea8a40d7ac 100644
--- a/fs/driver/CMakeLists.txt
+++ b/fs/driver/CMakeLists.txt
@@ -23,45 +23,48 @@
 set(SRCS fs_registerdriver.c fs_unregisterdriver.c fs_registerpipedriver.c
          fs_unregisterpipedriver.c fs_registerpseudodir.c)
 
-# Don't built-in block driver support if there are no mountpoints
-
 if(NOT CONFIG_DISABLE_MOUNTPOINT)
+  list(APPEND SRCS fs_finddriver.c)
+endif()
+
+if(NOT CONFIG_DISABLE_MOUNTPOINT OR CONFIG_MTD)
+  list(APPEND SRCS fs_findmtddriver.c fs_closemtddriver.c)
+endif()
+
+if(CONFIG_FS_BLOCK_DRIVER)
   list(
     APPEND
     SRCS
     fs_registerblockdriver.c
     fs_unregisterblockdriver.c
-    fs_finddriver.c
     fs_findblockdriver.c
     fs_openblockdriver.c
     fs_closeblockdriver.c
     fs_blockpartition.c
-    fs_findmtddriver.c
-    fs_blockmerge.c
-    fs_closemtddriver.c)
+    fs_blockmerge.c)
 
-  if(CONFIG_MTD)
-    list(APPEND SRCS fs_registermtddriver.c fs_unregistermtddriver.c)
+  if(CONFIG_BCH AND NOT CONFIG_DISABLE_PSEUDOFS_OPERATIONS)
+    list(APPEND SRCS fs_blockproxy.c)
+  endif()
+endif()
 
-    if(CONFIG_FS_MTD_PROXY)
-      list(APPEND SRCS fs_mtdproxy.c)
-    endif()
+if(CONFIG_MTD)
+  list(APPEND SRCS fs_registermtddriver.c fs_unregistermtddriver.c)
 
-    if(CONFIG_MTD_PARTITION)
-      list(APPEND SRCS fs_mtdpartition.c)
-    endif()
+  if(CONFIG_FS_MTD_PROXY)
+    list(APPEND SRCS fs_mtdproxy.c)
   endif()
 
-  if(CONFIG_BCH)
-    if(NOT CONFIG_DISABLE_PSEUDOFS_OPERATIONS)
-      list(APPEND SRCS fs_blockproxy.c)
-    endif()
+  if(CONFIG_MTD_PARTITION)
+    list(APPEND SRCS fs_mtdpartition.c)
   endif()
+endif()
 
-  if(CONFIG_FS_MTD_PROXY OR (CONFIG_BCH AND NOT
-                                            
CONFIG_DISABLE_PSEUDOFS_OPERATIONS))
-    list(APPEND SRCS fs_uniquedevname.c)
-  endif()
+if(CONFIG_FS_MTD_PROXY
+   OR (CONFIG_FS_BLOCK_DRIVER
+       AND CONFIG_BCH
+       AND NOT CONFIG_DISABLE_PSEUDOFS_OPERATIONS))
+  list(APPEND SRCS fs_uniquedevname.c)
 endif()
 
 target_sources(fs PRIVATE ${SRCS})
diff --git a/fs/driver/Make.defs b/fs/driver/Make.defs
index cb5fd551e55..856357d29ec 100644
--- a/fs/driver/Make.defs
+++ b/fs/driver/Make.defs
@@ -23,34 +23,39 @@
 CSRCS += fs_registerdriver.c fs_unregisterdriver.c fs_registerpseudodir.c
 CSRCS += fs_registerpipedriver.c fs_unregisterpipedriver.c
 
-# Don't built-in block driver support if there are no mountpoints
-
 ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y)
+CSRCS += fs_finddriver.c fs_findmtddriver.c fs_closemtddriver.c
+else ifeq ($(CONFIG_MTD),y)
+CSRCS += fs_findmtddriver.c fs_closemtddriver.c
+endif
+
+ifeq ($(CONFIG_FS_BLOCK_DRIVER),y)
 CSRCS += fs_registerblockdriver.c fs_unregisterblockdriver.c
 CSRCS += fs_findblockdriver.c fs_openblockdriver.c fs_closeblockdriver.c
-CSRCS += fs_blockpartition.c fs_findmtddriver.c fs_closemtddriver.c
-CSRCS += fs_blockmerge.c fs_finddriver.c
+CSRCS += fs_blockpartition.c fs_blockmerge.c
+
+ifeq ($(CONFIG_BCH),y)
+ifneq ($(CONFIG_DISABLE_PSEUDOFS_OPERATIONS),y)
+CSRCS += fs_blockproxy.c
+endif
+endif # CONFIG_BCH
+endif # CONFIG_FS_BLOCK_DRIVER
 
 ifeq ($(CONFIG_MTD),y)
 CSRCS += fs_registermtddriver.c fs_unregistermtddriver.c
+
 ifeq ($(CONFIG_FS_MTD_PROXY),y)
 CSRCS += fs_mtdproxy.c
 endif
+
 ifeq ($(CONFIG_MTD_PARTITION),y)
 CSRCS += fs_mtdpartition.c
 endif
-endif
-
-ifeq ($(CONFIG_BCH),y)
-ifneq ($(CONFIG_DISABLE_PSEUDOFS_OPERATIONS),y)
-CSRCS += fs_blockproxy.c
-endif
-endif # CONFIG_BCH
+endif # CONFIG_MTD
 
 ifneq ($(filter fs_blockproxy.c fs_mtdproxy.c,$(CSRCS)),)
 CSRCS += fs_uniquedevname.c
 endif
-endif # CONFIG_DISABLE_MOUNTPOINT
 
 # Include driver build support
 
diff --git a/fs/driver/driver.h b/fs/driver/driver.h
index 3671b4b7976..42dfa05c3af 100644
--- a/fs/driver/driver.h
+++ b/fs/driver/driver.h
@@ -69,7 +69,7 @@ extern "C"
  *
  ****************************************************************************/
 
-#ifndef CONFIG_DISABLE_MOUNTPOINT
+#ifdef CONFIG_FS_BLOCK_DRIVER
 int register_partition_with_inode(FAR const char *partition,
                                   mode_t mode, FAR struct inode *parent,
                                   off_t firstsector, off_t nsectors);
@@ -87,7 +87,7 @@ int register_partition_with_inode(FAR const char *partition,
  *
  ****************************************************************************/
 
-#ifndef CONFIG_DISABLE_MOUNTPOINT
+#ifdef CONFIG_FS_BLOCK_DRIVER
 int unique_devname(char prefix, FAR char *devbuf, size_t len);
 #endif
 
@@ -110,7 +110,8 @@ int unique_devname(char prefix, FAR char *devbuf, size_t 
len);
  *
  ****************************************************************************/
 
-#ifndef CONFIG_DISABLE_MOUNTPOINT
+#if defined(CONFIG_BCH) && defined(CONFIG_FS_BLOCK_DRIVER) && \
+    !defined(CONFIG_DISABLE_PSEUDOFS_OPERATIONS)
 int block_proxy(FAR struct file *filep, FAR const char *blkdev, int oflags);
 #endif
 
diff --git a/fs/driver/fs_blockproxy.c b/fs/driver/fs_blockproxy.c
index c760d5e0763..150d4187d7b 100644
--- a/fs/driver/fs_blockproxy.c
+++ b/fs/driver/fs_blockproxy.c
@@ -43,9 +43,6 @@
 
 #include "driver.h"
 
-#if !defined(CONFIG_DISABLE_MOUNTPOINT) && \
-    !defined(CONFIG_DISABLE_PSEUDOFS_OPERATIONS)
-
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -129,5 +126,3 @@ int block_proxy(FAR struct file *filep, FAR const char 
*blkdev, int oflags)
 
   return ret;
 }
-
-#endif /* !CONFIG_DISABLE_MOUNTPOINT && !CONFIG_DISABLE_PSEUDOFS_OPERATIONS */
diff --git a/fs/driver/fs_registerblockdriver.c 
b/fs/driver/fs_registerblockdriver.c
index aae4d026918..66cf761caad 100644
--- a/fs/driver/fs_registerblockdriver.c
+++ b/fs/driver/fs_registerblockdriver.c
@@ -34,8 +34,6 @@
 #include "inode/inode.h"
 #include "vfs/vfs.h"
 
-#ifndef CONFIG_DISABLE_MOUNTPOINT
-
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -98,5 +96,3 @@ int register_blockdriver(FAR const char *path,
   inode_unlock();
   return ret;
 }
-
-#endif /* !CONFIG_DISABLE_MOUNTPOINT */
diff --git a/fs/driver/fs_registermtddriver.c b/fs/driver/fs_registermtddriver.c
index c91d1f26736..7ec50ecd429 100644
--- a/fs/driver/fs_registermtddriver.c
+++ b/fs/driver/fs_registermtddriver.c
@@ -35,8 +35,6 @@
 #include "inode/inode.h"
 #include "vfs/vfs.h"
 
-#if defined(CONFIG_MTD) && !defined(CONFIG_DISABLE_MOUNTPOINT)
-
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -98,5 +96,3 @@ int register_mtddriver(FAR const char *path, FAR struct 
mtd_dev_s *mtd,
   inode_unlock();
   return ret;
 }
-
-#endif /* CONFIG_MTD && !CONFIG_DISABLE_MOUNTPOINT */
diff --git a/fs/vfs/fs_open.c b/fs/vfs/fs_open.c
index e897d6b9b78..6f591ccd019 100644
--- a/fs/vfs/fs_open.c
+++ b/fs/vfs/fs_open.c
@@ -197,8 +197,7 @@ static int file_vopen(FAR struct file *filep, FAR const 
char *path,
       goto errout_with_inode;
     }
 
-#if defined(CONFIG_BCH) && \
-    !defined(CONFIG_DISABLE_MOUNTPOINT) && \
+#if defined(CONFIG_BCH) && defined(CONFIG_FS_BLOCK_DRIVER) && \
     !defined(CONFIG_DISABLE_PSEUDOFS_OPERATIONS)
   /* If the inode is block driver, then we may return a character driver
    * proxy for the block driver.  block_proxy() will instantiate a BCH
diff --git a/fs/vfs/fs_stat.c b/fs/vfs/fs_stat.c
index 3cee7e05368..1f2f7d32085 100644
--- a/fs/vfs/fs_stat.c
+++ b/fs/vfs/fs_stat.c
@@ -468,7 +468,7 @@ int inode_stat(FAR struct inode *inode, FAR struct stat 
*buf, int resolve)
 
           buf->st_mode |= S_IFBLK;
 
-#ifndef CONFIG_DISABLE_MOUNTPOINT
+#ifdef CONFIG_FS_BLOCK_DRIVER
           if ((inode->u.i_bops != NULL) &&
               (inode->u.i_bops->geometry != NULL))
             {
diff --git a/fs/vfs/fs_unlink.c b/fs/vfs/fs_unlink.c
index fc336269c7c..272c8475226 100644
--- a/fs/vfs/fs_unlink.c
+++ b/fs/vfs/fs_unlink.c
@@ -144,7 +144,7 @@ int nx_unlink(FAR const char *pathname)
               goto errout_with_inode;
             }
         }
-#ifndef CONFIG_DISABLE_MOUNTPOINT
+#ifdef CONFIG_FS_BLOCK_DRIVER
       else if (INODE_IS_BLOCK(inode) && inode->u.i_bops->unlink)
         {
           /* Notify the block driver that it has been unlinked */
diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h
index 7c00d86dbe7..6b6f043f1e4 100644
--- a/include/nuttx/fs/fs.h
+++ b/include/nuttx/fs/fs.h
@@ -262,7 +262,7 @@ struct file_operations
 
 /* This structure provides information about the state of a block driver */
 
-#ifndef CONFIG_DISABLE_MOUNTPOINT
+#ifdef CONFIG_FS_BLOCK_DRIVER
 /* This structure is provided by block devices when they register with the
  * system.  It is used by file systems to perform filesystem transfers.  It
  * differs from the normal driver vtable in several ways -- most notably in
@@ -286,7 +286,9 @@ struct block_operations
   CODE int     (*unlink)(FAR struct inode *inode);
 #endif
 };
+#endif /* CONFIG_FS_BLOCK_DRIVER */
 
+#ifndef CONFIG_DISABLE_MOUNTPOINT
 /* This structure is provided by a filesystem to describe a mount point.
  * Note that this structure differs from file_operations ONLY in the form of
  * the open method.  Once the file is opened, it can be accessed either as a
@@ -465,9 +467,13 @@ struct mountpt_operations
 union inode_ops_u
 {
   FAR const struct file_operations     *i_ops;    /* Driver operations for 
inode */
-#ifndef CONFIG_DISABLE_MOUNTPOINT
+#ifdef CONFIG_FS_BLOCK_DRIVER
   FAR const struct block_operations    *i_bops;   /* Block driver operations */
+#endif
+#if !defined(CONFIG_DISABLE_MOUNTPOINT) || defined(CONFIG_MTD)
   FAR struct mtd_dev_s                 *i_mtd;    /* MTD device driver */
+#endif
+#ifndef CONFIG_DISABLE_MOUNTPOINT
   FAR const struct mountpt_operations  *i_mops;   /* Operations on a 
mountpoint */
 #endif
 #ifdef CONFIG_FS_NAMED_SEMAPHORES
@@ -680,7 +686,7 @@ int register_driver_with_size(FAR const char *path,
  *
  ****************************************************************************/
 
-#ifndef CONFIG_DISABLE_MOUNTPOINT
+#ifdef CONFIG_FS_BLOCK_DRIVER
 int register_blockdriver(FAR const char *path,
                          FAR const struct block_operations *bops,
                          mode_t mode, FAR void *priv);
@@ -710,7 +716,7 @@ int register_blockdriver(FAR const char *path,
  *
  ****************************************************************************/
 
-#ifndef CONFIG_DISABLE_MOUNTPOINT
+#ifdef CONFIG_FS_BLOCK_DRIVER
 int register_merge_blockdriver(FAR const char *merge, ...);
 #endif
 
@@ -737,7 +743,7 @@ int register_merge_blockdriver(FAR const char *merge, ...);
  *
  ****************************************************************************/
 
-#ifndef CONFIG_DISABLE_MOUNTPOINT
+#ifdef CONFIG_FS_BLOCK_DRIVER
 int register_blockpartition(FAR const char *partition,
                             mode_t mode, FAR const char *parent,
                             off_t firstsector, off_t nsectors);
@@ -761,7 +767,9 @@ int unregister_driver(FAR const char *path);
  *
  ****************************************************************************/
 
+#ifdef CONFIG_FS_BLOCK_DRIVER
 int unregister_blockdriver(FAR const char *path);
+#endif
 
 /****************************************************************************
  * Name: register_mtddriver
@@ -1426,8 +1434,10 @@ FAR void *find_driver(FAR const char *pathname);
  *
  ****************************************************************************/
 
+#ifdef CONFIG_FS_BLOCK_DRIVER
 int open_blockdriver(FAR const char *pathname, int mountflags,
                      FAR struct inode **ppinode);
+#endif
 
 /****************************************************************************
  * Name: close_blockdriver
@@ -1447,7 +1457,9 @@ int open_blockdriver(FAR const char *pathname, int 
mountflags,
  *
  ****************************************************************************/
 
+#ifdef CONFIG_FS_BLOCK_DRIVER
 int close_blockdriver(FAR struct inode *inode);
+#endif
 
 /****************************************************************************
  * Name: find_blockdriver
@@ -1471,8 +1483,10 @@ int close_blockdriver(FAR struct inode *inode);
  *
  ****************************************************************************/
 
+#ifdef CONFIG_FS_BLOCK_DRIVER
 int find_blockdriver(FAR const char *pathname, int mountflags,
                      FAR struct inode **ppinode);
+#endif
 
 /****************************************************************************
  * Name: find_mtddriver

Reply via email to