From 45afded784dfb6ad8cc92adbf9e3570686d7ecf5 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sat, 28 Nov 2020 12:37:01 -0600 Subject: [PATCH] Moved LFS_TRACE calls to API wrapper functions This removes quite a bit of extra code needed to entertwine the LFS_TRACE calls into the original funcions. Also changed temporary return type to match API declaration where necessary. --- lfs.c | 367 ++++++++++++++++++++--------------------------------- lfs.h | 2 + lfs_util.h | 1 + 3 files changed, 141 insertions(+), 229 deletions(-) diff --git a/lfs.c b/lfs.c index edcbb6a..b2e6c20 100644 --- a/lfs.c +++ b/lfs.c @@ -1922,11 +1922,9 @@ compact: /// Top level directory operations /// static int lfs_mkdirraw(lfs_t *lfs, const char *path) { - LFS_TRACE("lfs_mkdir(%p, \"%s\")", (void*)lfs, path); // deorphan if we haven't yet, needed at most once after poweron int err = lfs_fs_forceconsistency(lfs); if (err) { - LFS_TRACE("lfs_mkdir -> %d", err); return err; } @@ -1935,14 +1933,12 @@ static int lfs_mkdirraw(lfs_t *lfs, const char *path) { uint16_t id; err = lfs_dir_find(lfs, &cwd.m, &path, &id); if (!(err == LFS_ERR_NOENT && id != 0x3ff)) { - LFS_TRACE("lfs_mkdir -> %d", (err < 0) ? err : LFS_ERR_EXIST); return (err < 0) ? err : LFS_ERR_EXIST; } // check that name fits lfs_size_t nlen = strlen(path); if (nlen > lfs->name_max) { - LFS_TRACE("lfs_mkdir -> %d", LFS_ERR_NAMETOOLONG); return LFS_ERR_NAMETOOLONG; } @@ -1951,7 +1947,6 @@ static int lfs_mkdirraw(lfs_t *lfs, const char *path) { lfs_mdir_t dir; err = lfs_dir_alloc(lfs, &dir); if (err) { - LFS_TRACE("lfs_mkdir -> %d", err); return err; } @@ -1960,7 +1955,6 @@ static int lfs_mkdirraw(lfs_t *lfs, const char *path) { while (pred.split) { err = lfs_dir_fetch(lfs, &pred, pred.tail); if (err) { - LFS_TRACE("lfs_mkdir -> %d", err); return err; } } @@ -1971,7 +1965,6 @@ static int lfs_mkdirraw(lfs_t *lfs, const char *path) { {LFS_MKTAG(LFS_TYPE_SOFTTAIL, 0x3ff, 8), pred.tail})); lfs_pair_fromle32(pred.tail); if (err) { - LFS_TRACE("lfs_mkdir -> %d", err); return err; } @@ -1994,7 +1987,6 @@ static int lfs_mkdirraw(lfs_t *lfs, const char *path) { lfs_pair_fromle32(dir.pair); if (err) { lfs->mlist = cwd.next; - LFS_TRACE("lfs_mkdir -> %d", err); return err; } @@ -2012,24 +2004,19 @@ static int lfs_mkdirraw(lfs_t *lfs, const char *path) { LFS_TYPE_SOFTTAIL, 0x3ff, 8), dir.pair})); lfs_pair_fromle32(dir.pair); if (err) { - LFS_TRACE("lfs_mkdir -> %d", err); return err; } - LFS_TRACE("lfs_mkdir -> %d", 0); return 0; } static int lfs_dir_openraw(lfs_t *lfs, lfs_dir_t *dir, const char *path) { - LFS_TRACE("lfs_dir_open(%p, %p, \"%s\")", (void*)lfs, (void*)dir, path); lfs_stag_t tag = lfs_dir_find(lfs, &dir->m, &path, NULL); if (tag < 0) { - LFS_TRACE("lfs_dir_open -> %"PRId32, tag); return tag; } if (lfs_tag_type3(tag) != LFS_TYPE_DIR) { - LFS_TRACE("lfs_dir_open -> %d", LFS_ERR_NOTDIR); return LFS_ERR_NOTDIR; } @@ -2043,7 +2030,6 @@ static int lfs_dir_openraw(lfs_t *lfs, lfs_dir_t *dir, const char *path) { lfs_stag_t res = lfs_dir_get(lfs, &dir->m, LFS_MKTAG(0x700, 0x3ff, 0), LFS_MKTAG(LFS_TYPE_STRUCT, lfs_tag_id(tag), 8), pair); if (res < 0) { - LFS_TRACE("lfs_dir_open -> %"PRId32, res); return res; } lfs_pair_fromle32(pair); @@ -2052,7 +2038,6 @@ static int lfs_dir_openraw(lfs_t *lfs, lfs_dir_t *dir, const char *path) { // fetch first pair int err = lfs_dir_fetch(lfs, &dir->m, pair); if (err) { - LFS_TRACE("lfs_dir_open -> %d", err); return err; } @@ -2067,12 +2052,10 @@ static int lfs_dir_openraw(lfs_t *lfs, lfs_dir_t *dir, const char *path) { dir->next = (lfs_dir_t*)lfs->mlist; lfs->mlist = (struct lfs_mlist*)dir; - LFS_TRACE("lfs_dir_open -> %d", 0); return 0; } static int lfs_dir_closeraw(lfs_t *lfs, lfs_dir_t *dir) { - LFS_TRACE("lfs_dir_close(%p, %p)", (void*)lfs, (void*)dir); // remove from list of mdirs for (struct lfs_mlist **p = &lfs->mlist; *p; p = &(*p)->next) { if (*p == (struct lfs_mlist*)dir) { @@ -2081,13 +2064,10 @@ static int lfs_dir_closeraw(lfs_t *lfs, lfs_dir_t *dir) { } } - LFS_TRACE("lfs_dir_close -> %d", 0); return 0; } static int lfs_dir_readraw(lfs_t *lfs, lfs_dir_t *dir, struct lfs_info *info) { - LFS_TRACE("lfs_dir_read(%p, %p, %p)", - (void*)lfs, (void*)dir, (void*)info); memset(info, 0, sizeof(*info)); // special offset for '.' and '..' @@ -2095,26 +2075,22 @@ static int lfs_dir_readraw(lfs_t *lfs, lfs_dir_t *dir, struct lfs_info *info) { info->type = LFS_TYPE_DIR; strcpy(info->name, "."); dir->pos += 1; - LFS_TRACE("lfs_dir_read -> %d", true); return true; } else if (dir->pos == 1) { info->type = LFS_TYPE_DIR; strcpy(info->name, ".."); dir->pos += 1; - LFS_TRACE("lfs_dir_read -> %d", true); return true; } while (true) { if (dir->id == dir->m.count) { if (!dir->m.split) { - LFS_TRACE("lfs_dir_read -> %d", false); return false; } int err = lfs_dir_fetch(lfs, &dir->m, dir->m.tail); if (err) { - LFS_TRACE("lfs_dir_read -> %d", err); return err; } @@ -2123,7 +2099,6 @@ static int lfs_dir_readraw(lfs_t *lfs, lfs_dir_t *dir, struct lfs_info *info) { int err = lfs_dir_getinfo(lfs, &dir->m, dir->id, info); if (err && err != LFS_ERR_NOENT) { - LFS_TRACE("lfs_dir_read -> %d", err); return err; } @@ -2134,17 +2109,13 @@ static int lfs_dir_readraw(lfs_t *lfs, lfs_dir_t *dir, struct lfs_info *info) { } dir->pos += 1; - LFS_TRACE("lfs_dir_read -> %d", true); return true; } static int lfs_dir_seekraw(lfs_t *lfs, lfs_dir_t *dir, lfs_off_t off) { - LFS_TRACE("lfs_dir_seek(%p, %p, %"PRIu32")", - (void*)lfs, (void*)dir, off); // simply walk from head dir int err = lfs_dir_rewindraw(lfs, dir); if (err) { - LFS_TRACE("lfs_dir_seek -> %d", err); return err; } @@ -2163,13 +2134,11 @@ static int lfs_dir_seekraw(lfs_t *lfs, lfs_dir_t *dir, lfs_off_t off) { if (dir->id == dir->m.count) { if (!dir->m.split) { - LFS_TRACE("lfs_dir_seek -> %d", LFS_ERR_INVAL); return LFS_ERR_INVAL; } err = lfs_dir_fetch(lfs, &dir->m, dir->m.tail); if (err) { - LFS_TRACE("lfs_dir_seek -> %d", err); return err; } @@ -2177,29 +2146,23 @@ static int lfs_dir_seekraw(lfs_t *lfs, lfs_dir_t *dir, lfs_off_t off) { } } - LFS_TRACE("lfs_dir_seek -> %d", 0); return 0; } static lfs_soff_t lfs_dir_tellraw(lfs_t *lfs, lfs_dir_t *dir) { - LFS_TRACE("lfs_dir_tell(%p, %p)", (void*)lfs, (void*)dir); (void)lfs; - LFS_TRACE("lfs_dir_tell -> %"PRId32, dir->pos); return dir->pos; } static int lfs_dir_rewindraw(lfs_t *lfs, lfs_dir_t *dir) { - LFS_TRACE("lfs_dir_rewind(%p, %p)", (void*)lfs, (void*)dir); // reload the head dir int err = lfs_dir_fetch(lfs, &dir->m, dir->head); if (err) { - LFS_TRACE("lfs_dir_rewind -> %d", err); return err; } dir->id = 0; dir->pos = 0; - LFS_TRACE("lfs_dir_rewind -> %d", 0); return 0; } @@ -2398,16 +2361,10 @@ static int lfs_ctz_traverse(lfs_t *lfs, static int lfs_file_opencfgraw(lfs_t *lfs, lfs_file_t *file, const char *path, int flags, const struct lfs_file_config *cfg) { - LFS_TRACE("lfs_file_opencfg(%p, %p, \"%s\", %x, %p {" - ".buffer=%p, .attrs=%p, .attr_count=%"PRIu32"})", - (void*)lfs, (void*)file, path, flags, - (void*)cfg, cfg->buffer, (void*)cfg->attrs, cfg->attr_count); - // deorphan if we haven't yet, needed at most once after poweron if ((flags & 3) != LFS_O_RDONLY) { int err = lfs_fs_forceconsistency(lfs); if (err) { - LFS_TRACE("lfs_file_opencfg -> %d", err); return err; } } @@ -2538,29 +2495,23 @@ static int lfs_file_opencfgraw(lfs_t *lfs, lfs_file_t *file, } } - LFS_TRACE("lfs_file_opencfg -> %d", 0); return 0; cleanup: // clean up lingering resources file->flags |= LFS_F_ERRED; lfs_file_closeraw(lfs, file); - LFS_TRACE("lfs_file_opencfg -> %d", err); return err; } static int lfs_file_openraw(lfs_t *lfs, lfs_file_t *file, const char *path, int flags) { - LFS_TRACE("lfs_file_open(%p, %p, \"%s\", %x)", - (void*)lfs, (void*)file, path, flags); static const struct lfs_file_config defaults = {0}; int err = lfs_file_opencfgraw(lfs, file, path, flags, &defaults); - LFS_TRACE("lfs_file_open -> %d", err); return err; } static int lfs_file_closeraw(lfs_t *lfs, lfs_file_t *file) { - LFS_TRACE("lfs_file_close(%p, %p)", (void*)lfs, (void*)file); LFS_ASSERT(file->flags & LFS_F_OPENED); int err = lfs_file_syncraw(lfs, file); @@ -2579,7 +2530,6 @@ static int lfs_file_closeraw(lfs_t *lfs, lfs_file_t *file) { } file->flags &= ~LFS_F_OPENED; - LFS_TRACE("lfs_file_close -> %d", err); return err; } @@ -2747,19 +2697,16 @@ relocate: } static int lfs_file_syncraw(lfs_t *lfs, lfs_file_t *file) { - LFS_TRACE("lfs_file_sync(%p, %p)", (void*)lfs, (void*)file); LFS_ASSERT(file->flags & LFS_F_OPENED); if (file->flags & LFS_F_ERRED) { // it's not safe to do anything if our file errored - LFS_TRACE("lfs_file_sync -> %d", 0); return 0; } int err = lfs_file_flush(lfs, file); if (err) { file->flags |= LFS_F_ERRED; - LFS_TRACE("lfs_file_sync -> %d", err); return err; } @@ -2792,21 +2739,17 @@ static int lfs_file_syncraw(lfs_t *lfs, lfs_file_t *file) { file->cfg->attr_count), file->cfg->attrs})); if (err) { file->flags |= LFS_F_ERRED; - LFS_TRACE("lfs_file_sync -> %d", err); return err; } file->flags &= ~LFS_F_DIRTY; } - LFS_TRACE("lfs_file_sync -> %d", 0); return 0; } static lfs_ssize_t lfs_file_readraw(lfs_t *lfs, lfs_file_t *file, void *buffer, lfs_size_t size) { - LFS_TRACE("lfs_file_read(%p, %p, %p, %"PRIu32")", - (void*)lfs, (void*)file, buffer, size); LFS_ASSERT(file->flags & LFS_F_OPENED); LFS_ASSERT((file->flags & 3) != LFS_O_WRONLY); @@ -2817,14 +2760,12 @@ static lfs_ssize_t lfs_file_readraw(lfs_t *lfs, lfs_file_t *file, // flush out any writes int err = lfs_file_flush(lfs, file); if (err) { - LFS_TRACE("lfs_file_read -> %d", err); return err; } } if (file->pos >= file->ctz.size) { // eof if past end - LFS_TRACE("lfs_file_read -> %d", 0); return 0; } @@ -2840,7 +2781,6 @@ static lfs_ssize_t lfs_file_readraw(lfs_t *lfs, lfs_file_t *file, file->ctz.head, file->ctz.size, file->pos, &file->block, &file->off); if (err) { - LFS_TRACE("lfs_file_read -> %d", err); return err; } } else { @@ -2860,7 +2800,6 @@ static lfs_ssize_t lfs_file_readraw(lfs_t *lfs, lfs_file_t *file, LFS_MKTAG(LFS_TYPE_INLINESTRUCT, file->id, 0), file->off, data, diff); if (err) { - LFS_TRACE("lfs_file_read -> %d", err); return err; } } else { @@ -2868,7 +2807,6 @@ static lfs_ssize_t lfs_file_readraw(lfs_t *lfs, lfs_file_t *file, NULL, &file->cache, lfs->cfg->block_size, file->block, file->off, data, diff); if (err) { - LFS_TRACE("lfs_file_read -> %d", err); return err; } } @@ -2879,14 +2817,11 @@ static lfs_ssize_t lfs_file_readraw(lfs_t *lfs, lfs_file_t *file, nsize -= diff; } - LFS_TRACE("lfs_file_read -> %"PRId32, size); return size; } static lfs_ssize_t lfs_file_writeraw(lfs_t *lfs, lfs_file_t *file, const void *buffer, lfs_size_t size) { - LFS_TRACE("lfs_file_write(%p, %p, %p, %"PRIu32")", - (void*)lfs, (void*)file, buffer, size); LFS_ASSERT(file->flags & LFS_F_OPENED); LFS_ASSERT((file->flags & 3) != LFS_O_RDONLY); @@ -2897,7 +2832,6 @@ static lfs_ssize_t lfs_file_writeraw(lfs_t *lfs, lfs_file_t *file, // drop any reads int err = lfs_file_flush(lfs, file); if (err) { - LFS_TRACE("lfs_file_write -> %d", err); return err; } } @@ -2908,7 +2842,6 @@ static lfs_ssize_t lfs_file_writeraw(lfs_t *lfs, lfs_file_t *file, if (file->pos + size > lfs->file_max) { // Larger than file limit? - LFS_TRACE("lfs_file_write -> %d", LFS_ERR_FBIG); return LFS_ERR_FBIG; } @@ -2920,7 +2853,6 @@ static lfs_ssize_t lfs_file_writeraw(lfs_t *lfs, lfs_file_t *file, while (file->pos < pos) { lfs_ssize_t res = lfs_file_writeraw(lfs, file, &(uint8_t){0}, 1); if (res < 0) { - LFS_TRACE("lfs_file_write -> %"PRId32, res); return res; } } @@ -2934,7 +2866,6 @@ static lfs_ssize_t lfs_file_writeraw(lfs_t *lfs, lfs_file_t *file, int err = lfs_file_outline(lfs, file); if (err) { file->flags |= LFS_F_ERRED; - LFS_TRACE("lfs_file_write -> %d", err); return err; } } @@ -2951,7 +2882,6 @@ static lfs_ssize_t lfs_file_writeraw(lfs_t *lfs, lfs_file_t *file, file->pos-1, &file->block, &file->off); if (err) { file->flags |= LFS_F_ERRED; - LFS_TRACE("lfs_file_write -> %d", err); return err; } @@ -2966,7 +2896,6 @@ static lfs_ssize_t lfs_file_writeraw(lfs_t *lfs, lfs_file_t *file, &file->block, &file->off); if (err) { file->flags |= LFS_F_ERRED; - LFS_TRACE("lfs_file_write -> %d", err); return err; } } else { @@ -2987,7 +2916,6 @@ static lfs_ssize_t lfs_file_writeraw(lfs_t *lfs, lfs_file_t *file, goto relocate; } file->flags |= LFS_F_ERRED; - LFS_TRACE("lfs_file_write -> %d", err); return err; } @@ -2996,7 +2924,6 @@ relocate: err = lfs_file_relocate(lfs, file); if (err) { file->flags |= LFS_F_ERRED; - LFS_TRACE("lfs_file_write -> %d", err); return err; } } @@ -3010,20 +2937,16 @@ relocate: } file->flags &= ~LFS_F_ERRED; - LFS_TRACE("lfs_file_write -> %"PRId32, size); return size; } static lfs_soff_t lfs_file_seekraw(lfs_t *lfs, lfs_file_t *file, lfs_soff_t off, int whence) { - LFS_TRACE("lfs_file_seek(%p, %p, %"PRId32", %d)", - (void*)lfs, (void*)file, off, whence); LFS_ASSERT(file->flags & LFS_F_OPENED); // write out everything beforehand, may be noop if rdonly int err = lfs_file_flush(lfs, file); if (err) { - LFS_TRACE("lfs_file_seek -> %d", err); return err; } @@ -3039,24 +2962,19 @@ static lfs_soff_t lfs_file_seekraw(lfs_t *lfs, lfs_file_t *file, if (npos > lfs->file_max) { // file position out of range - LFS_TRACE("lfs_file_seek -> %d", LFS_ERR_INVAL); return LFS_ERR_INVAL; } // update pos file->pos = npos; - LFS_TRACE("lfs_file_seek -> %"PRId32, npos); return npos; } static int lfs_file_truncateraw(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { - LFS_TRACE("lfs_file_truncate(%p, %p, %"PRIu32")", - (void*)lfs, (void*)file, size); LFS_ASSERT(file->flags & LFS_F_OPENED); LFS_ASSERT((file->flags & 3) != LFS_O_RDONLY); if (size > LFS_FILE_MAX) { - LFS_TRACE("lfs_file_truncate -> %d", LFS_ERR_INVAL); return LFS_ERR_INVAL; } @@ -3066,7 +2984,6 @@ static int lfs_file_truncateraw(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { // need to flush since directly changing metadata int err = lfs_file_flush(lfs, file); if (err) { - LFS_TRACE("lfs_file_truncate -> %d", err); return err; } @@ -3075,7 +2992,6 @@ static int lfs_file_truncateraw(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { file->ctz.head, file->ctz.size, size, &file->block, &file->off); if (err) { - LFS_TRACE("lfs_file_truncate -> %d", err); return err; } @@ -3087,7 +3003,6 @@ static int lfs_file_truncateraw(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { if (file->pos != oldsize) { lfs_soff_t res = lfs_file_seekraw(lfs, file, 0, LFS_SEEK_END); if (res < 0) { - LFS_TRACE("lfs_file_truncate -> %"PRId32, res); return (int)res; } } @@ -3096,7 +3011,6 @@ static int lfs_file_truncateraw(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { while (file->pos < size) { lfs_ssize_t res = lfs_file_writeraw(lfs, file, &(uint8_t){0}, 1); if (res < 0) { - LFS_TRACE("lfs_file_truncate -> %"PRId32, res); return (int)res; } } @@ -3105,44 +3019,33 @@ static int lfs_file_truncateraw(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { // restore pos lfs_soff_t res = lfs_file_seekraw(lfs, file, pos, LFS_SEEK_SET); if (res < 0) { - LFS_TRACE("lfs_file_truncate -> %"PRId32, res); return (int)res; } - LFS_TRACE("lfs_file_truncate -> %d", 0); return 0; } static lfs_soff_t lfs_file_tellraw(lfs_t *lfs, lfs_file_t *file) { - LFS_TRACE("lfs_file_tell(%p, %p)", (void*)lfs, (void*)file); LFS_ASSERT(file->flags & LFS_F_OPENED); (void)lfs; - LFS_TRACE("lfs_file_tell -> %"PRId32, file->pos); return file->pos; } static int lfs_file_rewindraw(lfs_t *lfs, lfs_file_t *file) { - LFS_TRACE("lfs_file_rewind(%p, %p)", (void*)lfs, (void*)file); lfs_soff_t res = lfs_file_seekraw(lfs, file, 0, LFS_SEEK_SET); if (res < 0) { - LFS_TRACE("lfs_file_rewind -> %"PRId32, res); return (int)res; } - LFS_TRACE("lfs_file_rewind -> %d", 0); return 0; } static lfs_soff_t lfs_file_sizeraw(lfs_t *lfs, lfs_file_t *file) { - LFS_TRACE("lfs_file_size(%p, %p)", (void*)lfs, (void*)file); LFS_ASSERT(file->flags & LFS_F_OPENED); (void)lfs; if (file->flags & LFS_F_WRITING) { - LFS_TRACE("lfs_file_size -> %"PRId32, - lfs_max(file->pos, file->ctz.size)); return lfs_max(file->pos, file->ctz.size); } else { - LFS_TRACE("lfs_file_size -> %"PRId32, file->ctz.size); return file->ctz.size; } } @@ -3150,32 +3053,25 @@ static lfs_soff_t lfs_file_sizeraw(lfs_t *lfs, lfs_file_t *file) { /// General fs operations /// static int lfs_statraw(lfs_t *lfs, const char *path, struct lfs_info *info) { - LFS_TRACE("lfs_stat(%p, \"%s\", %p)", (void*)lfs, path, (void*)info); lfs_mdir_t cwd; lfs_stag_t tag = lfs_dir_find(lfs, &cwd, &path, NULL); if (tag < 0) { - LFS_TRACE("lfs_stat -> %"PRId32, tag); return (int)tag; } - int err = lfs_dir_getinfo(lfs, &cwd, lfs_tag_id(tag), info); - LFS_TRACE("lfs_stat -> %d", err); - return err; + return lfs_dir_getinfo(lfs, &cwd, lfs_tag_id(tag), info); } static int lfs_removeraw(lfs_t *lfs, const char *path) { - LFS_TRACE("lfs_remove(%p, \"%s\")", (void*)lfs, path); // deorphan if we haven't yet, needed at most once after poweron int err = lfs_fs_forceconsistency(lfs); if (err) { - LFS_TRACE("lfs_remove -> %d", err); return err; } lfs_mdir_t cwd; lfs_stag_t tag = lfs_dir_find(lfs, &cwd, &path, NULL); if (tag < 0 || lfs_tag_id(tag) == 0x3ff) { - LFS_TRACE("lfs_remove -> %"PRId32, (tag < 0) ? tag : LFS_ERR_INVAL); return (tag < 0) ? (int)tag : LFS_ERR_INVAL; } @@ -3187,19 +3083,16 @@ static int lfs_removeraw(lfs_t *lfs, const char *path) { lfs_stag_t res = lfs_dir_get(lfs, &cwd, LFS_MKTAG(0x700, 0x3ff, 0), LFS_MKTAG(LFS_TYPE_STRUCT, lfs_tag_id(tag), 8), pair); if (res < 0) { - LFS_TRACE("lfs_remove -> %"PRId32, res); return (int)res; } lfs_pair_fromle32(pair); err = lfs_dir_fetch(lfs, &dir.m, pair); if (err) { - LFS_TRACE("lfs_remove -> %d", err); return err; } if (dir.m.count > 0 || dir.m.split) { - LFS_TRACE("lfs_remove -> %d", LFS_ERR_NOTEMPTY); return LFS_ERR_NOTEMPTY; } @@ -3218,7 +3111,6 @@ static int lfs_removeraw(lfs_t *lfs, const char *path) { {LFS_MKTAG(LFS_TYPE_DELETE, lfs_tag_id(tag), 0), NULL})); if (err) { lfs->mlist = dir.next; - LFS_TRACE("lfs_remove -> %d", err); return err; } @@ -3229,28 +3121,22 @@ static int lfs_removeraw(lfs_t *lfs, const char *path) { err = lfs_fs_pred(lfs, dir.m.pair, &cwd); if (err) { - LFS_TRACE("lfs_remove -> %d", err); return err; } err = lfs_dir_drop(lfs, &cwd, &dir.m); if (err) { - LFS_TRACE("lfs_remove -> %d", err); return err; } } - LFS_TRACE("lfs_remove -> %d", 0); return 0; } static int lfs_renameraw(lfs_t *lfs, const char *oldpath, const char *newpath) { - LFS_TRACE("lfs_rename(%p, \"%s\", \"%s\")", (void*)lfs, oldpath, newpath); - // deorphan if we haven't yet, needed at most once after poweron int err = lfs_fs_forceconsistency(lfs); if (err) { - LFS_TRACE("lfs_rename -> %d", err); return err; } @@ -3258,8 +3144,6 @@ static int lfs_renameraw(lfs_t *lfs, const char *oldpath, const char *newpath) { lfs_mdir_t oldcwd; lfs_stag_t oldtag = lfs_dir_find(lfs, &oldcwd, &oldpath, NULL); if (oldtag < 0 || lfs_tag_id(oldtag) == 0x3ff) { - LFS_TRACE("lfs_rename -> %"PRId32, - (oldtag < 0) ? oldtag : LFS_ERR_INVAL); return (oldtag < 0) ? (int)oldtag : LFS_ERR_INVAL; } @@ -3269,8 +3153,6 @@ static int lfs_renameraw(lfs_t *lfs, const char *oldpath, const char *newpath) { lfs_stag_t prevtag = lfs_dir_find(lfs, &newcwd, &newpath, &newid); if ((prevtag < 0 || lfs_tag_id(prevtag) == 0x3ff) && !(prevtag == LFS_ERR_NOENT && newid != 0x3ff)) { - LFS_TRACE("lfs_rename -> %"PRId32, - (prevtag < 0) ? prevtag : LFS_ERR_INVAL); return (prevtag < 0) ? (int)prevtag : LFS_ERR_INVAL; } @@ -3284,7 +3166,6 @@ static int lfs_renameraw(lfs_t *lfs, const char *oldpath, const char *newpath) { // check that name fits lfs_size_t nlen = strlen(newpath); if (nlen > lfs->name_max) { - LFS_TRACE("lfs_rename -> %d", LFS_ERR_NAMETOOLONG); return LFS_ERR_NAMETOOLONG; } @@ -3295,11 +3176,9 @@ static int lfs_renameraw(lfs_t *lfs, const char *oldpath, const char *newpath) { newoldid += 1; } } else if (lfs_tag_type3(prevtag) != lfs_tag_type3(oldtag)) { - LFS_TRACE("lfs_rename -> %d", LFS_ERR_ISDIR); return LFS_ERR_ISDIR; } else if (samepair && newid == newoldid) { // we're renaming to ourselves?? - LFS_TRACE("lfs_rename -> %d", 0); return 0; } else if (lfs_tag_type3(prevtag) == LFS_TYPE_DIR) { // must be empty before removal @@ -3307,7 +3186,6 @@ static int lfs_renameraw(lfs_t *lfs, const char *oldpath, const char *newpath) { lfs_stag_t res = lfs_dir_get(lfs, &newcwd, LFS_MKTAG(0x700, 0x3ff, 0), LFS_MKTAG(LFS_TYPE_STRUCT, newid, 8), prevpair); if (res < 0) { - LFS_TRACE("lfs_rename -> %"PRId32, res); return (int)res; } lfs_pair_fromle32(prevpair); @@ -3315,12 +3193,10 @@ static int lfs_renameraw(lfs_t *lfs, const char *oldpath, const char *newpath) { // must be empty before removal err = lfs_dir_fetch(lfs, &prevdir.m, prevpair); if (err) { - LFS_TRACE("lfs_rename -> %d", err); return err; } if (prevdir.m.count > 0 || prevdir.m.split) { - LFS_TRACE("lfs_rename -> %d", LFS_ERR_NOTEMPTY); return LFS_ERR_NOTEMPTY; } @@ -3349,7 +3225,6 @@ static int lfs_renameraw(lfs_t *lfs, const char *oldpath, const char *newpath) { LFS_TYPE_DELETE, newoldid, 0), NULL})); if (err) { lfs->mlist = prevdir.next; - LFS_TRACE("lfs_rename -> %d", err); return err; } @@ -3362,7 +3237,6 @@ static int lfs_renameraw(lfs_t *lfs, const char *oldpath, const char *newpath) { {LFS_MKTAG(LFS_TYPE_DELETE, lfs_tag_id(oldtag), 0), NULL})); if (err) { lfs->mlist = prevdir.next; - LFS_TRACE("lfs_rename -> %d", err); return err; } } @@ -3374,29 +3248,23 @@ static int lfs_renameraw(lfs_t *lfs, const char *oldpath, const char *newpath) { err = lfs_fs_pred(lfs, prevdir.m.pair, &newcwd); if (err) { - LFS_TRACE("lfs_rename -> %d", err); return err; } err = lfs_dir_drop(lfs, &newcwd, &prevdir.m); if (err) { - LFS_TRACE("lfs_rename -> %d", err); return err; } } - LFS_TRACE("lfs_rename -> %d", 0); return 0; } static lfs_ssize_t lfs_getattrraw(lfs_t *lfs, const char *path, uint8_t type, void *buffer, lfs_size_t size) { - LFS_TRACE("lfs_getattr(%p, \"%s\", %"PRIu8", %p, %"PRIu32")", - (void*)lfs, path, type, buffer, size); lfs_mdir_t cwd; lfs_stag_t tag = lfs_dir_find(lfs, &cwd, &path, NULL); if (tag < 0) { - LFS_TRACE("lfs_getattr -> %"PRId32, tag); return tag; } @@ -3406,7 +3274,6 @@ static lfs_ssize_t lfs_getattrraw(lfs_t *lfs, const char *path, id = 0; int err = lfs_dir_fetch(lfs, &cwd, lfs->root); if (err) { - LFS_TRACE("lfs_getattr -> %d", err); return err; } } @@ -3417,17 +3284,13 @@ static lfs_ssize_t lfs_getattrraw(lfs_t *lfs, const char *path, buffer); if (tag < 0) { if (tag == LFS_ERR_NOENT) { - LFS_TRACE("lfs_getattr -> %d", LFS_ERR_NOATTR); return LFS_ERR_NOATTR; } - LFS_TRACE("lfs_getattr -> %"PRId32, tag); return tag; } - size = lfs_tag_size(tag); - LFS_TRACE("lfs_getattr -> %"PRId32, size); - return size; + return lfs_tag_size(tag); } static int lfs_commitattr(lfs_t *lfs, const char *path, @@ -3454,23 +3317,15 @@ static int lfs_commitattr(lfs_t *lfs, const char *path, static int lfs_setattrraw(lfs_t *lfs, const char *path, uint8_t type, const void *buffer, lfs_size_t size) { - LFS_TRACE("lfs_setattr(%p, \"%s\", %"PRIu8", %p, %"PRIu32")", - (void*)lfs, path, type, buffer, size); if (size > lfs->attr_max) { - LFS_TRACE("lfs_setattr -> %d", LFS_ERR_NOSPC); return LFS_ERR_NOSPC; } - int err = lfs_commitattr(lfs, path, type, buffer, size); - LFS_TRACE("lfs_setattr -> %d", err); - return err; + return lfs_commitattr(lfs, path, type, buffer, size); } static int lfs_removeattrraw(lfs_t *lfs, const char *path, uint8_t type) { - LFS_TRACE("lfs_removeattr(%p, \"%s\", %"PRIu8")", (void*)lfs, path, type); - int err = lfs_commitattr(lfs, path, type, NULL, 0x3ff); - LFS_TRACE("lfs_removeattr -> %d", err); - return err; + return lfs_commitattr(lfs, path, type, NULL, 0x3ff); } @@ -3600,27 +3455,10 @@ static int lfs_deinit(lfs_t *lfs) { } static int lfs_formatraw(lfs_t *lfs, const struct lfs_config *cfg) { - LFS_TRACE("lfs_format(%p, %p {.context=%p, " - ".read=%p, .prog=%p, .erase=%p, .sync=%p, " - ".read_size=%"PRIu32", .prog_size=%"PRIu32", " - ".block_size=%"PRIu32", .block_count=%"PRIu32", " - ".block_cycles=%"PRIu32", .cache_size=%"PRIu32", " - ".lookahead_size=%"PRIu32", .read_buffer=%p, " - ".prog_buffer=%p, .lookahead_buffer=%p, " - ".name_max=%"PRIu32", .file_max=%"PRIu32", " - ".attr_max=%"PRIu32"})", - (void*)lfs, (void*)cfg, cfg->context, - (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, - cfg->block_cycles, cfg->cache_size, cfg->lookahead_size, - cfg->read_buffer, cfg->prog_buffer, cfg->lookahead_buffer, - cfg->name_max, cfg->file_max, cfg->attr_max); int err = 0; { err = lfs_init(lfs, cfg); if (err) { - LFS_TRACE("lfs_format -> %d", err); return err; } @@ -3676,30 +3514,12 @@ static int lfs_formatraw(lfs_t *lfs, const struct lfs_config *cfg) { cleanup: lfs_deinit(lfs); - LFS_TRACE("lfs_format -> %d", err); return err; } static int lfs_mountraw(lfs_t *lfs, const struct lfs_config *cfg) { - LFS_TRACE("lfs_mount(%p, %p {.context=%p, " - ".read=%p, .prog=%p, .erase=%p, .sync=%p, " - ".read_size=%"PRIu32", .prog_size=%"PRIu32", " - ".block_size=%"PRIu32", .block_count=%"PRIu32", " - ".block_cycles=%"PRIu32", .cache_size=%"PRIu32", " - ".lookahead_size=%"PRIu32", .read_buffer=%p, " - ".prog_buffer=%p, .lookahead_buffer=%p, " - ".name_max=%"PRIu32", .file_max=%"PRIu32", " - ".attr_max=%"PRIu32"})", - (void*)lfs, (void*)cfg, cfg->context, - (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, - cfg->block_cycles, cfg->cache_size, cfg->lookahead_size, - cfg->read_buffer, cfg->prog_buffer, cfg->lookahead_buffer, - cfg->name_max, cfg->file_max, cfg->attr_max); int err = lfs_init(lfs, cfg); if (err) { - LFS_TRACE("lfs_mount -> %d", err); return err; } @@ -3815,20 +3635,15 @@ static int lfs_mountraw(lfs_t *lfs, const struct lfs_config *cfg) { // setup free lookahead lfs_alloc_reset(lfs); - LFS_TRACE("lfs_mount -> %d", 0); return 0; cleanup: lfs_unmountraw(lfs); - LFS_TRACE("lfs_mount -> %d", err); return err; } static int lfs_unmountraw(lfs_t *lfs) { - LFS_TRACE("lfs_unmount(%p)", (void*)lfs); - int err = lfs_deinit(lfs); - LFS_TRACE("lfs_unmount -> %d", err); - return err; + return lfs_deinit(lfs); } @@ -4242,15 +4057,12 @@ static int lfs_fs_size_count(void *p, lfs_block_t block) { } static lfs_ssize_t lfs_fs_sizeraw(lfs_t *lfs) { - LFS_TRACE("lfs_fs_size(%p)", (void*)lfs); lfs_size_t size = 0; int err = lfs_fs_traverseraw(lfs, lfs_fs_size_count, &size, false); if (err) { - LFS_TRACE("lfs_fs_size -> %d", err); return err; } - LFS_TRACE("lfs_fs_size -> %d", err); return size; } @@ -4676,26 +4488,9 @@ static int lfs1_unmount(lfs_t *lfs) { /// v1 migration /// static int lfs_migrateraw(lfs_t *lfs, const struct lfs_config *cfg) { - LFS_TRACE("lfs_migrate(%p, %p {.context=%p, " - ".read=%p, .prog=%p, .erase=%p, .sync=%p, " - ".read_size=%"PRIu32", .prog_size=%"PRIu32", " - ".block_size=%"PRIu32", .block_count=%"PRIu32", " - ".block_cycles=%"PRIu32", .cache_size=%"PRIu32", " - ".lookahead_size=%"PRIu32", .read_buffer=%p, " - ".prog_buffer=%p, .lookahead_buffer=%p, " - ".name_max=%"PRIu32", .file_max=%"PRIu32", " - ".attr_max=%"PRIu32"})", - (void*)lfs, (void*)cfg, cfg->context, - (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, - cfg->block_cycles, cfg->cache_size, cfg->lookahead_size, - cfg->read_buffer, cfg->prog_buffer, cfg->lookahead_buffer, - cfg->name_max, cfg->file_max, cfg->attr_max); struct lfs1 lfs1; int err = lfs1_mount(lfs, &lfs1, cfg); if (err) { - LFS_TRACE("lfs_migrate -> %d", err); return err; } @@ -4912,7 +4707,6 @@ static int lfs_migrateraw(lfs_t *lfs, const struct lfs_config *cfg) { cleanup: lfs1_unmount(lfs); - LFS_TRACE("lfs_migrate -> %d", err); return err; } @@ -4939,7 +4733,24 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) { return err; } + LFS_TRACE("lfs_format(%p, %p {.context=%p, " + ".read=%p, .prog=%p, .erase=%p, .sync=%p, " + ".read_size=%"PRIu32", .prog_size=%"PRIu32", " + ".block_size=%"PRIu32", .block_count=%"PRIu32", " + ".block_cycles=%"PRIu32", .cache_size=%"PRIu32", " + ".lookahead_size=%"PRIu32", .read_buffer=%p, " + ".prog_buffer=%p, .lookahead_buffer=%p, " + ".name_max=%"PRIu32", .file_max=%"PRIu32", " + ".attr_max=%"PRIu32"})", + (void*)lfs, (void*)cfg, cfg->context, + (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, + cfg->block_cycles, cfg->cache_size, cfg->lookahead_size, + cfg->read_buffer, cfg->prog_buffer, cfg->lookahead_buffer, + cfg->name_max, cfg->file_max, cfg->attr_max); err = lfs_formatraw(lfs, cfg); + LFS_TRACE("lfs_format -> %d", err); LFS_UNLOCK(cfg); return err; @@ -4951,7 +4762,24 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) { return err; } + LFS_TRACE("lfs_mount(%p, %p {.context=%p, " + ".read=%p, .prog=%p, .erase=%p, .sync=%p, " + ".read_size=%"PRIu32", .prog_size=%"PRIu32", " + ".block_size=%"PRIu32", .block_count=%"PRIu32", " + ".block_cycles=%"PRIu32", .cache_size=%"PRIu32", " + ".lookahead_size=%"PRIu32", .read_buffer=%p, " + ".prog_buffer=%p, .lookahead_buffer=%p, " + ".name_max=%"PRIu32", .file_max=%"PRIu32", " + ".attr_max=%"PRIu32"})", + (void*)lfs, (void*)cfg, cfg->context, + (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, + cfg->block_cycles, cfg->cache_size, cfg->lookahead_size, + cfg->read_buffer, cfg->prog_buffer, cfg->lookahead_buffer, + cfg->name_max, cfg->file_max, cfg->attr_max); err = lfs_mountraw(lfs, cfg); + LFS_TRACE("lfs_mount -> %d", err); LFS_UNLOCK(cfg); return err; @@ -4963,7 +4791,9 @@ int lfs_unmount(lfs_t *lfs) { return err; } + LFS_TRACE("lfs_unmount(%p)", (void*)lfs); err = lfs_unmountraw(lfs); + LFS_TRACE("lfs_unmount -> %d", err); LFS_UNLOCK(lfs->cfg); return err; @@ -4975,7 +4805,9 @@ int lfs_remove(lfs_t *lfs, const char *path) { return err; } + LFS_TRACE("lfs_remove(%p, \"%s\")", (void*)lfs, path); err = lfs_removeraw(lfs, path); + LFS_TRACE("lfs_remove -> %d", err); LFS_UNLOCK(lfs->cfg); return err; @@ -4987,7 +4819,9 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) { return err; } + LFS_TRACE("lfs_rename(%p, \"%s\", \"%s\")", (void*)lfs, oldpath, newpath); err = lfs_renameraw(lfs, oldpath, newpath); + LFS_TRACE("lfs_rename -> %d", err); LFS_UNLOCK(lfs->cfg); return err; @@ -4999,7 +4833,9 @@ int lfs_stat(lfs_t *lfs, const char *path, struct lfs_info *info) { return err; } + LFS_TRACE("lfs_stat(%p, \"%s\", %p)", (void*)lfs, path, (void*)info); err = lfs_statraw(lfs, path, info); + LFS_TRACE("lfs_stat -> %d", err); LFS_UNLOCK(lfs->cfg); return err; @@ -5012,10 +4848,13 @@ lfs_ssize_t lfs_getattr(lfs_t *lfs, const char *path, return err; } - err = lfs_getattrraw(lfs, path, type, buffer, size); + LFS_TRACE("lfs_getattr(%p, \"%s\", %"PRIu8", %p, %"PRIu32")", + (void*)lfs, path, type, buffer, size); + lfs_ssize_t res = lfs_getattrraw(lfs, path, type, buffer, size); + LFS_TRACE("lfs_getattr -> %"PRId32, res); LFS_UNLOCK(lfs->cfg); - return err; + return res; } int lfs_setattr(lfs_t *lfs, const char *path, @@ -5025,7 +4864,10 @@ int lfs_setattr(lfs_t *lfs, const char *path, return err; } + LFS_TRACE("lfs_setattr(%p, \"%s\", %"PRIu8", %p, %"PRIu32")", + (void*)lfs, path, type, buffer, size); err = lfs_setattrraw(lfs, path, type, buffer, size); + LFS_TRACE("lfs_setattr -> %d", err); LFS_UNLOCK(lfs->cfg); return err; @@ -5037,7 +4879,9 @@ int lfs_removeattr(lfs_t *lfs, const char *path, uint8_t type) { return err; } + LFS_TRACE("lfs_removeattr(%p, \"%s\", %"PRIu8")", (void*)lfs, path, type); err = lfs_removeattrraw(lfs, path, type); + LFS_TRACE("lfs_removeattr -> %d", err); LFS_UNLOCK(lfs->cfg); return err; @@ -5049,7 +4893,10 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file, const char *path, int flags) { return err; } + LFS_TRACE("lfs_file_open(%p, %p, \"%s\", %x)", + (void*)lfs, (void*)file, path, flags); err = lfs_file_openraw(lfs, file, path, flags); + LFS_TRACE("lfs_file_open -> %d", err); LFS_UNLOCK(lfs->cfg); return err; @@ -5057,13 +4904,18 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file, const char *path, int flags) { 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_config *cfg) { int err = LFS_LOCK(lfs->cfg); if (err) { return err; } - err = lfs_file_opencfgraw(lfs, file, path, flags, config); + LFS_TRACE("lfs_file_opencfg(%p, %p, \"%s\", %x, %p {" + ".buffer=%p, .attrs=%p, .attr_count=%"PRIu32"})", + (void*)lfs, (void*)file, path, flags, + (void*)cfg, cfg->buffer, (void*)cfg->attrs, cfg->attr_count); + err = lfs_file_opencfgraw(lfs, file, path, flags, cfg); + LFS_TRACE("lfs_file_opencfg -> %d", err); LFS_UNLOCK(lfs->cfg); return err; @@ -5075,7 +4927,9 @@ int lfs_file_close(lfs_t *lfs, lfs_file_t *file) { return err; } + LFS_TRACE("lfs_file_close(%p, %p)", (void*)lfs, (void*)file); err = lfs_file_closeraw(lfs, file); + LFS_TRACE("lfs_file_close -> %d", err); LFS_UNLOCK(lfs->cfg); return err; @@ -5087,7 +4941,9 @@ int lfs_file_sync(lfs_t *lfs, lfs_file_t *file) { return err; } + LFS_TRACE("lfs_file_sync(%p, %p)", (void*)lfs, (void*)file); err = lfs_file_syncraw(lfs, file); + LFS_TRACE("lfs_file_sync -> %d", err); LFS_UNLOCK(lfs->cfg); return err; @@ -5100,10 +4956,13 @@ lfs_ssize_t lfs_file_read(lfs_t *lfs, lfs_file_t *file, return err; } - err = lfs_file_readraw(lfs, file, buffer, size); + LFS_TRACE("lfs_file_read(%p, %p, %p, %"PRIu32")", + (void*)lfs, (void*)file, buffer, size); + lfs_ssize_t res = lfs_file_readraw(lfs, file, buffer, size); + LFS_TRACE("lfs_file_read -> %"PRId32, res); LFS_UNLOCK(lfs->cfg); - return err; + return res; } lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, @@ -5113,10 +4972,13 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, return err; } - err = lfs_file_writeraw(lfs, file, buffer, size); + LFS_TRACE("lfs_file_write(%p, %p, %p, %"PRIu32")", + (void*)lfs, (void*)file, buffer, size); + lfs_ssize_t res = lfs_file_writeraw(lfs, file, buffer, size); + LFS_TRACE("lfs_file_write -> %"PRId32, res); LFS_UNLOCK(lfs->cfg); - return err; + return res; } lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file, @@ -5126,10 +4988,13 @@ lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file, return err; } - err = lfs_file_seekraw(lfs, file, off, whence); + LFS_TRACE("lfs_file_seek(%p, %p, %"PRId32", %d)", + (void*)lfs, (void*)file, off, whence); + lfs_soff_t res = lfs_file_seekraw(lfs, file, off, whence); + LFS_TRACE("lfs_file_seek -> %"PRId32, res); LFS_UNLOCK(lfs->cfg); - return err; + return res; } int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { @@ -5138,7 +5003,10 @@ int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { return err; } + LFS_TRACE("lfs_file_truncate(%p, %p, %"PRIu32")", + (void*)lfs, (void*)file, size); err = lfs_file_truncateraw(lfs, file, size); + LFS_TRACE("lfs_file_truncate -> %d", err); LFS_UNLOCK(lfs->cfg); return err; @@ -5150,10 +5018,12 @@ lfs_soff_t lfs_file_tell(lfs_t *lfs, lfs_file_t *file) { return err; } - err = lfs_file_tellraw(lfs, file); + LFS_TRACE("lfs_file_tell(%p, %p)", (void*)lfs, (void*)file); + lfs_soff_t res = lfs_file_tellraw(lfs, file); + LFS_TRACE("lfs_file_tell -> %"PRId32, res); LFS_UNLOCK(lfs->cfg); - return err; + return res; } int lfs_file_rewind(lfs_t *lfs, lfs_file_t *file) { @@ -5162,7 +5032,9 @@ int lfs_file_rewind(lfs_t *lfs, lfs_file_t *file) { return err; } + LFS_TRACE("lfs_file_rewind(%p, %p)", (void*)lfs, (void*)file); err = lfs_file_rewindraw(lfs, file); + LFS_TRACE("lfs_file_rewind -> %d", err); LFS_UNLOCK(lfs->cfg); return err; @@ -5174,10 +5046,12 @@ lfs_soff_t lfs_file_size(lfs_t *lfs, lfs_file_t *file) { return err; } - err = lfs_file_sizeraw(lfs, file); + LFS_TRACE("lfs_file_size(%p, %p)", (void*)lfs, (void*)file); + lfs_soff_t res = lfs_file_sizeraw(lfs, file); + LFS_TRACE("lfs_file_size -> %"PRId32, res); LFS_UNLOCK(lfs->cfg); - return err; + return res; } int lfs_mkdir(lfs_t *lfs, const char *path) { @@ -5186,7 +5060,9 @@ int lfs_mkdir(lfs_t *lfs, const char *path) { return err; } + LFS_TRACE("lfs_mkdir(%p, \"%s\")", (void*)lfs, path); err = lfs_mkdirraw(lfs, path); + LFS_TRACE("lfs_mkdir -> %d", err); LFS_UNLOCK(lfs->cfg); return err; @@ -5198,7 +5074,9 @@ int lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path) { return err; } + LFS_TRACE("lfs_dir_open(%p, %p, \"%s\")", (void*)lfs, (void*)dir, path); err = lfs_dir_openraw(lfs, dir, path); + LFS_TRACE("lfs_dir_open -> %d", err); LFS_UNLOCK(lfs->cfg); return err; @@ -5210,7 +5088,9 @@ int lfs_dir_close(lfs_t *lfs, lfs_dir_t *dir) { return err; } + LFS_TRACE("lfs_dir_close(%p, %p)", (void*)lfs, (void*)dir); err = lfs_dir_closeraw(lfs, dir); + LFS_TRACE("lfs_dir_close -> %d", err); LFS_UNLOCK(lfs->cfg); return err; @@ -5222,7 +5102,10 @@ int lfs_dir_read(lfs_t *lfs, lfs_dir_t *dir, struct lfs_info *info) { return err; } + LFS_TRACE("lfs_dir_read(%p, %p, %p)", + (void*)lfs, (void*)dir, (void*)info); err = lfs_dir_readraw(lfs, dir, info); + LFS_TRACE("lfs_dir_read -> %d", err); LFS_UNLOCK(lfs->cfg); return err; @@ -5234,7 +5117,10 @@ int lfs_dir_seek(lfs_t *lfs, lfs_dir_t *dir, lfs_off_t off) { return err; } + LFS_TRACE("lfs_dir_seek(%p, %p, %"PRIu32")", + (void*)lfs, (void*)dir, off); err = lfs_dir_seekraw(lfs, dir, off); + LFS_TRACE("lfs_dir_seek -> %d", err); LFS_UNLOCK(lfs->cfg); return err; @@ -5246,10 +5132,12 @@ lfs_soff_t lfs_dir_tell(lfs_t *lfs, lfs_dir_t *dir) { return err; } - err = lfs_dir_tellraw(lfs, dir); + LFS_TRACE("lfs_dir_tell(%p, %p)", (void*)lfs, (void*)dir); + lfs_soff_t res = lfs_dir_tellraw(lfs, dir); + LFS_TRACE("lfs_dir_tell -> %"PRId32, res); LFS_UNLOCK(lfs->cfg); - return err; + return res; } int lfs_dir_rewind(lfs_t *lfs, lfs_dir_t *dir) { @@ -5258,7 +5146,9 @@ int lfs_dir_rewind(lfs_t *lfs, lfs_dir_t *dir) { return err; } + LFS_TRACE("lfs_dir_rewind(%p, %p)", (void*)lfs, (void*)dir); err = lfs_dir_rewindraw(lfs, dir); + LFS_TRACE("lfs_dir_rewind -> %d", err); LFS_UNLOCK(lfs->cfg); return err; @@ -5270,10 +5160,12 @@ lfs_ssize_t lfs_fs_size(lfs_t *lfs) { return err; } - err = lfs_fs_sizeraw(lfs); + LFS_TRACE("lfs_fs_size(%p)", (void*)lfs); + lfs_ssize_t res = lfs_fs_sizeraw(lfs); + LFS_TRACE("lfs_fs_size -> %"PRId32, res); LFS_UNLOCK(lfs->cfg); - return err; + return res; } int lfs_fs_traverse(lfs_t *lfs, int (*cb)(void *, lfs_block_t), void *data) { @@ -5298,7 +5190,24 @@ int lfs_migrate(lfs_t *lfs, const struct lfs_config *cfg) { return err; } + LFS_TRACE("lfs_migrate(%p, %p {.context=%p, " + ".read=%p, .prog=%p, .erase=%p, .sync=%p, " + ".read_size=%"PRIu32", .prog_size=%"PRIu32", " + ".block_size=%"PRIu32", .block_count=%"PRIu32", " + ".block_cycles=%"PRIu32", .cache_size=%"PRIu32", " + ".lookahead_size=%"PRIu32", .read_buffer=%p, " + ".prog_buffer=%p, .lookahead_buffer=%p, " + ".name_max=%"PRIu32", .file_max=%"PRIu32", " + ".attr_max=%"PRIu32"})", + (void*)lfs, (void*)cfg, cfg->context, + (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, + cfg->block_cycles, cfg->cache_size, cfg->lookahead_size, + cfg->read_buffer, cfg->prog_buffer, cfg->lookahead_buffer, + cfg->name_max, cfg->file_max, cfg->attr_max); err = lfs_migrateraw(lfs, cfg); + LFS_TRACE("lfs_migrate -> %d", err); LFS_UNLOCK(cfg); return err; diff --git a/lfs.h b/lfs.h index 3fec4df..0ac0639 100644 --- a/lfs.h +++ b/lfs.h @@ -16,6 +16,7 @@ extern "C" { #endif + /// Version info /// // Software library version @@ -657,6 +658,7 @@ int lfs_fs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data); int lfs_migrate(lfs_t *lfs, const struct lfs_config *cfg); #endif + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/lfs_util.h b/lfs_util.h index d3baffd..dbb4c5b 100644 --- a/lfs_util.h +++ b/lfs_util.h @@ -43,6 +43,7 @@ extern "C" { #endif + // Macros, may be replaced by system specific wrappers. Arguments to these // macros must not have side-effects as the macros can be removed for a smaller // code footprint