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 e337f31ad78bb2adfd17bf1612b631e353c2ec0f
Author: jingfei <[email protected]>
AuthorDate: Tue Jul 28 17:27:21 2026 +0800

    fs/partition: gate on BLOCK_PARTITION / MTD_PARTITION not mountpoint
    
    Build the partition table support whenever block or MTD partitions are
    available (CONFIG_BLOCK_PARTITION || CONFIG_MTD_PARTITION) instead of
    gating the whole directory on !CONFIG_DISABLE_MOUNTPOINT.  This lets the
    partition parser be built for raw block/MTD partition access without
    pulling in mountpoint support, and dropped entirely when neither kind of
    partition is configured.
    
    The Make.defs/CMakeLists.txt directory guard and the Kconfig menu guard
    switch to the BLOCK_PARTITION || MTD_PARTITION condition, and
    fs/Makefile includes fs/partition outside the mount point block, as
    CMake already does.  Inside
    fs_partition.c the block path (parse_block_partition, the block branch
    of read_partition_block, and the register_partition_with_inode call) is
    gated by CONFIG_BLOCK_PARTITION, and the MTD path by
    CONFIG_MTD_PARTITION.  In <nuttx/fs/partition.h> struct partition_s
    stays visible, since boards use it for static partition tables, and
    parse_block_partition() / parse_mtd_partition() are declared under
    their own option.
    
    [skip-cmake-parity]: CMake needs no change, since fs/CMakeLists.txt
    already adds every subdirectory and fs/partition/CMakeLists.txt gates
    itself.
    
    Also tighten two consistency points:
      - The register_partition_with_mtd prototype guard is narrowed from
        CONFIG_MTD to CONFIG_MTD_PARTITION so declaration, definition
        (fs_mtdpartition.c) and call site all agree.
      - fs_partition.c includes <errno.h> explicitly, since
        read_partition_block now returns -ENODEV when the state holds
        neither a block nor an MTD device.
    
    Signed-off-by: cuiziwei <[email protected]>
    Signed-off-by: jingfei <[email protected]>
---
 fs/Makefile                  |  2 +-
 fs/driver/driver.h           |  2 +-
 fs/partition/CMakeLists.txt  |  5 +++--
 fs/partition/Kconfig         |  2 +-
 fs/partition/Make.defs       |  5 +++--
 fs/partition/fs_partition.c  | 21 ++++++++++++++++++---
 fs/partition/partition.h     |  4 ++--
 include/nuttx/fs/partition.h |  8 ++++----
 8 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/fs/Makefile b/fs/Makefile
index 9b4620fcc39..860e347c6f6 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -41,13 +41,13 @@ include mqueue/Make.defs
 include shm/Make.defs
 include socket/Make.defs
 include event/Make.defs
+include partition/Make.defs
 
 # Additional files required is mount-able file systems are supported
 
 ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y)
 
 include mount/Make.defs
-include partition/Make.defs
 include fat/Make.defs
 include romfs/Make.defs
 include cromfs/Make.defs
diff --git a/fs/driver/driver.h b/fs/driver/driver.h
index c6658c83e79..0a2f34fc664 100644
--- a/fs/driver/driver.h
+++ b/fs/driver/driver.h
@@ -138,7 +138,7 @@ int block_proxy(FAR struct file *filep, FAR const char 
*blkdev, int oflags);
  *
  ****************************************************************************/
 
-#ifdef CONFIG_MTD
+#ifdef CONFIG_MTD_PARTITION
 int register_partition_with_mtd(FAR const char *partition,
                                 mode_t mode, FAR struct mtd_dev_s *parent,
                                 off_t firstblock, off_t nblocks);
diff --git a/fs/partition/CMakeLists.txt b/fs/partition/CMakeLists.txt
index 44c28e02af6..0ce3472bedf 100644
--- a/fs/partition/CMakeLists.txt
+++ b/fs/partition/CMakeLists.txt
@@ -20,9 +20,10 @@
 #
 # 
##############################################################################
 
-# Don't build anything if mountpoint doesn't support
+# Build the partition table support whenever block or MTD partitions are
+# available, independent of mountpoint support.
 
-if(NOT CONFIG_DISABLE_MOUNTPOINT)
+if(CONFIG_BLOCK_PARTITION OR CONFIG_MTD_PARTITION)
 
   set(SRCS fs_partition.c)
 
diff --git a/fs/partition/Kconfig b/fs/partition/Kconfig
index 4d1aa72821e..28828c25b6f 100644
--- a/fs/partition/Kconfig
+++ b/fs/partition/Kconfig
@@ -24,7 +24,7 @@
 # see the file kconfig-language.txt in the NuttX tools repository.
 #
 
-if !DISABLE_MOUNTPOINT
+if BLOCK_PARTITION || MTD_PARTITION
 
 menu "Partition Table"
 
diff --git a/fs/partition/Make.defs b/fs/partition/Make.defs
index 57c9eb886a2..3ba2ba6dc41 100644
--- a/fs/partition/Make.defs
+++ b/fs/partition/Make.defs
@@ -20,9 +20,10 @@
 #
 ############################################################################
 
-# Don't build anything if mountpoint doesn't support
+# Build the partition table support whenever block or MTD partitions are
+# available, independent of mountpoint support.
 
-ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y)
+ifneq ($(filter y,$(CONFIG_BLOCK_PARTITION) $(CONFIG_MTD_PARTITION)),)
 
 CSRCS += fs_partition.c
 
