Skip to content

fs: decouple block/MTD driver support from DISABLE_MOUNTPOINT - #22226

Merged
GUIDINGLI merged 3 commits into
apache:masterfrom
jingfei195887:fs/block-mtd-decouple
Nov 24, 2026
Merged

GUIDINGLI merged 3 commits into
apache:masterfrom
jingfei195887:fs/block-mtd-decouple

Conversation

@jingfei195887

Copy link
Copy Markdown
Contributor

Summary

Block and MTD driver support is tied to CONFIG_DISABLE_MOUNTPOINT:
the block driver inode helpers, struct block_operations, ftl.c and the
partition parser are all built only with mount points. A small target that
has no file system to mount but wants raw access to an FTL over MTD (for
example to read a boot partition) cannot build them; with
DISABLE_MOUNTPOINT=y and MTD=y on master, drivers/mtd/ftl.c and
drivers/bch fail to compile.

This series decouples them:

  • fs/driver: decouple block/MTD inode helpers from DISABLE_MOUNTPOINT.
    New CONFIG_FS_BLOCK_DRIVER gates the block driver inode helpers, the
    block_operations vtable and ftl.c. It is always enabled with mount
    points and only selectable with DISABLE_MOUNTPOINT. The MTD inode
    helpers are gated by CONFIG_MTD; find_mtddriver() /
    close_mtddriver() keep their -ENODEV stubs. mtd_proxy() opens its
    temporary FTL device with open_blockdriver() and then unlinks it, so
    FS_MTD_PROXY 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.
  • fs/driver: add CONFIG_BLOCK_PARTITION and CONFIG_BLOCK_MERGE.
    Separate options for fs_blockpartition.c and fs_blockmerge.c. Like
    FS_BLOCK_DRIVER they are always enabled with mount points and can only
    be turned off with DISABLE_MOUNTPOINT.
  • fs/partition: gate on BLOCK_PARTITION / MTD_PARTITION not mountpoint.
    The partition parser builds when either partition type is enabled.
    struct partition_s stays visible (boards use it for static tables);
    parse_block_partition() / parse_mtd_partition() are declared under
    their own option.

Impact

  • New feature / API change: new Kconfig options FS_BLOCK_DRIVER,
    BLOCK_PARTITION, BLOCK_MERGE. No function signature changes.
  • Configurations with mount points: the three options are forced to y, so
    the same objects are built as before (checked below).
  • Configurations with DISABLE_MOUNTPOINT=y: unchanged unless
    FS_BLOCK_DRIVER is selected.
  • Build: Make and CMake updated together.
  • Hardware, documentation (Kconfig help only), security: NO.

Testing

Host: Ubuntu 22.04 x86_64, gcc 13.1.0. Base: master e0a754b.

Build matrix on sim:nsh (Make), master vs this PR. The
DISABLE_MOUNTPOINT rows also set FS_BINFS=n DEV_LOOP=n, because the sim
board code mounts binfs and registers /dev/loop unconditionally.
FS_BLOCK_DRIVER and BLOCK_PARTITION do not exist on master, so the
master rows are built without them.

options on top of sim:nsh master this PR
(none) OK OK, same objects
MTD BCH FS_ROMFS RAMMTD MTD_PARTITION MBR_PARTITION OK OK, same objects
MTD BCH BLOCK_PARTITION=n BLOCK_MERGE=n OK OK, same objects (both options stay y with mount points)
DISABLE_MOUNTPOINT OK OK, same objects
DISABLE_MOUNTPOINT MTD RAMMTD ftl.c: g_bops has incomplete type OK
DISABLE_MOUNTPOINT FS_BLOCK_DRIVER MTD RAMMTD BCH FS_MTD_PROXY MTD_PARTITION bchlib_setup.c: no member i_bops OK
same + BLOCK_PARTITION=n BLOCK_MERGE=n MBR_PARTITION GPT_PARTITION bchlib_setup.c: no member i_bops OK; builds fs_partition.o, fs_mbr.o, fs_gpt.o, fs_mtdpartition.o, not fs_blockpartition.o / fs_blockmerge.o
DISABLE_MOUNTPOINT DISABLE_PSEUDOFS_OPERATIONS FS_BLOCK_DRIVER MTD RAMMTD BCH bchlib_setup.c: no member i_bops OK

All builds of this PR have 0 warnings. Each of the three commits was also
built on its own with the mount point and DISABLE_MOUNTPOINT rows above.

Runtime on sim:nsh with DISABLE_MOUNTPOINT FS_BLOCK_DRIVER MTD RAMMTD BCH FS_MTD_PROXY MTD_PARTITION (plus FS_BINFS=n DEV_LOOP=n SYSTEM_NXINIT=n INIT_ENTRYPOINT="nsh_main"). Master cannot build this
configuration, so the comparison is this PR with and without the
CONFIG_FS_BLOCK_DRIVER guard on the block-inode branch of nx_unlink().
dd if=/dev/rammtd of=/dev/null bs=512 count=8 opens the MTD device
through block_proxy() and mtd_proxy():

dd /dev after dd
without the nx_unlink() guard failed to open '/dev/rammtd', errno 6 (ENXIO) temporary FTL device tmpb000002 left behind
this PR 4096 bytes (8 blocks) copied, rc 0 no temporary device
  • ./tools/checkpatch.sh -m -g master..HEAD: all checks pass.
  • sim:nsh + MTD RAMMTD BCH FS_MTD_PROXY MTD_PARTITION MBR_PARTITION:
    Make and CMake builds pass with no warnings in the changed files;
    ostest exits with status 0.
  • Verified on sim only.

PR verification Self-Check

  • This PR introduces only one functional change.
  • I have updated all required description fields above.
  • My PR adheres to Contributing Guidelines and Documentation (git commit title and message, coding standard, etc).
  • My PR is still work in progress (not ready for review).
  • My PR is ready for review and can be safely merged into a codebase.

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]>
Add dedicated Kconfig options to gate the block partition and block
merge inode helpers separately from the base block driver inode helpers:

  CONFIG_BLOCK_PARTITION  gates fs_blockpartition.c
                          (register_blockpartition /
                          register_partition_with_inode)
  CONFIG_BLOCK_MERGE      gates fs_blockmerge.c
                          (register_merge_blockdriver)

Both depend on FS_BLOCK_DRIVER and, like it, are always enabled with
mount points, so existing configurations keep building these helpers
unchanged.  A target built with DISABLE_MOUNTPOINT that selects
FS_BLOCK_DRIVER but does not need block partition or merge support can
drop the corresponding object files.

The build layer (Make.defs/CMakeLists.txt) gates the two source files on
the new options, and the public/private prototypes
(register_blockpartition, register_merge_blockdriver,
register_partition_with_inode) follow the same guards.

Signed-off-by: cuiziwei <[email protected]>
Signed-off-by: jingfei <[email protected]>
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]>
@xiaoxiang781216 xiaoxiang781216 linked an issue Nov 23, 2026 that may be closed by this pull request
1 task done
@github-actions github-actions Bot added Area: Drivers Drivers issues Size: M The size of the change in this PR is medium labels Nov 23, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

mps2-an500-citest

  • flash: .text +8 B (+0.0%, 247,160 B / 4,194,304 B, total: 6% used)

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@GUIDINGLI
GUIDINGLI merged commit e337f31 into apache:master Nov 24, 2026
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Drivers Drivers issues Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[HELP] Improve NuttX bloated size

3 participants