jingfei195887 opened a new pull request, #22226:
URL: https://github.com/apache/nuttx/pull/22226

   ## 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 e0a754b0bee.
   
   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
   
   * [x] This PR introduces only one functional change.
   * [x] I have updated all required description fields above.
   * [x] 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).
   * [x] My PR is ready for review and can be safely merged into a codebase.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to