diff --git a/bd/lfs_filebd.c b/bd/lfs_filebd.c index 01ba701..2d36a42 100644 --- a/bd/lfs_filebd.c +++ b/bd/lfs_filebd.c @@ -12,7 +12,7 @@ int lfs_filebd_createcfg(const struct lfs_config *cfg, const char *path, const struct lfs_filebd_config *bdcfg) { - LFS_TRACE("lfs_filebd_createcfg(%p {.context=%p, " + LFS_FILEBD_TRACE("lfs_filebd_createcfg(%p {.context=%p, " ".read=%p, .prog=%p, .erase=%p, .sync=%p, " ".read_size=%"PRIu32", .prog_size=%"PRIu32", " ".block_size=%"PRIu32", .block_count=%"PRIu32"}, " @@ -30,16 +30,16 @@ int lfs_filebd_createcfg(const struct lfs_config *cfg, const char *path, bd->fd = open(path, O_RDWR | O_CREAT, 0666); if (bd->fd < 0) { int err = -errno; - LFS_TRACE("lfs_filebd_createcfg -> %d", err); + LFS_FILEBD_TRACE("lfs_filebd_createcfg -> %d", err); return err; } - LFS_TRACE("lfs_filebd_createcfg -> %d", 0); + LFS_FILEBD_TRACE("lfs_filebd_createcfg -> %d", 0); return 0; } int lfs_filebd_create(const struct lfs_config *cfg, const char *path) { - LFS_TRACE("lfs_filebd_create(%p {.context=%p, " + LFS_FILEBD_TRACE("lfs_filebd_create(%p {.context=%p, " ".read=%p, .prog=%p, .erase=%p, .sync=%p, " ".read_size=%"PRIu32", .prog_size=%"PRIu32", " ".block_size=%"PRIu32", .block_count=%"PRIu32"}, " @@ -51,26 +51,27 @@ int lfs_filebd_create(const struct lfs_config *cfg, const char *path) { path); static const struct lfs_filebd_config defaults = {.erase_value=-1}; int err = lfs_filebd_createcfg(cfg, path, &defaults); - LFS_TRACE("lfs_filebd_create -> %d", err); + LFS_FILEBD_TRACE("lfs_filebd_create -> %d", err); return err; } int lfs_filebd_destroy(const struct lfs_config *cfg) { - LFS_TRACE("lfs_filebd_destroy(%p)", (void*)cfg); + LFS_FILEBD_TRACE("lfs_filebd_destroy(%p)", (void*)cfg); lfs_filebd_t *bd = cfg->context; int err = close(bd->fd); if (err < 0) { err = -errno; - LFS_TRACE("lfs_filebd_destroy -> %d", err); + LFS_FILEBD_TRACE("lfs_filebd_destroy -> %d", err); return err; } - LFS_TRACE("lfs_filebd_destroy -> %d", 0); + LFS_FILEBD_TRACE("lfs_filebd_destroy -> %d", 0); return 0; } int lfs_filebd_read(const struct lfs_config *cfg, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) { - LFS_TRACE("lfs_filebd_read(%p, 0x%"PRIx32", %"PRIu32", %p, %"PRIu32")", + LFS_FILEBD_TRACE("lfs_filebd_read(%p, " + "0x%"PRIx32", %"PRIu32", %p, %"PRIu32")", (void*)cfg, block, off, buffer, size); lfs_filebd_t *bd = cfg->context; @@ -89,24 +90,24 @@ int lfs_filebd_read(const struct lfs_config *cfg, lfs_block_t block, (off_t)block*cfg->block_size + (off_t)off, SEEK_SET); if (res1 < 0) { int err = -errno; - LFS_TRACE("lfs_filebd_read -> %d", err); + LFS_FILEBD_TRACE("lfs_filebd_read -> %d", err); return err; } ssize_t res2 = read(bd->fd, buffer, size); if (res2 < 0) { int err = -errno; - LFS_TRACE("lfs_filebd_read -> %d", err); + LFS_FILEBD_TRACE("lfs_filebd_read -> %d", err); return err; } - LFS_TRACE("lfs_filebd_read -> %d", 0); + LFS_FILEBD_TRACE("lfs_filebd_read -> %d", 0); return 0; } int lfs_filebd_prog(const struct lfs_config *cfg, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) { - LFS_TRACE("lfs_filebd_prog(%p, 0x%"PRIx32", %"PRIu32", %p, %"PRIu32")", + LFS_FILEBD_TRACE("lfs_filebd_prog(%p, 0x%"PRIx32", %"PRIu32", %p, %"PRIu32")", (void*)cfg, block, off, buffer, size); lfs_filebd_t *bd = cfg->context; @@ -121,7 +122,7 @@ int lfs_filebd_prog(const struct lfs_config *cfg, lfs_block_t block, (off_t)block*cfg->block_size + (off_t)off, SEEK_SET); if (res1 < 0) { int err = -errno; - LFS_TRACE("lfs_filebd_prog -> %d", err); + LFS_FILEBD_TRACE("lfs_filebd_prog -> %d", err); return err; } @@ -130,7 +131,7 @@ int lfs_filebd_prog(const struct lfs_config *cfg, lfs_block_t block, ssize_t res2 = read(bd->fd, &c, 1); if (res2 < 0) { int err = -errno; - LFS_TRACE("lfs_filebd_prog -> %d", err); + LFS_FILEBD_TRACE("lfs_filebd_prog -> %d", err); return err; } @@ -143,23 +144,23 @@ int lfs_filebd_prog(const struct lfs_config *cfg, lfs_block_t block, (off_t)block*cfg->block_size + (off_t)off, SEEK_SET); if (res1 < 0) { int err = -errno; - LFS_TRACE("lfs_filebd_prog -> %d", err); + LFS_FILEBD_TRACE("lfs_filebd_prog -> %d", err); return err; } ssize_t res2 = write(bd->fd, buffer, size); if (res2 < 0) { int err = -errno; - LFS_TRACE("lfs_filebd_prog -> %d", err); + LFS_FILEBD_TRACE("lfs_filebd_prog -> %d", err); return err; } - LFS_TRACE("lfs_filebd_prog -> %d", 0); + LFS_FILEBD_TRACE("lfs_filebd_prog -> %d", 0); return 0; } int lfs_filebd_erase(const struct lfs_config *cfg, lfs_block_t block) { - LFS_TRACE("lfs_filebd_erase(%p, 0x%"PRIx32")", (void*)cfg, block); + LFS_FILEBD_TRACE("lfs_filebd_erase(%p, 0x%"PRIx32")", (void*)cfg, block); lfs_filebd_t *bd = cfg->context; // check if erase is valid @@ -170,7 +171,7 @@ int lfs_filebd_erase(const struct lfs_config *cfg, lfs_block_t block) { off_t res1 = lseek(bd->fd, (off_t)block*cfg->block_size, SEEK_SET); if (res1 < 0) { int err = -errno; - LFS_TRACE("lfs_filebd_erase -> %d", err); + LFS_FILEBD_TRACE("lfs_filebd_erase -> %d", err); return err; } @@ -178,27 +179,27 @@ int lfs_filebd_erase(const struct lfs_config *cfg, lfs_block_t block) { ssize_t res2 = write(bd->fd, &(uint8_t){bd->cfg->erase_value}, 1); if (res2 < 0) { int err = -errno; - LFS_TRACE("lfs_filebd_erase -> %d", err); + LFS_FILEBD_TRACE("lfs_filebd_erase -> %d", err); return err; } } } - LFS_TRACE("lfs_filebd_erase -> %d", 0); + LFS_FILEBD_TRACE("lfs_filebd_erase -> %d", 0); return 0; } int lfs_filebd_sync(const struct lfs_config *cfg) { - LFS_TRACE("lfs_filebd_sync(%p)", (void*)cfg); + LFS_FILEBD_TRACE("lfs_filebd_sync(%p)", (void*)cfg); // file sync lfs_filebd_t *bd = cfg->context; int err = fsync(bd->fd); if (err) { err = -errno; - LFS_TRACE("lfs_filebd_sync -> %d", 0); + LFS_FILEBD_TRACE("lfs_filebd_sync -> %d", 0); return err; } - LFS_TRACE("lfs_filebd_sync -> %d", 0); + LFS_FILEBD_TRACE("lfs_filebd_sync -> %d", 0); return 0; } diff --git a/bd/lfs_filebd.h b/bd/lfs_filebd.h index 271e873..0d56434 100644 --- a/bd/lfs_filebd.h +++ b/bd/lfs_filebd.h @@ -15,6 +15,14 @@ extern "C" { #endif + +// Block device specific tracing +#ifdef LFS_FILEBD_YES_TRACE +#define LFS_FILEBD_TRACE(...) LFS_TRACE(__VA_ARGS__) +#else +#define LFS_FILEBD_TRACE(...) +#endif + // filebd config (optional) struct lfs_filebd_config { // 8-bit erase value to use for simulating erases. -1 does not simulate diff --git a/bd/lfs_rambd.c b/bd/lfs_rambd.c index c7c507c..0a6b5cc 100644 --- a/bd/lfs_rambd.c +++ b/bd/lfs_rambd.c @@ -8,7 +8,7 @@ int lfs_rambd_createcfg(const struct lfs_config *cfg, const struct lfs_rambd_config *bdcfg) { - LFS_TRACE("lfs_rambd_createcfg(%p {.context=%p, " + LFS_RAMBD_TRACE("lfs_rambd_createcfg(%p {.context=%p, " ".read=%p, .prog=%p, .erase=%p, .sync=%p, " ".read_size=%"PRIu32", .prog_size=%"PRIu32", " ".block_size=%"PRIu32", .block_count=%"PRIu32"}, " @@ -27,7 +27,7 @@ int lfs_rambd_createcfg(const struct lfs_config *cfg, } else { bd->buffer = lfs_malloc(cfg->block_size * cfg->block_count); if (!bd->buffer) { - LFS_TRACE("lfs_rambd_createcfg -> %d", LFS_ERR_NOMEM); + LFS_RAMBD_TRACE("lfs_rambd_createcfg -> %d", LFS_ERR_NOMEM); return LFS_ERR_NOMEM; } } @@ -38,12 +38,12 @@ int lfs_rambd_createcfg(const struct lfs_config *cfg, cfg->block_size * cfg->block_count); } - LFS_TRACE("lfs_rambd_createcfg -> %d", 0); + LFS_RAMBD_TRACE("lfs_rambd_createcfg -> %d", 0); return 0; } int lfs_rambd_create(const struct lfs_config *cfg) { - LFS_TRACE("lfs_rambd_create(%p {.context=%p, " + LFS_RAMBD_TRACE("lfs_rambd_create(%p {.context=%p, " ".read=%p, .prog=%p, .erase=%p, .sync=%p, " ".read_size=%"PRIu32", .prog_size=%"PRIu32", " ".block_size=%"PRIu32", .block_count=%"PRIu32"})", @@ -53,24 +53,25 @@ int lfs_rambd_create(const struct lfs_config *cfg) { cfg->read_size, cfg->prog_size, cfg->block_size, cfg->block_count); static const struct lfs_rambd_config defaults = {.erase_value=-1}; int err = lfs_rambd_createcfg(cfg, &defaults); - LFS_TRACE("lfs_rambd_create -> %d", err); + LFS_RAMBD_TRACE("lfs_rambd_create -> %d", err); return err; } int lfs_rambd_destroy(const struct lfs_config *cfg) { - LFS_TRACE("lfs_rambd_destroy(%p)", (void*)cfg); + LFS_RAMBD_TRACE("lfs_rambd_destroy(%p)", (void*)cfg); // clean up memory lfs_rambd_t *bd = cfg->context; if (!bd->cfg->buffer) { lfs_free(bd->buffer); } - LFS_TRACE("lfs_rambd_destroy -> %d", 0); + LFS_RAMBD_TRACE("lfs_rambd_destroy -> %d", 0); return 0; } int lfs_rambd_read(const struct lfs_config *cfg, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) { - LFS_TRACE("lfs_rambd_read(%p, 0x%"PRIx32", %"PRIu32", %p, %"PRIu32")", + LFS_RAMBD_TRACE("lfs_rambd_read(%p, " + "0x%"PRIx32", %"PRIu32", %p, %"PRIu32")", (void*)cfg, block, off, buffer, size); lfs_rambd_t *bd = cfg->context; @@ -82,13 +83,14 @@ int lfs_rambd_read(const struct lfs_config *cfg, lfs_block_t block, // read data memcpy(buffer, &bd->buffer[block*cfg->block_size + off], size); - LFS_TRACE("lfs_rambd_read -> %d", 0); + LFS_RAMBD_TRACE("lfs_rambd_read -> %d", 0); return 0; } int lfs_rambd_prog(const struct lfs_config *cfg, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) { - LFS_TRACE("lfs_rambd_prog(%p, 0x%"PRIx32", %"PRIu32", %p, %"PRIu32")", + LFS_RAMBD_TRACE("lfs_rambd_prog(%p, " + "0x%"PRIx32", %"PRIu32", %p, %"PRIu32")", (void*)cfg, block, off, buffer, size); lfs_rambd_t *bd = cfg->context; @@ -108,12 +110,12 @@ int lfs_rambd_prog(const struct lfs_config *cfg, lfs_block_t block, // program data memcpy(&bd->buffer[block*cfg->block_size + off], buffer, size); - LFS_TRACE("lfs_rambd_prog -> %d", 0); + LFS_RAMBD_TRACE("lfs_rambd_prog -> %d", 0); return 0; } int lfs_rambd_erase(const struct lfs_config *cfg, lfs_block_t block) { - LFS_TRACE("lfs_rambd_erase(%p, 0x%"PRIx32")", (void*)cfg, block); + LFS_RAMBD_TRACE("lfs_rambd_erase(%p, 0x%"PRIx32")", (void*)cfg, block); lfs_rambd_t *bd = cfg->context; // check if erase is valid @@ -125,14 +127,14 @@ int lfs_rambd_erase(const struct lfs_config *cfg, lfs_block_t block) { bd->cfg->erase_value, cfg->block_size); } - LFS_TRACE("lfs_rambd_erase -> %d", 0); + LFS_RAMBD_TRACE("lfs_rambd_erase -> %d", 0); return 0; } int lfs_rambd_sync(const struct lfs_config *cfg) { - LFS_TRACE("lfs_rambd_sync(%p)", (void*)cfg); + LFS_RAMBD_TRACE("lfs_rambd_sync(%p)", (void*)cfg); // sync does nothing because we aren't backed by anything real (void)cfg; - LFS_TRACE("lfs_rambd_sync -> %d", 0); + LFS_RAMBD_TRACE("lfs_rambd_sync -> %d", 0); return 0; } diff --git a/bd/lfs_rambd.h b/bd/lfs_rambd.h index 139ddd6..56a45ce 100644 --- a/bd/lfs_rambd.h +++ b/bd/lfs_rambd.h @@ -15,6 +15,14 @@ extern "C" { #endif + +// Block device specific tracing +#ifdef LFS_RAMBD_YES_TRACE +#define LFS_RAMBD_TRACE(...) LFS_TRACE(__VA_ARGS__) +#else +#define LFS_RAMBD_TRACE(...) +#endif + // rambd config (optional) struct lfs_rambd_config { // 8-bit erase value to simulate erasing with. -1 indicates no erase diff --git a/bd/lfs_testbd.c b/bd/lfs_testbd.c index 8de7dcb..1ec6fb9 100644 --- a/bd/lfs_testbd.c +++ b/bd/lfs_testbd.c @@ -12,7 +12,7 @@ int lfs_testbd_createcfg(const struct lfs_config *cfg, const char *path, const struct lfs_testbd_config *bdcfg) { - LFS_TRACE("lfs_testbd_createcfg(%p {.context=%p, " + LFS_TESTBD_TRACE("lfs_testbd_createcfg(%p {.context=%p, " ".read=%p, .prog=%p, .erase=%p, .sync=%p, " ".read_size=%"PRIu32", .prog_size=%"PRIu32", " ".block_size=%"PRIu32", .block_count=%"PRIu32"}, " @@ -38,9 +38,9 @@ int lfs_testbd_createcfg(const struct lfs_config *cfg, const char *path, if (bd->cfg->wear_buffer) { bd->wear = bd->cfg->wear_buffer; } else { - bd->wear = lfs_malloc(sizeof(lfs_testbd_wear_t) * cfg->block_count); + bd->wear = lfs_malloc(sizeof(lfs_testbd_wear_t)*cfg->block_count); if (!bd->wear) { - LFS_TRACE("lfs_testbd_createcfg -> %d", LFS_ERR_NOMEM); + LFS_TESTBD_TRACE("lfs_testbd_createcfg -> %d", LFS_ERR_NOMEM); return LFS_ERR_NOMEM; } } @@ -54,7 +54,7 @@ int lfs_testbd_createcfg(const struct lfs_config *cfg, const char *path, .erase_value = bd->cfg->erase_value, }; int err = lfs_filebd_createcfg(cfg, path, &bd->u.file.cfg); - LFS_TRACE("lfs_testbd_createcfg -> %d", err); + LFS_TESTBD_TRACE("lfs_testbd_createcfg -> %d", err); return err; } else { bd->u.ram.cfg = (struct lfs_rambd_config){ @@ -62,13 +62,13 @@ int lfs_testbd_createcfg(const struct lfs_config *cfg, const char *path, .buffer = bd->cfg->buffer, }; int err = lfs_rambd_createcfg(cfg, &bd->u.ram.cfg); - LFS_TRACE("lfs_testbd_createcfg -> %d", err); + LFS_TESTBD_TRACE("lfs_testbd_createcfg -> %d", err); return err; } } int lfs_testbd_create(const struct lfs_config *cfg, const char *path) { - LFS_TRACE("lfs_testbd_create(%p {.context=%p, " + LFS_TESTBD_TRACE("lfs_testbd_create(%p {.context=%p, " ".read=%p, .prog=%p, .erase=%p, .sync=%p, " ".read_size=%"PRIu32", .prog_size=%"PRIu32", " ".block_size=%"PRIu32", .block_count=%"PRIu32"}, " @@ -80,12 +80,12 @@ int lfs_testbd_create(const struct lfs_config *cfg, const char *path) { path); static const struct lfs_testbd_config defaults = {.erase_value=-1}; int err = lfs_testbd_createcfg(cfg, path, &defaults); - LFS_TRACE("lfs_testbd_create -> %d", err); + LFS_TESTBD_TRACE("lfs_testbd_create -> %d", err); return err; } int lfs_testbd_destroy(const struct lfs_config *cfg) { - LFS_TRACE("lfs_testbd_destroy(%p)", (void*)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) { lfs_free(bd->wear); @@ -93,11 +93,11 @@ int lfs_testbd_destroy(const struct lfs_config *cfg) { if (bd->persist) { int err = lfs_filebd_destroy(cfg); - LFS_TRACE("lfs_testbd_destroy -> %d", err); + LFS_TESTBD_TRACE("lfs_testbd_destroy -> %d", err); return err; } else { int err = lfs_rambd_destroy(cfg); - LFS_TRACE("lfs_testbd_destroy -> %d", err); + LFS_TESTBD_TRACE("lfs_testbd_destroy -> %d", err); return err; } } @@ -145,7 +145,8 @@ 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, lfs_off_t off, void *buffer, lfs_size_t size) { - LFS_TRACE("lfs_testbd_read(%p, 0x%"PRIx32", %"PRIu32", %p, %"PRIu32")", + LFS_TESTBD_TRACE("lfs_testbd_read(%p, " + "0x%"PRIx32", %"PRIu32", %p, %"PRIu32")", (void*)cfg, block, off, buffer, size); lfs_testbd_t *bd = cfg->context; @@ -157,19 +158,20 @@ int lfs_testbd_read(const struct lfs_config *cfg, lfs_block_t block, // block bad? if (bd->cfg->erase_cycles && bd->wear[block] >= bd->cfg->erase_cycles && bd->cfg->badblock_behavior == LFS_TESTBD_BADBLOCK_READERROR) { - LFS_TRACE("lfs_testbd_read -> %d", LFS_ERR_CORRUPT); + LFS_TESTBD_TRACE("lfs_testbd_read -> %d", LFS_ERR_CORRUPT); return LFS_ERR_CORRUPT; } // read int err = lfs_testbd_rawread(cfg, block, off, buffer, size); - LFS_TRACE("lfs_testbd_read -> %d", err); + LFS_TESTBD_TRACE("lfs_testbd_read -> %d", err); return err; } int lfs_testbd_prog(const struct lfs_config *cfg, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) { - LFS_TRACE("lfs_testbd_prog(%p, 0x%"PRIx32", %"PRIu32", %p, %"PRIu32")", + LFS_TESTBD_TRACE("lfs_testbd_prog(%p, " + "0x%"PRIx32", %"PRIu32", %p, %"PRIu32")", (void*)cfg, block, off, buffer, size); lfs_testbd_t *bd = cfg->context; @@ -182,13 +184,13 @@ int lfs_testbd_prog(const struct lfs_config *cfg, lfs_block_t block, if (bd->cfg->erase_cycles && bd->wear[block] >= bd->cfg->erase_cycles) { if (bd->cfg->badblock_behavior == LFS_TESTBD_BADBLOCK_PROGERROR) { - LFS_TRACE("lfs_testbd_prog -> %d", LFS_ERR_CORRUPT); + LFS_TESTBD_TRACE("lfs_testbd_prog -> %d", LFS_ERR_CORRUPT); return LFS_ERR_CORRUPT; } else if (bd->cfg->badblock_behavior == LFS_TESTBD_BADBLOCK_PROGNOOP || bd->cfg->badblock_behavior == LFS_TESTBD_BADBLOCK_ERASENOOP) { - LFS_TRACE("lfs_testbd_prog -> %d", 0); + LFS_TESTBD_TRACE("lfs_testbd_prog -> %d", 0); return 0; } } @@ -196,7 +198,7 @@ int lfs_testbd_prog(const struct lfs_config *cfg, lfs_block_t block, // prog int err = lfs_testbd_rawprog(cfg, block, off, buffer, size); if (err) { - LFS_TRACE("lfs_testbd_prog -> %d", err); + LFS_TESTBD_TRACE("lfs_testbd_prog -> %d", err); return err; } @@ -211,12 +213,12 @@ int lfs_testbd_prog(const struct lfs_config *cfg, lfs_block_t block, } } - LFS_TRACE("lfs_testbd_prog -> %d", 0); + LFS_TESTBD_TRACE("lfs_testbd_prog -> %d", 0); return 0; } int lfs_testbd_erase(const struct lfs_config *cfg, lfs_block_t block) { - LFS_TRACE("lfs_testbd_erase(%p, 0x%"PRIx32")", (void*)cfg, block); + LFS_TESTBD_TRACE("lfs_testbd_erase(%p, 0x%"PRIx32")", (void*)cfg, block); lfs_testbd_t *bd = cfg->context; // check if erase is valid @@ -227,11 +229,11 @@ int lfs_testbd_erase(const struct lfs_config *cfg, lfs_block_t block) { if (bd->wear[block] >= bd->cfg->erase_cycles) { if (bd->cfg->badblock_behavior == LFS_TESTBD_BADBLOCK_ERASEERROR) { - LFS_TRACE("lfs_testbd_erase -> %d", LFS_ERR_CORRUPT); + LFS_TESTBD_TRACE("lfs_testbd_erase -> %d", LFS_ERR_CORRUPT); return LFS_ERR_CORRUPT; } else if (bd->cfg->badblock_behavior == LFS_TESTBD_BADBLOCK_ERASENOOP) { - LFS_TRACE("lfs_testbd_erase -> %d", 0); + LFS_TESTBD_TRACE("lfs_testbd_erase -> %d", 0); return 0; } } else { @@ -243,7 +245,7 @@ int lfs_testbd_erase(const struct lfs_config *cfg, lfs_block_t block) { // erase int err = lfs_testbd_rawerase(cfg, block); if (err) { - LFS_TRACE("lfs_testbd_erase -> %d", err); + LFS_TESTBD_TRACE("lfs_testbd_erase -> %d", err); return err; } @@ -258,14 +260,14 @@ int lfs_testbd_erase(const struct lfs_config *cfg, lfs_block_t block) { } } - LFS_TRACE("lfs_testbd_prog -> %d", 0); + LFS_TESTBD_TRACE("lfs_testbd_prog -> %d", 0); return 0; } int lfs_testbd_sync(const struct lfs_config *cfg) { - LFS_TRACE("lfs_testbd_sync(%p)", (void*)cfg); + LFS_TESTBD_TRACE("lfs_testbd_sync(%p)", (void*)cfg); int err = lfs_testbd_rawsync(cfg); - LFS_TRACE("lfs_testbd_sync -> %d", err); + LFS_TESTBD_TRACE("lfs_testbd_sync -> %d", err); return err; } @@ -273,20 +275,20 @@ 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_block_t block) { - LFS_TRACE("lfs_testbd_getwear(%p, %"PRIu32")", (void*)cfg, block); + LFS_TESTBD_TRACE("lfs_testbd_getwear(%p, %"PRIu32")", (void*)cfg, block); lfs_testbd_t *bd = cfg->context; // check if block is valid LFS_ASSERT(bd->cfg->erase_cycles); LFS_ASSERT(block < cfg->block_count); - LFS_TRACE("lfs_testbd_getwear -> %"PRIu32, bd->wear[block]); + LFS_TESTBD_TRACE("lfs_testbd_getwear -> %"PRIu32, bd->wear[block]); return bd->wear[block]; } int lfs_testbd_setwear(const struct lfs_config *cfg, lfs_block_t block, lfs_testbd_wear_t wear) { - LFS_TRACE("lfs_testbd_setwear(%p, %"PRIu32")", (void*)cfg, block); + LFS_TESTBD_TRACE("lfs_testbd_setwear(%p, %"PRIu32")", (void*)cfg, block); lfs_testbd_t *bd = cfg->context; // check if block is valid @@ -295,6 +297,6 @@ int lfs_testbd_setwear(const struct lfs_config *cfg, bd->wear[block] = wear; - LFS_TRACE("lfs_testbd_setwear -> %d", 0); + LFS_TESTBD_TRACE("lfs_testbd_setwear -> %d", 0); return 0; } diff --git a/bd/lfs_testbd.h b/bd/lfs_testbd.h index 68180ac..b1fb2e9 100644 --- a/bd/lfs_testbd.h +++ b/bd/lfs_testbd.h @@ -19,6 +19,13 @@ extern "C" #endif +// Block device specific tracing +#ifdef LFS_TESTBD_YES_TRACE +#define LFS_TESTBD_TRACE(...) LFS_TRACE(__VA_ARGS__) +#else +#define LFS_TESTBD_TRACE(...) +#endif + // Mode determining how "bad blocks" behave during testing. This simulates // some real-world circumstances such as progs not sticking (prog-noop), // a readonly disk (erase-noop), and ECC failures (read-error).