Skip to content

Commit e337f31

Browse files
jingfei195887GUIDINGLI
authored andcommitted
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 <cuiziwei@xiaomi.com> Signed-off-by: jingfei <jingfei@xiaomi.com>
1 parent cb79c69 commit e337f31

8 files changed

Lines changed: 33 additions & 16 deletions

File tree

‎fs/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ include mqueue/Make.defs
4141
include shm/Make.defs
4242
include socket/Make.defs
4343
include event/Make.defs
44+
include partition/Make.defs
4445

4546
# Additional files required is mount-able file systems are supported
4647

4748
ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y)
4849

4950
include mount/Make.defs
50-
include partition/Make.defs
5151
include fat/Make.defs
5252
include romfs/Make.defs
5353
include cromfs/Make.defs

‎fs/driver/driver.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ int block_proxy(FAR struct file *filep, FAR const char *blkdev, int oflags);
138138
*
139139
****************************************************************************/
140140

141-
#ifdef CONFIG_MTD
141+
#ifdef CONFIG_MTD_PARTITION
142142
int register_partition_with_mtd(FAR const char *partition,
143143
mode_t mode, FAR struct mtd_dev_s *parent,
144144
off_t firstblock, off_t nblocks);

‎fs/partition/CMakeLists.txt‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
#
2121
# ##############################################################################
2222

23-
# Don't build anything if mountpoint doesn't support
23+
# Build the partition table support whenever block or MTD partitions are
24+
# available, independent of mountpoint support.
2425

25-
if(NOT CONFIG_DISABLE_MOUNTPOINT)
26+
if(CONFIG_BLOCK_PARTITION OR CONFIG_MTD_PARTITION)
2627

2728
set(SRCS fs_partition.c)
2829

‎fs/partition/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# see the file kconfig-language.txt in the NuttX tools repository.
2525
#
2626

27-
if !DISABLE_MOUNTPOINT
27+
if BLOCK_PARTITION || MTD_PARTITION
2828

2929
menu "Partition Table"
3030

‎fs/partition/Make.defs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@
2020
#
2121
############################################################################
2222

23-
# Don't build anything if mountpoint doesn't support
23+
# Build the partition table support whenever block or MTD partitions are
24+
# available, independent of mountpoint support.
2425

25-
ifneq ($(CONFIG_DISABLE_MOUNTPOINT),y)
26+
ifneq ($(filter y,$(CONFIG_BLOCK_PARTITION) $(CONFIG_MTD_PARTITION)),)
2627

2728
CSRCS += fs_partition.c
2829

‎fs/partition/fs_partition.c‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <sys/mount.h>
2828

2929
#include <assert.h>
30+
#include <errno.h>
3031
#include <stdio.h>
3132

3233
#include <nuttx/fs/fs.h>
@@ -105,13 +106,16 @@ static void register_partition(FAR struct partition_s *part, FAR void *arg)
105106
}
106107

107108
snprintf(path, PATH_MAX, "%s/%s", reg->dir, part->name);
109+
#ifdef CONFIG_BLOCK_PARTITION
108110
if (state->blk != NULL)
109111
{
110112
register_partition_with_inode(path, 0660, state->blk,
111113
part->firstblock, part->nblocks);
112114
}
113-
#ifdef CONFIG_MTD
114-
else
115+
#endif
116+
117+
#ifdef CONFIG_MTD_PARTITION
118+
if (state->mtd != NULL)
115119
{
116120
register_partition_with_mtd(path, 0660, state->mtd,
117121
part->firstblock, part->nblocks);
@@ -175,15 +179,22 @@ int read_partition_block(FAR struct partition_state_s *state,
175179
FAR void *buffer, size_t startblock,
176180
size_t nblocks)
177181
{
182+
#ifdef CONFIG_BLOCK_PARTITION
178183
if (state->blk)
179184
{
180185
return state->blk->u.i_bops->read(state->blk,
181186
buffer, startblock, nblocks);
182187
}
183-
else
188+
#endif
189+
190+
#ifdef CONFIG_MTD_PARTITION
191+
if (state->mtd)
184192
{
185193
return state->mtd->bread(state->mtd, startblock, nblocks, buffer);
186194
}
195+
#endif
196+
197+
return -ENODEV;
187198
}
188199

189200
/****************************************************************************
@@ -202,6 +213,7 @@ int read_partition_block(FAR struct partition_state_s *state,
202213
*
203214
****************************************************************************/
204215

216+
#ifdef CONFIG_BLOCK_PARTITION
205217
int parse_block_partition(FAR const char *path,
206218
partition_handler_t handler,
207219
FAR void *arg)
@@ -258,6 +270,7 @@ int parse_block_partition(FAR const char *path,
258270
close_blockdriver(state.blk);
259271
return ret;
260272
}
273+
#endif /* CONFIG_BLOCK_PARTITION */
261274

262275
/****************************************************************************
263276
* Name: parse_mtd_partition
@@ -275,6 +288,7 @@ int parse_block_partition(FAR const char *path,
275288
*
276289
****************************************************************************/
277290

291+
#ifdef CONFIG_MTD_PARTITION
278292
int parse_mtd_partition(FAR struct mtd_dev_s *mtd,
279293
partition_handler_t handler,
280294
FAR void *arg)
@@ -303,3 +317,4 @@ int parse_mtd_partition(FAR struct mtd_dev_s *mtd,
303317

304318
return parse_partition(&state, handler, arg);
305319
}
320+
#endif /* CONFIG_MTD_PARTITION */

‎fs/partition/partition.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <nuttx/fs/partition.h>
3232
#include <nuttx/mtd/mtd.h>
3333

34-
#ifndef CONFIG_DISABLE_MOUNTPOINT
34+
#if defined(CONFIG_BLOCK_PARTITION) || defined(CONFIG_MTD_PARTITION)
3535

3636
/****************************************************************************
3737
* Public Types
@@ -78,6 +78,6 @@ int parse_txtable_partition(FAR struct partition_state_s *state,
7878
FAR void *arg);
7979
#endif
8080

81-
#endif /* CONFIG_DISABLE_MOUNTPOINT */
81+
#endif /* CONFIG_BLOCK_PARTITION || CONFIG_MTD_PARTITION */
8282

8383
#endif /* __FS_PARTITION_PARTITION_H */

‎include/nuttx/fs/partition.h‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
#include <limits.h>
3333
#include <sys/types.h>
3434

35-
#ifndef CONFIG_DISABLE_MOUNTPOINT
36-
3735
#ifdef __cplusplus
3836
extern "C"
3937
{
@@ -75,9 +73,11 @@ typedef CODE void
7573
*
7674
****************************************************************************/
7775

76+
#ifdef CONFIG_BLOCK_PARTITION
7877
int parse_block_partition(FAR const char *path,
7978
partition_handler_t handler,
8079
FAR void *arg);
80+
#endif
8181

8282
/****************************************************************************
8383
* Name: parse_mtd_partition
@@ -95,15 +95,15 @@ int parse_block_partition(FAR const char *path,
9595
*
9696
****************************************************************************/
9797

98+
#ifdef CONFIG_MTD_PARTITION
9899
struct mtd_dev_s;
99100
int parse_mtd_partition(FAR struct mtd_dev_s *mtd,
100101
partition_handler_t handler,
101102
FAR void *arg);
103+
#endif
102104

103105
#if defined(__cplusplus)
104106
}
105107
#endif
106108

107-
#endif /* CONFIG_DISABLE_MOUNTPOINT */
108-
109109
#endif /* __INCLUDE_NUTTX_FS_PARTITION_H */

0 commit comments

Comments
 (0)