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

xiaoxiang781216 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 87e8600a59b fs: add CONFIG_FS_MTD_PROXY to make MTD-to-block 
auto-conversion optional
87e8600a59b is described below

commit 87e8600a59b95e426b6a3eb590558cd933bcae1a
Author: xuxingliang <[email protected]>
AuthorDate: Fri Nov 13 17:49:43 2026 +0800

    fs: add CONFIG_FS_MTD_PROXY to make MTD-to-block auto-conversion optional
    
    mount() and open_blockdriver() auto-create FTL block devices for MTD
    partitions via register_mtdpartition().  This pulls in fs_mtdproxy.c
    (~3KB with snprintf) even when not needed.
    
    Add CONFIG_FS_MTD_PROXY (default y for backward compatibility) to gate
    this auto-conversion.  When disabled, MTD devices must be explicitly
    registered as block devices if needed.
    
    Independent of CONFIG_MTD_READONLY: read-only systems may still want
    the proxy for mounting ROMFS on MTD.
    
    Signed-off-by: xuxingliang <[email protected]>
    Signed-off-by: v-liuchenxu3 <[email protected]>
---
 fs/Kconfig                     | 11 +++++++++++
 fs/driver/CMakeLists.txt       |  7 +++++--
 fs/driver/Make.defs            |  2 ++
 fs/driver/driver.h             |  2 +-
 fs/driver/fs_openblockdriver.c |  2 +-
 fs/mount/fs_mount.c            |  2 +-
 6 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/fs/Kconfig b/fs/Kconfig
index bf244d5d15e..5671e2bdb68 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -214,6 +214,17 @@ config FS_HEAPBUF_SECTION
                Allocated fs heap from the specified section. If not
                specified, it will alloc from kernel heap.
 
+config FS_MTD_PROXY
+       bool "Auto-create FTL block device when mounting MTD"
+       default y
+       depends on MTD
+       ---help---
+               When enabled, mount() and open_blockdriver() will automatically
+               create a temporary FTL block device for an MTD device that is
+               passed as the source.  Disable this to save code space when
+               the block device is created manually (e.g. via
+               ftl_initialize_by_path).
+
 source "fs/vfs/Kconfig"
 source "fs/aio/Kconfig"
 source "fs/semaphore/Kconfig"
diff --git a/fs/driver/CMakeLists.txt b/fs/driver/CMakeLists.txt
index 5d3230c556d..1cb92fba9b3 100644
--- a/fs/driver/CMakeLists.txt
+++ b/fs/driver/CMakeLists.txt
@@ -41,8 +41,11 @@ if(NOT CONFIG_DISABLE_MOUNTPOINT)
     fs_closemtddriver.c)
 
   if(CONFIG_MTD)
-    list(APPEND SRCS fs_registermtddriver.c fs_unregistermtddriver.c
-         fs_mtdproxy.c)
+    list(APPEND SRCS fs_registermtddriver.c fs_unregistermtddriver.c)
+
+    if(CONFIG_FS_MTD_PROXY)
+      list(APPEND SRCS fs_mtdproxy.c)
+    endif()
 
     if(CONFIG_MTD_PARTITION)
       list(APPEND SRCS fs_mtdpartition.c)
diff --git a/fs/driver/Make.defs b/fs/driver/Make.defs
index 1085fa97202..450ac113fa4 100644
--- a/fs/driver/Make.defs
+++ b/fs/driver/Make.defs
@@ -33,7 +33,9 @@ CSRCS += fs_blockmerge.c fs_finddriver.c
 
 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
diff --git a/fs/driver/driver.h b/fs/driver/driver.h
index 2feb7ac34c7..84bfa24ebee 100644
--- a/fs/driver/driver.h
+++ b/fs/driver/driver.h
@@ -148,7 +148,7 @@ int register_partition_with_mtd(FAR const char *partition,
  *
  ****************************************************************************/
 
-#ifdef CONFIG_MTD
+#ifdef CONFIG_FS_MTD_PROXY
 int mtd_proxy(FAR const char *mtddev, int mountflags,
               FAR struct inode **ppinode);
 #endif
diff --git a/fs/driver/fs_openblockdriver.c b/fs/driver/fs_openblockdriver.c
index ee76a78c943..ca29d835642 100644
--- a/fs/driver/fs_openblockdriver.c
+++ b/fs/driver/fs_openblockdriver.c
@@ -82,7 +82,7 @@ int open_blockdriver(FAR const char *pathname, int mountflags,
   ret = find_blockdriver(pathname, mountflags, &inode);
   if (ret < 0)
     {
-#ifdef CONFIG_MTD
+#ifdef CONFIG_FS_MTD_PROXY
       /* Not block device, mtd device? let's try it. */
 
       return mtd_proxy(pathname, mountflags, ppinode);
diff --git a/fs/mount/fs_mount.c b/fs/mount/fs_mount.c
index ed73a084a55..a64e14ba603 100644
--- a/fs/mount/fs_mount.c
+++ b/fs/mount/fs_mount.c
@@ -354,7 +354,7 @@ int nx_mount(FAR const char *source, FAR const char *target,
               ret = -ENODEV;
               goto errout_with_inode;
             }
-#ifdef CONFIG_MTD
+#ifdef CONFIG_FS_MTD_PROXY
           else
             {
               inode_release(drvr_inode);

Reply via email to