Simplified config

Before, the lfs had multiple paths to determine config options:
- lfs_config struct passed during initialization
- lfs_bd_info struct passed during block device initialization
- compile time options

This allowed different developers to provide their own needs
to the filesystem, such as the block device capabilities and
the higher level user's own tweaks.

However, this comes with additional complexity and action required
when the configurations are incompatible.

For now, this has been reduced to all information (including block
device function pointers) being passed through the lfs_config struct.
We just defer more complicated handling of configuration options to
the top level user.

This simplifies configuration handling and gives the top level user
the responsibility to handle configuration, which they probably would
have wanted to do anyways.
This commit is contained in:
Christopher Haster
2017-04-22 11:42:05 -05:00
parent 3b9d6630c8
commit 789286a257
13 changed files with 254 additions and 416 deletions

View File

@@ -43,8 +43,6 @@ lfs_t lfs;
lfs_emubd_t bd;
lfs_file_t file[4];
lfs_dir_t dir[4];
struct lfs_bd_info bd_info;
struct lfs_bd_stats bd_stats;
struct lfs_info info;
uint8_t buffer[1024];
@@ -56,17 +54,41 @@ lfs_size_t rsize;
uintmax_t res;
const struct lfs_config config = {{
.bd = &bd,
.bd_ops = &lfs_emubd_ops,
#ifndef LFS_READ_SIZE
#define LFS_READ_SIZE 1
#endif
#ifndef LFS_PROG_SIZE
#define LFS_PROG_SIZE 1
#endif
#ifndef LFS_BLOCK_SIZE
#define LFS_BLOCK_SIZE 512
#endif
#ifndef LFS_BLOCK_COUNT
#define LFS_BLOCK_COUNT 1024
#endif
const struct lfs_config cfg = {{
.context = &bd,
.read = &lfs_emubd_read,
.prog = &lfs_emubd_prog,
.erase = &lfs_emubd_erase,
.sync = &lfs_emubd_sync,
.read_size = LFS_READ_SIZE,
.prog_size = LFS_PROG_SIZE,
.block_size = LFS_BLOCK_SIZE,
.block_count = LFS_BLOCK_COUNT,
}};
// Entry point
int main() {{
lfs_emubd_create(&bd, "blocks");
lfs_emubd_create(&cfg, "blocks");
{tests}
lfs_emubd_destroy(&bd);
lfs_emubd_destroy(&cfg);
}}