Block Device Drivers
Block device drivers have these properties:
include/nuttx/fs/fs.h
. All structures and APIs needed to work with block drivers are provided in this header file.struct block_operations
. Each block device driver must implement an instance ofstruct block_operations
. That structure defines a call table with the following methods:int register_blockdriver(const char *path, const struct block_operations *bops, mode_t mode, void *priv);
. Each block driver registers itself by callingregister_blockdriver()
, passing it thepath
where it will appear in the pseudo file system and it’s initialized instance ofstruct block_operations
.User Access. Users do not normally access block drivers directly, rather, they access block drivers indirectly through the
mount()
API. Themount()
API binds a block driver instance with a file system and with a mountpoint. Then the user may use the block driver to access the file system on the underlying media. Example: See thecmd_mount()
implementation inapps/nshlib/nsh_fscmds.c
.Accessing a Character Driver as a Block Device. See the loop device at
drivers/loop.c
. Example: See thecmd_losetup()
implementation inapps/nshlib/nsh_fscmds.c
.Accessing a Block Driver as Character Device. See the Block-to-Character (BCH) conversion logic in
drivers/bch/
. Example: See thecmd_dd()
implementation inapps/nshlib/nsh_ddcmd.c
.Examples.
drivers/loop.c
,drivers/mmcsd/mmcsd_spi.c
,drivers/ramdisk.c
, etc.