diff --git a/fs/partition/fs_partition.c b/fs/partition/fs_partition.c
index 68ef61550f2..0c2c7983807 100644
--- a/fs/partition/fs_partition.c
+++ b/fs/partition/fs_partition.c
@@ -27,6 +27,7 @@
 #include <sys/mount.h>
 
 #include <assert.h>
+#include <errno.h>
 #include <stdio.h>
 
 #include <nuttx/fs/fs.h>
@@ -105,13 +106,16 @@ static void register_partition(FAR struct partition_s 
*part, FAR void *arg)
         }
 
       snprintf(path, PATH_MAX, "%s/%s", reg->dir, part->name);
+#ifdef CONFIG_BLOCK_PARTITION
       if (state->blk != NULL)
         {
           register_partition_with_inode(path, 0660, state->blk,
                                         part->firstblock, part->nblocks);
         }
-#ifdef CONFIG_MTD
-      else
+#endif
+
+#ifdef CONFIG_MTD_PARTITION
+      if (state->mtd != NULL)
         {
           register_partition_with_mtd(path, 0660, state->mtd,
                                       part->firstblock, part->nblocks);
@@ -175,15 +179,22 @@ int read_partition_block(FAR struct partition_state_s 
*state,
                          FAR void *buffer, size_t startblock,
                          size_t nblocks)
 {
+#ifdef CONFIG_BLOCK_PARTITION
   if (state->blk)
     {
       return state->blk->u.i_bops->read(state->blk,
                                         buffer, startblock, nblocks);
     }
-  else
+#endif
+
+#ifdef CONFIG_MTD_PARTITION
+  if (state->mtd)
     {
       return state->mtd->bread(state->mtd, startblock, nblocks, buffer);
     }
+#endif
+
+  return -ENODEV;
 }
 
 /****************************************************************************
@@ -202,6 +213,7 @@ int read_partition_block(FAR struct partition_state_s 
*state,
  *
  ****************************************************************************/
 
+#ifdef CONFIG_BLOCK_PARTITION
 int parse_block_partition(FAR const char *path,
                           partition_handler_t handler,
                           FAR void *arg)
@@ -258,6 +270,7 @@ int parse_block_partition(FAR const char *path,
   close_blockdriver(state.blk);
   return ret;
 }
+#endif /* CONFIG_BLOCK_PARTITION */
 
 /****************************************************************************
  * Name: parse_mtd_partition
@@ -275,6 +288,7 @@ int parse_block_partition(FAR const char *path,
  *
  ****************************************************************************/
 
+#ifdef CONFIG_MTD_PARTITION
 int parse_mtd_partition(FAR struct mtd_dev_s *mtd,
                         partition_handler_t handler,
                         FAR void *arg)
@@ -303,3 +317,4 @@ int parse_mtd_partition(FAR struct mtd_dev_s *mtd,
 
   return parse_partition(&state, handler, arg);
 }
+#endif /* CONFIG_MTD_PARTITION */
diff --git a/fs/partition/partition.h b/fs/partition/partition.h
index 1e488a92d50..00d5a705179 100644
--- a/fs/partition/partition.h
+++ b/fs/partition/partition.h
@@ -31,7 +31,7 @@
 #include <nuttx/fs/partition.h>
 #include <nuttx/mtd/mtd.h>
 
-#ifndef CONFIG_DISABLE_MOUNTPOINT
+#if defined(CONFIG_BLOCK_PARTITION) || defined(CONFIG_MTD_PARTITION)
 
 /****************************************************************************
  * Public Types
@@ -78,6 +78,6 @@ int parse_txtable_partition(FAR struct partition_state_s 
*state,
                             FAR void *arg);
 #endif
 
-#endif /* CONFIG_DISABLE_MOUNTPOINT */
+#endif /* CONFIG_BLOCK_PARTITION || CONFIG_MTD_PARTITION */
 
 #endif /* __FS_PARTITION_PARTITION_H */
diff --git a/include/nuttx/fs/partition.h b/include/nuttx/fs/partition.h
index 729ce75da54..16b5ed1b792 100644
--- a/include/nuttx/fs/partition.h
+++ b/include/nuttx/fs/partition.h
@@ -32,8 +32,6 @@
 #include <limits.h>
 #include <sys/types.h>
 
-#ifndef CONFIG_DISABLE_MOUNTPOINT
-
 #ifdef __cplusplus
 extern "C"
 {
@@ -75,9 +73,11 @@ typedef CODE void
  *
  ****************************************************************************/
 
+#ifdef CONFIG_BLOCK_PARTITION
 int parse_block_partition(FAR const char *path,
                           partition_handler_t handler,
                           FAR void *arg);
+#endif
 
 /****************************************************************************
  * Name: parse_mtd_partition
@@ -95,15 +95,15 @@ int parse_block_partition(FAR const char *path,
  *
  ****************************************************************************/
 
+#ifdef CONFIG_MTD_PARTITION
 struct mtd_dev_s;
 int parse_mtd_partition(FAR struct mtd_dev_s *mtd,
                         partition_handler_t handler,
                         FAR void *arg);
+#endif
 
 #if defined(__cplusplus)
 }
 #endif
 
-#endif /* CONFIG_DISABLE_MOUNTPOINT */
-
 #endif /* __INCLUDE_NUTTX_FS_PARTITION_H */

Reply via email to