From a549413077f3a34acbfcaf61570ec1e3f266551c Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Mon, 23 Nov 2020 01:59:59 -0600 Subject: [PATCH] Rename config structs to cfg structs Since this is already going to be a breaking API change, this renames structs/variables named _config -> _cfg. This is in order to be consistent with functions such as lfs_file_opencfg. --- README.md | 2 +- bd/lfs_filebd.c | 18 +++++++++--------- bd/lfs_filebd.h | 22 +++++++++++----------- bd/lfs_rambd.c | 18 +++++++++--------- bd/lfs_rambd.h | 22 +++++++++++----------- bd/lfs_testbd.c | 34 +++++++++++++++++----------------- bd/lfs_testbd.h | 30 +++++++++++++++--------------- lfs.c | 14 +++++++------- lfs.h | 30 +++++++++++++++--------------- scripts/test.py | 4 ++-- tests/test_attrs.toml | 8 ++++---- 11 files changed, 101 insertions(+), 101 deletions(-) diff --git a/README.md b/README.md index f900674..bd2b4d0 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ lfs_t lfs; lfs_file_t file; // configuration of the filesystem is provided by this struct -const struct lfs_config cfg = { +const struct lfs_cfg cfg = { // block device operations .read = user_provided_block_device_read, .prog = user_provided_block_device_prog, diff --git a/bd/lfs_filebd.c b/bd/lfs_filebd.c index 2d36a42..d684778 100644 --- a/bd/lfs_filebd.c +++ b/bd/lfs_filebd.c @@ -10,8 +10,8 @@ #include #include -int lfs_filebd_createcfg(const struct lfs_config *cfg, const char *path, - const struct lfs_filebd_config *bdcfg) { +int lfs_filebd_createcfg(const struct lfs_cfg *cfg, const char *path, + const struct lfs_filebd_cfg *bdcfg) { LFS_FILEBD_TRACE("lfs_filebd_createcfg(%p {.context=%p, " ".read=%p, .prog=%p, .erase=%p, .sync=%p, " ".read_size=%"PRIu32", .prog_size=%"PRIu32", " @@ -38,7 +38,7 @@ int lfs_filebd_createcfg(const struct lfs_config *cfg, const char *path, return 0; } -int lfs_filebd_create(const struct lfs_config *cfg, const char *path) { +int lfs_filebd_create(const struct lfs_cfg *cfg, const char *path) { LFS_FILEBD_TRACE("lfs_filebd_create(%p {.context=%p, " ".read=%p, .prog=%p, .erase=%p, .sync=%p, " ".read_size=%"PRIu32", .prog_size=%"PRIu32", " @@ -49,13 +49,13 @@ int lfs_filebd_create(const struct lfs_config *cfg, const char *path) { (void*)(uintptr_t)cfg->erase, (void*)(uintptr_t)cfg->sync, cfg->read_size, cfg->prog_size, cfg->block_size, cfg->block_count, path); - static const struct lfs_filebd_config defaults = {.erase_value=-1}; + static const struct lfs_filebd_cfg defaults = {.erase_value=-1}; int err = lfs_filebd_createcfg(cfg, path, &defaults); LFS_FILEBD_TRACE("lfs_filebd_create -> %d", err); return err; } -int lfs_filebd_destroy(const struct lfs_config *cfg) { +int lfs_filebd_destroy(const struct lfs_cfg *cfg) { LFS_FILEBD_TRACE("lfs_filebd_destroy(%p)", (void*)cfg); lfs_filebd_t *bd = cfg->context; int err = close(bd->fd); @@ -68,7 +68,7 @@ int lfs_filebd_destroy(const struct lfs_config *cfg) { return 0; } -int lfs_filebd_read(const struct lfs_config *cfg, lfs_block_t block, +int lfs_filebd_read(const struct lfs_cfg *cfg, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) { LFS_FILEBD_TRACE("lfs_filebd_read(%p, " "0x%"PRIx32", %"PRIu32", %p, %"PRIu32")", @@ -105,7 +105,7 @@ int lfs_filebd_read(const struct lfs_config *cfg, lfs_block_t block, return 0; } -int lfs_filebd_prog(const struct lfs_config *cfg, lfs_block_t block, +int lfs_filebd_prog(const struct lfs_cfg *cfg, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) { LFS_FILEBD_TRACE("lfs_filebd_prog(%p, 0x%"PRIx32", %"PRIu32", %p, %"PRIu32")", (void*)cfg, block, off, buffer, size); @@ -159,7 +159,7 @@ int lfs_filebd_prog(const struct lfs_config *cfg, lfs_block_t block, return 0; } -int lfs_filebd_erase(const struct lfs_config *cfg, lfs_block_t block) { +int lfs_filebd_erase(const struct lfs_cfg *cfg, lfs_block_t block) { LFS_FILEBD_TRACE("lfs_filebd_erase(%p, 0x%"PRIx32")", (void*)cfg, block); lfs_filebd_t *bd = cfg->context; @@ -189,7 +189,7 @@ int lfs_filebd_erase(const struct lfs_config *cfg, lfs_block_t block) { return 0; } -int lfs_filebd_sync(const struct lfs_config *cfg) { +int lfs_filebd_sync(const struct lfs_cfg *cfg) { LFS_FILEBD_TRACE("lfs_filebd_sync(%p)", (void*)cfg); // file sync lfs_filebd_t *bd = cfg->context; diff --git a/bd/lfs_filebd.h b/bd/lfs_filebd.h index d35b133..f719852 100644 --- a/bd/lfs_filebd.h +++ b/bd/lfs_filebd.h @@ -23,7 +23,7 @@ extern "C" #endif // filebd config (optional) -struct lfs_filebd_config { +struct lfs_filebd_cfg { // 8-bit erase value to use for simulating erases. -1 does not simulate // erases, which can speed up testing by avoiding all the extra block-device // operations to store the erase value. @@ -33,36 +33,36 @@ struct lfs_filebd_config { // filebd state typedef struct lfs_filebd { int fd; - const struct lfs_filebd_config *cfg; + const struct lfs_filebd_cfg *cfg; } lfs_filebd_t; -// Create a file block device using the geometry in lfs_config -int lfs_filebd_create(const struct lfs_config *cfg, const char *path); -int lfs_filebd_createcfg(const struct lfs_config *cfg, const char *path, - const struct lfs_filebd_config *bdcfg); +// Create a file block device using the geometry in lfs_cfg +int lfs_filebd_create(const struct lfs_cfg *cfg, const char *path); +int lfs_filebd_createcfg(const struct lfs_cfg *cfg, const char *path, + const struct lfs_filebd_cfg *bdcfg); // Clean up memory associated with block device -int lfs_filebd_destroy(const struct lfs_config *cfg); +int lfs_filebd_destroy(const struct lfs_cfg *cfg); // Read a block -int lfs_filebd_read(const struct lfs_config *cfg, lfs_block_t block, +int lfs_filebd_read(const struct lfs_cfg *cfg, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size); // Program a block // // The block must have previously been erased. -int lfs_filebd_prog(const struct lfs_config *cfg, lfs_block_t block, +int lfs_filebd_prog(const struct lfs_cfg *cfg, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size); // Erase a block // // A block must be erased before being programmed. The // state of an erased block is undefined. -int lfs_filebd_erase(const struct lfs_config *cfg, lfs_block_t block); +int lfs_filebd_erase(const struct lfs_cfg *cfg, lfs_block_t block); // Sync the block device -int lfs_filebd_sync(const struct lfs_config *cfg); +int lfs_filebd_sync(const struct lfs_cfg *cfg); #ifdef __cplusplus diff --git a/bd/lfs_rambd.c b/bd/lfs_rambd.c index 0a6b5cc..567d3bf 100644 --- a/bd/lfs_rambd.c +++ b/bd/lfs_rambd.c @@ -6,8 +6,8 @@ */ #include "bd/lfs_rambd.h" -int lfs_rambd_createcfg(const struct lfs_config *cfg, - const struct lfs_rambd_config *bdcfg) { +int lfs_rambd_createcfg(const struct lfs_cfg *cfg, + const struct lfs_rambd_cfg *bdcfg) { LFS_RAMBD_TRACE("lfs_rambd_createcfg(%p {.context=%p, " ".read=%p, .prog=%p, .erase=%p, .sync=%p, " ".read_size=%"PRIu32", .prog_size=%"PRIu32", " @@ -42,7 +42,7 @@ int lfs_rambd_createcfg(const struct lfs_config *cfg, return 0; } -int lfs_rambd_create(const struct lfs_config *cfg) { +int lfs_rambd_create(const struct lfs_cfg *cfg) { LFS_RAMBD_TRACE("lfs_rambd_create(%p {.context=%p, " ".read=%p, .prog=%p, .erase=%p, .sync=%p, " ".read_size=%"PRIu32", .prog_size=%"PRIu32", " @@ -51,13 +51,13 @@ int lfs_rambd_create(const struct lfs_config *cfg) { (void*)(uintptr_t)cfg->read, (void*)(uintptr_t)cfg->prog, (void*)(uintptr_t)cfg->erase, (void*)(uintptr_t)cfg->sync, cfg->read_size, cfg->prog_size, cfg->block_size, cfg->block_count); - static const struct lfs_rambd_config defaults = {.erase_value=-1}; + static const struct lfs_rambd_cfg defaults = {.erase_value=-1}; int err = lfs_rambd_createcfg(cfg, &defaults); LFS_RAMBD_TRACE("lfs_rambd_create -> %d", err); return err; } -int lfs_rambd_destroy(const struct lfs_config *cfg) { +int lfs_rambd_destroy(const struct lfs_cfg *cfg) { LFS_RAMBD_TRACE("lfs_rambd_destroy(%p)", (void*)cfg); // clean up memory lfs_rambd_t *bd = cfg->context; @@ -68,7 +68,7 @@ int lfs_rambd_destroy(const struct lfs_config *cfg) { return 0; } -int lfs_rambd_read(const struct lfs_config *cfg, lfs_block_t block, +int lfs_rambd_read(const struct lfs_cfg *cfg, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) { LFS_RAMBD_TRACE("lfs_rambd_read(%p, " "0x%"PRIx32", %"PRIu32", %p, %"PRIu32")", @@ -87,7 +87,7 @@ int lfs_rambd_read(const struct lfs_config *cfg, lfs_block_t block, return 0; } -int lfs_rambd_prog(const struct lfs_config *cfg, lfs_block_t block, +int lfs_rambd_prog(const struct lfs_cfg *cfg, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) { LFS_RAMBD_TRACE("lfs_rambd_prog(%p, " "0x%"PRIx32", %"PRIu32", %p, %"PRIu32")", @@ -114,7 +114,7 @@ int lfs_rambd_prog(const struct lfs_config *cfg, lfs_block_t block, return 0; } -int lfs_rambd_erase(const struct lfs_config *cfg, lfs_block_t block) { +int lfs_rambd_erase(const struct lfs_cfg *cfg, lfs_block_t block) { LFS_RAMBD_TRACE("lfs_rambd_erase(%p, 0x%"PRIx32")", (void*)cfg, block); lfs_rambd_t *bd = cfg->context; @@ -131,7 +131,7 @@ int lfs_rambd_erase(const struct lfs_config *cfg, lfs_block_t block) { return 0; } -int lfs_rambd_sync(const struct lfs_config *cfg) { +int lfs_rambd_sync(const struct lfs_cfg *cfg) { LFS_RAMBD_TRACE("lfs_rambd_sync(%p)", (void*)cfg); // sync does nothing because we aren't backed by anything real (void)cfg; diff --git a/bd/lfs_rambd.h b/bd/lfs_rambd.h index 2c2d121..09efd48 100644 --- a/bd/lfs_rambd.h +++ b/bd/lfs_rambd.h @@ -23,7 +23,7 @@ extern "C" #endif // rambd config (optional) -struct lfs_rambd_config { +struct lfs_rambd_cfg { // 8-bit erase value to simulate erasing with. -1 indicates no erase // occurs, which is still a valid block device int32_t erase_value; @@ -35,36 +35,36 @@ struct lfs_rambd_config { // rambd state typedef struct lfs_rambd { uint8_t *buffer; - const struct lfs_rambd_config *cfg; + const struct lfs_rambd_cfg *cfg; } lfs_rambd_t; -// Create a RAM block device using the geometry in lfs_config -int lfs_rambd_create(const struct lfs_config *cfg); -int lfs_rambd_createcfg(const struct lfs_config *cfg, - const struct lfs_rambd_config *bdcfg); +// Create a RAM block device using the geometry in lfs_cfg +int lfs_rambd_create(const struct lfs_cfg *cfg); +int lfs_rambd_createcfg(const struct lfs_cfg *cfg, + const struct lfs_rambd_cfg *bdcfg); // Clean up memory associated with block device -int lfs_rambd_destroy(const struct lfs_config *cfg); +int lfs_rambd_destroy(const struct lfs_cfg *cfg); // Read a block -int lfs_rambd_read(const struct lfs_config *cfg, lfs_block_t block, +int lfs_rambd_read(const struct lfs_cfg *cfg, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size); // Program a block // // The block must have previously been erased. -int lfs_rambd_prog(const struct lfs_config *cfg, lfs_block_t block, +int lfs_rambd_prog(const struct lfs_cfg *cfg, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size); // Erase a block // // A block must be erased before being programmed. The // state of an erased block is undefined. -int lfs_rambd_erase(const struct lfs_config *cfg, lfs_block_t block); +int lfs_rambd_erase(const struct lfs_cfg *cfg, lfs_block_t block); // Sync the block device -int lfs_rambd_sync(const struct lfs_config *cfg); +int lfs_rambd_sync(const struct lfs_cfg *cfg); #ifdef __cplusplus diff --git a/bd/lfs_testbd.c b/bd/lfs_testbd.c index 1ec6fb9..f098a1c 100644 --- a/bd/lfs_testbd.c +++ b/bd/lfs_testbd.c @@ -10,8 +10,8 @@ #include -int lfs_testbd_createcfg(const struct lfs_config *cfg, const char *path, - const struct lfs_testbd_config *bdcfg) { +int lfs_testbd_createcfg(const struct lfs_cfg *cfg, const char *path, + const struct lfs_testbd_cfg *bdcfg) { LFS_TESTBD_TRACE("lfs_testbd_createcfg(%p {.context=%p, " ".read=%p, .prog=%p, .erase=%p, .sync=%p, " ".read_size=%"PRIu32", .prog_size=%"PRIu32", " @@ -50,14 +50,14 @@ int lfs_testbd_createcfg(const struct lfs_config *cfg, const char *path, // create underlying block device if (bd->persist) { - bd->u.file.cfg = (struct lfs_filebd_config){ + bd->u.file.cfg = (struct lfs_filebd_cfg){ .erase_value = bd->cfg->erase_value, }; int err = lfs_filebd_createcfg(cfg, path, &bd->u.file.cfg); LFS_TESTBD_TRACE("lfs_testbd_createcfg -> %d", err); return err; } else { - bd->u.ram.cfg = (struct lfs_rambd_config){ + bd->u.ram.cfg = (struct lfs_rambd_cfg){ .erase_value = bd->cfg->erase_value, .buffer = bd->cfg->buffer, }; @@ -67,7 +67,7 @@ int lfs_testbd_createcfg(const struct lfs_config *cfg, const char *path, } } -int lfs_testbd_create(const struct lfs_config *cfg, const char *path) { +int lfs_testbd_create(const struct lfs_cfg *cfg, const char *path) { LFS_TESTBD_TRACE("lfs_testbd_create(%p {.context=%p, " ".read=%p, .prog=%p, .erase=%p, .sync=%p, " ".read_size=%"PRIu32", .prog_size=%"PRIu32", " @@ -78,13 +78,13 @@ int lfs_testbd_create(const struct lfs_config *cfg, const char *path) { (void*)(uintptr_t)cfg->erase, (void*)(uintptr_t)cfg->sync, cfg->read_size, cfg->prog_size, cfg->block_size, cfg->block_count, path); - static const struct lfs_testbd_config defaults = {.erase_value=-1}; + static const struct lfs_testbd_cfg defaults = {.erase_value=-1}; int err = lfs_testbd_createcfg(cfg, path, &defaults); LFS_TESTBD_TRACE("lfs_testbd_create -> %d", err); return err; } -int lfs_testbd_destroy(const struct lfs_config *cfg) { +int lfs_testbd_destroy(const struct lfs_cfg *cfg) { LFS_TESTBD_TRACE("lfs_testbd_destroy(%p)", (void*)cfg); lfs_testbd_t *bd = cfg->context; if (bd->cfg->erase_cycles && !bd->cfg->wear_buffer) { @@ -103,7 +103,7 @@ int lfs_testbd_destroy(const struct lfs_config *cfg) { } /// Internal mapping to block devices /// -static int lfs_testbd_rawread(const struct lfs_config *cfg, lfs_block_t block, +static int lfs_testbd_rawread(const struct lfs_cfg *cfg, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) { lfs_testbd_t *bd = cfg->context; if (bd->persist) { @@ -113,7 +113,7 @@ static int lfs_testbd_rawread(const struct lfs_config *cfg, lfs_block_t block, } } -static int lfs_testbd_rawprog(const struct lfs_config *cfg, lfs_block_t block, +static int lfs_testbd_rawprog(const struct lfs_cfg *cfg, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) { lfs_testbd_t *bd = cfg->context; if (bd->persist) { @@ -123,7 +123,7 @@ static int lfs_testbd_rawprog(const struct lfs_config *cfg, lfs_block_t block, } } -static int lfs_testbd_rawerase(const struct lfs_config *cfg, +static int lfs_testbd_rawerase(const struct lfs_cfg *cfg, lfs_block_t block) { lfs_testbd_t *bd = cfg->context; if (bd->persist) { @@ -133,7 +133,7 @@ static int lfs_testbd_rawerase(const struct lfs_config *cfg, } } -static int lfs_testbd_rawsync(const struct lfs_config *cfg) { +static int lfs_testbd_rawsync(const struct lfs_cfg *cfg) { lfs_testbd_t *bd = cfg->context; if (bd->persist) { return lfs_filebd_sync(cfg); @@ -143,7 +143,7 @@ static int lfs_testbd_rawsync(const struct lfs_config *cfg) { } /// block device API /// -int lfs_testbd_read(const struct lfs_config *cfg, lfs_block_t block, +int lfs_testbd_read(const struct lfs_cfg *cfg, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) { LFS_TESTBD_TRACE("lfs_testbd_read(%p, " "0x%"PRIx32", %"PRIu32", %p, %"PRIu32")", @@ -168,7 +168,7 @@ int lfs_testbd_read(const struct lfs_config *cfg, lfs_block_t block, return err; } -int lfs_testbd_prog(const struct lfs_config *cfg, lfs_block_t block, +int lfs_testbd_prog(const struct lfs_cfg *cfg, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) { LFS_TESTBD_TRACE("lfs_testbd_prog(%p, " "0x%"PRIx32", %"PRIu32", %p, %"PRIu32")", @@ -217,7 +217,7 @@ int lfs_testbd_prog(const struct lfs_config *cfg, lfs_block_t block, return 0; } -int lfs_testbd_erase(const struct lfs_config *cfg, lfs_block_t block) { +int lfs_testbd_erase(const struct lfs_cfg *cfg, lfs_block_t block) { LFS_TESTBD_TRACE("lfs_testbd_erase(%p, 0x%"PRIx32")", (void*)cfg, block); lfs_testbd_t *bd = cfg->context; @@ -264,7 +264,7 @@ int lfs_testbd_erase(const struct lfs_config *cfg, lfs_block_t block) { return 0; } -int lfs_testbd_sync(const struct lfs_config *cfg) { +int lfs_testbd_sync(const struct lfs_cfg *cfg) { LFS_TESTBD_TRACE("lfs_testbd_sync(%p)", (void*)cfg); int err = lfs_testbd_rawsync(cfg); LFS_TESTBD_TRACE("lfs_testbd_sync -> %d", err); @@ -273,7 +273,7 @@ int lfs_testbd_sync(const struct lfs_config *cfg) { /// simulated wear operations /// -lfs_testbd_swear_t lfs_testbd_getwear(const struct lfs_config *cfg, +lfs_testbd_swear_t lfs_testbd_getwear(const struct lfs_cfg *cfg, lfs_block_t block) { LFS_TESTBD_TRACE("lfs_testbd_getwear(%p, %"PRIu32")", (void*)cfg, block); lfs_testbd_t *bd = cfg->context; @@ -286,7 +286,7 @@ lfs_testbd_swear_t lfs_testbd_getwear(const struct lfs_config *cfg, return bd->wear[block]; } -int lfs_testbd_setwear(const struct lfs_config *cfg, +int lfs_testbd_setwear(const struct lfs_cfg *cfg, lfs_block_t block, lfs_testbd_wear_t wear) { LFS_TESTBD_TRACE("lfs_testbd_setwear(%p, %"PRIu32")", (void*)cfg, block); lfs_testbd_t *bd = cfg->context; diff --git a/bd/lfs_testbd.h b/bd/lfs_testbd.h index 06b6190..50c18ce 100644 --- a/bd/lfs_testbd.h +++ b/bd/lfs_testbd.h @@ -44,7 +44,7 @@ typedef uint32_t lfs_testbd_wear_t; typedef int32_t lfs_testbd_swear_t; // testbd config, this is required for testing -struct lfs_testbd_config { +struct lfs_testbd_cfg { // 8-bit erase value to use for simulating erases. -1 does not simulate // erases, which can speed up testing by avoiding all the extra block-device // operations to store the erase value. @@ -73,11 +73,11 @@ typedef struct lfs_testbd { union { struct { lfs_filebd_t bd; - struct lfs_filebd_config cfg; + struct lfs_filebd_cfg cfg; } file; struct { lfs_rambd_t bd; - struct lfs_rambd_config cfg; + struct lfs_rambd_cfg cfg; } ram; } u; @@ -85,51 +85,51 @@ typedef struct lfs_testbd { uint32_t power_cycles; lfs_testbd_wear_t *wear; - const struct lfs_testbd_config *cfg; + const struct lfs_testbd_cfg *cfg; } lfs_testbd_t; /// Block device API /// -// Create a test block device using the geometry in lfs_config +// Create a test block device using the geometry in lfs_cfg // // Note that filebd is used if a path is provided, if path is NULL // testbd will use rambd which can be much faster. -int lfs_testbd_create(const struct lfs_config *cfg, const char *path); -int lfs_testbd_createcfg(const struct lfs_config *cfg, const char *path, - const struct lfs_testbd_config *bdcfg); +int lfs_testbd_create(const struct lfs_cfg *cfg, const char *path); +int lfs_testbd_createcfg(const struct lfs_cfg *cfg, const char *path, + const struct lfs_testbd_cfg *bdcfg); // Clean up memory associated with block device -int lfs_testbd_destroy(const struct lfs_config *cfg); +int lfs_testbd_destroy(const struct lfs_cfg *cfg); // Read a block -int lfs_testbd_read(const struct lfs_config *cfg, lfs_block_t block, +int lfs_testbd_read(const struct lfs_cfg *cfg, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size); // Program a block // // The block must have previously been erased. -int lfs_testbd_prog(const struct lfs_config *cfg, lfs_block_t block, +int lfs_testbd_prog(const struct lfs_cfg *cfg, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size); // Erase a block // // A block must be erased before being programmed. The // state of an erased block is undefined. -int lfs_testbd_erase(const struct lfs_config *cfg, lfs_block_t block); +int lfs_testbd_erase(const struct lfs_cfg *cfg, lfs_block_t block); // Sync the block device -int lfs_testbd_sync(const struct lfs_config *cfg); +int lfs_testbd_sync(const struct lfs_cfg *cfg); /// Additional extended API for driving test features /// // Get simulated wear on a given block -lfs_testbd_swear_t lfs_testbd_getwear(const struct lfs_config *cfg, +lfs_testbd_swear_t lfs_testbd_getwear(const struct lfs_cfg *cfg, lfs_block_t block); // Manually set simulated wear on a given block -int lfs_testbd_setwear(const struct lfs_config *cfg, +int lfs_testbd_setwear(const struct lfs_cfg *cfg, lfs_block_t block, lfs_testbd_wear_t wear); diff --git a/lfs.c b/lfs.c index 1ff4f90..a19d4f9 100644 --- a/lfs.c +++ b/lfs.c @@ -32,7 +32,7 @@ #define LFS_CFG_FILE_MAX(lfs) ((void)lfs, LFS_FILE_MAX) #define LFS_CFG_ATTR_MAX(lfs) ((void)lfs, LFS_ATTR_MAX) #else -// direct config towards dynamic lfs_config struct +// direct config towards dynamic lfs_cfg struct #define LFS_CFG_READ(lfs, block, off, buffer, size) \ lfs->cfg->read(lfs->cfg, block, off, buffer, size) #define LFS_CFG_PROG(lfs, block, off, buffer, size) \ @@ -62,7 +62,7 @@ #define LFS_FILE_CFG_ATTRS(file) LFS_FILE_ATTRS #define LFS_FILE_CFG_ATTR_COUNT(file) LFS_FILE_ATTR_COUNT #else -// direct config towards dynamic lfs_config struct +// direct config towards dynamic lfs_cfg struct #define LFS_FILE_CFG_BUFFER(file) file->cfg->buffer #define LFS_FILE_CFG_ATTRS(file) file->cfg->attrs #define LFS_FILE_CFG_ATTR_COUNT(file) file->cfg->attr_count @@ -2596,7 +2596,7 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file, LFS_TRACE("lfs_file_open(%p, %p, \"%s\", %x)", (void*)lfs, (void*)file, path, flags); #ifndef LFS_FILE_STATICCFG - static const struct lfs_file_config defaults = {0}; + static const struct lfs_file_cfg defaults = {0}; file->cfg = &defaults; #endif int err = lfs_file_opencommon(lfs, file, path, flags); @@ -2607,7 +2607,7 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file, #if !defined(LFS_FILE_STATICCFG) int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file, const char *path, int flags, - const struct lfs_file_config *cfg) { + const struct lfs_file_cfg *cfg) { LFS_TRACE("lfs_file_opencfg(%p, %p, \"%s\", %x, %p {" ".buffer=%p, .attrs=%p, .attr_count=%"PRIu32"})", (void*)lfs, (void*)file, path, flags, @@ -3731,7 +3731,7 @@ int lfs_format(lfs_t *lfs) { #endif #if !defined(LFS_STATICCFG) -int lfs_formatcfg(lfs_t *lfs, const struct lfs_config *cfg) { +int lfs_formatcfg(lfs_t *lfs, const struct lfs_cfg *cfg) { LFS_TRACE("lfs_formatcfg(%p, %p {.context=%p, " ".read=%p, .prog=%p, .erase=%p, .sync=%p, " ".read_size=%"PRIu32", .prog_size=%"PRIu32", " @@ -3892,7 +3892,7 @@ int lfs_mount(lfs_t *lfs) { #endif #if !defined(LFS_STATICCFG) -int lfs_mountcfg(lfs_t *lfs, const struct lfs_config *cfg) { +int lfs_mountcfg(lfs_t *lfs, const struct lfs_cfg *cfg) { LFS_TRACE("lfs_mountcfg(%p, %p {.context=%p, " ".read=%p, .prog=%p, .erase=%p, .sync=%p, " ".read_size=%"PRIu32", .prog_size=%"PRIu32", " @@ -5008,7 +5008,7 @@ int lfs_migrate(lfs_t *lfs) { #endif #if !defined(LFS_STATICCFG) -int lfs_migratecfg(lfs_t *lfs, const struct lfs_config *cfg) { +int lfs_migratecfg(lfs_t *lfs, const struct lfs_cfg *cfg) { LFS_TRACE("lfs_migratecfg(%p, %p {.context=%p, " ".read=%p, .prog=%p, .erase=%p, .sync=%p, " ".read_size=%"PRIu32", .prog_size=%"PRIu32", " diff --git a/lfs.h b/lfs.h index 445c355..50c2284 100644 --- a/lfs.h +++ b/lfs.h @@ -127,31 +127,31 @@ enum lfs_whence_flags { #if !defined(LFS_STATICCFG) // Configuration provided during initialization of the littlefs -struct lfs_config { +struct lfs_cfg { // Opaque user provided context that can be used to pass // information to the block device operations void *context; // Read a region in a block. Negative error codes are propogated // to the user. - int (*read)(const struct lfs_config *c, lfs_block_t block, + int (*read)(const struct lfs_cfg *c, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size); // Program a region in a block. The block must have previously // been erased. Negative error codes are propogated to the user. // May return LFS_ERR_CORRUPT if the block should be considered bad. - int (*prog)(const struct lfs_config *c, lfs_block_t block, + int (*prog)(const struct lfs_cfg *c, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size); // Erase a block. A block must be erased before being programmed. // The state of an erased block is undefined. Negative error codes // are propogated to the user. // May return LFS_ERR_CORRUPT if the block should be considered bad. - int (*erase)(const struct lfs_config *c, lfs_block_t block); + int (*erase)(const struct lfs_cfg *c, lfs_block_t block); // Sync the state of the underlying block device. Negative error codes // are propogated to the user. - int (*sync)(const struct lfs_config *c); + int (*sync)(const struct lfs_cfg *c); // Minimum size of a block read. All read operations will be a // multiple of this value. @@ -223,7 +223,7 @@ struct lfs_config { #else // Static configuration if LFS_STATICCFG is defined, there are defaults // for some of these, but some are required. For full documentation, see -// the lfs_config struct above. +// the lfs_cfg struct above. // Block device operations int lfs_read(lfs_block_t block, @@ -279,7 +279,7 @@ int lfs_sync(void); #if !defined(LFS_FILE_STATICCFG) // Optional configuration provided during lfs_file_opencfg -struct lfs_file_config { +struct lfs_file_cfg { // Optional statically allocated file buffer. Must be cache_size. // By default lfs_malloc is used to allocate this buffer. void *buffer; @@ -302,7 +302,7 @@ struct lfs_file_config { }; #else // Static configuration if LFS_FILE_STATICCFG is defined. For full -// documentation, see the lfs_file_config struct above. +// documentation, see the lfs_file_cfg struct above. #ifndef LFS_FILE_BUFFER #define LFS_FILE_BUFFER NULL #endif @@ -393,7 +393,7 @@ typedef struct lfs_file { lfs_cache_t cache; #ifndef LFS_FILE_STATICCFG - const struct lfs_file_config *cfg; + const struct lfs_file_cfg *cfg; #endif } lfs_file_t; @@ -438,7 +438,7 @@ typedef struct lfs { } free; #ifndef LFS_STATICCFG - const struct lfs_config *cfg; + const struct lfs_cfg *cfg; #endif lfs_size_t name_max; lfs_size_t file_max; @@ -470,7 +470,7 @@ int lfs_format(lfs_t *lfs); // be zeroed for defaults and backwards compatibility. // // Returns a negative error code on failure. -int lfs_formatcfg(lfs_t *lfs, const struct lfs_config *config); +int lfs_formatcfg(lfs_t *lfs, const struct lfs_cfg *config); #endif #if defined(LFS_STATICCFG) @@ -491,7 +491,7 @@ int lfs_mount(lfs_t *lfs); // be zeroed for defaults and backwards compatibility. // // Returns a negative error code on failure. -int lfs_mountcfg(lfs_t *lfs, const struct lfs_config *config); +int lfs_mountcfg(lfs_t *lfs, const struct lfs_cfg *config); #endif // Unmounts a littlefs @@ -579,7 +579,7 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file, // Returns a negative error code on failure. int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file, const char *path, int flags, - const struct lfs_file_config *config); + const struct lfs_file_cfg *config); #endif // Close a file @@ -721,7 +721,7 @@ int lfs_fs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data); // not leave the filesystem mounted. // // Returns a negative error code on failure. -int lfs_migrate(lfs_t *lfs, const struct lfs_config *cfg); +int lfs_migrate(lfs_t *lfs, const struct lfs_cfg *cfg); #endif #if defined(LFS_MIGRATE) && !defined(LFS_STATICCFG) @@ -737,7 +737,7 @@ int lfs_migrate(lfs_t *lfs, const struct lfs_config *cfg); // be zeroed for defaults and backwards compatibility. // // Returns a negative error code on failure. -int lfs_migratecfg(lfs_t *lfs, const struct lfs_config *cfg); +int lfs_migratecfg(lfs_t *lfs, const struct lfs_cfg *cfg); #endif diff --git a/scripts/test.py b/scripts/test.py index e5869c2..244d1ed 100755 --- a/scripts/test.py +++ b/scripts/test.py @@ -66,7 +66,7 @@ PROLOGUE = """ __attribute__((unused)) lfs_size_t size; __attribute__((unused)) int err; - __attribute__((unused)) const struct lfs_config cfg = { + __attribute__((unused)) const struct lfs_cfg cfg = { .context = &bd, .read = lfs_testbd_read, .prog = lfs_testbd_prog, @@ -81,7 +81,7 @@ PROLOGUE = """ .lookahead_size = LFS_LOOKAHEAD_SIZE, }; - __attribute__((unused)) const struct lfs_testbd_config bdcfg = { + __attribute__((unused)) const struct lfs_testbd_cfg bdcfg = { .erase_value = LFS_ERASE_VALUE, .erase_cycles = LFS_ERASE_CYCLES, .badblock_behavior = LFS_BADBLOCK_BEHAVIOR, diff --git a/tests/test_attrs.toml b/tests/test_attrs.toml index f57a491..9cc44b2 100644 --- a/tests/test_attrs.toml +++ b/tests/test_attrs.toml @@ -170,7 +170,7 @@ code = ''' {'B', buffer+4, 6}, {'C', buffer+10, 5}, }; - struct lfs_file_config cfg1 = {.attrs=attrs1, .attr_count=3}; + struct lfs_file_cfg cfg1 = {.attrs=attrs1, .attr_count=3}; lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0; memcpy(buffer, "aaaa", 4); @@ -228,7 +228,7 @@ code = ''' {'B', buffer+4, 9}, {'C', buffer+13, 5}, }; - struct lfs_file_config cfg2 = {.attrs=attrs2, .attr_count=3}; + struct lfs_file_cfg cfg2 = {.attrs=attrs2, .attr_count=3}; lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDWR, &cfg2) => 0; memcpy(buffer+4, "fffffffff", 9); lfs_file_close(&lfs, &file) => 0; @@ -245,7 +245,7 @@ code = ''' {'B', buffer+4, 9}, {'C', buffer+13, 5}, }; - struct lfs_file_config cfg3 = {.attrs=attrs3, .attr_count=3}; + struct lfs_file_cfg cfg3 = {.attrs=attrs3, .attr_count=3}; lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg3) => 0; lfs_file_close(&lfs, &file) => 0; @@ -280,7 +280,7 @@ code = ''' {'C', "", 0}, {'D', "hhhh", 4}, }; - struct lfs_file_config cfg1 = {.attrs=attrs1, .attr_count=3}; + struct lfs_file_cfg cfg1 = {.attrs=attrs1, .attr_count=3}; lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0;