From 2588948d70d05c3bc4cc54529b80fd99ccfb7842 Mon Sep 17 00:00:00 2001 From: Haneef Mubarak Date: Thu, 11 Jul 2019 15:46:17 -0700 Subject: [PATCH 01/27] removed preventing compile on some archs --- emubd/lfs_emubd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emubd/lfs_emubd.c b/emubd/lfs_emubd.c index 3f31bfa..10158c6 100644 --- a/emubd/lfs_emubd.c +++ b/emubd/lfs_emubd.c @@ -11,7 +11,7 @@ #include #include #include -#include +//#include #include #include #include From 2e92f7a49b430c3aba0891e17b2bc00d92781953 Mon Sep 17 00:00:00 2001 From: Haneef Mubarak Date: Fri, 12 Jul 2019 11:46:18 -0700 Subject: [PATCH 02/27] actually removed --- emubd/lfs_emubd.c | 1 - 1 file changed, 1 deletion(-) diff --git a/emubd/lfs_emubd.c b/emubd/lfs_emubd.c index 10158c6..712fcba 100644 --- a/emubd/lfs_emubd.c +++ b/emubd/lfs_emubd.c @@ -11,7 +11,6 @@ #include #include #include -//#include #include #include #include From 6a1ee914904707cb65af5d9a9412cf6139c08b78 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 31 May 2019 04:40:19 -0500 Subject: [PATCH 03/27] Added trace statements through LFS_YES_TRACE To use, compile and run with LFS_YES_TRACE defined: make CFLAGS+=-DLFS_YES_TRACE=1 test_format The name LFS_YES_TRACE was chosen to match the LFS_NO_DEBUG and LFS_NO_WARN defines for the similar levels of output. The YES is necessary to avoid a conflict with the actual LFS_TRACE macro that gets emitting. LFS_TRACE can also be defined directly to provide a custom trace formatter. Hopefully having trace statements at the littlefs C API helps debugging and reproducing issues. --- Makefile | 3 + emubd/lfs_emubd.c | 138 +++++++++++++++++++++------ lfs.c | 237 ++++++++++++++++++++++++++++++++++++++++++++-- lfs_util.h | 12 ++- 4 files changed, 350 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index 185d8e5..364f299 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,9 @@ endif ifdef WORD override CFLAGS += -m$(WORD) endif +ifdef TRACE +override CFLAGS += -DLFS_YES_TRACE +endif override CFLAGS += -I. override CFLAGS += -std=c99 -Wall -pedantic override CFLAGS += -Wextra -Wshadow -Wjump-misses-init diff --git a/emubd/lfs_emubd.c b/emubd/lfs_emubd.c index 3f31bfa..374c51c 100644 --- a/emubd/lfs_emubd.c +++ b/emubd/lfs_emubd.c @@ -55,6 +55,15 @@ static inline void lfs_emubd_fromle32(lfs_emubd_t *emu) { // Block device emulated on existing filesystem int lfs_emubd_create(const struct lfs_config *cfg, const char *path) { + LFS_TRACE("lfs_emubd_create(%p {.context=%p, " + ".read=%p, .prog=%p, .erase=%p, .sync=%p, " + ".read_size=%"PRIu32", .prog_size=%"PRIu32", " + ".block_size=%"PRIu32", .block_count=%"PRIu32"}, \"%s\")", + (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, + path); lfs_emubd_t *emu = cfg->context; emu->cfg.read_size = cfg->read_size; emu->cfg.prog_size = cfg->prog_size; @@ -65,7 +74,9 @@ int lfs_emubd_create(const struct lfs_config *cfg, const char *path) { size_t pathlen = strlen(path); emu->path = malloc(pathlen + 1 + LFS_NAME_MAX + 1); if (!emu->path) { - return -ENOMEM; + int err = -ENOMEM; + LFS_TRACE("lfs_emubd_create -> %"PRId32, err); + return err; } strcpy(emu->path, path); @@ -76,7 +87,9 @@ int lfs_emubd_create(const struct lfs_config *cfg, const char *path) { // Create directory if it doesn't exist int err = mkdir(path, 0777); if (err && errno != EEXIST) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_create -> %"PRId32, err); + return err; } // Load stats to continue incrementing @@ -88,12 +101,16 @@ int lfs_emubd_create(const struct lfs_config *cfg, const char *path) { size_t res = fread(&emu->stats, sizeof(emu->stats), 1, f); lfs_emubd_fromle32(emu); if (res < 1) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_create -> %"PRId32, err); + return err; } err = fclose(f); if (err) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_create -> %"PRId32, err); + return err; } } @@ -106,27 +123,36 @@ int lfs_emubd_create(const struct lfs_config *cfg, const char *path) { size_t res = fread(&emu->history, sizeof(emu->history), 1, f); lfs_emubd_fromle32(emu); if (res < 1) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_create -> %"PRId32, err); + return err; } err = fclose(f); if (err) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_create -> %"PRId32, err); + return err; } } + LFS_TRACE("lfs_emubd_create -> %"PRId32, 0); return 0; } void lfs_emubd_destroy(const struct lfs_config *cfg) { + LFS_TRACE("lfs_emubd_destroy(%p)", (void*)cfg); lfs_emubd_sync(cfg); lfs_emubd_t *emu = cfg->context; free(emu->path); + LFS_TRACE("lfs_emubd_destroy -> %s", "void"); } int lfs_emubd_read(const struct lfs_config *cfg, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) { + LFS_TRACE("lfs_emubd_read(%p, %"PRIu32", %"PRIu32", %p, %"PRIu32")", + (void*)cfg, block, off, buffer, size); lfs_emubd_t *emu = cfg->context; uint8_t *data = buffer; @@ -143,32 +169,43 @@ int lfs_emubd_read(const struct lfs_config *cfg, lfs_block_t block, FILE *f = fopen(emu->path, "rb"); if (!f && errno != ENOENT) { - return -errno; + int err = -errno; + LFS_TRACE("lfs_emubd_read -> %d", err); + return err; } if (f) { int err = fseek(f, off, SEEK_SET); if (err) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_read -> %d", err); + return err; } size_t res = fread(data, 1, size, f); if (res < size && !feof(f)) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_read -> %d", err); + return err; } err = fclose(f); if (err) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_read -> %d", err); + return err; } } emu->stats.read_count += 1; + LFS_TRACE("lfs_emubd_read -> %d", 0); return 0; } int lfs_emubd_prog(const struct lfs_config *cfg, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) { + LFS_TRACE("lfs_emubd_prog(%p, %"PRIu32", %"PRIu32", %p, %"PRIu32")", + (void*)cfg, block, off, buffer, size); lfs_emubd_t *emu = cfg->context; const uint8_t *data = buffer; @@ -182,7 +219,9 @@ int lfs_emubd_prog(const struct lfs_config *cfg, lfs_block_t block, FILE *f = fopen(emu->path, "r+b"); if (!f) { - return (errno == EACCES) ? 0 : -errno; + int err = (errno == EACCES) ? 0 : -errno; + LFS_TRACE("lfs_emubd_prog -> %d", err); + return err; } // Check that file was erased @@ -190,28 +229,38 @@ int lfs_emubd_prog(const struct lfs_config *cfg, lfs_block_t block, int err = fseek(f, off, SEEK_SET); if (err) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_prog -> %d", err); + return err; } size_t res = fwrite(data, 1, size, f); if (res < size) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_prog -> %d", err); + return err; } err = fseek(f, off, SEEK_SET); if (err) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_prog -> %d", err); + return err; } uint8_t dat; res = fread(&dat, 1, 1, f); if (res < 1) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_prog -> %d", err); + return err; } err = fclose(f); if (err) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_prog -> %d", err); + return err; } // update history and stats @@ -222,10 +271,12 @@ int lfs_emubd_prog(const struct lfs_config *cfg, lfs_block_t block, } emu->stats.prog_count += 1; + LFS_TRACE("lfs_emubd_prog -> %d", 0); return 0; } int lfs_emubd_erase(const struct lfs_config *cfg, lfs_block_t block) { + LFS_TRACE("lfs_emubd_erase(%p, %"PRIu32")", (void*)cfg, block); lfs_emubd_t *emu = cfg->context; // Check if erase is valid @@ -236,89 +287,118 @@ int lfs_emubd_erase(const struct lfs_config *cfg, lfs_block_t block) { struct stat st; int err = stat(emu->path, &st); if (err && errno != ENOENT) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_erase -> %d", err); + return err; } if (!err && S_ISREG(st.st_mode) && (S_IWUSR & st.st_mode)) { err = unlink(emu->path); if (err) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_erase -> %d", err); + return err; } } if (err || (S_ISREG(st.st_mode) && (S_IWUSR & st.st_mode))) { FILE *f = fopen(emu->path, "w"); if (!f) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_erase -> %d", err); + return err; } err = fclose(f); if (err) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_erase -> %d", err); + return err; } } emu->stats.erase_count += 1; + LFS_TRACE("lfs_emubd_erase -> %d", 0); return 0; } int lfs_emubd_sync(const struct lfs_config *cfg) { + LFS_TRACE("lfs_emubd_sync(%p)", (void*)cfg); lfs_emubd_t *emu = cfg->context; // Just write out info/stats for later lookup snprintf(emu->child, LFS_NAME_MAX, ".config"); FILE *f = fopen(emu->path, "w"); if (!f) { - return -errno; + int err = -errno; + LFS_TRACE("lfs_emubd_sync -> %d", err); + return err; } lfs_emubd_tole32(emu); size_t res = fwrite(&emu->cfg, sizeof(emu->cfg), 1, f); lfs_emubd_fromle32(emu); if (res < 1) { - return -errno; + int err = -errno; + LFS_TRACE("lfs_emubd_sync -> %d", err); + return err; } int err = fclose(f); if (err) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_sync -> %d", err); + return err; } snprintf(emu->child, LFS_NAME_MAX, ".stats"); f = fopen(emu->path, "w"); if (!f) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_sync -> %d", err); + return err; } lfs_emubd_tole32(emu); res = fwrite(&emu->stats, sizeof(emu->stats), 1, f); lfs_emubd_fromle32(emu); if (res < 1) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_sync -> %d", err); + return err; } err = fclose(f); if (err) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_sync -> %d", err); + return err; } snprintf(emu->child, LFS_NAME_MAX, ".history"); f = fopen(emu->path, "w"); if (!f) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_sync -> %d", err); + return err; } lfs_emubd_tole32(emu); res = fwrite(&emu->history, sizeof(emu->history), 1, f); lfs_emubd_fromle32(emu); if (res < 1) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_sync -> %d", err); + return err; } err = fclose(f); if (err) { - return -errno; + err = -errno; + LFS_TRACE("lfs_emubd_sync -> %d", err); + return err; } + LFS_TRACE("lfs_emubd_sync -> %d", 0); return 0; } diff --git a/lfs.c b/lfs.c index c554135..4edf6b7 100644 --- a/lfs.c +++ b/lfs.c @@ -1821,9 +1821,11 @@ compact: /// Top level directory operations /// int lfs_mkdir(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; } @@ -1831,12 +1833,14 @@ int lfs_mkdir(lfs_t *lfs, const char *path) { uint16_t id; err = lfs_dir_find(lfs, &cwd, &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; } @@ -1845,6 +1849,7 @@ int lfs_mkdir(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; } @@ -1853,6 +1858,7 @@ int lfs_mkdir(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; } } @@ -1863,6 +1869,7 @@ int lfs_mkdir(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; } @@ -1875,6 +1882,7 @@ int lfs_mkdir(lfs_t *lfs, const char *path) { {LFS_MKTAG(LFS_TYPE_SOFTTAIL, 0x3ff, 8), dir.pair})); lfs_pair_fromle32(dir.pair); if (err) { + LFS_TRACE("lfs_mkdir -> %d", err); return err; } lfs_fs_preporphans(lfs, -1); @@ -1891,19 +1899,24 @@ int lfs_mkdir(lfs_t *lfs, const char *path) { : LFS_MKTAG(LFS_FROM_NOOP, 0, 0), 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; } int lfs_dir_open(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 -> %d", tag); return tag; } if (lfs_tag_type3(tag) != LFS_TYPE_DIR) { + LFS_TRACE("lfs_dir_open -> %d", LFS_ERR_NOTDIR); return LFS_ERR_NOTDIR; } @@ -1917,6 +1930,7 @@ int lfs_dir_open(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 -> %d", res); return res; } lfs_pair_fromle32(pair); @@ -1925,6 +1939,7 @@ int lfs_dir_open(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; } @@ -1939,10 +1954,12 @@ int lfs_dir_open(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; } int lfs_dir_close(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) { @@ -1951,10 +1968,13 @@ int lfs_dir_close(lfs_t *lfs, lfs_dir_t *dir) { } } + LFS_TRACE("lfs_dir_close -> %d", 0); return 0; } int lfs_dir_read(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 '..' @@ -1962,22 +1982,26 @@ int lfs_dir_read(lfs_t *lfs, lfs_dir_t *dir, struct lfs_info *info) { info->type = LFS_TYPE_DIR; strcpy(info->name, "."); dir->pos += 1; - return 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; - return 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; } @@ -1986,6 +2010,7 @@ int lfs_dir_read(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; } @@ -1996,13 +2021,17 @@ int lfs_dir_read(lfs_t *lfs, lfs_dir_t *dir, struct lfs_info *info) { } dir->pos += 1; + LFS_TRACE("lfs_dir_read -> %d", true); return true; } int lfs_dir_seek(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_rewind(lfs, dir); if (err) { + LFS_TRACE("lfs_dir_seek -> %d", err); return err; } @@ -2017,28 +2046,35 @@ int lfs_dir_seek(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; } } } + LFS_TRACE("lfs_dir_seek -> %d", 0); return 0; } lfs_soff_t lfs_dir_tell(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; } int lfs_dir_rewind(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; } @@ -2046,6 +2082,7 @@ int lfs_dir_rewind(lfs_t *lfs, lfs_dir_t *dir) { dir->m.pair[1] = dir->head[1]; dir->id = 0; dir->pos = 0; + LFS_TRACE("lfs_dir_rewind -> %d", 0); return 0; } @@ -2248,10 +2285,15 @@ static int lfs_ctz_traverse(lfs_t *lfs, int lfs_file_opencfg(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\", 0x%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; } } @@ -2381,22 +2423,29 @@ int lfs_file_opencfg(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_close(lfs, file); + LFS_TRACE("lfs_file_opencfg -> %d", err); return err; } int lfs_file_open(lfs_t *lfs, lfs_file_t *file, const char *path, int flags) { + LFS_TRACE("lfs_file_open(%p, %p, \"%s\", 0x%x)", + (void*)lfs, (void*)file, path, flags); static const struct lfs_file_config defaults = {0}; - return lfs_file_opencfg(lfs, file, path, flags, &defaults); + int err = lfs_file_opencfg(lfs, file, path, flags, &defaults); + LFS_TRACE("lfs_file_open -> %d", err); + return err; } int lfs_file_close(lfs_t *lfs, lfs_file_t *file) { + LFS_TRACE("lfs_file_close(%p, %p)", (void*)lfs, (void*)file); int err = lfs_file_sync(lfs, file); // remove from list of mdirs @@ -2412,6 +2461,7 @@ int lfs_file_close(lfs_t *lfs, lfs_file_t *file) { lfs_free(file->cache.buffer); } + LFS_TRACE("lfs_file_close -> %d", err); return err; } @@ -2564,10 +2614,12 @@ relocate: } int lfs_file_sync(lfs_t *lfs, lfs_file_t *file) { + LFS_TRACE("lfs_file_sync(%p, %p)", (void*)lfs, (void*)file); while (true) { int err = lfs_file_flush(lfs, file); if (err) { file->flags |= LFS_F_ERRED; + LFS_TRACE("lfs_file_sync -> %d", err); return err; } @@ -2604,12 +2656,14 @@ int lfs_file_sync(lfs_t *lfs, lfs_file_t *file) { goto relocate; } 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; relocate: @@ -2618,6 +2672,7 @@ relocate: err = lfs_file_relocate(lfs, file); if (err) { file->flags |= LFS_F_ERRED; + LFS_TRACE("lfs_file_sync -> %d", err); return err; } } @@ -2625,10 +2680,13 @@ relocate: lfs_ssize_t lfs_file_read(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); uint8_t *data = buffer; lfs_size_t nsize = size; if ((file->flags & 3) == LFS_O_WRONLY) { + LFS_TRACE("lfs_file_read -> %"PRId32, LFS_ERR_BADF); return LFS_ERR_BADF; } @@ -2636,12 +2694,14 @@ lfs_ssize_t lfs_file_read(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 -> %"PRId32, err); return err; } } if (file->pos >= file->ctz.size) { // eof if past end + LFS_TRACE("lfs_file_read -> %"PRId32, 0); return 0; } @@ -2657,6 +2717,7 @@ lfs_ssize_t lfs_file_read(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 -> %"PRId32, err); return err; } } else { @@ -2676,6 +2737,7 @@ lfs_ssize_t lfs_file_read(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 -> %"PRId32, err); return err; } } else { @@ -2683,6 +2745,7 @@ lfs_ssize_t lfs_file_read(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 -> %"PRId32, err); return err; } } @@ -2693,15 +2756,19 @@ lfs_ssize_t lfs_file_read(lfs_t *lfs, lfs_file_t *file, nsize -= diff; } + LFS_TRACE("lfs_file_read -> %"PRId32, size); return size; } lfs_ssize_t lfs_file_write(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); const uint8_t *data = buffer; lfs_size_t nsize = size; if ((file->flags & 3) == LFS_O_RDONLY) { + LFS_TRACE("lfs_file_write -> %"PRId32, LFS_ERR_BADF); return LFS_ERR_BADF; } @@ -2709,6 +2776,7 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, // drop any reads int err = lfs_file_flush(lfs, file); if (err) { + LFS_TRACE("lfs_file_write -> %"PRId32, err); return err; } } @@ -2719,6 +2787,7 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, if (file->pos + size > lfs->file_max) { // Larger than file limit? + LFS_TRACE("lfs_file_write -> %"PRId32, LFS_ERR_FBIG); return LFS_ERR_FBIG; } @@ -2730,6 +2799,7 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, while (file->pos < pos) { lfs_ssize_t res = lfs_file_write(lfs, file, &(uint8_t){0}, 1); if (res < 0) { + LFS_TRACE("lfs_file_write -> %"PRId32, res); return res; } } @@ -2745,6 +2815,7 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, int err = lfs_file_relocate(lfs, file); if (err) { file->flags |= LFS_F_ERRED; + LFS_TRACE("lfs_file_write -> %"PRId32, err); return err; } } @@ -2761,6 +2832,7 @@ lfs_ssize_t lfs_file_write(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 -> %"PRId32, err); return err; } @@ -2775,6 +2847,7 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, &file->block, &file->off); if (err) { file->flags |= LFS_F_ERRED; + LFS_TRACE("lfs_file_write -> %"PRId32, err); return err; } } else { @@ -2795,6 +2868,7 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, goto relocate; } file->flags |= LFS_F_ERRED; + LFS_TRACE("lfs_file_write -> %"PRId32, err); return err; } @@ -2803,6 +2877,7 @@ relocate: err = lfs_file_relocate(lfs, file); if (err) { file->flags |= LFS_F_ERRED; + LFS_TRACE("lfs_file_write -> %"PRId32, err); return err; } } @@ -2816,14 +2891,18 @@ relocate: } file->flags &= ~LFS_F_ERRED; + LFS_TRACE("lfs_file_write -> %"PRId32, size); return size; } lfs_soff_t lfs_file_seek(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); // write out everything beforehand, may be noop if rdonly int err = lfs_file_flush(lfs, file); if (err) { + LFS_TRACE("lfs_file_seek -> %"PRId32, err); return err; } @@ -2839,20 +2918,26 @@ lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file, if (npos > lfs->file_max) { // file position out of range + LFS_TRACE("lfs_file_seek -> %"PRId32, LFS_ERR_INVAL); return LFS_ERR_INVAL; } // update pos file->pos = npos; + LFS_TRACE("lfs_file_seek -> %"PRId32, npos); return npos; } int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { + LFS_TRACE("lfs_file_truncate(%p, %p, %"PRIu32")", + (void*)lfs, (void*)file, size); if ((file->flags & 3) == LFS_O_RDONLY) { + LFS_TRACE("lfs_file_truncate -> %d", LFS_ERR_BADF); return LFS_ERR_BADF; } if (size > LFS_FILE_MAX) { + LFS_TRACE("lfs_file_truncate -> %d", LFS_ERR_INVAL); return LFS_ERR_INVAL; } @@ -2861,6 +2946,7 @@ int lfs_file_truncate(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; } @@ -2869,6 +2955,7 @@ int lfs_file_truncate(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; } @@ -2882,6 +2969,7 @@ int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { if (file->pos != oldsize) { int err = lfs_file_seek(lfs, file, 0, LFS_SEEK_END); if (err < 0) { + LFS_TRACE("lfs_file_truncate -> %d", err); return err; } } @@ -2890,6 +2978,7 @@ int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { while (file->pos < size) { lfs_ssize_t res = lfs_file_write(lfs, file, &(uint8_t){0}, 1); if (res < 0) { + LFS_TRACE("lfs_file_truncate -> %d", res); return res; } } @@ -2897,32 +2986,43 @@ int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { // restore pos int err = lfs_file_seek(lfs, file, pos, LFS_SEEK_SET); if (err < 0) { + LFS_TRACE("lfs_file_truncate -> %d", err); return err; } } + LFS_TRACE("lfs_file_truncate -> %d", 0); return 0; } lfs_soff_t lfs_file_tell(lfs_t *lfs, lfs_file_t *file) { + LFS_TRACE("lfs_file_tell(%p, %p)", (void*)lfs, (void*)file); (void)lfs; + LFS_TRACE("lfs_file_tell -> %"PRId32, file->pos); return file->pos; } int lfs_file_rewind(lfs_t *lfs, lfs_file_t *file) { + LFS_TRACE("lfs_file_rewind(%p, %p)", (void*)lfs, (void*)file); lfs_soff_t res = lfs_file_seek(lfs, file, 0, LFS_SEEK_SET); if (res < 0) { + LFS_TRACE("lfs_file_rewind -> %d", res); return res; } + LFS_TRACE("lfs_file_rewind -> %d", 0); return 0; } lfs_soff_t lfs_file_size(lfs_t *lfs, lfs_file_t *file) { + LFS_TRACE("lfs_file_size(%p, %p)", (void*)lfs, (void*)file); (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; } } @@ -2930,25 +3030,32 @@ lfs_soff_t lfs_file_size(lfs_t *lfs, lfs_file_t *file) { /// General fs operations /// int lfs_stat(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 -> %d", tag); return tag; } - return lfs_dir_getinfo(lfs, &cwd, lfs_tag_id(tag), info); + int err = lfs_dir_getinfo(lfs, &cwd, lfs_tag_id(tag), info); + LFS_TRACE("lfs_stat -> %d", err); + return err; } int lfs_remove(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 -> %d", (tag < 0) ? tag : LFS_ERR_INVAL); return (tag < 0) ? tag : LFS_ERR_INVAL; } @@ -2959,16 +3066,19 @@ int lfs_remove(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 -> %d", res); return res; } lfs_pair_fromle32(pair); err = lfs_dir_fetch(lfs, &dir, pair); if (err) { + LFS_TRACE("lfs_remove -> %d", err); return err; } if (dir.count > 0 || dir.split) { + LFS_TRACE("lfs_remove -> %d", LFS_ERR_NOTEMPTY); return LFS_ERR_NOTEMPTY; } @@ -2980,6 +3090,7 @@ int lfs_remove(lfs_t *lfs, const char *path) { err = lfs_dir_commit(lfs, &cwd, LFS_MKATTRS( {LFS_MKTAG(LFS_TYPE_DELETE, lfs_tag_id(tag), 0), NULL})); if (err) { + LFS_TRACE("lfs_remove -> %d", err); return err; } @@ -2989,22 +3100,28 @@ int lfs_remove(lfs_t *lfs, const char *path) { err = lfs_fs_pred(lfs, dir.pair, &cwd); if (err) { + LFS_TRACE("lfs_remove -> %d", err); return err; } err = lfs_dir_drop(lfs, &cwd, &dir); if (err) { + LFS_TRACE("lfs_remove -> %d", err); return err; } } + LFS_TRACE("lfs_remove -> %d", 0); return 0; } int lfs_rename(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; } @@ -3012,6 +3129,7 @@ int lfs_rename(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 -> %d", (oldtag < 0) ? oldtag : LFS_ERR_INVAL); return (oldtag < 0) ? oldtag : LFS_ERR_INVAL; } @@ -3021,6 +3139,7 @@ int lfs_rename(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 -> %d", (prevtag < 0) ? prevtag : LFS_ERR_INVAL); return (prevtag < 0) ? prevtag : LFS_ERR_INVAL; } @@ -3029,9 +3148,11 @@ int lfs_rename(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; } } else if (lfs_tag_type3(prevtag) != lfs_tag_type3(oldtag)) { + LFS_TRACE("lfs_rename -> %d", LFS_ERR_ISDIR); return LFS_ERR_ISDIR; } else if (lfs_tag_type3(prevtag) == LFS_TYPE_DIR) { // must be empty before removal @@ -3039,6 +3160,7 @@ int lfs_rename(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 -> %d", res); return res; } lfs_pair_fromle32(prevpair); @@ -3046,10 +3168,12 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) { // must be empty before removal err = lfs_dir_fetch(lfs, &prevdir, prevpair); if (err) { + LFS_TRACE("lfs_rename -> %d", err); return err; } if (prevdir.count > 0 || prevdir.split) { + LFS_TRACE("lfs_rename -> %d", LFS_ERR_NOTEMPTY); return LFS_ERR_NOTEMPTY; } @@ -3079,6 +3203,7 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) { newpath}, {LFS_MKTAG(LFS_FROM_MOVE, newid, lfs_tag_id(oldtag)), &oldcwd})); if (err) { + LFS_TRACE("lfs_rename -> %d", err); return err; } @@ -3087,6 +3212,7 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) { if (lfs_pair_cmp(oldcwd.pair, newcwd.pair) != 0) { err = lfs_dir_commit(lfs, &oldcwd, NULL, 0); if (err) { + LFS_TRACE("lfs_rename -> %d", err); return err; } } @@ -3097,23 +3223,29 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) { err = lfs_fs_pred(lfs, prevdir.pair, &newcwd); if (err) { + LFS_TRACE("lfs_rename -> %d", err); return err; } err = lfs_dir_drop(lfs, &newcwd, &prevdir); if (err) { + LFS_TRACE("lfs_rename -> %d", err); return err; } } + LFS_TRACE("lfs_rename -> %d", 0); return 0; } lfs_ssize_t lfs_getattr(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; } @@ -3123,6 +3255,7 @@ lfs_ssize_t lfs_getattr(lfs_t *lfs, const char *path, id = 0; int err = lfs_dir_fetch(lfs, &cwd, lfs->root); if (err) { + LFS_TRACE("lfs_getattr -> %"PRId32, err); return err; } } @@ -3133,12 +3266,17 @@ lfs_ssize_t lfs_getattr(lfs_t *lfs, const char *path, buffer); if (tag < 0) { if (tag == LFS_ERR_NOENT) { + LFS_TRACE("lfs_getattr -> %"PRId32, LFS_ERR_NOATTR); return LFS_ERR_NOATTR; } + + LFS_TRACE("lfs_getattr -> %"PRId32, tag); return tag; } - return lfs_tag_size(tag); + size = lfs_tag_size(tag); + LFS_TRACE("lfs_getattr -> %"PRId32, size); + return size; } static int lfs_commitattr(lfs_t *lfs, const char *path, @@ -3165,15 +3303,23 @@ static int lfs_commitattr(lfs_t *lfs, const char *path, int lfs_setattr(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; } - return lfs_commitattr(lfs, path, type, buffer, size); + int err = lfs_commitattr(lfs, path, type, buffer, size); + LFS_TRACE("lfs_setattr -> %d", err); + return err; } int lfs_removeattr(lfs_t *lfs, const char *path, uint8_t type) { - return lfs_commitattr(lfs, path, type, NULL, 0x3ff); + 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; } @@ -3291,10 +3437,27 @@ static int lfs_deinit(lfs_t *lfs) { } int lfs_format(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; } @@ -3350,12 +3513,30 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) { cleanup: lfs_deinit(lfs); + LFS_TRACE("lfs_format -> %d", err); return err; } int lfs_mount(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; } @@ -3440,7 +3621,7 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) { // has gstate? err = lfs_dir_getgstate(lfs, &dir, &lfs->gpending); if (err) { - return err; + goto cleanup; } } @@ -3466,21 +3647,28 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) { lfs->free.i = 0; lfs_alloc_ack(lfs); + LFS_TRACE("lfs_mount -> %d", 0); return 0; cleanup: lfs_unmount(lfs); + LFS_TRACE("lfs_mount -> %d", err); return err; } int lfs_unmount(lfs_t *lfs) { - return lfs_deinit(lfs); + LFS_TRACE("lfs_unmount(%p)", (void*)lfs); + int err = lfs_deinit(lfs); + LFS_TRACE("lfs_unmount -> %d", err); + return err; } /// Filesystem filesystem operations /// int lfs_fs_traverse(lfs_t *lfs, int (*cb)(void *data, lfs_block_t block), void *data) { + LFS_TRACE("lfs_fs_traverse(%p, %p, %p)", + (void*)lfs, (void*)(uintptr_t)cb, data); // iterate over metadata pairs lfs_mdir_t dir = {.tail = {0, 1}}; @@ -3489,6 +3677,7 @@ int lfs_fs_traverse(lfs_t *lfs, if (lfs->lfs1) { int err = lfs1_traverse(lfs, cb, data); if (err) { + LFS_TRACE("lfs_fs_traverse -> %d", err); return err; } @@ -3501,6 +3690,7 @@ int lfs_fs_traverse(lfs_t *lfs, for (int i = 0; i < 2; i++) { int err = cb(data, dir.tail[i]); if (err) { + LFS_TRACE("lfs_fs_traverse -> %d", err); return err; } } @@ -3508,6 +3698,7 @@ int lfs_fs_traverse(lfs_t *lfs, // iterate through ids in directory int err = lfs_dir_fetch(lfs, &dir, dir.tail); if (err) { + LFS_TRACE("lfs_fs_traverse -> %d", err); return err; } @@ -3519,6 +3710,7 @@ int lfs_fs_traverse(lfs_t *lfs, if (tag == LFS_ERR_NOENT) { continue; } + LFS_TRACE("lfs_fs_traverse -> %d", tag); return tag; } lfs_ctz_fromle32(&ctz); @@ -3527,6 +3719,7 @@ int lfs_fs_traverse(lfs_t *lfs, err = lfs_ctz_traverse(lfs, NULL, &lfs->rcache, ctz.head, ctz.size, cb, data); if (err) { + LFS_TRACE("lfs_fs_traverse -> %d", err); return err; } } @@ -3543,6 +3736,7 @@ int lfs_fs_traverse(lfs_t *lfs, int err = lfs_ctz_traverse(lfs, &f->cache, &lfs->rcache, f->ctz.head, f->ctz.size, cb, data); if (err) { + LFS_TRACE("lfs_fs_traverse -> %d", err); return err; } } @@ -3551,11 +3745,13 @@ int lfs_fs_traverse(lfs_t *lfs, int err = lfs_ctz_traverse(lfs, &f->cache, &lfs->rcache, f->block, f->pos, cb, data); if (err) { + LFS_TRACE("lfs_fs_traverse -> %d", err); return err; } } } + LFS_TRACE("lfs_fs_traverse -> %d", 0); return 0; } @@ -3819,13 +4015,16 @@ static int lfs_fs_size_count(void *p, lfs_block_t block) { } lfs_ssize_t lfs_fs_size(lfs_t *lfs) { + LFS_TRACE("lfs_fs_size(%p)", (void*)lfs); lfs_size_t size = 0; int err = lfs_fs_traverse(lfs, lfs_fs_size_count, &size); if (err) { + LFS_TRACE("lfs_fs_size -> %"PRId32, err); return err; } - return size; + LFS_TRACE("lfs_fs_size -> %"PRId32, err); + return size; } #ifdef LFS_MIGRATE @@ -4249,9 +4448,26 @@ static int lfs1_unmount(lfs_t *lfs) { /// v1 migration /// int lfs_migrate(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; } @@ -4466,6 +4682,7 @@ int lfs_migrate(lfs_t *lfs, const struct lfs_config *cfg) { cleanup: lfs1_unmount(lfs); + LFS_TRACE("lfs_migrate -> %d", err); return err; } diff --git a/lfs_util.h b/lfs_util.h index 5a34eb3..5e29b61 100644 --- a/lfs_util.h +++ b/lfs_util.h @@ -31,7 +31,10 @@ #ifndef LFS_NO_ASSERT #include #endif -#if !defined(LFS_NO_DEBUG) || !defined(LFS_NO_WARN) || !defined(LFS_NO_ERROR) +#if !defined(LFS_NO_DEBUG) || \ + !defined(LFS_NO_WARN) || \ + !defined(LFS_NO_ERROR) || \ + defined(LFS_YES_TRACE) #include #endif @@ -46,6 +49,13 @@ extern "C" // code footprint // Logging functions +#ifdef LFS_YES_TRACE +#define LFS_TRACE(fmt, ...) \ + printf("lfs trace:%d: " fmt "\n", __LINE__, __VA_ARGS__) +#else +#define LFS_TRACE(fmt, ...) +#endif + #ifndef LFS_NO_DEBUG #define LFS_DEBUG(fmt, ...) \ printf("lfs debug:%d: " fmt "\n", __LINE__, __VA_ARGS__) From e279c8ff9043ae50b9b34468eced7c199a4a71df Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 16 Jul 2019 15:40:26 -0500 Subject: [PATCH 04/27] Tweaked debug output - Changed "No more free space" to be an error as suggested by davidefer - Tweaked output to be more parsable (no space between lfs and warn) --- lfs.c | 2 +- lfs_util.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lfs.c b/lfs.c index 4edf6b7..8ce1872 100644 --- a/lfs.c +++ b/lfs.c @@ -471,7 +471,7 @@ static int lfs_alloc(lfs_t *lfs, lfs_block_t *block) { // check if we have looked at all blocks since last ack if (lfs->free.ack == 0) { - LFS_WARN("No more free space %"PRIu32, + LFS_ERROR("No more free space %"PRIu32, lfs->free.i + lfs->free.off); return LFS_ERR_NOSPC; } diff --git a/lfs_util.h b/lfs_util.h index 5e29b61..80fab55 100644 --- a/lfs_util.h +++ b/lfs_util.h @@ -51,28 +51,28 @@ extern "C" // Logging functions #ifdef LFS_YES_TRACE #define LFS_TRACE(fmt, ...) \ - printf("lfs trace:%d: " fmt "\n", __LINE__, __VA_ARGS__) + printf("lfs_trace:%d: " fmt "\n", __LINE__, __VA_ARGS__) #else #define LFS_TRACE(fmt, ...) #endif #ifndef LFS_NO_DEBUG #define LFS_DEBUG(fmt, ...) \ - printf("lfs debug:%d: " fmt "\n", __LINE__, __VA_ARGS__) + printf("lfs_debug:%d: " fmt "\n", __LINE__, __VA_ARGS__) #else #define LFS_DEBUG(fmt, ...) #endif #ifndef LFS_NO_WARN #define LFS_WARN(fmt, ...) \ - printf("lfs warn:%d: " fmt "\n", __LINE__, __VA_ARGS__) + printf("lfs_warn:%d: " fmt "\n", __LINE__, __VA_ARGS__) #else #define LFS_WARN(fmt, ...) #endif #ifndef LFS_NO_ERROR #define LFS_ERROR(fmt, ...) \ - printf("lfs error:%d: " fmt "\n", __LINE__, __VA_ARGS__) + printf("lfs_error:%d: " fmt "\n", __LINE__, __VA_ARGS__) #else #define LFS_ERROR(fmt, ...) #endif From 52a90b8dccee821217d0baf7a4a466d4ca88c453 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 16 Jul 2019 15:55:29 -0500 Subject: [PATCH 05/27] Added asserts on positive return values from block device functions This has been a large source of porting errors, partially due to my fault in not having enough porting documentation, which is also planned. In the short term, asserts should at least help catch these types of errors instead of just letting the filesystem collapse after recieving an odd error code. --- lfs.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lfs.c b/lfs.c index 8ce1872..f7235f6 100644 --- a/lfs.c +++ b/lfs.c @@ -92,6 +92,7 @@ static int lfs_bd_read(lfs_t *lfs, lfs->cfg->cache_size); int err = lfs->cfg->read(lfs->cfg, rcache->block, rcache->off, rcache->buffer, rcache->size); + LFS_ASSERT(err <= 0); if (err) { return err; } @@ -136,6 +137,7 @@ static int lfs_bd_flush(lfs_t *lfs, lfs_size_t diff = lfs_alignup(pcache->size, lfs->cfg->prog_size); int err = lfs->cfg->prog(lfs->cfg, pcache->block, pcache->off, pcache->buffer, diff); + LFS_ASSERT(err <= 0); if (err) { return err; } @@ -170,7 +172,9 @@ static int lfs_bd_sync(lfs_t *lfs, return err; } - return lfs->cfg->sync(lfs->cfg); + err = lfs->cfg->sync(lfs->cfg); + LFS_ASSERT(err <= 0); + return err; } static int lfs_bd_prog(lfs_t *lfs, @@ -221,7 +225,9 @@ static int lfs_bd_prog(lfs_t *lfs, static int lfs_bd_erase(lfs_t *lfs, lfs_block_t block) { LFS_ASSERT(block < lfs->cfg->block_count); - return lfs->cfg->erase(lfs->cfg, block); + int err = lfs->cfg->erase(lfs->cfg, block); + LFS_ASSERT(err <= 0); + return err; } From 1aaf1cb6c06eb9cef9cd232ee41123d69e9cb79b Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 16 Jul 2019 20:53:39 -0500 Subject: [PATCH 06/27] Minor improvements to testing framework - Moved scripts into scripts folder - Removed what have been relatively unhelpful assert printing --- Makefile | 17 +++++++-- {tests => scripts}/corrupt.py | 0 {tests => scripts}/debug.py | 0 {tests => scripts}/stats.py | 0 {tests => scripts}/template.fmt | 17 --------- {tests => scripts}/test.py | 2 +- tests/test_alloc.sh | 34 +++++++++--------- tests/test_attrs.sh | 18 +++++----- tests/test_corrupt.sh | 6 ++-- tests/test_dirs.sh | 64 ++++++++++++++++----------------- tests/test_entries.sh | 18 +++++----- tests/test_files.sh | 16 ++++----- tests/test_format.sh | 14 ++++---- tests/test_interspersed.sh | 10 +++--- tests/test_move.sh | 50 +++++++++++++------------- tests/test_orphan.sh | 10 +++--- tests/test_paths.sh | 28 +++++++-------- tests/test_seek.sh | 22 ++++++------ tests/test_truncate.sh | 28 +++++++-------- 19 files changed, 174 insertions(+), 180 deletions(-) rename {tests => scripts}/corrupt.py (100%) rename {tests => scripts}/debug.py (100%) rename {tests => scripts}/stats.py (100%) rename {tests => scripts}/template.fmt (80%) rename {tests => scripts}/test.py (96%) diff --git a/Makefile b/Makefile index 364f299..d5be549 100644 --- a/Makefile +++ b/Makefile @@ -42,9 +42,20 @@ size: $(OBJ) $(SIZE) -t $^ .SUFFIXES: -test: test_format test_dirs test_files test_seek test_truncate \ - test_entries test_interspersed test_alloc test_paths test_attrs \ - test_move test_orphan test_corrupt +test: \ + test_format \ + test_dirs \ + test_files \ + test_seek \ + test_truncate \ + test_entries \ + test_interspersed \ + test_alloc \ + test_paths \ + test_attrs \ + test_move \ + test_orphan \ + test_corrupt @rm test.c test_%: tests/test_%.sh diff --git a/tests/corrupt.py b/scripts/corrupt.py similarity index 100% rename from tests/corrupt.py rename to scripts/corrupt.py diff --git a/tests/debug.py b/scripts/debug.py similarity index 100% rename from tests/debug.py rename to scripts/debug.py diff --git a/tests/stats.py b/scripts/stats.py similarity index 100% rename from tests/stats.py rename to scripts/stats.py diff --git a/tests/template.fmt b/scripts/template.fmt similarity index 80% rename from tests/template.fmt rename to scripts/template.fmt index 7fdec7c..b5ad8f8 100644 --- a/tests/template.fmt +++ b/scripts/template.fmt @@ -7,25 +7,8 @@ // test stuff -static void test_log(const char *s, uintmax_t v) {{ - printf("%s: %jd\n", s, v); -}} - static void test_assert(const char *file, unsigned line, const char *s, uintmax_t v, uintmax_t e) {{ - static const char *last[6] = {{0, 0}}; - if (v != e || !(last[0] == s || last[1] == s || - last[2] == s || last[3] == s || - last[4] == s || last[5] == s)) {{ - test_log(s, v); - last[0] = last[1]; - last[1] = last[2]; - last[2] = last[3]; - last[3] = last[4]; - last[4] = last[5]; - last[5] = s; - }} - if (v != e) {{ fprintf(stderr, "\033[31m%s:%u: assert %s failed with %jd, " "expected %jd\033[0m\n", file, line, s, v, e); diff --git a/tests/test.py b/scripts/test.py similarity index 96% rename from tests/test.py rename to scripts/test.py index 2d4f599..9d243ce 100755 --- a/tests/test.py +++ b/scripts/test.py @@ -6,7 +6,7 @@ import subprocess import os def generate(test): - with open("tests/template.fmt") as file: + with open("scripts/template.fmt") as file: template = file.read() lines = [] diff --git a/tests/test_alloc.sh b/tests/test_alloc.sh index 3f993e9..ce60652 100755 --- a/tests/test_alloc.sh +++ b/tests/test_alloc.sh @@ -3,14 +3,14 @@ set -eu echo "=== Allocator tests ===" rm -rf blocks -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; TEST SIZE=15000 lfs_mkdir() { -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "$1") => 0; lfs_unmount(&lfs) => 0; @@ -18,7 +18,7 @@ TEST } lfs_remove() { -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_remove(&lfs, "$1/eggs") => 0; lfs_remove(&lfs, "$1/bacon") => 0; @@ -29,7 +29,7 @@ TEST } lfs_alloc_singleproc() { -tests/test.py << TEST +scripts/test.py << TEST const char *names[] = {"bacon", "eggs", "pancakes"}; lfs_mount(&lfs, &cfg) => 0; for (unsigned n = 0; n < sizeof(names)/sizeof(names[0]); n++) { @@ -53,7 +53,7 @@ TEST lfs_alloc_multiproc() { for name in bacon eggs pancakes do -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "$1/$name", LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0; @@ -71,7 +71,7 @@ done lfs_verify() { for name in bacon eggs pancakes do -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "$1/$name", LFS_O_RDONLY) => 0; size = strlen("$name"); @@ -115,7 +115,7 @@ lfs_remove multiprocreuse lfs_remove singleprocreuse echo "--- Exhaustion test ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); size = strlen("exhaustion"); @@ -139,7 +139,7 @@ tests/test.py << TEST lfs_file_close(&lfs, &file[0]) => 0; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_RDONLY); size = strlen("exhaustion"); @@ -151,7 +151,7 @@ tests/test.py << TEST TEST echo "--- Exhaustion wraparound test ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_remove(&lfs, "exhaustion") => 0; @@ -186,7 +186,7 @@ tests/test.py << TEST lfs_file_close(&lfs, &file[0]) => 0; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_RDONLY); size = strlen("exhaustion"); @@ -199,7 +199,7 @@ tests/test.py << TEST TEST echo "--- Dir exhaustion test ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; // find out max file size @@ -248,7 +248,7 @@ tests/test.py << TEST TEST echo "--- Chained dir exhaustion test ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; // find out max file size @@ -317,10 +317,10 @@ TEST echo "--- Split dir test ---" rm -rf blocks -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; // create one block hole for half a directory @@ -362,7 +362,7 @@ TEST echo "--- Outdated lookahead test ---" rm -rf blocks -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; lfs_mount(&lfs, &cfg) => 0; @@ -424,7 +424,7 @@ TEST echo "--- Outdated lookahead and split dir test ---" rm -rf blocks -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; lfs_mount(&lfs, &cfg) => 0; @@ -482,4 +482,4 @@ tests/test.py << TEST TEST echo "--- Results ---" -tests/stats.py +scripts/stats.py diff --git a/tests/test_attrs.sh b/tests/test_attrs.sh index e4ff4ce..ed8c0d3 100755 --- a/tests/test_attrs.sh +++ b/tests/test_attrs.sh @@ -3,7 +3,7 @@ set -eu echo "=== Attr tests ===" rm -rf blocks -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; lfs_mount(&lfs, &cfg) => 0; @@ -17,7 +17,7 @@ tests/test.py << TEST TEST echo "--- Set/get attribute ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_setattr(&lfs, "hello", 'A', "aaaa", 4) => 0; lfs_setattr(&lfs, "hello", 'B', "bbbbbb", 6) => 0; @@ -69,7 +69,7 @@ tests/test.py << TEST lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_getattr(&lfs, "hello", 'A', buffer, 4) => 4; lfs_getattr(&lfs, "hello", 'B', buffer+4, 9) => 9; @@ -86,7 +86,7 @@ tests/test.py << TEST TEST echo "--- Set/get root attribute ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_setattr(&lfs, "/", 'A', "aaaa", 4) => 0; lfs_setattr(&lfs, "/", 'B', "bbbbbb", 6) => 0; @@ -137,7 +137,7 @@ tests/test.py << TEST lfs_getattr(&lfs, "/", 'C', buffer+10, 5) => 5; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_getattr(&lfs, "/", 'A', buffer, 4) => 4; lfs_getattr(&lfs, "/", 'B', buffer+4, 9) => 9; @@ -154,7 +154,7 @@ tests/test.py << TEST TEST echo "--- Set/get file attribute ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; struct lfs_attr attrs1[] = { {'A', buffer, 4}, @@ -229,7 +229,7 @@ tests/test.py << TEST lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; struct lfs_attr attrs2[] = { {'A', buffer, 4}, @@ -252,7 +252,7 @@ tests/test.py << TEST TEST echo "--- Deferred file attributes ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; struct lfs_attr attrs1[] = { {'B', "gggg", 4}, @@ -283,4 +283,4 @@ tests/test.py << TEST TEST echo "--- Results ---" -tests/stats.py +scripts/stats.py diff --git a/tests/test_corrupt.sh b/tests/test_corrupt.sh index 81b0674..fae3291 100755 --- a/tests/test_corrupt.sh +++ b/tests/test_corrupt.sh @@ -7,7 +7,7 @@ NAMEMULT=64 FILEMULT=1 lfs_mktree() { -tests/test.py ${1:-} << TEST +scripts/test.py ${1:-} << TEST lfs_format(&lfs, &cfg) => 0; lfs_mount(&lfs, &cfg) => 0; @@ -38,7 +38,7 @@ TEST } lfs_chktree() { -tests/test.py ${1:-} << TEST +scripts/test.py ${1:-} << TEST lfs_mount(&lfs, &cfg) => 0; for (int i = 1; i < 10; i++) { for (int j = 0; j < $NAMEMULT; j++) { @@ -115,4 +115,4 @@ lfs_mktree lfs_chktree echo "--- Results ---" -tests/stats.py +scripts/stats.py diff --git a/tests/test_dirs.sh b/tests/test_dirs.sh index 5f2020f..f73103d 100755 --- a/tests/test_dirs.sh +++ b/tests/test_dirs.sh @@ -5,12 +5,12 @@ LARGESIZE=128 echo "=== Directory tests ===" rm -rf blocks -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; TEST echo "--- Root directory ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "/") => 0; lfs_dir_close(&lfs, &dir[0]) => 0; @@ -18,14 +18,14 @@ tests/test.py << TEST TEST echo "--- Directory creation ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "potato") => 0; lfs_unmount(&lfs) => 0; TEST echo "--- File creation ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "burito", LFS_O_CREAT | LFS_O_WRONLY) => 0; lfs_file_close(&lfs, &file[0]) => 0; @@ -33,7 +33,7 @@ tests/test.py << TEST TEST echo "--- Directory iteration ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "/") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -54,7 +54,7 @@ tests/test.py << TEST TEST echo "--- Directory failures ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "potato") => LFS_ERR_EXIST; lfs_dir_open(&lfs, &dir[0], "tomato") => LFS_ERR_NOENT; @@ -65,14 +65,14 @@ tests/test.py << TEST TEST echo "--- Nested directories ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "potato/baked") => 0; lfs_mkdir(&lfs, "potato/sweet") => 0; lfs_mkdir(&lfs, "potato/fried") => 0; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "potato") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -96,7 +96,7 @@ tests/test.py << TEST TEST echo "--- Multi-block directory ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "cactus") => 0; for (int i = 0; i < $LARGESIZE; i++) { @@ -105,7 +105,7 @@ tests/test.py << TEST } lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "cactus") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -125,7 +125,7 @@ tests/test.py << TEST TEST echo "--- Directory remove ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_remove(&lfs, "potato") => LFS_ERR_NOTEMPTY; lfs_remove(&lfs, "potato/sweet") => 0; @@ -161,7 +161,7 @@ tests/test.py << TEST lfs_dir_close(&lfs, &dir[0]) => 0; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "/") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -182,7 +182,7 @@ tests/test.py << TEST TEST echo "--- Directory rename ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "coldpotato") => 0; lfs_mkdir(&lfs, "coldpotato/baked") => 0; @@ -190,12 +190,12 @@ tests/test.py << TEST lfs_mkdir(&lfs, "coldpotato/fried") => 0; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_rename(&lfs, "coldpotato", "hotpotato") => 0; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "hotpotato") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -217,7 +217,7 @@ tests/test.py << TEST lfs_dir_close(&lfs, &dir[0]) => 0; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "warmpotato") => 0; lfs_mkdir(&lfs, "warmpotato/mushy") => 0; @@ -228,7 +228,7 @@ tests/test.py << TEST lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "warmpotato") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -250,7 +250,7 @@ tests/test.py << TEST lfs_dir_close(&lfs, &dir[0]) => 0; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "coldpotato") => 0; lfs_rename(&lfs, "warmpotato/baked", "coldpotato/baked") => 0; @@ -260,7 +260,7 @@ tests/test.py << TEST lfs_remove(&lfs, "warmpotato") => 0; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "coldpotato") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -284,7 +284,7 @@ tests/test.py << TEST TEST echo "--- Recursive remove ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_remove(&lfs, "coldpotato") => LFS_ERR_NOTEMPTY; @@ -306,7 +306,7 @@ tests/test.py << TEST lfs_remove(&lfs, "coldpotato") => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "/") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -327,7 +327,7 @@ tests/test.py << TEST TEST echo "--- Multi-block rename ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; for (int i = 0; i < $LARGESIZE; i++) { sprintf((char*)buffer, "cactus/test%03d", i); @@ -336,7 +336,7 @@ tests/test.py << TEST } lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "cactus") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -356,7 +356,7 @@ tests/test.py << TEST TEST echo "--- Multi-block remove ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_remove(&lfs, "cactus") => LFS_ERR_NOTEMPTY; @@ -368,7 +368,7 @@ tests/test.py << TEST lfs_remove(&lfs, "cactus") => 0; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "/") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -386,7 +386,7 @@ tests/test.py << TEST TEST echo "--- Multi-block directory with files ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "prickly-pear") => 0; for (int i = 0; i < $LARGESIZE; i++) { @@ -400,7 +400,7 @@ tests/test.py << TEST } lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "prickly-pear") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -421,7 +421,7 @@ tests/test.py << TEST TEST echo "--- Multi-block rename with files ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; for (int i = 0; i < $LARGESIZE; i++) { sprintf((char*)buffer, "prickly-pear/test%03d", i); @@ -430,7 +430,7 @@ tests/test.py << TEST } lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "prickly-pear") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -451,7 +451,7 @@ tests/test.py << TEST TEST echo "--- Multi-block remove with files ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_remove(&lfs, "prickly-pear") => LFS_ERR_NOTEMPTY; @@ -463,7 +463,7 @@ tests/test.py << TEST lfs_remove(&lfs, "prickly-pear") => 0; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "/") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -481,4 +481,4 @@ tests/test.py << TEST TEST echo "--- Results ---" -tests/stats.py +scripts/stats.py diff --git a/tests/test_entries.sh b/tests/test_entries.sh index 4728b7f..15cae7a 100755 --- a/tests/test_entries.sh +++ b/tests/test_entries.sh @@ -30,7 +30,7 @@ TEST } echo "--- Entry grow test ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; lfs_mount(&lfs, &cfg) => 0; @@ -50,7 +50,7 @@ tests/test.py << TEST TEST echo "--- Entry shrink test ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; lfs_mount(&lfs, &cfg) => 0; @@ -70,7 +70,7 @@ tests/test.py << TEST TEST echo "--- Entry spill test ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; lfs_mount(&lfs, &cfg) => 0; @@ -87,7 +87,7 @@ tests/test.py << TEST TEST echo "--- Entry push spill test ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; lfs_mount(&lfs, &cfg) => 0; @@ -107,7 +107,7 @@ tests/test.py << TEST TEST echo "--- Entry push spill two test ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; lfs_mount(&lfs, &cfg) => 0; @@ -129,7 +129,7 @@ tests/test.py << TEST TEST echo "--- Entry drop test ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; lfs_mount(&lfs, &cfg) => 0; @@ -159,7 +159,7 @@ tests/test.py << TEST TEST echo "--- Create too big ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; lfs_mount(&lfs, &cfg) => 0; @@ -182,7 +182,7 @@ tests/test.py << TEST TEST echo "--- Resize too big ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; lfs_mount(&lfs, &cfg) => 0; @@ -218,4 +218,4 @@ tests/test.py << TEST TEST echo "--- Results ---" -tests/stats.py +scripts/stats.py diff --git a/tests/test_files.sh b/tests/test_files.sh index 5251c61..7e86ae5 100755 --- a/tests/test_files.sh +++ b/tests/test_files.sh @@ -7,12 +7,12 @@ LARGESIZE=262144 echo "=== File tests ===" rm -rf blocks -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; TEST echo "--- Simple file test ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "hello", LFS_O_WRONLY | LFS_O_CREAT) => 0; size = strlen("Hello World!\n"); @@ -29,7 +29,7 @@ tests/test.py << TEST TEST w_test() { -tests/test.py ${4:-} << TEST +scripts/test.py ${4:-} << TEST size = $1; lfs_size_t chunk = 31; srand(0); @@ -49,7 +49,7 @@ TEST } r_test() { -tests/test.py << TEST +scripts/test.py << TEST size = $1; lfs_size_t chunk = 29; srand(0); @@ -105,7 +105,7 @@ r_test $LARGESIZE largeavacado r_test 0 noavacado echo "--- Dir check ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "/") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -136,10 +136,10 @@ tests/test.py << TEST TEST echo "--- Many file test ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST // Create 300 files of 6 bytes lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "directory") => 0; @@ -155,4 +155,4 @@ tests/test.py << TEST TEST echo "--- Results ---" -tests/stats.py +scripts/stats.py diff --git a/tests/test_format.sh b/tests/test_format.sh index 5a11535..425bdb2 100755 --- a/tests/test_format.sh +++ b/tests/test_format.sh @@ -5,12 +5,12 @@ echo "=== Formatting tests ===" rm -rf blocks echo "--- Basic formatting ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; TEST echo "--- Basic mounting ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; lfs_mount(&lfs, &cfg) => 0; @@ -20,18 +20,18 @@ TEST echo "--- Invalid superblocks ---" ln -f -s /dev/zero blocks/0 ln -f -s /dev/zero blocks/1 -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => LFS_ERR_NOSPC; TEST rm blocks/0 blocks/1 echo "--- Invalid mount ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => LFS_ERR_CORRUPT; TEST echo "--- Expanding superblock ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; lfs_mount(&lfs, &cfg) => 0; for (int i = 0; i < 100; i++) { @@ -40,11 +40,11 @@ tests/test.py << TEST } lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "dummy") => 0; lfs_unmount(&lfs) => 0; TEST echo "--- Results ---" -tests/stats.py +scripts/stats.py diff --git a/tests/test_interspersed.sh b/tests/test_interspersed.sh index 52e24bc..5eead1a 100755 --- a/tests/test_interspersed.sh +++ b/tests/test_interspersed.sh @@ -3,12 +3,12 @@ set -eu echo "=== Interspersed tests ===" rm -rf blocks -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; TEST echo "--- Interspersed file test ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "a", LFS_O_WRONLY | LFS_O_CREAT) => 0; lfs_file_open(&lfs, &file[1], "b", LFS_O_WRONLY | LFS_O_CREAT) => 0; @@ -78,7 +78,7 @@ tests/test.py << TEST TEST echo "--- Interspersed remove file test ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "e", LFS_O_WRONLY | LFS_O_CREAT) => 0; @@ -124,7 +124,7 @@ tests/test.py << TEST TEST echo "--- Remove inconveniently test ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "e", LFS_O_WRONLY | LFS_O_TRUNC) => 0; lfs_file_open(&lfs, &file[1], "f", LFS_O_WRONLY | LFS_O_CREAT) => 0; @@ -183,4 +183,4 @@ tests/test.py << TEST TEST echo "--- Results ---" -tests/stats.py +scripts/stats.py diff --git a/tests/test_move.sh b/tests/test_move.sh index 458ca1e..9988887 100755 --- a/tests/test_move.sh +++ b/tests/test_move.sh @@ -3,7 +3,7 @@ set -eu echo "=== Move tests ===" rm -rf blocks -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; lfs_mount(&lfs, &cfg) => 0; @@ -26,12 +26,12 @@ tests/test.py << TEST TEST echo "--- Move file ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_rename(&lfs, "a/hello", "b/hello") => 0; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "a") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -54,13 +54,13 @@ tests/test.py << TEST TEST echo "--- Move file corrupt source ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_rename(&lfs, "b/hello", "c/hello") => 0; lfs_unmount(&lfs) => 0; TEST -tests/corrupt.py -n 1 -tests/test.py << TEST +scripts/corrupt.py -n 1 +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "b") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -81,13 +81,13 @@ tests/test.py << TEST TEST echo "--- Move file corrupt source and dest ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_rename(&lfs, "c/hello", "d/hello") => 0; lfs_unmount(&lfs) => 0; TEST -tests/corrupt.py -n 2 -tests/test.py << TEST +scripts/corrupt.py -n 2 +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "c") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -108,12 +108,12 @@ tests/test.py << TEST TEST echo "--- Move file after corrupt ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_rename(&lfs, "c/hello", "d/hello") => 0; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "c") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -134,12 +134,12 @@ tests/test.py << TEST TEST echo "--- Move dir ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_rename(&lfs, "a/hi", "b/hi") => 0; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "a") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -160,13 +160,13 @@ tests/test.py << TEST TEST echo "--- Move dir corrupt source ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_rename(&lfs, "b/hi", "c/hi") => 0; lfs_unmount(&lfs) => 0; TEST -tests/corrupt.py -n 1 -tests/test.py << TEST +scripts/corrupt.py -n 1 +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "b") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -187,13 +187,13 @@ tests/test.py << TEST TEST echo "--- Move dir corrupt source and dest ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_rename(&lfs, "c/hi", "d/hi") => 0; lfs_unmount(&lfs) => 0; TEST -tests/corrupt.py -n 2 -tests/test.py << TEST +scripts/corrupt.py -n 2 +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "c") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -216,12 +216,12 @@ tests/test.py << TEST TEST echo "--- Move dir after corrupt ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_rename(&lfs, "c/hi", "d/hi") => 0; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "c") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -244,7 +244,7 @@ tests/test.py << TEST TEST echo "--- Move check ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "a/hi") => LFS_ERR_NOENT; @@ -282,7 +282,7 @@ tests/test.py << TEST TEST echo "--- Move state stealing ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_remove(&lfs, "b") => 0; @@ -290,7 +290,7 @@ tests/test.py << TEST lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "a/hi") => LFS_ERR_NOENT; @@ -329,4 +329,4 @@ TEST echo "--- Results ---" -tests/stats.py +scripts/stats.py diff --git a/tests/test_orphan.sh b/tests/test_orphan.sh index 9c2cb7b..cf1fa9f 100755 --- a/tests/test_orphan.sh +++ b/tests/test_orphan.sh @@ -3,12 +3,12 @@ set -eu echo "=== Orphan tests ===" rm -rf blocks -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; TEST echo "--- Orphan test ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "parent") => 0; lfs_mkdir(&lfs, "parent/orphan") => 0; @@ -17,8 +17,8 @@ tests/test.py << TEST TEST # corrupt most recent commit, this should be the update to the previous # linked-list entry and should orphan the child -tests/corrupt.py -tests/test.py << TEST +scripts/corrupt.py +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_stat(&lfs, "parent/orphan", &info) => LFS_ERR_NOENT; @@ -42,4 +42,4 @@ tests/test.py << TEST TEST echo "--- Results ---" -tests/stats.py +scripts/stats.py diff --git a/tests/test_paths.sh b/tests/test_paths.sh index 3cffcfe..5389248 100755 --- a/tests/test_paths.sh +++ b/tests/test_paths.sh @@ -3,11 +3,11 @@ set -eu echo "=== Path tests ===" rm -rf blocks -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "tea") => 0; lfs_mkdir(&lfs, "coffee") => 0; @@ -25,7 +25,7 @@ tests/test.py << TEST TEST echo "--- Root path tests ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_stat(&lfs, "tea/hottea", &info) => 0; strcmp(info.name, "hottea") => 0; @@ -39,7 +39,7 @@ tests/test.py << TEST TEST echo "--- Redundant slash path tests ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_stat(&lfs, "/tea/hottea", &info) => 0; strcmp(info.name, "hottea") => 0; @@ -55,7 +55,7 @@ tests/test.py << TEST TEST echo "--- Dot path tests ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_stat(&lfs, "./tea/hottea", &info) => 0; strcmp(info.name, "hottea") => 0; @@ -73,7 +73,7 @@ tests/test.py << TEST TEST echo "--- Dot dot path tests ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_stat(&lfs, "coffee/../tea/hottea", &info) => 0; strcmp(info.name, "hottea") => 0; @@ -91,7 +91,7 @@ tests/test.py << TEST TEST echo "--- Trailing dot path tests ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_stat(&lfs, "tea/hottea/", &info) => 0; strcmp(info.name, "hottea") => 0; @@ -107,7 +107,7 @@ tests/test.py << TEST TEST echo "--- Root dot dot path tests ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_stat(&lfs, "coffee/../../../../../../tea/hottea", &info) => 0; strcmp(info.name, "hottea") => 0; @@ -119,7 +119,7 @@ tests/test.py << TEST TEST echo "--- Root tests ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_stat(&lfs, "/", &info) => 0; info.type => LFS_TYPE_DIR; @@ -140,7 +140,7 @@ tests/test.py << TEST TEST echo "--- Sketchy path tests ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "dirt/ground") => LFS_ERR_NOENT; lfs_mkdir(&lfs, "dirt/ground/earth") => LFS_ERR_NOENT; @@ -148,7 +148,7 @@ tests/test.py << TEST TEST echo "--- Superblock conflict test ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "littlefs") => 0; lfs_remove(&lfs, "littlefs") => 0; @@ -156,7 +156,7 @@ tests/test.py << TEST TEST echo "--- Max path test ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; memset(buffer, 'w', LFS_NAME_MAX+1); buffer[LFS_NAME_MAX+2] = '\0'; @@ -174,7 +174,7 @@ tests/test.py << TEST TEST echo "--- Really big path test ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; memset(buffer, 'w', LFS_NAME_MAX); buffer[LFS_NAME_MAX+1] = '\0'; @@ -198,4 +198,4 @@ tests/test.py << TEST TEST echo "--- Results ---" -tests/stats.py +scripts/stats.py diff --git a/tests/test_seek.sh b/tests/test_seek.sh index 97a6f15..83c3685 100755 --- a/tests/test_seek.sh +++ b/tests/test_seek.sh @@ -7,7 +7,7 @@ LARGESIZE=132 echo "=== Seek tests ===" rm -rf blocks -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "hello") => 0; @@ -28,7 +28,7 @@ tests/test.py << TEST TEST echo "--- Simple dir seek ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "hello") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -70,7 +70,7 @@ tests/test.py << TEST TEST echo "--- Large dir seek ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir[0], "hello") => 0; lfs_dir_read(&lfs, &dir[0], &info) => 1; @@ -112,7 +112,7 @@ tests/test.py << TEST TEST echo "--- Simple file seek ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "hello/kitty042", LFS_O_RDONLY) => 0; @@ -161,7 +161,7 @@ tests/test.py << TEST TEST echo "--- Large file seek ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "hello/kitty042", LFS_O_RDONLY) => 0; @@ -210,7 +210,7 @@ tests/test.py << TEST TEST echo "--- Simple file seek and write ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "hello/kitty042", LFS_O_RDWR) => 0; @@ -251,7 +251,7 @@ tests/test.py << TEST TEST echo "--- Large file seek and write ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "hello/kitty042", LFS_O_RDWR) => 0; @@ -294,7 +294,7 @@ tests/test.py << TEST TEST echo "--- Boundary seek and write ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "hello/kitty042", LFS_O_RDWR) => 0; @@ -322,7 +322,7 @@ tests/test.py << TEST TEST echo "--- Out-of-bounds seek ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "hello/kitty042", LFS_O_RDWR) => 0; @@ -360,7 +360,7 @@ TEST echo "--- Inline write and seek ---" for SIZE in $SMALLSIZE $MEDIUMSIZE $LARGESIZE do -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "hello/tinykitty$SIZE", LFS_O_RDWR | LFS_O_CREAT) => 0; @@ -426,4 +426,4 @@ TEST done echo "--- Results ---" -tests/stats.py +scripts/stats.py diff --git a/tests/test_truncate.sh b/tests/test_truncate.sh index c12fc0d..3810d00 100755 --- a/tests/test_truncate.sh +++ b/tests/test_truncate.sh @@ -7,12 +7,12 @@ LARGESIZE=8192 echo "=== Truncate tests ===" rm -rf blocks -tests/test.py << TEST +scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; TEST echo "--- Simple truncate ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "baldynoop", LFS_O_WRONLY | LFS_O_CREAT) => 0; @@ -27,7 +27,7 @@ tests/test.py << TEST lfs_file_close(&lfs, &file[0]) => 0; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "baldynoop", LFS_O_RDWR) => 0; lfs_file_size(&lfs, &file[0]) => $LARGESIZE; @@ -38,7 +38,7 @@ tests/test.py << TEST lfs_file_close(&lfs, &file[0]) => 0; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "baldynoop", LFS_O_RDONLY) => 0; lfs_file_size(&lfs, &file[0]) => $MEDIUMSIZE; @@ -55,7 +55,7 @@ tests/test.py << TEST TEST echo "--- Truncate and read ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "baldyread", LFS_O_WRONLY | LFS_O_CREAT) => 0; @@ -70,7 +70,7 @@ tests/test.py << TEST lfs_file_close(&lfs, &file[0]) => 0; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "baldyread", LFS_O_RDWR) => 0; lfs_file_size(&lfs, &file[0]) => $LARGESIZE; @@ -88,7 +88,7 @@ tests/test.py << TEST lfs_file_close(&lfs, &file[0]) => 0; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "baldyread", LFS_O_RDONLY) => 0; lfs_file_size(&lfs, &file[0]) => $MEDIUMSIZE; @@ -105,7 +105,7 @@ tests/test.py << TEST TEST echo "--- Truncate and write ---" -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "baldywrite", LFS_O_WRONLY | LFS_O_CREAT) => 0; @@ -120,7 +120,7 @@ tests/test.py << TEST lfs_file_close(&lfs, &file[0]) => 0; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "baldywrite", LFS_O_RDWR) => 0; lfs_file_size(&lfs, &file[0]) => $LARGESIZE; @@ -138,7 +138,7 @@ tests/test.py << TEST lfs_file_close(&lfs, &file[0]) => 0; lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file[0], "baldywrite", LFS_O_RDONLY) => 0; lfs_file_size(&lfs, &file[0]) => $MEDIUMSIZE; @@ -160,7 +160,7 @@ STARTSIZES="$1" STARTSEEKS="$2" HOTSIZES="$3" COLDSIZES="$4" -tests/test.py << TEST +scripts/test.py << TEST static const lfs_off_t startsizes[] = {$STARTSIZES}; static const lfs_off_t startseeks[] = {$STARTSEEKS}; static const lfs_off_t hotsizes[] = {$HOTSIZES}; @@ -192,7 +192,7 @@ tests/test.py << TEST lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST static const lfs_off_t startsizes[] = {$STARTSIZES}; static const lfs_off_t hotsizes[] = {$HOTSIZES}; static const lfs_off_t coldsizes[] = {$COLDSIZES}; @@ -224,7 +224,7 @@ tests/test.py << TEST lfs_unmount(&lfs) => 0; TEST -tests/test.py << TEST +scripts/test.py << TEST static const lfs_off_t startsizes[] = {$STARTSIZES}; static const lfs_off_t hotsizes[] = {$HOTSIZES}; static const lfs_off_t coldsizes[] = {$COLDSIZES}; @@ -299,4 +299,4 @@ truncate_test \ "2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE" echo "--- Results ---" -tests/stats.py +scripts/stats.py From 53a6e0471215b680426f97d9afce241d739ee49d Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 17 Jul 2019 17:05:20 -0500 Subject: [PATCH 07/27] Changed block_cycles disable from 0 to -1 As it is now, block_cycles = 0 disables wear leveling. This was a mistake as 0 is the "default" value for several other config options. It's even worse when migrating from v1 as it's easy to miss the addition of block_cycles and end up with a filesystem that is not actually wear-leveling. Clearly, block_cycles = 0 should do anything but disable wear-leveling. Here, I've changed block_cycles = 0 to assert. Forcing users to set a value for block_cycles (500 is suggested). block_cycles can be set to -1 to explicitly disable wear leveling if desired. --- lfs.c | 8 +++++--- lfs.h | 9 ++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lfs.c b/lfs.c index c554135..0417202 100644 --- a/lfs.c +++ b/lfs.c @@ -1453,7 +1453,7 @@ static int lfs_dir_compact(lfs_t *lfs, // increment revision count dir->rev += 1; - if (lfs->cfg->block_cycles && + if (lfs->cfg->block_cycles > 0 && (dir->rev % (lfs->cfg->block_cycles+1) == 0)) { if (lfs_pair_cmp(dir->pair, (const lfs_block_t[2]){0, 1}) == 0) { // oh no! we're writing too much to the superblock, @@ -3192,8 +3192,10 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) { LFS_ASSERT(4*lfs_npw2(0xffffffff / (lfs->cfg->block_size-2*4)) <= lfs->cfg->block_size); - // we don't support some corner cases - LFS_ASSERT(lfs->cfg->block_cycles < 0xffffffff); + // block_cycles = 0 is no longer supported, must either set a number + // of erase cycles before moving logs to another block (~500 suggested), + // or explicitly disable wear-leveling with -1. + LFS_ASSERT(lfs->cfg->block_cycles != 0); // setup read cache if (lfs->cfg->read_buffer) { diff --git a/lfs.h b/lfs.h index c78b3d6..276b5a5 100644 --- a/lfs.h +++ b/lfs.h @@ -190,9 +190,12 @@ struct lfs_config { // Number of erasable blocks on the device. lfs_size_t block_count; - // Number of erase cycles before we should move data to another block. - // May be zero, in which case no block-level wear-leveling is performed. - uint32_t block_cycles; + // Number of erase cycles before we should move logs to another block. + // Suggested values are in the range 100-1000, with large values having + // better performance at the cost of less consistent wear distribution. + // + // Set to -1 to disable block-level wear-leveling. + int32_t block_cycles; // Size of block caches. Each cache buffers a portion of a block in RAM. // The littlefs needs a read cache, a program cache, and one additional From df2e676562aec4db2f979da1ecc8b9e3bcc2ea44 Mon Sep 17 00:00:00 2001 From: Ar2rL Date: Sun, 21 Jul 2019 11:34:14 +0200 Subject: [PATCH 08/27] Add necessary flag to mark file as being opened. --- lfs.h | 1 + 1 file changed, 1 insertion(+) diff --git a/lfs.h b/lfs.h index c78b3d6..9577a17 100644 --- a/lfs.h +++ b/lfs.h @@ -136,6 +136,7 @@ enum lfs_open_flags { LFS_F_READING = 0x040000, // File has been read since last flush LFS_F_ERRED = 0x080000, // An error occured during write LFS_F_INLINE = 0x100000, // Currently inlined in directory entry + LFS_F_OPENED = 0x200000, // File has been opened }; // File seek flags From 72a3758958d7773e90ffed75d2e25df9365d2a9c Mon Sep 17 00:00:00 2001 From: Ar2rL Date: Sun, 21 Jul 2019 11:34:53 +0200 Subject: [PATCH 09/27] Use LFS_F_OPENED flag to protect against use of not opened or closed file. --- lfs.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/lfs.c b/lfs.c index c554135..a3cb85b 100644 --- a/lfs.c +++ b/lfs.c @@ -2248,6 +2248,9 @@ static int lfs_ctz_traverse(lfs_t *lfs, int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file, const char *path, int flags, const struct lfs_file_config *cfg) { + // do not allow open for already opened file + LFS_ASSERT(0 == (file->flags & LFS_F_OPENED)); + // deorphan if we haven't yet, needed at most once after poweron if ((flags & 3) != LFS_O_RDONLY) { int err = lfs_fs_forceconsistency(lfs); @@ -2381,6 +2384,8 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file, } } + file->flags |= LFS_F_OPENED; + return 0; cleanup: @@ -2397,6 +2402,8 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file, } int lfs_file_close(lfs_t *lfs, lfs_file_t *file) { + LFS_ASSERT(file->flags & LFS_F_OPENED); + int err = lfs_file_sync(lfs, file); // remove from list of mdirs @@ -2412,10 +2419,14 @@ int lfs_file_close(lfs_t *lfs, lfs_file_t *file) { lfs_free(file->cache.buffer); } + file->flags &= ~LFS_F_OPENED; + return err; } static int lfs_file_relocate(lfs_t *lfs, lfs_file_t *file) { + LFS_ASSERT(file->flags & LFS_F_OPENED); + while (true) { // just relocate what exists into new block lfs_block_t nblock; @@ -2486,6 +2497,8 @@ relocate: } static int lfs_file_flush(lfs_t *lfs, lfs_file_t *file) { + LFS_ASSERT(file->flags & LFS_F_OPENED); + if (file->flags & LFS_F_READING) { if (!(file->flags & LFS_F_INLINE)) { lfs_cache_drop(lfs, &file->cache); @@ -2564,6 +2577,8 @@ relocate: } int lfs_file_sync(lfs_t *lfs, lfs_file_t *file) { + LFS_ASSERT(file->flags & LFS_F_OPENED); + while (true) { int err = lfs_file_flush(lfs, file); if (err) { @@ -2628,6 +2643,8 @@ lfs_ssize_t lfs_file_read(lfs_t *lfs, lfs_file_t *file, uint8_t *data = buffer; lfs_size_t nsize = size; + LFS_ASSERT(file->flags & LFS_F_OPENED); + if ((file->flags & 3) == LFS_O_WRONLY) { return LFS_ERR_BADF; } @@ -2701,6 +2718,8 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, const uint8_t *data = buffer; lfs_size_t nsize = size; + LFS_ASSERT(file->flags & LFS_F_OPENED); + if ((file->flags & 3) == LFS_O_RDONLY) { return LFS_ERR_BADF; } @@ -2821,6 +2840,8 @@ relocate: lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file, lfs_soff_t off, int 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) { @@ -2848,6 +2869,8 @@ lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file, } int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { + LFS_ASSERT(file->flags & LFS_F_OPENED); + if ((file->flags & 3) == LFS_O_RDONLY) { return LFS_ERR_BADF; } @@ -2906,6 +2929,7 @@ int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { lfs_soff_t lfs_file_tell(lfs_t *lfs, lfs_file_t *file) { (void)lfs; + LFS_ASSERT(file->flags & LFS_F_OPENED); return file->pos; } @@ -2920,6 +2944,7 @@ int lfs_file_rewind(lfs_t *lfs, lfs_file_t *file) { lfs_soff_t lfs_file_size(lfs_t *lfs, lfs_file_t *file) { (void)lfs; + LFS_ASSERT(file->flags & LFS_F_OPENED); if (file->flags & LFS_F_WRITING) { return lfs_max(file->pos, file->ctz.size); } else { @@ -3324,7 +3349,7 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) { }; lfs_superblock_tole32(&superblock); - err = lfs_dir_commit(lfs, &root, LFS_MKATTRS( + err = lfs_dir_commit(lfs, &root, LFS_MKATTRS( {LFS_MKTAG(LFS_TYPE_CREATE, 0, 0), NULL}, {LFS_MKTAG(LFS_TYPE_SUPERBLOCK, 0, 8), "littlefs"}, {LFS_MKTAG(LFS_TYPE_INLINESTRUCT, 0, sizeof(superblock)), @@ -4311,7 +4336,7 @@ int lfs_migrate(lfs_t *lfs, const struct lfs_config *cfg) { entry1.d.type &= ~0x80; } - + // also fetch name char name[LFS_NAME_MAX+1]; memset(name, 0, sizeof(name)); From 7e1bad3eeeb41edd19a8c0cd70a4d1f36742ffbf Mon Sep 17 00:00:00 2001 From: Ar2rL Date: Sun, 21 Jul 2019 14:36:40 +0200 Subject: [PATCH 10/27] Set LFS_F_OPENED flag at places required by lfs internal logic. --- lfs.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lfs.c b/lfs.c index a3cb85b..bccc4ac 100644 --- a/lfs.c +++ b/lfs.c @@ -2262,7 +2262,7 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file, // setup simple file details int err; file->cfg = cfg; - file->flags = flags; + file->flags = flags | LFS_F_OPENED; file->pos = 0; file->cache.buffer = NULL; @@ -2384,8 +2384,6 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file, } } - file->flags |= LFS_F_OPENED; - return 0; cleanup: @@ -2514,7 +2512,7 @@ static int lfs_file_flush(lfs_t *lfs, lfs_file_t *file) { lfs_file_t orig = { .ctz.head = file->ctz.head, .ctz.size = file->ctz.size, - .flags = LFS_O_RDONLY, + .flags = LFS_O_RDONLY | LFS_F_OPENED, .pos = file->pos, .cache = lfs->rcache, }; From eb013e6dd6e1cb26e430c632c762436a81a11522 Mon Sep 17 00:00:00 2001 From: "Peter A. Bigot" Date: Tue, 23 Jul 2019 11:05:04 -0500 Subject: [PATCH 11/27] lfs: correct documentation on lookahead-related values The size of the lookahead buffer is required to be a multiple of 8 bytes in anticipation of a future improvement. The buffer itself need only be aligned to support access through a uint32_t pointer. Signed-off-by: Peter A. Bigot --- lfs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lfs.h b/lfs.h index c78b3d6..d09124b 100644 --- a/lfs.h +++ b/lfs.h @@ -204,7 +204,7 @@ struct lfs_config { // Size of the lookahead buffer in bytes. A larger lookahead buffer // increases the number of blocks found during an allocation pass. The // lookahead buffer is stored as a compact bitmap, so each byte of RAM - // can track 8 blocks. Must be a multiple of 4. + // can track 8 blocks. Must be a multiple of 8. lfs_size_t lookahead_size; // Optional statically allocated read buffer. Must be cache_size. @@ -216,7 +216,7 @@ struct lfs_config { void *prog_buffer; // Optional statically allocated lookahead buffer. Must be lookahead_size - // and aligned to a 64-bit boundary. By default lfs_malloc is used to + // and aligned to a 32-bit boundary. By default lfs_malloc is used to // allocate this buffer. void *lookahead_buffer; From 649640c605a41fb1a8cb4cbaa4a620e9edbedbd6 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 31 May 2019 06:42:15 -0500 Subject: [PATCH 12/27] Fixed workaround for erase sizes >1024 B Introduced in 0b76635, the workaround for erases sizes >1024 is to commit with an unaligned CRC tag. Upon reading an unaligned CRC, littlefs should treat the metadata pair as "requires erased". While necessary for portability, this also lets us workaround the lack of handling of erases sizes >1024. Unfortunately, this workaround wasn't implemented correctly (by me) in the case that the metadata-pair does not immediately compact. This is solved here by added the erase check to lfs_dir_commit. Note this is still only a part of a workaround which should be replaced. One potential solution is to pad the commit with multiple smaller CRC tags until we reach the next prog_size boundary. found by kazink --- lfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lfs.c b/lfs.c index c554135..af3a5d7 100644 --- a/lfs.c +++ b/lfs.c @@ -1247,7 +1247,7 @@ static int lfs_dir_commitcrc(lfs_t *lfs, struct lfs_commit *commit) { // build crc tag bool reset = ~lfs_frombe32(tag) >> 31; tag = LFS_MKTAG(LFS_TYPE_CRC + reset, 0x3ff, - off - (commit->off+sizeof(lfs_tag_t))); + lfs_min(off - (commit->off+sizeof(lfs_tag_t)), 0x3fe)); // write out crc uint32_t footer[2]; @@ -1760,6 +1760,8 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_mdir_t *dir, // successful commit, update dir dir->off = commit.off; dir->etag = commit.ptag; + // workaround to handle prog_size >1024 + dir->erased = (dir->off % lfs->cfg->prog_size == 0); // note we able to have already handled move here if (lfs_gstate_hasmovehere(&lfs->gpending, dir->pair)) { From 72e3bb44482e417d8a0408ecd16cb7ef96a6c2fc Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 26 Jul 2019 11:11:34 -0500 Subject: [PATCH 13/27] Refactored a handful of things in tests - Now test errors have correct line reporting! #line directives are passed to the compiler that reference the relevant line in the test case shell script. --- Multi-block directory --- ./tests/test_dirs.sh:109: assert failed with 0, expected 1 lfs_unmount(&lfs) => 1 - Cleaned up the number of implicit global variables provided to tests. A lot of these were infrequently used and made it difficult to remember what was provided. This isn't an MCU, so there's very little cost to stack allocations when needed. - Minimized the results.py script (previously stats.py) output to match minimization of test output. --- emubd/lfs_emubd.c | 6 +- scripts/results.py | 28 +++ scripts/stats.py | 30 --- scripts/template.fmt | 27 ++- scripts/test.py | 52 ++++-- tests/test_alloc.sh | 219 +++++++++++----------- tests/test_attrs.sh | 88 +++++---- tests/test_corrupt.sh | 22 ++- tests/test_dirs.sh | 289 ++++++++++++++-------------- tests/test_entries.sh | 102 ++++++---- tests/test_files.sh | 72 +++---- tests/test_format.sh | 5 +- tests/test_interspersed.sh | 150 +++++++-------- tests/test_move.sh | 257 ++++++++++++------------- tests/test_orphan.sh | 5 +- tests/test_paths.sh | 55 +++--- tests/test_seek.sh | 374 +++++++++++++++++++------------------ tests/test_truncate.sh | 166 ++++++++-------- 18 files changed, 1011 insertions(+), 936 deletions(-) create mode 100755 scripts/results.py delete mode 100755 scripts/stats.py diff --git a/emubd/lfs_emubd.c b/emubd/lfs_emubd.c index 374c51c..943ddfb 100644 --- a/emubd/lfs_emubd.c +++ b/emubd/lfs_emubd.c @@ -197,7 +197,7 @@ int lfs_emubd_read(const struct lfs_config *cfg, lfs_block_t block, } } - emu->stats.read_count += 1; + emu->stats.read_count += size; LFS_TRACE("lfs_emubd_read -> %d", 0); return 0; } @@ -270,7 +270,7 @@ int lfs_emubd_prog(const struct lfs_config *cfg, lfs_block_t block, emu->history.blocks[0] = block; } - emu->stats.prog_count += 1; + emu->stats.prog_count += size; LFS_TRACE("lfs_emubd_prog -> %d", 0); return 0; } @@ -317,7 +317,7 @@ int lfs_emubd_erase(const struct lfs_config *cfg, lfs_block_t block) { } } - emu->stats.erase_count += 1; + emu->stats.erase_count += cfg->block_size; LFS_TRACE("lfs_emubd_erase -> %d", 0); return 0; } diff --git a/scripts/results.py b/scripts/results.py new file mode 100755 index 0000000..0e5cfc6 --- /dev/null +++ b/scripts/results.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python2 + +import struct +import sys +import time +import os +import re + +def main(): + with open('blocks/.config') as file: + read_size, prog_size, block_size, block_count = ( + struct.unpack(' " #e, v, e) +// implicit variable for asserts +uintmax_t test; // utility functions for traversals static int __attribute__((used)) test_count(void *p, lfs_block_t b) {{ @@ -27,23 +31,17 @@ static int __attribute__((used)) test_count(void *p, lfs_block_t b) {{ return 0; }} - // lfs declarations lfs_t lfs; lfs_emubd_t bd; -lfs_file_t file[4]; -lfs_dir_t dir[4]; +// other declarations for convenience +lfs_file_t file; +lfs_dir_t dir; struct lfs_info info; - uint8_t buffer[1024]; -uint8_t wbuffer[1024]; -uint8_t rbuffer[1024]; -lfs_size_t size; -lfs_size_t wsize; -lfs_size_t rsize; - -uintmax_t test; +char path[1024]; +// test configuration options #ifndef LFS_READ_SIZE #define LFS_READ_SIZE 16 #endif @@ -94,6 +92,5 @@ int main(void) {{ lfs_emubd_create(&cfg, "blocks"); {tests} - lfs_emubd_destroy(&cfg); }} diff --git a/scripts/test.py b/scripts/test.py index 9d243ce..3135c65 100755 --- a/scripts/test.py +++ b/scripts/test.py @@ -5,24 +5,36 @@ import sys import subprocess import os + def generate(test): with open("scripts/template.fmt") as file: template = file.read() + haslines = 'TEST_LINE' in os.environ and 'TEST_FILE' in os.environ + lines = [] - for line in re.split('(?<=(?:.;| [{}]))\n', test.read()): - match = re.match('(?: *\n)*( *)(.*)=>(.*);', line, re.DOTALL | re.MULTILINE) + for offset, line in enumerate( + re.split('(?<=(?:.;| [{}]))\n', test.read())): + match = re.match('((?: *\n)*)( *)(.*)=>(.*);', + line, re.DOTALL | re.MULTILINE) if match: - tab, test, expect = match.groups() - lines.append(tab+'test = {test};'.format(test=test.strip())) - lines.append(tab+'test_assert("{name}", test, {expect});'.format( - name = re.match('\w*', test.strip()).group(), - expect = expect.strip())) + preface, tab, test, expect = match.groups() + lines.extend(['']*preface.count('\n')) + lines.append(tab+'test_assert({test}, {expect});'.format( + test=test.strip(), expect=expect.strip())) else: lines.append(line) # Create test file with open('test.c', 'w') as file: + if 'TEST_LINE' in os.environ and 'TEST_FILE' in os.environ: + lines.insert(0, '#line %d "%s"' % ( + int(os.environ['TEST_LINE']) + 1, + os.environ['TEST_FILE'])) + lines.append('#line %d "test.c"' % ( + template[:template.find('{tests}')].count('\n') + + len(lines) + 2)) + file.write(template.format(tests='\n'.join(lines))) # Remove build artifacts to force rebuild @@ -44,18 +56,26 @@ def execute(): subprocess.check_call(["./lfs"]) def main(test=None): - if test and not test.startswith('-'): - with open(test) as file: - generate(file) - else: - generate(sys.stdin) + try: + if test and not test.startswith('-'): + with open(test) as file: + generate(file) + else: + generate(sys.stdin) - compile() + compile() - if test == '-s': - sys.exit(1) + if test == '-s': + sys.exit(1) - execute() + execute() + + except subprocess.CalledProcessError: + # Python stack trace is counterproductive, just exit + sys.exit(2) + except KeyboardInterrupt: + # Python stack trace is counterproductive, just exit + sys.exit(3) if __name__ == "__main__": main(*sys.argv[1:]) diff --git a/tests/test_alloc.sh b/tests/test_alloc.sh index ce60652..d9f233b 100755 --- a/tests/test_alloc.sh +++ b/tests/test_alloc.sh @@ -1,5 +1,7 @@ #!/bin/bash -set -eu +set -euE +export TEST_FILE=$0 +trap 'export TEST_LINE=$LINENO' DEBUG echo "=== Allocator tests ===" rm -rf blocks @@ -31,20 +33,21 @@ TEST lfs_alloc_singleproc() { scripts/test.py << TEST const char *names[] = {"bacon", "eggs", "pancakes"}; + lfs_file_t files[sizeof(names)/sizeof(names[0])]; lfs_mount(&lfs, &cfg) => 0; for (unsigned n = 0; n < sizeof(names)/sizeof(names[0]); n++) { - sprintf((char*)buffer, "$1/%s", names[n]); - lfs_file_open(&lfs, &file[n], (char*)buffer, + sprintf(path, "$1/%s", names[n]); + lfs_file_open(&lfs, &files[n], path, LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0; } for (unsigned n = 0; n < sizeof(names)/sizeof(names[0]); n++) { - size = strlen(names[n]); + lfs_size_t size = strlen(names[n]); for (int i = 0; i < $SIZE; i++) { - lfs_file_write(&lfs, &file[n], names[n], size) => size; + lfs_file_write(&lfs, &files[n], names[n], size) => size; } } for (unsigned n = 0; n < sizeof(names)/sizeof(names[0]); n++) { - lfs_file_close(&lfs, &file[n]) => 0; + lfs_file_close(&lfs, &files[n]) => 0; } lfs_unmount(&lfs) => 0; TEST @@ -55,14 +58,14 @@ for name in bacon eggs pancakes do scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "$1/$name", + lfs_file_open(&lfs, &file, "$1/$name", LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0; - size = strlen("$name"); + lfs_size_t size = strlen("$name"); memcpy(buffer, "$name", size); for (int i = 0; i < $SIZE; i++) { - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_write(&lfs, &file, buffer, size) => size; } - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST done @@ -73,13 +76,13 @@ for name in bacon eggs pancakes do scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "$1/$name", LFS_O_RDONLY) => 0; - size = strlen("$name"); + lfs_file_open(&lfs, &file, "$1/$name", LFS_O_RDONLY) => 0; + lfs_size_t size = strlen("$name"); for (int i = 0; i < $SIZE; i++) { - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "$name", size) => 0; } - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST done @@ -117,17 +120,17 @@ lfs_remove singleprocreuse echo "--- Exhaustion test ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); - size = strlen("exhaustion"); + lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); + lfs_size_t size = strlen("exhaustion"); memcpy(buffer, "exhaustion", size); - lfs_file_write(&lfs, &file[0], buffer, size) => size; - lfs_file_sync(&lfs, &file[0]) => 0; + lfs_file_write(&lfs, &file, buffer, size) => size; + lfs_file_sync(&lfs, &file) => 0; size = strlen("blahblahblahblah"); memcpy(buffer, "blahblahblahblah", size); lfs_ssize_t res; while (true) { - res = lfs_file_write(&lfs, &file[0], buffer, size); + res = lfs_file_write(&lfs, &file, buffer, size); if (res < 0) { break; } @@ -136,17 +139,17 @@ scripts/test.py << TEST } res => LFS_ERR_NOSPC; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_RDONLY); - size = strlen("exhaustion"); - lfs_file_size(&lfs, &file[0]) => size; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_open(&lfs, &file, "exhaustion", LFS_O_RDONLY); + lfs_size_t size = strlen("exhaustion"); + lfs_file_size(&lfs, &file) => size; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "exhaustion", size) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST @@ -155,26 +158,26 @@ scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_remove(&lfs, "exhaustion") => 0; - lfs_file_open(&lfs, &file[0], "padding", LFS_O_WRONLY | LFS_O_CREAT); - size = strlen("buffering"); + lfs_file_open(&lfs, &file, "padding", LFS_O_WRONLY | LFS_O_CREAT); + lfs_size_t size = strlen("buffering"); memcpy(buffer, "buffering", size); for (int i = 0; i < $SIZE; i++) { - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_write(&lfs, &file, buffer, size) => size; } - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_remove(&lfs, "padding") => 0; - lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); + lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); size = strlen("exhaustion"); memcpy(buffer, "exhaustion", size); - lfs_file_write(&lfs, &file[0], buffer, size) => size; - lfs_file_sync(&lfs, &file[0]) => 0; + lfs_file_write(&lfs, &file, buffer, size) => size; + lfs_file_sync(&lfs, &file) => 0; size = strlen("blahblahblahblah"); memcpy(buffer, "blahblahblahblah", size); lfs_ssize_t res; while (true) { - res = lfs_file_write(&lfs, &file[0], buffer, size); + res = lfs_file_write(&lfs, &file, buffer, size); if (res < 0) { break; } @@ -183,17 +186,17 @@ scripts/test.py << TEST } res => LFS_ERR_NOSPC; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_RDONLY); - size = strlen("exhaustion"); - lfs_file_size(&lfs, &file[0]) => size; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_open(&lfs, &file, "exhaustion", LFS_O_RDONLY); + lfs_size_t size = strlen("exhaustion"); + lfs_file_size(&lfs, &file) => size; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "exhaustion", size) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_remove(&lfs, "exhaustion") => 0; lfs_unmount(&lfs) => 0; TEST @@ -204,13 +207,13 @@ scripts/test.py << TEST // find out max file size lfs_mkdir(&lfs, "exhaustiondir") => 0; - size = strlen("blahblahblahblah"); + lfs_size_t size = strlen("blahblahblahblah"); memcpy(buffer, "blahblahblahblah", size); - lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); + lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); int count = 0; int err; while (true) { - err = lfs_file_write(&lfs, &file[0], buffer, size); + err = lfs_file_write(&lfs, &file, buffer, size); if (err < 0) { break; } @@ -218,28 +221,28 @@ scripts/test.py << TEST count += 1; } err => LFS_ERR_NOSPC; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_remove(&lfs, "exhaustion") => 0; lfs_remove(&lfs, "exhaustiondir") => 0; // see if dir fits with max file size - lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); + lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); for (int i = 0; i < count; i++) { - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_write(&lfs, &file, buffer, size) => size; } - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_mkdir(&lfs, "exhaustiondir") => 0; lfs_remove(&lfs, "exhaustiondir") => 0; lfs_remove(&lfs, "exhaustion") => 0; // see if dir fits with > max file size - lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); + lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); for (int i = 0; i < count+1; i++) { - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_write(&lfs, &file, buffer, size) => size; } - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_mkdir(&lfs, "exhaustiondir") => LFS_ERR_NOSPC; @@ -254,16 +257,16 @@ scripts/test.py << TEST // find out max file size lfs_mkdir(&lfs, "exhaustiondir") => 0; for (int i = 0; i < 10; i++) { - sprintf((char*)buffer, "dirwithanexhaustivelylongnameforpadding%d", i); - lfs_mkdir(&lfs, (char*)buffer) => 0; + sprintf(path, "dirwithanexhaustivelylongnameforpadding%d", i); + lfs_mkdir(&lfs, path) => 0; } - size = strlen("blahblahblahblah"); + lfs_size_t size = strlen("blahblahblahblah"); memcpy(buffer, "blahblahblahblah", size); - lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); + lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); int count = 0; int err; while (true) { - err = lfs_file_write(&lfs, &file[0], buffer, size); + err = lfs_file_write(&lfs, &file, buffer, size); if (err < 0) { break; } @@ -271,25 +274,25 @@ scripts/test.py << TEST count += 1; } err => LFS_ERR_NOSPC; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_remove(&lfs, "exhaustion") => 0; lfs_remove(&lfs, "exhaustiondir") => 0; for (int i = 0; i < 10; i++) { - sprintf((char*)buffer, "dirwithanexhaustivelylongnameforpadding%d", i); - lfs_remove(&lfs, (char*)buffer) => 0; + sprintf(path, "dirwithanexhaustivelylongnameforpadding%d", i); + lfs_remove(&lfs, path) => 0; } // see that chained dir fails - lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); + lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); for (int i = 0; i < count+1; i++) { - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_write(&lfs, &file, buffer, size) => size; } - lfs_file_sync(&lfs, &file[0]) => 0; + lfs_file_sync(&lfs, &file) => 0; for (int i = 0; i < 10; i++) { - sprintf((char*)buffer, "dirwithanexhaustivelylongnameforpadding%d", i); - lfs_mkdir(&lfs, (char*)buffer) => 0; + sprintf(path, "dirwithanexhaustivelylongnameforpadding%d", i); + lfs_mkdir(&lfs, path) => 0; } lfs_mkdir(&lfs, "exhaustiondir") => LFS_ERR_NOSPC; @@ -301,22 +304,21 @@ scripts/test.py << TEST break; } - lfs_ssize_t filesize = lfs_file_size(&lfs, &file[0]); + lfs_ssize_t filesize = lfs_file_size(&lfs, &file); filesize > 0 => true; - lfs_file_truncate(&lfs, &file[0], filesize - size) => 0; - lfs_file_sync(&lfs, &file[0]) => 0; + lfs_file_truncate(&lfs, &file, filesize - size) => 0; + lfs_file_sync(&lfs, &file) => 0; } err => 0; lfs_mkdir(&lfs, "exhaustiondir2") => LFS_ERR_NOSPC; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST echo "--- Split dir test ---" -rm -rf blocks scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; TEST @@ -324,22 +326,22 @@ scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; // create one block hole for half a directory - lfs_file_open(&lfs, &file[0], "bump", LFS_O_WRONLY | LFS_O_CREAT) => 0; + lfs_file_open(&lfs, &file, "bump", LFS_O_WRONLY | LFS_O_CREAT) => 0; for (lfs_size_t i = 0; i < cfg.block_size; i += 2) { memcpy(&buffer[i], "hi", 2); } - lfs_file_write(&lfs, &file[0], buffer, cfg.block_size) => cfg.block_size; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_write(&lfs, &file, buffer, cfg.block_size) => cfg.block_size; + lfs_file_close(&lfs, &file) => 0; - lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); - size = strlen("blahblahblahblah"); + lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); + lfs_size_t size = strlen("blahblahblahblah"); memcpy(buffer, "blahblahblahblah", size); for (lfs_size_t i = 0; i < (cfg.block_count-4)*(cfg.block_size-8); i += size) { - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_write(&lfs, &file, buffer, size) => size; } - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; // remount to force reset of lookahead lfs_unmount(&lfs) => 0; @@ -349,137 +351,134 @@ scripts/test.py << TEST lfs_remove(&lfs, "bump") => 0; lfs_mkdir(&lfs, "splitdir") => 0; - lfs_file_open(&lfs, &file[0], "splitdir/bump", + lfs_file_open(&lfs, &file, "splitdir/bump", LFS_O_WRONLY | LFS_O_CREAT) => 0; for (lfs_size_t i = 0; i < cfg.block_size; i += 2) { memcpy(&buffer[i], "hi", 2); } - lfs_file_write(&lfs, &file[0], buffer, 2*cfg.block_size) => LFS_ERR_NOSPC; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_write(&lfs, &file, buffer, 2*cfg.block_size) => LFS_ERR_NOSPC; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST echo "--- Outdated lookahead test ---" -rm -rf blocks scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; lfs_mount(&lfs, &cfg) => 0; // fill completely with two files - lfs_file_open(&lfs, &file[0], "exhaustion1", + lfs_file_open(&lfs, &file, "exhaustion1", LFS_O_WRONLY | LFS_O_CREAT) => 0; - size = strlen("blahblahblahblah"); + lfs_size_t size = strlen("blahblahblahblah"); memcpy(buffer, "blahblahblahblah", size); for (lfs_size_t i = 0; i < ((cfg.block_count-2)/2)*(cfg.block_size-8); i += size) { - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_write(&lfs, &file, buffer, size) => size; } - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; - lfs_file_open(&lfs, &file[0], "exhaustion2", + lfs_file_open(&lfs, &file, "exhaustion2", LFS_O_WRONLY | LFS_O_CREAT) => 0; size = strlen("blahblahblahblah"); memcpy(buffer, "blahblahblahblah", size); for (lfs_size_t i = 0; i < ((cfg.block_count-2+1)/2)*(cfg.block_size-8); i += size) { - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_write(&lfs, &file, buffer, size) => size; } - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; // remount to force reset of lookahead lfs_unmount(&lfs) => 0; lfs_mount(&lfs, &cfg) => 0; // rewrite one file - lfs_file_open(&lfs, &file[0], "exhaustion1", + lfs_file_open(&lfs, &file, "exhaustion1", LFS_O_WRONLY | LFS_O_TRUNC) => 0; - lfs_file_sync(&lfs, &file[0]) => 0; + lfs_file_sync(&lfs, &file) => 0; size = strlen("blahblahblahblah"); memcpy(buffer, "blahblahblahblah", size); for (lfs_size_t i = 0; i < ((cfg.block_count-2)/2)*(cfg.block_size-8); i += size) { - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_write(&lfs, &file, buffer, size) => size; } - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; // rewrite second file, this requires lookahead does not // use old population - lfs_file_open(&lfs, &file[0], "exhaustion2", + lfs_file_open(&lfs, &file, "exhaustion2", LFS_O_WRONLY | LFS_O_TRUNC) => 0; - lfs_file_sync(&lfs, &file[0]) => 0; + lfs_file_sync(&lfs, &file) => 0; size = strlen("blahblahblahblah"); memcpy(buffer, "blahblahblahblah", size); for (lfs_size_t i = 0; i < ((cfg.block_count-2+1)/2)*(cfg.block_size-8); i += size) { - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_write(&lfs, &file, buffer, size) => size; } - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; TEST echo "--- Outdated lookahead and split dir test ---" -rm -rf blocks scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; lfs_mount(&lfs, &cfg) => 0; // fill completely with two files - lfs_file_open(&lfs, &file[0], "exhaustion1", + lfs_file_open(&lfs, &file, "exhaustion1", LFS_O_WRONLY | LFS_O_CREAT) => 0; - size = strlen("blahblahblahblah"); + lfs_size_t size = strlen("blahblahblahblah"); memcpy(buffer, "blahblahblahblah", size); for (lfs_size_t i = 0; i < ((cfg.block_count-2)/2)*(cfg.block_size-8); i += size) { - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_write(&lfs, &file, buffer, size) => size; } - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; - lfs_file_open(&lfs, &file[0], "exhaustion2", + lfs_file_open(&lfs, &file, "exhaustion2", LFS_O_WRONLY | LFS_O_CREAT) => 0; size = strlen("blahblahblahblah"); memcpy(buffer, "blahblahblahblah", size); for (lfs_size_t i = 0; i < ((cfg.block_count-2+1)/2)*(cfg.block_size-8); i += size) { - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_write(&lfs, &file, buffer, size) => size; } - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; // remount to force reset of lookahead lfs_unmount(&lfs) => 0; lfs_mount(&lfs, &cfg) => 0; // rewrite one file with a hole of one block - lfs_file_open(&lfs, &file[0], "exhaustion1", + lfs_file_open(&lfs, &file, "exhaustion1", LFS_O_WRONLY | LFS_O_TRUNC) => 0; - lfs_file_sync(&lfs, &file[0]) => 0; + lfs_file_sync(&lfs, &file) => 0; size = strlen("blahblahblahblah"); memcpy(buffer, "blahblahblahblah", size); for (lfs_size_t i = 0; i < ((cfg.block_count-2)/2 - 1)*(cfg.block_size-8); i += size) { - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_write(&lfs, &file, buffer, size) => size; } - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; // try to allocate a directory, should fail! lfs_mkdir(&lfs, "split") => LFS_ERR_NOSPC; // file should not fail - lfs_file_open(&lfs, &file[0], "notasplit", + lfs_file_open(&lfs, &file, "notasplit", LFS_O_WRONLY | LFS_O_CREAT) => 0; - lfs_file_write(&lfs, &file[0], "hi", 2) => 2; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_write(&lfs, &file, "hi", 2) => 2; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST -echo "--- Results ---" -scripts/stats.py +scripts/results.py diff --git a/tests/test_attrs.sh b/tests/test_attrs.sh index ed8c0d3..612cae1 100755 --- a/tests/test_attrs.sh +++ b/tests/test_attrs.sh @@ -1,5 +1,7 @@ #!/bin/bash set -eu +export TEST_FILE=$0 +trap 'export TEST_LINE=$LINENO' DEBUG echo "=== Attr tests ===" rm -rf blocks @@ -8,17 +10,18 @@ scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "hello") => 0; - lfs_file_open(&lfs, &file[0], "hello/hello", + lfs_file_open(&lfs, &file, "hello/hello", LFS_O_WRONLY | LFS_O_CREAT) => 0; - lfs_file_write(&lfs, &file[0], "hello", strlen("hello")) + lfs_file_write(&lfs, &file, "hello", strlen("hello")) => strlen("hello"); - lfs_file_close(&lfs, &file[0]); + lfs_file_close(&lfs, &file); lfs_unmount(&lfs) => 0; TEST echo "--- Set/get attribute ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; + memset(buffer, 0, sizeof(buffer)); lfs_setattr(&lfs, "hello", 'A', "aaaa", 4) => 0; lfs_setattr(&lfs, "hello", 'B', "bbbbbb", 6) => 0; lfs_setattr(&lfs, "hello", 'C', "ccccc", 5) => 0; @@ -71,6 +74,7 @@ scripts/test.py << TEST TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; + memset(buffer, 0, sizeof(buffer)); lfs_getattr(&lfs, "hello", 'A', buffer, 4) => 4; lfs_getattr(&lfs, "hello", 'B', buffer+4, 9) => 9; lfs_getattr(&lfs, "hello", 'C', buffer+13, 5) => 5; @@ -78,16 +82,17 @@ scripts/test.py << TEST memcmp(buffer+4, "fffffffff", 9) => 0; memcmp(buffer+13, "ccccc", 5) => 0; - lfs_file_open(&lfs, &file[0], "hello/hello", LFS_O_RDONLY) => 0; - lfs_file_read(&lfs, &file[0], buffer, sizeof(buffer)) => strlen("hello"); + lfs_file_open(&lfs, &file, "hello/hello", LFS_O_RDONLY) => 0; + lfs_file_read(&lfs, &file, buffer, sizeof(buffer)) => strlen("hello"); memcmp(buffer, "hello", strlen("hello")) => 0; - lfs_file_close(&lfs, &file[0]); + lfs_file_close(&lfs, &file); lfs_unmount(&lfs) => 0; TEST echo "--- Set/get root attribute ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; + memset(buffer, 0, sizeof(buffer)); lfs_setattr(&lfs, "/", 'A', "aaaa", 4) => 0; lfs_setattr(&lfs, "/", 'B', "bbbbbb", 6) => 0; lfs_setattr(&lfs, "/", 'C', "ccccc", 5) => 0; @@ -139,6 +144,7 @@ scripts/test.py << TEST TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; + memset(buffer, 0, sizeof(buffer)); lfs_getattr(&lfs, "/", 'A', buffer, 4) => 4; lfs_getattr(&lfs, "/", 'B', buffer+4, 9) => 9; lfs_getattr(&lfs, "/", 'C', buffer+13, 5) => 5; @@ -146,16 +152,17 @@ scripts/test.py << TEST memcmp(buffer+4, "fffffffff", 9) => 0; memcmp(buffer+13, "ccccc", 5) => 0; - lfs_file_open(&lfs, &file[0], "hello/hello", LFS_O_RDONLY) => 0; - lfs_file_read(&lfs, &file[0], buffer, sizeof(buffer)) => strlen("hello"); + lfs_file_open(&lfs, &file, "hello/hello", LFS_O_RDONLY) => 0; + lfs_file_read(&lfs, &file, buffer, sizeof(buffer)) => strlen("hello"); memcmp(buffer, "hello", strlen("hello")) => 0; - lfs_file_close(&lfs, &file[0]); + lfs_file_close(&lfs, &file); lfs_unmount(&lfs) => 0; TEST echo "--- Set/get file attribute ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; + memset(buffer, 0, sizeof(buffer)); struct lfs_attr attrs1[] = { {'A', buffer, 4}, {'B', buffer+4, 6}, @@ -163,55 +170,55 @@ scripts/test.py << TEST }; struct lfs_file_config cfg1 = {.attrs=attrs1, .attr_count=3}; - lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_WRONLY, &cfg1) => 0; + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0; memcpy(buffer, "aaaa", 4); memcpy(buffer+4, "bbbbbb", 6); memcpy(buffer+10, "ccccc", 5); - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; memset(buffer, 0, 15); - lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_RDONLY, &cfg1) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0; + lfs_file_close(&lfs, &file) => 0; memcmp(buffer, "aaaa", 4) => 0; memcmp(buffer+4, "bbbbbb", 6) => 0; memcmp(buffer+10, "ccccc", 5) => 0; attrs1[1].size = 0; - lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_WRONLY, &cfg1) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0; + lfs_file_close(&lfs, &file) => 0; memset(buffer, 0, 15); attrs1[1].size = 6; - lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_RDONLY, &cfg1) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0; + lfs_file_close(&lfs, &file) => 0; memcmp(buffer, "aaaa", 4) => 0; memcmp(buffer+4, "\0\0\0\0\0\0", 6) => 0; memcmp(buffer+10, "ccccc", 5) => 0; attrs1[1].size = 6; - lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_WRONLY, &cfg1) => 0; + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0; memcpy(buffer+4, "dddddd", 6); - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; memset(buffer, 0, 15); attrs1[1].size = 6; - lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_RDONLY, &cfg1) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0; + lfs_file_close(&lfs, &file) => 0; memcmp(buffer, "aaaa", 4) => 0; memcmp(buffer+4, "dddddd", 6) => 0; memcmp(buffer+10, "ccccc", 5) => 0; attrs1[1].size = 3; - lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_WRONLY, &cfg1) => 0; + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0; memcpy(buffer+4, "eee", 3); - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; memset(buffer, 0, 15); attrs1[1].size = 6; - lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_RDONLY, &cfg1) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0; + lfs_file_close(&lfs, &file) => 0; memcmp(buffer, "aaaa", 4) => 0; memcmp(buffer+4, "eee\0\0\0", 6) => 0; memcmp(buffer+10, "ccccc", 5) => 0; attrs1[0].size = LFS_ATTR_MAX+1; - lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_WRONLY, &cfg1) + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => LFS_ERR_NOSPC; struct lfs_attr attrs2[] = { @@ -220,17 +227,18 @@ scripts/test.py << TEST {'C', buffer+13, 5}, }; struct lfs_file_config cfg2 = {.attrs=attrs2, .attr_count=3}; - lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_RDWR, &cfg2) => 0; + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDWR, &cfg2) => 0; memcpy(buffer+4, "fffffffff", 9); - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; attrs1[0].size = 4; - lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_RDONLY, &cfg1) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg1) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; + memset(buffer, 0, sizeof(buffer)); struct lfs_attr attrs2[] = { {'A', buffer, 4}, {'B', buffer+4, 9}, @@ -238,22 +246,23 @@ scripts/test.py << TEST }; struct lfs_file_config cfg2 = {.attrs=attrs2, .attr_count=3}; - lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_RDONLY, &cfg2) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_RDONLY, &cfg2) => 0; + lfs_file_close(&lfs, &file) => 0; memcmp(buffer, "aaaa", 4) => 0; memcmp(buffer+4, "fffffffff", 9) => 0; memcmp(buffer+13, "ccccc", 5) => 0; - lfs_file_open(&lfs, &file[0], "hello/hello", LFS_O_RDONLY) => 0; - lfs_file_read(&lfs, &file[0], buffer, sizeof(buffer)) => strlen("hello"); + lfs_file_open(&lfs, &file, "hello/hello", LFS_O_RDONLY) => 0; + lfs_file_read(&lfs, &file, buffer, sizeof(buffer)) => strlen("hello"); memcmp(buffer, "hello", strlen("hello")) => 0; - lfs_file_close(&lfs, &file[0]); + lfs_file_close(&lfs, &file); lfs_unmount(&lfs) => 0; TEST echo "--- Deferred file attributes ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; + memset(buffer, 0, sizeof(buffer)); struct lfs_attr attrs1[] = { {'B', "gggg", 4}, {'C', "", 0}, @@ -261,7 +270,7 @@ scripts/test.py << TEST }; struct lfs_file_config cfg1 = {.attrs=attrs1, .attr_count=3}; - lfs_file_opencfg(&lfs, &file[0], "hello/hello", LFS_O_WRONLY, &cfg1) => 0; + lfs_file_opencfg(&lfs, &file, "hello/hello", LFS_O_WRONLY, &cfg1) => 0; lfs_getattr(&lfs, "hello/hello", 'B', buffer, 9) => 9; lfs_getattr(&lfs, "hello/hello", 'C', buffer+9, 9) => 5; @@ -270,7 +279,7 @@ scripts/test.py << TEST memcmp(buffer+9, "ccccc\0\0\0\0", 9) => 0; memcmp(buffer+18, "\0\0\0\0\0\0\0\0\0", 9) => 0; - lfs_file_sync(&lfs, &file[0]) => 0; + lfs_file_sync(&lfs, &file) => 0; lfs_getattr(&lfs, "hello/hello", 'B', buffer, 9) => 4; lfs_getattr(&lfs, "hello/hello", 'C', buffer+9, 9) => 0; lfs_getattr(&lfs, "hello/hello", 'D', buffer+18, 9) => 4; @@ -278,9 +287,8 @@ scripts/test.py << TEST memcmp(buffer+9, "\0\0\0\0\0\0\0\0\0", 9) => 0; memcmp(buffer+18, "hhhh\0\0\0\0\0", 9) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST -echo "--- Results ---" -scripts/stats.py +scripts/results.py diff --git a/tests/test_corrupt.sh b/tests/test_corrupt.sh index fae3291..3001522 100755 --- a/tests/test_corrupt.sh +++ b/tests/test_corrupt.sh @@ -1,5 +1,7 @@ #!/bin/bash set -eu +export TEST_FILE=$0 +trap 'export TEST_LINE=$LINENO' DEBUG echo "=== Corrupt tests ===" @@ -23,15 +25,15 @@ scripts/test.py ${1:-} << TEST buffer[j+$NAMEMULT+1] = '0'+i; } buffer[2*$NAMEMULT+1] = '\0'; - lfs_file_open(&lfs, &file[0], (char*)buffer, + lfs_file_open(&lfs, &file, (char*)buffer, LFS_O_WRONLY | LFS_O_CREAT) => 0; - size = $NAMEMULT; + lfs_size_t size = $NAMEMULT; for (int j = 0; j < i*$FILEMULT; j++) { - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_write(&lfs, &file, buffer, size) => size; } - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; } lfs_unmount(&lfs) => 0; TEST @@ -53,15 +55,16 @@ scripts/test.py ${1:-} << TEST buffer[j+$NAMEMULT+1] = '0'+i; } buffer[2*$NAMEMULT+1] = '\0'; - lfs_file_open(&lfs, &file[0], (char*)buffer, LFS_O_RDONLY) => 0; + lfs_file_open(&lfs, &file, (char*)buffer, LFS_O_RDONLY) => 0; - size = $NAMEMULT; + lfs_size_t size = $NAMEMULT; for (int j = 0; j < i*$FILEMULT; j++) { - lfs_file_read(&lfs, &file[0], rbuffer, size) => size; + uint8_t rbuffer[1024]; + lfs_file_read(&lfs, &file, rbuffer, size) => size; memcmp(buffer, rbuffer, size) => 0; } - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; } lfs_unmount(&lfs) => 0; TEST @@ -114,5 +117,4 @@ done lfs_mktree lfs_chktree -echo "--- Results ---" -scripts/stats.py +scripts/results.py diff --git a/tests/test_dirs.sh b/tests/test_dirs.sh index f73103d..0125bfd 100755 --- a/tests/test_dirs.sh +++ b/tests/test_dirs.sh @@ -1,9 +1,12 @@ #!/bin/bash set -eu +export TEST_FILE=$0 +trap 'export TEST_LINE=$LINENO' DEBUG + +echo "=== Directory tests ===" LARGESIZE=128 -echo "=== Directory tests ===" rm -rf blocks scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; @@ -12,8 +15,8 @@ TEST echo "--- Root directory ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "/") => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; + lfs_dir_open(&lfs, &dir, "/") => 0; + lfs_dir_close(&lfs, &dir) => 0; lfs_unmount(&lfs) => 0; TEST @@ -27,29 +30,29 @@ TEST echo "--- File creation ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "burito", LFS_O_CREAT | LFS_O_WRONLY) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_open(&lfs, &file, "burito", LFS_O_CREAT | LFS_O_WRONLY) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST echo "--- Directory iteration ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "/") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "/") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "burito") => 0; info.type => LFS_TYPE_REG; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "potato") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; lfs_unmount(&lfs) => 0; TEST @@ -57,10 +60,10 @@ echo "--- Directory failures ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "potato") => LFS_ERR_EXIST; - lfs_dir_open(&lfs, &dir[0], "tomato") => LFS_ERR_NOENT; - lfs_dir_open(&lfs, &dir[0], "burito") => LFS_ERR_NOTDIR; - lfs_file_open(&lfs, &file[0], "tomato", LFS_O_RDONLY) => LFS_ERR_NOENT; - lfs_file_open(&lfs, &file[0], "potato", LFS_O_RDONLY) => LFS_ERR_ISDIR; + lfs_dir_open(&lfs, &dir, "tomato") => LFS_ERR_NOENT; + lfs_dir_open(&lfs, &dir, "burito") => LFS_ERR_NOTDIR; + lfs_file_open(&lfs, &file, "tomato", LFS_O_RDONLY) => LFS_ERR_NOENT; + lfs_file_open(&lfs, &file, "potato", LFS_O_RDONLY) => LFS_ERR_ISDIR; lfs_unmount(&lfs) => 0; TEST @@ -74,24 +77,24 @@ scripts/test.py << TEST TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "potato") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "potato") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "baked") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "fried") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "sweet") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; lfs_unmount(&lfs) => 0; TEST @@ -100,27 +103,27 @@ scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "cactus") => 0; for (int i = 0; i < $LARGESIZE; i++) { - sprintf((char*)buffer, "cactus/test%03d", i); - lfs_mkdir(&lfs, (char*)buffer) => 0; + sprintf(path, "cactus/test%03d", i); + lfs_mkdir(&lfs, path) => 0; } lfs_unmount(&lfs) => 0; TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "cactus") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "cactus") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; info.type => LFS_TYPE_DIR; for (int i = 0; i < $LARGESIZE; i++) { - sprintf((char*)buffer, "test%03d", i); - lfs_dir_read(&lfs, &dir[0], &info) => 1; - strcmp(info.name, (char*)buffer) => 0; + sprintf(path, "test%03d", i); + lfs_dir_read(&lfs, &dir, &info) => 1; + strcmp(info.name, path) => 0; info.type => LFS_TYPE_DIR; } - lfs_dir_read(&lfs, &dir[0], &info) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; lfs_unmount(&lfs) => 0; TEST @@ -132,52 +135,52 @@ scripts/test.py << TEST lfs_remove(&lfs, "potato/baked") => 0; lfs_remove(&lfs, "potato/fried") => 0; - lfs_dir_open(&lfs, &dir[0], "potato") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "potato") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; lfs_remove(&lfs, "potato") => 0; - lfs_dir_open(&lfs, &dir[0], "/") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "/") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "burito") => 0; info.type => LFS_TYPE_REG; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "cactus") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; lfs_unmount(&lfs) => 0; TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "/") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "/") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "burito") => 0; info.type => LFS_TYPE_REG; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "cactus") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; lfs_unmount(&lfs) => 0; TEST @@ -197,24 +200,24 @@ scripts/test.py << TEST TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "hotpotato") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "hotpotato") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "baked") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "fried") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "sweet") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; lfs_unmount(&lfs) => 0; TEST scripts/test.py << TEST @@ -230,24 +233,24 @@ scripts/test.py << TEST TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "warmpotato") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "warmpotato") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "baked") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "fried") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "sweet") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; lfs_unmount(&lfs) => 0; TEST scripts/test.py << TEST @@ -262,24 +265,24 @@ scripts/test.py << TEST TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "coldpotato") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "coldpotato") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "baked") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "fried") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "sweet") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; lfs_unmount(&lfs) => 0; TEST @@ -288,41 +291,41 @@ scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_remove(&lfs, "coldpotato") => LFS_ERR_NOTEMPTY; - lfs_dir_open(&lfs, &dir[0], "coldpotato") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "coldpotato") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; while (true) { - int err = lfs_dir_read(&lfs, &dir[0], &info); + int err = lfs_dir_read(&lfs, &dir, &info); err >= 0 => 1; if (err == 0) { break; } - strcpy((char*)buffer, "coldpotato/"); - strcat((char*)buffer, info.name); - lfs_remove(&lfs, (char*)buffer) => 0; + strcpy(path, "coldpotato/"); + strcat(path, info.name); + lfs_remove(&lfs, path) => 0; } lfs_remove(&lfs, "coldpotato") => 0; TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "/") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "/") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "burito") => 0; info.type => LFS_TYPE_REG; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "cactus") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; lfs_unmount(&lfs) => 0; TEST @@ -330,28 +333,30 @@ echo "--- Multi-block rename ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; for (int i = 0; i < $LARGESIZE; i++) { - sprintf((char*)buffer, "cactus/test%03d", i); - sprintf((char*)wbuffer, "cactus/tedd%03d", i); - lfs_rename(&lfs, (char*)buffer, (char*)wbuffer) => 0; + char oldpath[1024]; + char newpath[1024]; + sprintf(oldpath, "cactus/test%03d", i); + sprintf(newpath, "cactus/tedd%03d", i); + lfs_rename(&lfs, oldpath, newpath) => 0; } lfs_unmount(&lfs) => 0; TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "cactus") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "cactus") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; info.type => LFS_TYPE_DIR; for (int i = 0; i < $LARGESIZE; i++) { - sprintf((char*)buffer, "tedd%03d", i); - lfs_dir_read(&lfs, &dir[0], &info) => 1; - strcmp(info.name, (char*)buffer) => 0; + sprintf(path, "tedd%03d", i); + lfs_dir_read(&lfs, &dir, &info) => 1; + strcmp(info.name, path) => 0; info.type => LFS_TYPE_DIR; } - lfs_dir_read(&lfs, &dir[0], &info) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; lfs_unmount(&lfs) => 0; TEST @@ -361,8 +366,8 @@ scripts/test.py << TEST lfs_remove(&lfs, "cactus") => LFS_ERR_NOTEMPTY; for (int i = 0; i < $LARGESIZE; i++) { - sprintf((char*)buffer, "cactus/tedd%03d", i); - lfs_remove(&lfs, (char*)buffer) => 0; + sprintf(path, "cactus/tedd%03d", i); + lfs_remove(&lfs, path) => 0; } lfs_remove(&lfs, "cactus") => 0; @@ -370,18 +375,18 @@ scripts/test.py << TEST TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "/") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "/") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "burito") => 0; info.type => LFS_TYPE_REG; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; lfs_unmount(&lfs) => 0; TEST @@ -390,33 +395,32 @@ scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "prickly-pear") => 0; for (int i = 0; i < $LARGESIZE; i++) { - sprintf((char*)buffer, "prickly-pear/test%03d", i); - lfs_file_open(&lfs, &file[0], (char*)buffer, - LFS_O_WRONLY | LFS_O_CREAT) => 0; - size = 6; - memcpy(wbuffer, "Hello", size); - lfs_file_write(&lfs, &file[0], wbuffer, size) => size; - lfs_file_close(&lfs, &file[0]) => 0; + sprintf(path, "prickly-pear/test%03d", i); + lfs_file_open(&lfs, &file, path, LFS_O_WRONLY | LFS_O_CREAT) => 0; + lfs_size_t size = 6; + memcpy(buffer, "Hello", size); + lfs_file_write(&lfs, &file, buffer, size) => size; + lfs_file_close(&lfs, &file) => 0; } lfs_unmount(&lfs) => 0; TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "prickly-pear") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "prickly-pear") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; info.type => LFS_TYPE_DIR; for (int i = 0; i < $LARGESIZE; i++) { - sprintf((char*)buffer, "test%03d", i); - lfs_dir_read(&lfs, &dir[0], &info) => 1; - strcmp(info.name, (char*)buffer) => 0; + sprintf(path, "test%03d", i); + lfs_dir_read(&lfs, &dir, &info) => 1; + strcmp(info.name, path) => 0; info.type => LFS_TYPE_REG; info.size => 6; } - lfs_dir_read(&lfs, &dir[0], &info) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; lfs_unmount(&lfs) => 0; TEST @@ -424,29 +428,31 @@ echo "--- Multi-block rename with files ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; for (int i = 0; i < $LARGESIZE; i++) { - sprintf((char*)buffer, "prickly-pear/test%03d", i); - sprintf((char*)wbuffer, "prickly-pear/tedd%03d", i); - lfs_rename(&lfs, (char*)buffer, (char*)wbuffer) => 0; + char oldpath[1024]; + char newpath[1024]; + sprintf(oldpath, "prickly-pear/test%03d", i); + sprintf(newpath, "prickly-pear/tedd%03d", i); + lfs_rename(&lfs, oldpath, newpath) => 0; } lfs_unmount(&lfs) => 0; TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "prickly-pear") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "prickly-pear") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; info.type => LFS_TYPE_DIR; for (int i = 0; i < $LARGESIZE; i++) { - sprintf((char*)buffer, "tedd%03d", i); - lfs_dir_read(&lfs, &dir[0], &info) => 1; - strcmp(info.name, (char*)buffer) => 0; + sprintf(path, "tedd%03d", i); + lfs_dir_read(&lfs, &dir, &info) => 1; + strcmp(info.name, path) => 0; info.type => LFS_TYPE_REG; info.size => 6; } - lfs_dir_read(&lfs, &dir[0], &info) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; lfs_unmount(&lfs) => 0; TEST @@ -456,8 +462,8 @@ scripts/test.py << TEST lfs_remove(&lfs, "prickly-pear") => LFS_ERR_NOTEMPTY; for (int i = 0; i < $LARGESIZE; i++) { - sprintf((char*)buffer, "prickly-pear/tedd%03d", i); - lfs_remove(&lfs, (char*)buffer) => 0; + sprintf(path, "prickly-pear/tedd%03d", i); + lfs_remove(&lfs, path) => 0; } lfs_remove(&lfs, "prickly-pear") => 0; @@ -465,20 +471,19 @@ scripts/test.py << TEST TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "/") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "/") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "burito") => 0; info.type => LFS_TYPE_REG; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; lfs_unmount(&lfs) => 0; TEST -echo "--- Results ---" -scripts/stats.py +scripts/results.py diff --git a/tests/test_entries.sh b/tests/test_entries.sh index 15cae7a..5075faf 100755 --- a/tests/test_entries.sh +++ b/tests/test_entries.sh @@ -1,19 +1,22 @@ #!/bin/bash set -eu +export TEST_FILE=$0 +trap 'export TEST_LINE=$LINENO' DEBUG + +echo "=== Entry tests ===" # Note: These tests are intended for 512 byte inline size at different # inline sizes they should still pass, but won't be testing anything -echo "=== Entry tests ===" rm -rf blocks function read_file { cat << TEST size = $2; - lfs_file_open(&lfs, &file[0], "$1", LFS_O_RDONLY) => 0; - lfs_file_read(&lfs, &file[0], rbuffer, size) => size; + lfs_file_open(&lfs, &file, "$1", LFS_O_RDONLY) => 0; + lfs_file_read(&lfs, &file, rbuffer, size) => size; memcmp(rbuffer, wbuffer, size) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; TEST } @@ -21,11 +24,11 @@ function write_file { cat << TEST size = $2; - lfs_file_open(&lfs, &file[0], "$1", + lfs_file_open(&lfs, &file, "$1", LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => 0; memset(wbuffer, 'c', size); - lfs_file_write(&lfs, &file[0], wbuffer, size) => size; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_write(&lfs, &file, wbuffer, size) => size; + lfs_file_close(&lfs, &file) => 0; TEST } @@ -33,6 +36,10 @@ echo "--- Entry grow test ---" scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; + uint8_t wbuffer[1024]; + uint8_t rbuffer[1024]; + lfs_size_t size; + lfs_mount(&lfs, &cfg) => 0; $(write_file "hi0" 20) $(write_file "hi1" 20) @@ -53,6 +60,10 @@ echo "--- Entry shrink test ---" scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; + uint8_t wbuffer[1024]; + uint8_t rbuffer[1024]; + lfs_size_t size; + lfs_mount(&lfs, &cfg) => 0; $(write_file "hi0" 20) $(write_file "hi1" 200) @@ -73,6 +84,10 @@ echo "--- Entry spill test ---" scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; + uint8_t wbuffer[1024]; + uint8_t rbuffer[1024]; + lfs_size_t size; + lfs_mount(&lfs, &cfg) => 0; $(write_file "hi0" 200) $(write_file "hi1" 200) @@ -90,6 +105,10 @@ echo "--- Entry push spill test ---" scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; + uint8_t wbuffer[1024]; + uint8_t rbuffer[1024]; + lfs_size_t size; + lfs_mount(&lfs, &cfg) => 0; $(write_file "hi0" 200) $(write_file "hi1" 20) @@ -110,6 +129,10 @@ echo "--- Entry push spill two test ---" scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; + uint8_t wbuffer[1024]; + uint8_t rbuffer[1024]; + lfs_size_t size; + lfs_mount(&lfs, &cfg) => 0; $(write_file "hi0" 200) $(write_file "hi1" 20) @@ -132,6 +155,10 @@ echo "--- Entry drop test ---" scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; + uint8_t wbuffer[1024]; + uint8_t rbuffer[1024]; + lfs_size_t size; + lfs_mount(&lfs, &cfg) => 0; $(write_file "hi0" 200) $(write_file "hi1" 200) @@ -163,21 +190,23 @@ scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; lfs_mount(&lfs, &cfg) => 0; - memset(buffer, 'm', 200); - buffer[200] = '\0'; + memset(path, 'm', 200); + path[200] = '\0'; - size = 400; - lfs_file_open(&lfs, &file[0], (char*)buffer, + lfs_size_t size = 400; + lfs_file_open(&lfs, &file, path, LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => 0; + uint8_t wbuffer[1024]; memset(wbuffer, 'c', size); - lfs_file_write(&lfs, &file[0], wbuffer, size) => size; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_write(&lfs, &file, wbuffer, size) => size; + lfs_file_close(&lfs, &file) => 0; size = 400; - lfs_file_open(&lfs, &file[0], (char*)buffer, LFS_O_RDONLY) => 0; - lfs_file_read(&lfs, &file[0], rbuffer, size) => size; + lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) => 0; + uint8_t rbuffer[1024]; + lfs_file_read(&lfs, &file, rbuffer, size) => size; memcmp(rbuffer, wbuffer, size) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST @@ -186,36 +215,37 @@ scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; lfs_mount(&lfs, &cfg) => 0; - memset(buffer, 'm', 200); - buffer[200] = '\0'; + memset(path, 'm', 200); + path[200] = '\0'; + + lfs_size_t size = 40; + lfs_file_open(&lfs, &file, path, + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => 0; + uint8_t wbuffer[1024]; + memset(wbuffer, 'c', size); + lfs_file_write(&lfs, &file, wbuffer, size) => size; + lfs_file_close(&lfs, &file) => 0; size = 40; - lfs_file_open(&lfs, &file[0], (char*)buffer, - LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => 0; - memset(wbuffer, 'c', size); - lfs_file_write(&lfs, &file[0], wbuffer, size) => size; - lfs_file_close(&lfs, &file[0]) => 0; - - size = 40; - lfs_file_open(&lfs, &file[0], (char*)buffer, LFS_O_RDONLY) => 0; - lfs_file_read(&lfs, &file[0], rbuffer, size) => size; + lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) => 0; + uint8_t rbuffer[1024]; + lfs_file_read(&lfs, &file, rbuffer, size) => size; memcmp(rbuffer, wbuffer, size) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; size = 400; - lfs_file_open(&lfs, &file[0], (char*)buffer, + lfs_file_open(&lfs, &file, path, LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => 0; memset(wbuffer, 'c', size); - lfs_file_write(&lfs, &file[0], wbuffer, size) => size; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_write(&lfs, &file, wbuffer, size) => size; + lfs_file_close(&lfs, &file) => 0; size = 400; - lfs_file_open(&lfs, &file[0], (char*)buffer, LFS_O_RDONLY) => 0; - lfs_file_read(&lfs, &file[0], rbuffer, size) => size; + lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) => 0; + lfs_file_read(&lfs, &file, rbuffer, size) => size; memcmp(rbuffer, wbuffer, size) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST -echo "--- Results ---" -scripts/stats.py +scripts/results.py diff --git a/tests/test_files.sh b/tests/test_files.sh index 7e86ae5..be3f4e6 100755 --- a/tests/test_files.sh +++ b/tests/test_files.sh @@ -1,11 +1,14 @@ #!/bin/bash set -eu +export TEST_FILE=$0 +trap 'export TEST_LINE=$LINENO' DEBUG + +echo "=== File tests ===" SMALLSIZE=32 MEDIUMSIZE=8192 LARGESIZE=262144 -echo "=== File tests ===" rm -rf blocks scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; @@ -14,58 +17,60 @@ TEST echo "--- Simple file test ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "hello", LFS_O_WRONLY | LFS_O_CREAT) => 0; - size = strlen("Hello World!\n"); + lfs_file_open(&lfs, &file, "hello", LFS_O_WRONLY | LFS_O_CREAT) => 0; + lfs_size_t size = strlen("Hello World!\n"); + uint8_t wbuffer[1024]; memcpy(wbuffer, "Hello World!\n", size); - lfs_file_write(&lfs, &file[0], wbuffer, size) => size; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_write(&lfs, &file, wbuffer, size) => size; + lfs_file_close(&lfs, &file) => 0; - lfs_file_open(&lfs, &file[0], "hello", LFS_O_RDONLY) => 0; + lfs_file_open(&lfs, &file, "hello", LFS_O_RDONLY) => 0; size = strlen("Hello World!\n"); - lfs_file_read(&lfs, &file[0], rbuffer, size) => size; + uint8_t rbuffer[1024]; + lfs_file_read(&lfs, &file, rbuffer, size) => size; memcmp(rbuffer, wbuffer, size) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST w_test() { scripts/test.py ${4:-} << TEST - size = $1; + lfs_size_t size = $1; lfs_size_t chunk = 31; srand(0); lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "$2", + lfs_file_open(&lfs, &file, "$2", ${3:-LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC}) => 0; for (lfs_size_t i = 0; i < size; i += chunk) { chunk = (chunk < size - i) ? chunk : size - i; for (lfs_size_t b = 0; b < chunk; b++) { buffer[b] = rand() & 0xff; } - lfs_file_write(&lfs, &file[0], buffer, chunk) => chunk; + lfs_file_write(&lfs, &file, buffer, chunk) => chunk; } - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST } r_test() { scripts/test.py << TEST - size = $1; + lfs_size_t size = $1; lfs_size_t chunk = 29; srand(0); lfs_mount(&lfs, &cfg) => 0; lfs_stat(&lfs, "$2", &info) => 0; info.type => LFS_TYPE_REG; info.size => size; - lfs_file_open(&lfs, &file[0], "$2", ${3:-LFS_O_RDONLY}) => 0; + lfs_file_open(&lfs, &file, "$2", ${3:-LFS_O_RDONLY}) => 0; for (lfs_size_t i = 0; i < size; i += chunk) { chunk = (chunk < size - i) ? chunk : size - i; - lfs_file_read(&lfs, &file[0], buffer, chunk) => chunk; + lfs_file_read(&lfs, &file, buffer, chunk) => chunk; for (lfs_size_t b = 0; b < chunk && i+b < size; b++) { buffer[b] => rand() & 0xff; } } - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST } @@ -107,31 +112,31 @@ r_test 0 noavacado echo "--- Dir check ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "/") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; - lfs_dir_read(&lfs, &dir[0], &info) => 1; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "/") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "hello") => 0; info.type => LFS_TYPE_REG; info.size => strlen("Hello World!\n"); - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "largeavacado") => 0; info.type => LFS_TYPE_REG; info.size => $LARGESIZE; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "mediumavacado") => 0; info.type => LFS_TYPE_REG; info.size => $MEDIUMSIZE; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "noavacado") => 0; info.type => LFS_TYPE_REG; info.size => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "smallavacado") => 0; info.type => LFS_TYPE_REG; info.size => $SMALLSIZE; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; lfs_unmount(&lfs) => 0; TEST @@ -144,15 +149,14 @@ scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "directory") => 0; for (unsigned i = 0; i < 300; i++) { - snprintf((char*)buffer, sizeof(buffer), "file_%03d", i); - lfs_file_open(&lfs, &file[0], (char*)buffer, LFS_O_WRONLY | LFS_O_CREAT) => 0; - size = 6; - memcpy(wbuffer, "Hello", size); - lfs_file_write(&lfs, &file[0], wbuffer, size) => size; - lfs_file_close(&lfs, &file[0]) => 0; + sprintf(path, "file_%03d", i); + lfs_file_open(&lfs, &file, path, LFS_O_WRONLY | LFS_O_CREAT) => 0; + lfs_size_t size = 6; + memcpy(buffer, "Hello", size); + lfs_file_write(&lfs, &file, buffer, size) => size; + lfs_file_close(&lfs, &file) => 0; } lfs_unmount(&lfs) => 0; TEST -echo "--- Results ---" -scripts/stats.py +scripts/results.py diff --git a/tests/test_format.sh b/tests/test_format.sh index 425bdb2..f0972bd 100755 --- a/tests/test_format.sh +++ b/tests/test_format.sh @@ -1,5 +1,7 @@ #!/bin/bash set -eu +export TEST_FILE=$0 +trap 'export TEST_LINE=$LINENO' DEBUG echo "=== Formatting tests ===" rm -rf blocks @@ -46,5 +48,4 @@ scripts/test.py << TEST lfs_unmount(&lfs) => 0; TEST -echo "--- Results ---" -scripts/stats.py +scripts/results.py diff --git a/tests/test_interspersed.sh b/tests/test_interspersed.sh index 5eead1a..84c5dd8 100755 --- a/tests/test_interspersed.sh +++ b/tests/test_interspersed.sh @@ -1,5 +1,7 @@ #!/bin/bash set -eu +export TEST_FILE=$0 +trap 'export TEST_LINE=$LINENO' DEBUG echo "=== Interspersed tests ===" rm -rf blocks @@ -10,69 +12,70 @@ TEST echo "--- Interspersed file test ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "a", LFS_O_WRONLY | LFS_O_CREAT) => 0; - lfs_file_open(&lfs, &file[1], "b", LFS_O_WRONLY | LFS_O_CREAT) => 0; - lfs_file_open(&lfs, &file[2], "c", LFS_O_WRONLY | LFS_O_CREAT) => 0; - lfs_file_open(&lfs, &file[3], "d", LFS_O_WRONLY | LFS_O_CREAT) => 0; + lfs_file_t files[4]; + lfs_file_open(&lfs, &files[0], "a", LFS_O_WRONLY | LFS_O_CREAT) => 0; + lfs_file_open(&lfs, &files[1], "b", LFS_O_WRONLY | LFS_O_CREAT) => 0; + lfs_file_open(&lfs, &files[2], "c", LFS_O_WRONLY | LFS_O_CREAT) => 0; + lfs_file_open(&lfs, &files[3], "d", LFS_O_WRONLY | LFS_O_CREAT) => 0; for (int i = 0; i < 10; i++) { - lfs_file_write(&lfs, &file[0], (const void*)"a", 1) => 1; - lfs_file_write(&lfs, &file[1], (const void*)"b", 1) => 1; - lfs_file_write(&lfs, &file[2], (const void*)"c", 1) => 1; - lfs_file_write(&lfs, &file[3], (const void*)"d", 1) => 1; + lfs_file_write(&lfs, &files[0], (const void*)"a", 1) => 1; + lfs_file_write(&lfs, &files[1], (const void*)"b", 1) => 1; + lfs_file_write(&lfs, &files[2], (const void*)"c", 1) => 1; + lfs_file_write(&lfs, &files[3], (const void*)"d", 1) => 1; } - lfs_file_close(&lfs, &file[0]); - lfs_file_close(&lfs, &file[1]); - lfs_file_close(&lfs, &file[2]); - lfs_file_close(&lfs, &file[3]); + lfs_file_close(&lfs, &files[0]); + lfs_file_close(&lfs, &files[1]); + lfs_file_close(&lfs, &files[2]); + lfs_file_close(&lfs, &files[3]); - lfs_dir_open(&lfs, &dir[0], "/") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "/") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "a") => 0; info.type => LFS_TYPE_REG; info.size => 10; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "b") => 0; info.type => LFS_TYPE_REG; info.size => 10; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "c") => 0; info.type => LFS_TYPE_REG; info.size => 10; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "d") => 0; info.type => LFS_TYPE_REG; info.size => 10; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; - lfs_file_open(&lfs, &file[0], "a", LFS_O_RDONLY) => 0; - lfs_file_open(&lfs, &file[1], "b", LFS_O_RDONLY) => 0; - lfs_file_open(&lfs, &file[2], "c", LFS_O_RDONLY) => 0; - lfs_file_open(&lfs, &file[3], "d", LFS_O_RDONLY) => 0; + lfs_file_open(&lfs, &files[0], "a", LFS_O_RDONLY) => 0; + lfs_file_open(&lfs, &files[1], "b", LFS_O_RDONLY) => 0; + lfs_file_open(&lfs, &files[2], "c", LFS_O_RDONLY) => 0; + lfs_file_open(&lfs, &files[3], "d", LFS_O_RDONLY) => 0; for (int i = 0; i < 10; i++) { - lfs_file_read(&lfs, &file[0], buffer, 1) => 1; + lfs_file_read(&lfs, &files[0], buffer, 1) => 1; buffer[0] => 'a'; - lfs_file_read(&lfs, &file[1], buffer, 1) => 1; + lfs_file_read(&lfs, &files[1], buffer, 1) => 1; buffer[0] => 'b'; - lfs_file_read(&lfs, &file[2], buffer, 1) => 1; + lfs_file_read(&lfs, &files[2], buffer, 1) => 1; buffer[0] => 'c'; - lfs_file_read(&lfs, &file[3], buffer, 1) => 1; + lfs_file_read(&lfs, &files[3], buffer, 1) => 1; buffer[0] => 'd'; } - lfs_file_close(&lfs, &file[0]); - lfs_file_close(&lfs, &file[1]); - lfs_file_close(&lfs, &file[2]); - lfs_file_close(&lfs, &file[3]); + lfs_file_close(&lfs, &files[0]); + lfs_file_close(&lfs, &files[1]); + lfs_file_close(&lfs, &files[2]); + lfs_file_close(&lfs, &files[3]); lfs_unmount(&lfs) => 0; TEST @@ -80,10 +83,11 @@ TEST echo "--- Interspersed remove file test ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "e", LFS_O_WRONLY | LFS_O_CREAT) => 0; + lfs_file_t files[4]; + lfs_file_open(&lfs, &files[0], "e", LFS_O_WRONLY | LFS_O_CREAT) => 0; for (int i = 0; i < 5; i++) { - lfs_file_write(&lfs, &file[0], (const void*)"e", 1) => 1; + lfs_file_write(&lfs, &files[0], (const void*)"e", 1) => 1; } lfs_remove(&lfs, "a") => 0; @@ -92,33 +96,33 @@ scripts/test.py << TEST lfs_remove(&lfs, "d") => 0; for (int i = 0; i < 5; i++) { - lfs_file_write(&lfs, &file[0], (const void*)"e", 1) => 1; + lfs_file_write(&lfs, &files[0], (const void*)"e", 1) => 1; } - lfs_file_close(&lfs, &file[0]); + lfs_file_close(&lfs, &files[0]); - lfs_dir_open(&lfs, &dir[0], "/") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "/") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "e") => 0; info.type => LFS_TYPE_REG; info.size => 10; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; - lfs_file_open(&lfs, &file[0], "e", LFS_O_RDONLY) => 0; + lfs_file_open(&lfs, &files[0], "e", LFS_O_RDONLY) => 0; for (int i = 0; i < 10; i++) { - lfs_file_read(&lfs, &file[0], buffer, 1) => 1; + lfs_file_read(&lfs, &files[0], buffer, 1) => 1; buffer[0] => 'e'; } - lfs_file_close(&lfs, &file[0]); + lfs_file_close(&lfs, &files[0]); lfs_unmount(&lfs) => 0; TEST @@ -126,61 +130,61 @@ TEST echo "--- Remove inconveniently test ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "e", LFS_O_WRONLY | LFS_O_TRUNC) => 0; - lfs_file_open(&lfs, &file[1], "f", LFS_O_WRONLY | LFS_O_CREAT) => 0; - lfs_file_open(&lfs, &file[2], "g", LFS_O_WRONLY | LFS_O_CREAT) => 0; + lfs_file_t files[4]; + lfs_file_open(&lfs, &files[0], "e", LFS_O_WRONLY | LFS_O_TRUNC) => 0; + lfs_file_open(&lfs, &files[1], "f", LFS_O_WRONLY | LFS_O_CREAT) => 0; + lfs_file_open(&lfs, &files[2], "g", LFS_O_WRONLY | LFS_O_CREAT) => 0; for (int i = 0; i < 5; i++) { - lfs_file_write(&lfs, &file[0], (const void*)"e", 1) => 1; - lfs_file_write(&lfs, &file[1], (const void*)"f", 1) => 1; - lfs_file_write(&lfs, &file[2], (const void*)"g", 1) => 1; + lfs_file_write(&lfs, &files[0], (const void*)"e", 1) => 1; + lfs_file_write(&lfs, &files[1], (const void*)"f", 1) => 1; + lfs_file_write(&lfs, &files[2], (const void*)"g", 1) => 1; } lfs_remove(&lfs, "f") => 0; for (int i = 0; i < 5; i++) { - lfs_file_write(&lfs, &file[0], (const void*)"e", 1) => 1; - lfs_file_write(&lfs, &file[1], (const void*)"f", 1) => 1; - lfs_file_write(&lfs, &file[2], (const void*)"g", 1) => 1; + lfs_file_write(&lfs, &files[0], (const void*)"e", 1) => 1; + lfs_file_write(&lfs, &files[1], (const void*)"f", 1) => 1; + lfs_file_write(&lfs, &files[2], (const void*)"g", 1) => 1; } - lfs_file_close(&lfs, &file[0]); - lfs_file_close(&lfs, &file[1]); - lfs_file_close(&lfs, &file[2]); + lfs_file_close(&lfs, &files[0]); + lfs_file_close(&lfs, &files[1]); + lfs_file_close(&lfs, &files[2]); - lfs_dir_open(&lfs, &dir[0], "/") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "/") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; info.type => LFS_TYPE_DIR; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "e") => 0; info.type => LFS_TYPE_REG; info.size => 10; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "g") => 0; info.type => LFS_TYPE_REG; info.size => 10; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; - lfs_file_open(&lfs, &file[0], "e", LFS_O_RDONLY) => 0; - lfs_file_open(&lfs, &file[1], "g", LFS_O_RDONLY) => 0; + lfs_file_open(&lfs, &files[0], "e", LFS_O_RDONLY) => 0; + lfs_file_open(&lfs, &files[1], "g", LFS_O_RDONLY) => 0; for (int i = 0; i < 10; i++) { - lfs_file_read(&lfs, &file[0], buffer, 1) => 1; + lfs_file_read(&lfs, &files[0], buffer, 1) => 1; buffer[0] => 'e'; - lfs_file_read(&lfs, &file[1], buffer, 1) => 1; + lfs_file_read(&lfs, &files[1], buffer, 1) => 1; buffer[0] => 'g'; } - lfs_file_close(&lfs, &file[0]); - lfs_file_close(&lfs, &file[1]); + lfs_file_close(&lfs, &files[0]); + lfs_file_close(&lfs, &files[1]); lfs_unmount(&lfs) => 0; TEST -echo "--- Results ---" -scripts/stats.py +scripts/results.py diff --git a/tests/test_move.sh b/tests/test_move.sh index 9988887..f52ef22 100755 --- a/tests/test_move.sh +++ b/tests/test_move.sh @@ -1,5 +1,7 @@ #!/bin/bash set -eu +export TEST_FILE=$0 +trap 'export TEST_LINE=$LINENO' DEBUG echo "=== Move tests ===" rm -rf blocks @@ -17,11 +19,11 @@ scripts/test.py << TEST lfs_mkdir(&lfs, "a/hi/bonjour") => 0; lfs_mkdir(&lfs, "a/hi/ohayo") => 0; - lfs_file_open(&lfs, &file[0], "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0; - lfs_file_write(&lfs, &file[0], "hola\n", 5) => 5; - lfs_file_write(&lfs, &file[0], "bonjour\n", 8) => 8; - lfs_file_write(&lfs, &file[0], "ohayo\n", 6) => 6; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_open(&lfs, &file, "a/hello", LFS_O_CREAT | LFS_O_WRONLY) => 0; + lfs_file_write(&lfs, &file, "hola\n", 5) => 5; + lfs_file_write(&lfs, &file, "bonjour\n", 8) => 8; + lfs_file_write(&lfs, &file, "ohayo\n", 6) => 6; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST @@ -33,23 +35,23 @@ scripts/test.py << TEST TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "a") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "a") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "hi") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; - lfs_dir_open(&lfs, &dir[0], "b") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; + lfs_dir_open(&lfs, &dir, "b") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "hello") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; lfs_unmount(&lfs) => 0; TEST @@ -62,21 +64,21 @@ TEST scripts/corrupt.py -n 1 scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "b") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "b") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; - lfs_dir_open(&lfs, &dir[0], "c") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; + lfs_dir_open(&lfs, &dir, "c") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "hello") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; lfs_unmount(&lfs) => 0; TEST @@ -89,21 +91,21 @@ TEST scripts/corrupt.py -n 2 scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "c") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "c") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "hello") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; - lfs_dir_open(&lfs, &dir[0], "d") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; + lfs_dir_open(&lfs, &dir, "d") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; lfs_unmount(&lfs) => 0; TEST @@ -115,21 +117,21 @@ scripts/test.py << TEST TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "c") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "c") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; - lfs_dir_open(&lfs, &dir[0], "d") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; + lfs_dir_open(&lfs, &dir, "d") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "hello") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; lfs_unmount(&lfs) => 0; TEST @@ -141,21 +143,21 @@ scripts/test.py << TEST TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "a") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "a") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; - lfs_dir_open(&lfs, &dir[0], "b") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; + lfs_dir_open(&lfs, &dir, "b") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "hi") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; lfs_unmount(&lfs) => 0; TEST @@ -168,21 +170,21 @@ TEST scripts/corrupt.py -n 1 scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "b") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "b") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; - lfs_dir_open(&lfs, &dir[0], "c") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; + lfs_dir_open(&lfs, &dir, "c") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "hi") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; lfs_unmount(&lfs) => 0; TEST @@ -195,23 +197,23 @@ TEST scripts/corrupt.py -n 2 scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "c") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "c") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "hi") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; - lfs_dir_open(&lfs, &dir[0], "d") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; + lfs_dir_open(&lfs, &dir, "d") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "hello") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; lfs_unmount(&lfs) => 0; TEST @@ -223,23 +225,23 @@ scripts/test.py << TEST TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "c") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "c") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; - lfs_dir_open(&lfs, &dir[0], "d") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; + lfs_dir_open(&lfs, &dir, "d") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "hello") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "hi") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; lfs_unmount(&lfs) => 0; TEST @@ -247,36 +249,36 @@ echo "--- Move check ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "a/hi") => LFS_ERR_NOENT; - lfs_dir_open(&lfs, &dir[0], "b/hi") => LFS_ERR_NOENT; - lfs_dir_open(&lfs, &dir[0], "c/hi") => LFS_ERR_NOENT; + lfs_dir_open(&lfs, &dir, "a/hi") => LFS_ERR_NOENT; + lfs_dir_open(&lfs, &dir, "b/hi") => LFS_ERR_NOENT; + lfs_dir_open(&lfs, &dir, "c/hi") => LFS_ERR_NOENT; - lfs_dir_open(&lfs, &dir[0], "d/hi") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "d/hi") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "bonjour") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "hola") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "ohayo") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; - lfs_dir_open(&lfs, &dir[0], "a/hello") => LFS_ERR_NOENT; - lfs_dir_open(&lfs, &dir[0], "b/hello") => LFS_ERR_NOENT; - lfs_dir_open(&lfs, &dir[0], "c/hello") => LFS_ERR_NOENT; + lfs_dir_open(&lfs, &dir, "a/hello") => LFS_ERR_NOENT; + lfs_dir_open(&lfs, &dir, "b/hello") => LFS_ERR_NOENT; + lfs_dir_open(&lfs, &dir, "c/hello") => LFS_ERR_NOENT; - lfs_file_open(&lfs, &file[0], "d/hello", LFS_O_RDONLY) => 0; - lfs_file_read(&lfs, &file[0], buffer, 5) => 5; + lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => 0; + lfs_file_read(&lfs, &file, buffer, 5) => 5; memcmp(buffer, "hola\n", 5) => 0; - lfs_file_read(&lfs, &file[0], buffer, 8) => 8; + lfs_file_read(&lfs, &file, buffer, 8) => 8; memcmp(buffer, "bonjour\n", 8) => 0; - lfs_file_read(&lfs, &file[0], buffer, 6) => 6; + lfs_file_read(&lfs, &file, buffer, 6) => 6; memcmp(buffer, "ohayo\n", 6) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST @@ -293,40 +295,39 @@ TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "a/hi") => LFS_ERR_NOENT; - lfs_dir_open(&lfs, &dir[0], "b") => LFS_ERR_NOENT; - lfs_dir_open(&lfs, &dir[0], "c") => LFS_ERR_NOENT; + lfs_dir_open(&lfs, &dir, "a/hi") => LFS_ERR_NOENT; + lfs_dir_open(&lfs, &dir, "b") => LFS_ERR_NOENT; + lfs_dir_open(&lfs, &dir, "c") => LFS_ERR_NOENT; - lfs_dir_open(&lfs, &dir[0], "d/hi") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "d/hi") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "bonjour") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "hola") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "ohayo") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; + lfs_dir_read(&lfs, &dir, &info) => 0; + lfs_dir_close(&lfs, &dir) => 0; - lfs_dir_open(&lfs, &dir[0], "a/hello") => LFS_ERR_NOENT; - lfs_dir_open(&lfs, &dir[0], "b") => LFS_ERR_NOENT; - lfs_dir_open(&lfs, &dir[0], "c") => LFS_ERR_NOENT; + lfs_dir_open(&lfs, &dir, "a/hello") => LFS_ERR_NOENT; + lfs_dir_open(&lfs, &dir, "b") => LFS_ERR_NOENT; + lfs_dir_open(&lfs, &dir, "c") => LFS_ERR_NOENT; - lfs_file_open(&lfs, &file[0], "d/hello", LFS_O_RDONLY) => 0; - lfs_file_read(&lfs, &file[0], buffer, 5) => 5; + lfs_file_open(&lfs, &file, "d/hello", LFS_O_RDONLY) => 0; + lfs_file_read(&lfs, &file, buffer, 5) => 5; memcmp(buffer, "hola\n", 5) => 0; - lfs_file_read(&lfs, &file[0], buffer, 8) => 8; + lfs_file_read(&lfs, &file, buffer, 8) => 8; memcmp(buffer, "bonjour\n", 8) => 0; - lfs_file_read(&lfs, &file[0], buffer, 6) => 6; + lfs_file_read(&lfs, &file, buffer, 6) => 6; memcmp(buffer, "ohayo\n", 6) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST -echo "--- Results ---" -scripts/stats.py +scripts/results.py diff --git a/tests/test_orphan.sh b/tests/test_orphan.sh index cf1fa9f..b0a8493 100755 --- a/tests/test_orphan.sh +++ b/tests/test_orphan.sh @@ -1,5 +1,7 @@ #!/bin/bash set -eu +export TEST_FILE=$0 +trap 'export TEST_LINE=$LINENO' DEBUG echo "=== Orphan tests ===" rm -rf blocks @@ -41,5 +43,4 @@ scripts/test.py << TEST lfs_unmount(&lfs) => 0; TEST -echo "--- Results ---" -scripts/stats.py +scripts/results.py diff --git a/tests/test_paths.sh b/tests/test_paths.sh index 5389248..f720e39 100755 --- a/tests/test_paths.sh +++ b/tests/test_paths.sh @@ -1,5 +1,7 @@ #!/bin/bash set -eu +export TEST_FILE=$0 +trap 'export TEST_LINE=$LINENO' DEBUG echo "=== Path tests ===" rm -rf blocks @@ -126,7 +128,7 @@ scripts/test.py << TEST strcmp(info.name, "/") => 0; lfs_mkdir(&lfs, "/") => LFS_ERR_EXIST; - lfs_file_open(&lfs, &file[0], "/", LFS_O_WRONLY | LFS_O_CREAT) + lfs_file_open(&lfs, &file, "/", LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_ISDIR; // more corner cases @@ -158,17 +160,17 @@ TEST echo "--- Max path test ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - memset(buffer, 'w', LFS_NAME_MAX+1); - buffer[LFS_NAME_MAX+2] = '\0'; - lfs_mkdir(&lfs, (char*)buffer) => LFS_ERR_NAMETOOLONG; - lfs_file_open(&lfs, &file[0], (char*)buffer, + memset(path, 'w', LFS_NAME_MAX+1); + path[LFS_NAME_MAX+2] = '\0'; + lfs_mkdir(&lfs, path) => LFS_ERR_NAMETOOLONG; + lfs_file_open(&lfs, &file, path, LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_NAMETOOLONG; - memcpy(buffer, "coffee/", strlen("coffee/")); - memset(buffer+strlen("coffee/"), 'w', LFS_NAME_MAX+1); - buffer[strlen("coffee/")+LFS_NAME_MAX+2] = '\0'; - lfs_mkdir(&lfs, (char*)buffer) => LFS_ERR_NAMETOOLONG; - lfs_file_open(&lfs, &file[0], (char*)buffer, + memcpy(path, "coffee/", strlen("coffee/")); + memset(path+strlen("coffee/"), 'w', LFS_NAME_MAX+1); + path[strlen("coffee/")+LFS_NAME_MAX+2] = '\0'; + lfs_mkdir(&lfs, path) => LFS_ERR_NAMETOOLONG; + lfs_file_open(&lfs, &file, path, LFS_O_WRONLY | LFS_O_CREAT) => LFS_ERR_NAMETOOLONG; lfs_unmount(&lfs) => 0; TEST @@ -176,26 +178,25 @@ TEST echo "--- Really big path test ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - memset(buffer, 'w', LFS_NAME_MAX); - buffer[LFS_NAME_MAX+1] = '\0'; - lfs_mkdir(&lfs, (char*)buffer) => 0; - lfs_remove(&lfs, (char*)buffer) => 0; - lfs_file_open(&lfs, &file[0], (char*)buffer, + memset(path, 'w', LFS_NAME_MAX); + path[LFS_NAME_MAX+1] = '\0'; + lfs_mkdir(&lfs, path) => 0; + lfs_remove(&lfs, path) => 0; + lfs_file_open(&lfs, &file, path, LFS_O_WRONLY | LFS_O_CREAT) => 0; - lfs_file_close(&lfs, &file[0]) => 0; - lfs_remove(&lfs, (char*)buffer) => 0; + lfs_file_close(&lfs, &file) => 0; + lfs_remove(&lfs, path) => 0; - memcpy(buffer, "coffee/", strlen("coffee/")); - memset(buffer+strlen("coffee/"), 'w', LFS_NAME_MAX); - buffer[strlen("coffee/")+LFS_NAME_MAX+1] = '\0'; - lfs_mkdir(&lfs, (char*)buffer) => 0; - lfs_remove(&lfs, (char*)buffer) => 0; - lfs_file_open(&lfs, &file[0], (char*)buffer, + memcpy(path, "coffee/", strlen("coffee/")); + memset(path+strlen("coffee/"), 'w', LFS_NAME_MAX); + path[strlen("coffee/")+LFS_NAME_MAX+1] = '\0'; + lfs_mkdir(&lfs, path) => 0; + lfs_remove(&lfs, path) => 0; + lfs_file_open(&lfs, &file, path, LFS_O_WRONLY | LFS_O_CREAT) => 0; - lfs_file_close(&lfs, &file[0]) => 0; - lfs_remove(&lfs, (char*)buffer) => 0; + lfs_file_close(&lfs, &file) => 0; + lfs_remove(&lfs, path) => 0; lfs_unmount(&lfs) => 0; TEST -echo "--- Results ---" -scripts/stats.py +scripts/results.py diff --git a/tests/test_seek.sh b/tests/test_seek.sh index 83c3685..e5696d0 100755 --- a/tests/test_seek.sh +++ b/tests/test_seek.sh @@ -1,28 +1,31 @@ #!/bin/bash set -eu +export TEST_FILE=$0 +trap 'export TEST_LINE=$LINENO' DEBUG + +echo "=== Seek tests ===" SMALLSIZE=4 MEDIUMSIZE=128 LARGESIZE=132 -echo "=== Seek tests ===" rm -rf blocks scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; lfs_mount(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "hello") => 0; for (int i = 0; i < $LARGESIZE; i++) { - sprintf((char*)buffer, "hello/kitty%03d", i); - lfs_file_open(&lfs, &file[0], (char*)buffer, + sprintf(path, "hello/kitty%03d", i); + lfs_file_open(&lfs, &file, path, LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0; - size = strlen("kittycatcat"); + lfs_size_t size = strlen("kittycatcat"); memcpy(buffer, "kittycatcat", size); for (int j = 0; j < $LARGESIZE; j++) { - lfs_file_write(&lfs, &file[0], buffer, size); + lfs_file_write(&lfs, &file, buffer, size); } - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; } lfs_unmount(&lfs) => 0; TEST @@ -30,330 +33,330 @@ TEST echo "--- Simple dir seek ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "hello") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "hello") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; lfs_soff_t pos; int i; for (i = 0; i < $SMALLSIZE; i++) { - sprintf((char*)buffer, "kitty%03d", i); - lfs_dir_read(&lfs, &dir[0], &info) => 1; - strcmp(info.name, (char*)buffer) => 0; - pos = lfs_dir_tell(&lfs, &dir[0]); + sprintf(path, "kitty%03d", i); + lfs_dir_read(&lfs, &dir, &info) => 1; + strcmp(info.name, path) => 0; + pos = lfs_dir_tell(&lfs, &dir); } pos >= 0 => 1; - lfs_dir_seek(&lfs, &dir[0], pos) => 0; - sprintf((char*)buffer, "kitty%03d", i); - lfs_dir_read(&lfs, &dir[0], &info) => 1; - strcmp(info.name, (char*)buffer) => 0; + lfs_dir_seek(&lfs, &dir, pos) => 0; + sprintf(path, "kitty%03d", i); + lfs_dir_read(&lfs, &dir, &info) => 1; + strcmp(info.name, path) => 0; - lfs_dir_rewind(&lfs, &dir[0]) => 0; - sprintf((char*)buffer, "kitty%03d", 0); - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_rewind(&lfs, &dir) => 0; + sprintf(path, "kitty%03d", 0); + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; - strcmp(info.name, (char*)buffer) => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; + strcmp(info.name, path) => 0; - lfs_dir_seek(&lfs, &dir[0], pos) => 0; - sprintf((char*)buffer, "kitty%03d", i); - lfs_dir_read(&lfs, &dir[0], &info) => 1; - strcmp(info.name, (char*)buffer) => 0; + lfs_dir_seek(&lfs, &dir, pos) => 0; + sprintf(path, "kitty%03d", i); + lfs_dir_read(&lfs, &dir, &info) => 1; + strcmp(info.name, path) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; + lfs_dir_close(&lfs, &dir) => 0; lfs_unmount(&lfs) => 0; TEST echo "--- Large dir seek ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_dir_open(&lfs, &dir[0], "hello") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_open(&lfs, &dir, "hello") => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; lfs_soff_t pos; int i; for (i = 0; i < $MEDIUMSIZE; i++) { - sprintf((char*)buffer, "kitty%03d", i); - lfs_dir_read(&lfs, &dir[0], &info) => 1; - strcmp(info.name, (char*)buffer) => 0; - pos = lfs_dir_tell(&lfs, &dir[0]); + sprintf(path, "kitty%03d", i); + lfs_dir_read(&lfs, &dir, &info) => 1; + strcmp(info.name, path) => 0; + pos = lfs_dir_tell(&lfs, &dir); } pos >= 0 => 1; - lfs_dir_seek(&lfs, &dir[0], pos) => 0; - sprintf((char*)buffer, "kitty%03d", i); - lfs_dir_read(&lfs, &dir[0], &info) => 1; - strcmp(info.name, (char*)buffer) => 0; + lfs_dir_seek(&lfs, &dir, pos) => 0; + sprintf(path, "kitty%03d", i); + lfs_dir_read(&lfs, &dir, &info) => 1; + strcmp(info.name, path) => 0; - lfs_dir_rewind(&lfs, &dir[0]) => 0; - sprintf((char*)buffer, "kitty%03d", 0); - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_rewind(&lfs, &dir) => 0; + sprintf(path, "kitty%03d", 0); + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, ".") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; + lfs_dir_read(&lfs, &dir, &info) => 1; strcmp(info.name, "..") => 0; - lfs_dir_read(&lfs, &dir[0], &info) => 1; - strcmp(info.name, (char*)buffer) => 0; + lfs_dir_read(&lfs, &dir, &info) => 1; + strcmp(info.name, path) => 0; - lfs_dir_seek(&lfs, &dir[0], pos) => 0; - sprintf((char*)buffer, "kitty%03d", i); - lfs_dir_read(&lfs, &dir[0], &info) => 1; - strcmp(info.name, (char*)buffer) => 0; + lfs_dir_seek(&lfs, &dir, pos) => 0; + sprintf(path, "kitty%03d", i); + lfs_dir_read(&lfs, &dir, &info) => 1; + strcmp(info.name, path) => 0; - lfs_dir_close(&lfs, &dir[0]) => 0; + lfs_dir_close(&lfs, &dir) => 0; lfs_unmount(&lfs) => 0; TEST echo "--- Simple file seek ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "hello/kitty042", LFS_O_RDONLY) => 0; + lfs_file_open(&lfs, &file, "hello/kitty042", LFS_O_RDONLY) => 0; lfs_soff_t pos; - size = strlen("kittycatcat"); + lfs_size_t size = strlen("kittycatcat"); for (int i = 0; i < $SMALLSIZE; i++) { - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - pos = lfs_file_tell(&lfs, &file[0]); + pos = lfs_file_tell(&lfs, &file); } pos >= 0 => 1; - lfs_file_seek(&lfs, &file[0], pos, LFS_SEEK_SET) => pos; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, pos, LFS_SEEK_SET) => pos; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - lfs_file_rewind(&lfs, &file[0]) => 0; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_rewind(&lfs, &file) => 0; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - lfs_file_seek(&lfs, &file[0], 0, LFS_SEEK_CUR) => size; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, 0, LFS_SEEK_CUR) => size; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - lfs_file_seek(&lfs, &file[0], size, LFS_SEEK_CUR) => 3*size; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, size, LFS_SEEK_CUR) => 3*size; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - lfs_file_seek(&lfs, &file[0], pos, LFS_SEEK_SET) => pos; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, pos, LFS_SEEK_SET) => pos; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - lfs_file_seek(&lfs, &file[0], -size, LFS_SEEK_CUR) => pos; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, -size, LFS_SEEK_CUR) => pos; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - lfs_file_seek(&lfs, &file[0], -size, LFS_SEEK_END) >= 0 => 1; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, -size, LFS_SEEK_END) >= 0 => 1; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - size = lfs_file_size(&lfs, &file[0]); - lfs_file_seek(&lfs, &file[0], 0, LFS_SEEK_CUR) => size; + size = lfs_file_size(&lfs, &file); + lfs_file_seek(&lfs, &file, 0, LFS_SEEK_CUR) => size; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST echo "--- Large file seek ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "hello/kitty042", LFS_O_RDONLY) => 0; + lfs_file_open(&lfs, &file, "hello/kitty042", LFS_O_RDONLY) => 0; lfs_soff_t pos; - size = strlen("kittycatcat"); + lfs_size_t size = strlen("kittycatcat"); for (int i = 0; i < $MEDIUMSIZE; i++) { - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - pos = lfs_file_tell(&lfs, &file[0]); + pos = lfs_file_tell(&lfs, &file); } pos >= 0 => 1; - lfs_file_seek(&lfs, &file[0], pos, LFS_SEEK_SET) => pos; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, pos, LFS_SEEK_SET) => pos; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - lfs_file_rewind(&lfs, &file[0]) => 0; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_rewind(&lfs, &file) => 0; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - lfs_file_seek(&lfs, &file[0], 0, LFS_SEEK_CUR) => size; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, 0, LFS_SEEK_CUR) => size; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - lfs_file_seek(&lfs, &file[0], size, LFS_SEEK_CUR) => 3*size; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, size, LFS_SEEK_CUR) => 3*size; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - lfs_file_seek(&lfs, &file[0], pos, LFS_SEEK_SET) => pos; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, pos, LFS_SEEK_SET) => pos; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - lfs_file_seek(&lfs, &file[0], -size, LFS_SEEK_CUR) => pos; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, -size, LFS_SEEK_CUR) => pos; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - lfs_file_seek(&lfs, &file[0], -size, LFS_SEEK_END) >= 0 => 1; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, -size, LFS_SEEK_END) >= 0 => 1; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - size = lfs_file_size(&lfs, &file[0]); - lfs_file_seek(&lfs, &file[0], 0, LFS_SEEK_CUR) => size; + size = lfs_file_size(&lfs, &file); + lfs_file_seek(&lfs, &file, 0, LFS_SEEK_CUR) => size; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST echo "--- Simple file seek and write ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "hello/kitty042", LFS_O_RDWR) => 0; + lfs_file_open(&lfs, &file, "hello/kitty042", LFS_O_RDWR) => 0; lfs_soff_t pos; - size = strlen("kittycatcat"); + lfs_size_t size = strlen("kittycatcat"); for (int i = 0; i < $SMALLSIZE; i++) { - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - pos = lfs_file_tell(&lfs, &file[0]); + pos = lfs_file_tell(&lfs, &file); } pos >= 0 => 1; memcpy(buffer, "doggodogdog", size); - lfs_file_seek(&lfs, &file[0], pos, LFS_SEEK_SET) => pos; - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, pos, LFS_SEEK_SET) => pos; + lfs_file_write(&lfs, &file, buffer, size) => size; - lfs_file_seek(&lfs, &file[0], pos, LFS_SEEK_SET) => pos; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, pos, LFS_SEEK_SET) => pos; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "doggodogdog", size) => 0; - lfs_file_rewind(&lfs, &file[0]) => 0; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_rewind(&lfs, &file) => 0; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - lfs_file_seek(&lfs, &file[0], pos, LFS_SEEK_SET) => pos; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, pos, LFS_SEEK_SET) => pos; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "doggodogdog", size) => 0; - lfs_file_seek(&lfs, &file[0], -size, LFS_SEEK_END) >= 0 => 1; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, -size, LFS_SEEK_END) >= 0 => 1; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - size = lfs_file_size(&lfs, &file[0]); - lfs_file_seek(&lfs, &file[0], 0, LFS_SEEK_CUR) => size; + size = lfs_file_size(&lfs, &file); + lfs_file_seek(&lfs, &file, 0, LFS_SEEK_CUR) => size; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST echo "--- Large file seek and write ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "hello/kitty042", LFS_O_RDWR) => 0; + lfs_file_open(&lfs, &file, "hello/kitty042", LFS_O_RDWR) => 0; lfs_soff_t pos; - size = strlen("kittycatcat"); + lfs_size_t size = strlen("kittycatcat"); for (int i = 0; i < $MEDIUMSIZE; i++) { - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_read(&lfs, &file, buffer, size) => size; if (i != $SMALLSIZE) { memcmp(buffer, "kittycatcat", size) => 0; } - pos = lfs_file_tell(&lfs, &file[0]); + pos = lfs_file_tell(&lfs, &file); } pos >= 0 => 1; memcpy(buffer, "doggodogdog", size); - lfs_file_seek(&lfs, &file[0], pos, LFS_SEEK_SET) => pos; - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, pos, LFS_SEEK_SET) => pos; + lfs_file_write(&lfs, &file, buffer, size) => size; - lfs_file_seek(&lfs, &file[0], pos, LFS_SEEK_SET) => pos; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, pos, LFS_SEEK_SET) => pos; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "doggodogdog", size) => 0; - lfs_file_rewind(&lfs, &file[0]) => 0; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_rewind(&lfs, &file) => 0; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - lfs_file_seek(&lfs, &file[0], pos, LFS_SEEK_SET) => pos; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, pos, LFS_SEEK_SET) => pos; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "doggodogdog", size) => 0; - lfs_file_seek(&lfs, &file[0], -size, LFS_SEEK_END) >= 0 => 1; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, -size, LFS_SEEK_END) >= 0 => 1; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - size = lfs_file_size(&lfs, &file[0]); - lfs_file_seek(&lfs, &file[0], 0, LFS_SEEK_CUR) => size; + size = lfs_file_size(&lfs, &file); + lfs_file_seek(&lfs, &file, 0, LFS_SEEK_CUR) => size; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST echo "--- Boundary seek and write ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "hello/kitty042", LFS_O_RDWR) => 0; + lfs_file_open(&lfs, &file, "hello/kitty042", LFS_O_RDWR) => 0; - size = strlen("hedgehoghog"); + lfs_size_t size = strlen("hedgehoghog"); const lfs_soff_t offsets[] = {512, 1020, 513, 1021, 511, 1019}; for (unsigned i = 0; i < sizeof(offsets) / sizeof(offsets[0]); i++) { lfs_soff_t off = offsets[i]; memcpy(buffer, "hedgehoghog", size); - lfs_file_seek(&lfs, &file[0], off, LFS_SEEK_SET) => off; - lfs_file_write(&lfs, &file[0], buffer, size) => size; - lfs_file_seek(&lfs, &file[0], off, LFS_SEEK_SET) => off; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off; + lfs_file_write(&lfs, &file, buffer, size) => size; + lfs_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "hedgehoghog", size) => 0; - lfs_file_seek(&lfs, &file[0], 0, LFS_SEEK_SET) => 0; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_seek(&lfs, &file, 0, LFS_SEEK_SET) => 0; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "kittycatcat", size) => 0; - lfs_file_sync(&lfs, &file[0]) => 0; + lfs_file_sync(&lfs, &file) => 0; } - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST echo "--- Out-of-bounds seek ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "hello/kitty042", LFS_O_RDWR) => 0; + lfs_file_open(&lfs, &file, "hello/kitty042", LFS_O_RDWR) => 0; - size = strlen("kittycatcat"); - lfs_file_size(&lfs, &file[0]) => $LARGESIZE*size; - lfs_file_seek(&lfs, &file[0], ($LARGESIZE+$SMALLSIZE)*size, + lfs_size_t size = strlen("kittycatcat"); + lfs_file_size(&lfs, &file) => $LARGESIZE*size; + lfs_file_seek(&lfs, &file, ($LARGESIZE+$SMALLSIZE)*size, LFS_SEEK_SET) => ($LARGESIZE+$SMALLSIZE)*size; - lfs_file_read(&lfs, &file[0], buffer, size) => 0; + lfs_file_read(&lfs, &file, buffer, size) => 0; memcpy(buffer, "porcupineee", size); - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_write(&lfs, &file, buffer, size) => size; - lfs_file_seek(&lfs, &file[0], ($LARGESIZE+$SMALLSIZE)*size, + lfs_file_seek(&lfs, &file, ($LARGESIZE+$SMALLSIZE)*size, LFS_SEEK_SET) => ($LARGESIZE+$SMALLSIZE)*size; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "porcupineee", size) => 0; - lfs_file_seek(&lfs, &file[0], $LARGESIZE*size, + lfs_file_seek(&lfs, &file, $LARGESIZE*size, LFS_SEEK_SET) => $LARGESIZE*size; - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "\0\0\0\0\0\0\0\0\0\0\0", size) => 0; - lfs_file_seek(&lfs, &file[0], -(($LARGESIZE+$SMALLSIZE)*size), + lfs_file_seek(&lfs, &file, -(($LARGESIZE+$SMALLSIZE)*size), LFS_SEEK_CUR) => LFS_ERR_INVAL; - lfs_file_tell(&lfs, &file[0]) => ($LARGESIZE+1)*size; + lfs_file_tell(&lfs, &file) => ($LARGESIZE+1)*size; - lfs_file_seek(&lfs, &file[0], -(($LARGESIZE+2*$SMALLSIZE)*size), + lfs_file_seek(&lfs, &file, -(($LARGESIZE+2*$SMALLSIZE)*size), LFS_SEEK_END) => LFS_ERR_INVAL; - lfs_file_tell(&lfs, &file[0]) => ($LARGESIZE+1)*size; + lfs_file_tell(&lfs, &file) => ($LARGESIZE+1)*size; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST @@ -362,68 +365,67 @@ for SIZE in $SMALLSIZE $MEDIUMSIZE $LARGESIZE do scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "hello/tinykitty$SIZE", + lfs_file_open(&lfs, &file, "hello/tinykitty$SIZE", LFS_O_RDWR | LFS_O_CREAT) => 0; int j = 0; int k = 0; memcpy(buffer, "abcdefghijklmnopqrstuvwxyz", 26); for (unsigned i = 0; i < $SIZE; i++) { - lfs_file_write(&lfs, &file[0], &buffer[j++ % 26], 1) => 1; - lfs_file_tell(&lfs, &file[0]) => i+1; - lfs_file_size(&lfs, &file[0]) => i+1; + lfs_file_write(&lfs, &file, &buffer[j++ % 26], 1) => 1; + lfs_file_tell(&lfs, &file) => i+1; + lfs_file_size(&lfs, &file) => i+1; } - lfs_file_seek(&lfs, &file[0], 0, LFS_SEEK_SET) => 0; - lfs_file_tell(&lfs, &file[0]) => 0; - lfs_file_size(&lfs, &file[0]) => $SIZE; + lfs_file_seek(&lfs, &file, 0, LFS_SEEK_SET) => 0; + lfs_file_tell(&lfs, &file) => 0; + lfs_file_size(&lfs, &file) => $SIZE; for (unsigned i = 0; i < $SIZE; i++) { uint8_t c; - lfs_file_read(&lfs, &file[0], &c, 1) => 1; + lfs_file_read(&lfs, &file, &c, 1) => 1; c => buffer[k++ % 26]; } - lfs_file_sync(&lfs, &file[0]) => 0; - lfs_file_tell(&lfs, &file[0]) => $SIZE; - lfs_file_size(&lfs, &file[0]) => $SIZE; + lfs_file_sync(&lfs, &file) => 0; + lfs_file_tell(&lfs, &file) => $SIZE; + lfs_file_size(&lfs, &file) => $SIZE; - lfs_file_seek(&lfs, &file[0], 0, LFS_SEEK_SET) => 0; + lfs_file_seek(&lfs, &file, 0, LFS_SEEK_SET) => 0; for (unsigned i = 0; i < $SIZE; i++) { - lfs_file_write(&lfs, &file[0], &buffer[j++ % 26], 1) => 1; - lfs_file_tell(&lfs, &file[0]) => i+1; - lfs_file_size(&lfs, &file[0]) => $SIZE; - lfs_file_sync(&lfs, &file[0]) => 0; - lfs_file_tell(&lfs, &file[0]) => i+1; - lfs_file_size(&lfs, &file[0]) => $SIZE; + lfs_file_write(&lfs, &file, &buffer[j++ % 26], 1) => 1; + lfs_file_tell(&lfs, &file) => i+1; + lfs_file_size(&lfs, &file) => $SIZE; + lfs_file_sync(&lfs, &file) => 0; + lfs_file_tell(&lfs, &file) => i+1; + lfs_file_size(&lfs, &file) => $SIZE; if (i < $SIZE-2) { uint8_t c[3]; - lfs_file_seek(&lfs, &file[0], -1, LFS_SEEK_CUR) => i; - lfs_file_read(&lfs, &file[0], &c, 3) => 3; - lfs_file_tell(&lfs, &file[0]) => i+3; - lfs_file_size(&lfs, &file[0]) => $SIZE; - lfs_file_seek(&lfs, &file[0], i+1, LFS_SEEK_SET) => i+1; - lfs_file_tell(&lfs, &file[0]) => i+1; - lfs_file_size(&lfs, &file[0]) => $SIZE; + lfs_file_seek(&lfs, &file, -1, LFS_SEEK_CUR) => i; + lfs_file_read(&lfs, &file, &c, 3) => 3; + lfs_file_tell(&lfs, &file) => i+3; + lfs_file_size(&lfs, &file) => $SIZE; + lfs_file_seek(&lfs, &file, i+1, LFS_SEEK_SET) => i+1; + lfs_file_tell(&lfs, &file) => i+1; + lfs_file_size(&lfs, &file) => $SIZE; } } - lfs_file_seek(&lfs, &file[0], 0, LFS_SEEK_SET) => 0; - lfs_file_tell(&lfs, &file[0]) => 0; - lfs_file_size(&lfs, &file[0]) => $SIZE; + lfs_file_seek(&lfs, &file, 0, LFS_SEEK_SET) => 0; + lfs_file_tell(&lfs, &file) => 0; + lfs_file_size(&lfs, &file) => $SIZE; for (unsigned i = 0; i < $SIZE; i++) { uint8_t c; - lfs_file_read(&lfs, &file[0], &c, 1) => 1; + lfs_file_read(&lfs, &file, &c, 1) => 1; c => buffer[k++ % 26]; } - lfs_file_sync(&lfs, &file[0]) => 0; - lfs_file_tell(&lfs, &file[0]) => $SIZE; - lfs_file_size(&lfs, &file[0]) => $SIZE; + lfs_file_sync(&lfs, &file) => 0; + lfs_file_tell(&lfs, &file) => $SIZE; + lfs_file_size(&lfs, &file) => $SIZE; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST done -echo "--- Results ---" -scripts/stats.py +scripts/results.py diff --git a/tests/test_truncate.sh b/tests/test_truncate.sh index 3810d00..ee42693 100755 --- a/tests/test_truncate.sh +++ b/tests/test_truncate.sh @@ -1,11 +1,14 @@ #!/bin/bash set -eu +export TEST_FILE=$0 +trap 'export TEST_LINE=$LINENO' DEBUG + +echo "=== Truncate tests ===" SMALLSIZE=32 MEDIUMSIZE=2048 LARGESIZE=8192 -echo "=== Truncate tests ===" rm -rf blocks scripts/test.py << TEST lfs_format(&lfs, &cfg) => 0; @@ -14,143 +17,143 @@ TEST echo "--- Simple truncate ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "baldynoop", + lfs_file_open(&lfs, &file, "baldynoop", LFS_O_WRONLY | LFS_O_CREAT) => 0; strcpy((char*)buffer, "hair"); - size = strlen((char*)buffer); + lfs_size_t size = strlen((char*)buffer); for (lfs_off_t j = 0; j < $LARGESIZE; j += size) { - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_write(&lfs, &file, buffer, size) => size; } - lfs_file_size(&lfs, &file[0]) => $LARGESIZE; + lfs_file_size(&lfs, &file) => $LARGESIZE; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "baldynoop", LFS_O_RDWR) => 0; - lfs_file_size(&lfs, &file[0]) => $LARGESIZE; + lfs_file_open(&lfs, &file, "baldynoop", LFS_O_RDWR) => 0; + lfs_file_size(&lfs, &file) => $LARGESIZE; - lfs_file_truncate(&lfs, &file[0], $MEDIUMSIZE) => 0; - lfs_file_size(&lfs, &file[0]) => $MEDIUMSIZE; + lfs_file_truncate(&lfs, &file, $MEDIUMSIZE) => 0; + lfs_file_size(&lfs, &file) => $MEDIUMSIZE; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "baldynoop", LFS_O_RDONLY) => 0; - lfs_file_size(&lfs, &file[0]) => $MEDIUMSIZE; + lfs_file_open(&lfs, &file, "baldynoop", LFS_O_RDONLY) => 0; + lfs_file_size(&lfs, &file) => $MEDIUMSIZE; - size = strlen("hair"); + lfs_size_t size = strlen("hair"); for (lfs_off_t j = 0; j < $MEDIUMSIZE; j += size) { - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "hair", size) => 0; } - lfs_file_read(&lfs, &file[0], buffer, size) => 0; + lfs_file_read(&lfs, &file, buffer, size) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST echo "--- Truncate and read ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "baldyread", + lfs_file_open(&lfs, &file, "baldyread", LFS_O_WRONLY | LFS_O_CREAT) => 0; strcpy((char*)buffer, "hair"); - size = strlen((char*)buffer); + lfs_size_t size = strlen((char*)buffer); for (lfs_off_t j = 0; j < $LARGESIZE; j += size) { - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_write(&lfs, &file, buffer, size) => size; } - lfs_file_size(&lfs, &file[0]) => $LARGESIZE; + lfs_file_size(&lfs, &file) => $LARGESIZE; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "baldyread", LFS_O_RDWR) => 0; - lfs_file_size(&lfs, &file[0]) => $LARGESIZE; + lfs_file_open(&lfs, &file, "baldyread", LFS_O_RDWR) => 0; + lfs_file_size(&lfs, &file) => $LARGESIZE; - lfs_file_truncate(&lfs, &file[0], $MEDIUMSIZE) => 0; - lfs_file_size(&lfs, &file[0]) => $MEDIUMSIZE; + lfs_file_truncate(&lfs, &file, $MEDIUMSIZE) => 0; + lfs_file_size(&lfs, &file) => $MEDIUMSIZE; - size = strlen("hair"); + lfs_size_t size = strlen("hair"); for (lfs_off_t j = 0; j < $MEDIUMSIZE; j += size) { - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "hair", size) => 0; } - lfs_file_read(&lfs, &file[0], buffer, size) => 0; + lfs_file_read(&lfs, &file, buffer, size) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "baldyread", LFS_O_RDONLY) => 0; - lfs_file_size(&lfs, &file[0]) => $MEDIUMSIZE; + lfs_file_open(&lfs, &file, "baldyread", LFS_O_RDONLY) => 0; + lfs_file_size(&lfs, &file) => $MEDIUMSIZE; - size = strlen("hair"); + lfs_size_t size = strlen("hair"); for (lfs_off_t j = 0; j < $MEDIUMSIZE; j += size) { - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "hair", size) => 0; } - lfs_file_read(&lfs, &file[0], buffer, size) => 0; + lfs_file_read(&lfs, &file, buffer, size) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST echo "--- Truncate and write ---" scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "baldywrite", + lfs_file_open(&lfs, &file, "baldywrite", LFS_O_WRONLY | LFS_O_CREAT) => 0; strcpy((char*)buffer, "hair"); - size = strlen((char*)buffer); + lfs_size_t size = strlen((char*)buffer); for (lfs_off_t j = 0; j < $LARGESIZE; j += size) { - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_write(&lfs, &file, buffer, size) => size; } - lfs_file_size(&lfs, &file[0]) => $LARGESIZE; + lfs_file_size(&lfs, &file) => $LARGESIZE; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "baldywrite", LFS_O_RDWR) => 0; - lfs_file_size(&lfs, &file[0]) => $LARGESIZE; + lfs_file_open(&lfs, &file, "baldywrite", LFS_O_RDWR) => 0; + lfs_file_size(&lfs, &file) => $LARGESIZE; - lfs_file_truncate(&lfs, &file[0], $MEDIUMSIZE) => 0; - lfs_file_size(&lfs, &file[0]) => $MEDIUMSIZE; + lfs_file_truncate(&lfs, &file, $MEDIUMSIZE) => 0; + lfs_file_size(&lfs, &file) => $MEDIUMSIZE; strcpy((char*)buffer, "bald"); - size = strlen((char*)buffer); + lfs_size_t size = strlen((char*)buffer); for (lfs_off_t j = 0; j < $MEDIUMSIZE; j += size) { - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_write(&lfs, &file, buffer, size) => size; } - lfs_file_size(&lfs, &file[0]) => $MEDIUMSIZE; + lfs_file_size(&lfs, &file) => $MEDIUMSIZE; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; - lfs_file_open(&lfs, &file[0], "baldywrite", LFS_O_RDONLY) => 0; - lfs_file_size(&lfs, &file[0]) => $MEDIUMSIZE; + lfs_file_open(&lfs, &file, "baldywrite", LFS_O_RDONLY) => 0; + lfs_file_size(&lfs, &file) => $MEDIUMSIZE; - size = strlen("bald"); + lfs_size_t size = strlen("bald"); for (lfs_off_t j = 0; j < $MEDIUMSIZE; j += size) { - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "bald", size) => 0; } - lfs_file_read(&lfs, &file[0], buffer, size) => 0; + lfs_file_read(&lfs, &file, buffer, size) => 0; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; TEST @@ -168,26 +171,26 @@ scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; for (unsigned i = 0; i < sizeof(startsizes)/sizeof(startsizes[0]); i++) { - sprintf((char*)buffer, "hairyhead%d", i); - lfs_file_open(&lfs, &file[0], (const char*)buffer, + sprintf(path, "hairyhead%d", i); + lfs_file_open(&lfs, &file, path, LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => 0; strcpy((char*)buffer, "hair"); - size = strlen((char*)buffer); + lfs_size_t size = strlen((char*)buffer); for (lfs_off_t j = 0; j < startsizes[i]; j += size) { - lfs_file_write(&lfs, &file[0], buffer, size) => size; + lfs_file_write(&lfs, &file, buffer, size) => size; } - lfs_file_size(&lfs, &file[0]) => startsizes[i]; + lfs_file_size(&lfs, &file) => startsizes[i]; if (startseeks[i] != startsizes[i]) { - lfs_file_seek(&lfs, &file[0], + lfs_file_seek(&lfs, &file, startseeks[i], LFS_SEEK_SET) => startseeks[i]; } - lfs_file_truncate(&lfs, &file[0], hotsizes[i]) => 0; - lfs_file_size(&lfs, &file[0]) => hotsizes[i]; + lfs_file_truncate(&lfs, &file, hotsizes[i]) => 0; + lfs_file_size(&lfs, &file) => hotsizes[i]; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; } lfs_unmount(&lfs) => 0; @@ -200,26 +203,26 @@ scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; for (unsigned i = 0; i < sizeof(startsizes)/sizeof(startsizes[0]); i++) { - sprintf((char*)buffer, "hairyhead%d", i); - lfs_file_open(&lfs, &file[0], (const char*)buffer, LFS_O_RDWR) => 0; - lfs_file_size(&lfs, &file[0]) => hotsizes[i]; + sprintf(path, "hairyhead%d", i); + lfs_file_open(&lfs, &file, path, LFS_O_RDWR) => 0; + lfs_file_size(&lfs, &file) => hotsizes[i]; - size = strlen("hair"); + lfs_size_t size = strlen("hair"); lfs_off_t j = 0; for (; j < startsizes[i] && j < hotsizes[i]; j += size) { - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "hair", size) => 0; } for (; j < hotsizes[i]; j += size) { - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "\0\0\0\0", size) => 0; } - lfs_file_truncate(&lfs, &file[0], coldsizes[i]) => 0; - lfs_file_size(&lfs, &file[0]) => coldsizes[i]; + lfs_file_truncate(&lfs, &file, coldsizes[i]) => 0; + lfs_file_size(&lfs, &file) => coldsizes[i]; - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; } lfs_unmount(&lfs) => 0; @@ -232,24 +235,24 @@ scripts/test.py << TEST lfs_mount(&lfs, &cfg) => 0; for (unsigned i = 0; i < sizeof(startsizes)/sizeof(startsizes[0]); i++) { - sprintf((char*)buffer, "hairyhead%d", i); - lfs_file_open(&lfs, &file[0], (const char*)buffer, LFS_O_RDONLY) => 0; - lfs_file_size(&lfs, &file[0]) => coldsizes[i]; + sprintf(path, "hairyhead%d", i); + lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) => 0; + lfs_file_size(&lfs, &file) => coldsizes[i]; - size = strlen("hair"); + lfs_size_t size = strlen("hair"); lfs_off_t j = 0; for (; j < startsizes[i] && j < hotsizes[i] && j < coldsizes[i]; j += size) { - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "hair", size) => 0; } for (; j < coldsizes[i]; j += size) { - lfs_file_read(&lfs, &file[0], buffer, size) => size; + lfs_file_read(&lfs, &file, buffer, size) => size; memcmp(buffer, "\0\0\0\0", size) => 0; } - lfs_file_close(&lfs, &file[0]) => 0; + lfs_file_close(&lfs, &file) => 0; } lfs_unmount(&lfs) => 0; @@ -298,5 +301,4 @@ truncate_test \ "2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE" \ "2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE, 2*$LARGESIZE" -echo "--- Results ---" -scripts/stats.py +scripts/results.py From ef1c926940f176b20078e56ae4dddd268d9c0497 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 24 Jul 2019 14:19:39 -0500 Subject: [PATCH 14/27] Increased testing to include geometries that can't be fully tested This is primarily to get better test coverage over devices with very large erase/prog/read sizes. The unfortunate state of the tests is that most of them rely on a specific block device size, so that ENOSPC and ECORRUPT errors occur in specific situations. This should be improved in the future, but at least for now we can open up some of the simpler tests to run on these different configurations. Also added testing over both 0x00 and 0xff erase values in emubd. Also added a number of small file tests that expose issues prevalent on NAND devices. --- .travis.yml | 12 ++++++++ emubd/lfs_emubd.c | 2 +- emubd/lfs_emubd.h | 16 ++-------- tests/template.fmt | 2 +- tests/test_files.sh | 71 +++++++++++++++++++++++++++++++++++++++++---- 5 files changed, 81 insertions(+), 22 deletions(-) diff --git a/.travis.yml b/.travis.yml index dcfedf6..04f8720 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,8 +23,20 @@ script: - make test QUIET=1 CFLAGS+="-DLFS_BLOCK_COUNT=1023 -DLFS_LOOKAHEAD_SIZE=256" - make clean test QUIET=1 CFLAGS+="-DLFS_INLINE_MAX=0" + - make clean test QUIET=1 CFLAGS+="-DLFS_EMUBD_ERASE_VALUE=0xff" - make clean test QUIET=1 CFLAGS+="-DLFS_NO_INTRINSICS" + # additional configurations that don't support all tests (this should be + # fixed but at the moment it is what it is) + - make test_files QUIET=1 + CFLAGS+="-DLFS_READ_SIZE=1 -DLFS_BLOCK_SIZE=4096" + - make test_files QUIET=1 + CFLAGS+="-DLFS_READ_SIZE=\(2*1024\) -DLFS_BLOCK_SIZE=\(64*1024\)" + - make test_files QUIET=1 + CFLAGS+="-DLFS_READ_SIZE=\(8*1024\) -DLFS_BLOCK_SIZE=\(64*1024\)" + - make test_files QUIET=1 + CFLAGS+="-DLFS_READ_SIZE=11 -DLFS_BLOCK_SIZE=704" + # compile and find the code size with the smallest configuration - make clean size OBJ="$(ls lfs*.o | tr '\n' ' ')" diff --git a/emubd/lfs_emubd.c b/emubd/lfs_emubd.c index 3f31bfa..3c77945 100644 --- a/emubd/lfs_emubd.c +++ b/emubd/lfs_emubd.c @@ -83,7 +83,7 @@ int lfs_emubd_create(const struct lfs_config *cfg, const char *path) { snprintf(emu->child, LFS_NAME_MAX, ".stats"); FILE *f = fopen(emu->path, "r"); if (!f) { - memset(&emu->stats, 0, sizeof(emu->stats)); + memset(&emu->stats, LFS_EMUBD_ERASE_VALUE, sizeof(emu->stats)); } else { size_t res = fread(&emu->stats, sizeof(emu->stats), 1, f); lfs_emubd_fromle32(emu); diff --git a/emubd/lfs_emubd.h b/emubd/lfs_emubd.h index 64afa3e..0fd78c1 100644 --- a/emubd/lfs_emubd.h +++ b/emubd/lfs_emubd.h @@ -17,20 +17,8 @@ extern "C" // Config options -#ifndef LFS_EMUBD_READ_SIZE -#define LFS_EMUBD_READ_SIZE 1 -#endif - -#ifndef LFS_EMUBD_PROG_SIZE -#define LFS_EMUBD_PROG_SIZE 1 -#endif - -#ifndef LFS_EMUBD_ERASE_SIZE -#define LFS_EMUBD_ERASE_SIZE 512 -#endif - -#ifndef LFS_EMUBD_TOTAL_SIZE -#define LFS_EMUBD_TOTAL_SIZE 524288 +#ifndef LFS_EMUBD_ERASE_VALUE +#define LFS_EMUBD_ERASE_VALUE 0x00 #endif diff --git a/tests/template.fmt b/tests/template.fmt index 7fdec7c..b52d907 100644 --- a/tests/template.fmt +++ b/tests/template.fmt @@ -82,7 +82,7 @@ uintmax_t test; #endif #ifndef LFS_CACHE_SIZE -#define LFS_CACHE_SIZE 64 +#define LFS_CACHE_SIZE (64 % LFS_PROG_SIZE == 0 ? 64 : LFS_PROG_SIZE) #endif #ifndef LFS_LOOKAHEAD_SIZE diff --git a/tests/test_files.sh b/tests/test_files.sh index 5251c61..950636a 100755 --- a/tests/test_files.sh +++ b/tests/test_files.sh @@ -135,20 +135,79 @@ tests/test.py << TEST lfs_unmount(&lfs) => 0; TEST -echo "--- Many file test ---" +echo "--- Many files test ---" tests/test.py << TEST lfs_format(&lfs, &cfg) => 0; TEST tests/test.py << TEST - // Create 300 files of 6 bytes + // Create 300 files of 7 bytes lfs_mount(&lfs, &cfg) => 0; - lfs_mkdir(&lfs, "directory") => 0; for (unsigned i = 0; i < 300; i++) { snprintf((char*)buffer, sizeof(buffer), "file_%03d", i); - lfs_file_open(&lfs, &file[0], (char*)buffer, LFS_O_WRONLY | LFS_O_CREAT) => 0; - size = 6; - memcpy(wbuffer, "Hello", size); + lfs_file_open(&lfs, &file[0], (char*)buffer, + LFS_O_RDWR | LFS_O_CREAT | LFS_O_EXCL) => 0; + size = 7; + snprintf((char*)wbuffer, size, "Hi %03d", i); lfs_file_write(&lfs, &file[0], wbuffer, size) => size; + lfs_file_rewind(&lfs, &file[0]) => 0; + lfs_file_read(&lfs, &file[0], rbuffer, size) => size; + memcmp(wbuffer, rbuffer, size) => 0; + lfs_file_close(&lfs, &file[0]) => 0; + } + lfs_unmount(&lfs) => 0; +TEST + +echo "--- Many files with flush test ---" +tests/test.py << TEST + lfs_format(&lfs, &cfg) => 0; +TEST +tests/test.py << TEST + // Create 300 files of 7 bytes + lfs_mount(&lfs, &cfg) => 0; + for (unsigned i = 0; i < 300; i++) { + snprintf((char*)buffer, sizeof(buffer), "file_%03d", i); + lfs_file_open(&lfs, &file[0], (char*)buffer, + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; + size = 7; + snprintf((char*)wbuffer, size, "Hi %03d", i); + lfs_file_write(&lfs, &file[0], wbuffer, size) => size; + lfs_file_close(&lfs, &file[0]) => 0; + + snprintf((char*)buffer, sizeof(buffer), "file_%03d", i); + lfs_file_open(&lfs, &file[0], (char*)buffer, LFS_O_RDONLY) => 0; + size = 7; + snprintf((char*)wbuffer, size, "Hi %03d", i); + lfs_file_read(&lfs, &file[0], rbuffer, size) => size; + memcmp(wbuffer, rbuffer, size) => 0; + lfs_file_close(&lfs, &file[0]) => 0; + } + lfs_unmount(&lfs) => 0; +TEST + +echo "--- Many files with power cycle test ---" +tests/test.py << TEST + lfs_format(&lfs, &cfg) => 0; +TEST +tests/test.py << TEST + // Create 300 files of 7 bytes + lfs_mount(&lfs, &cfg) => 0; + for (unsigned i = 0; i < 300; i++) { + snprintf((char*)buffer, sizeof(buffer), "file_%03d", i); + lfs_file_open(&lfs, &file[0], (char*)buffer, + LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; + size = 7; + snprintf((char*)wbuffer, size, "Hi %03d", i); + lfs_file_write(&lfs, &file[0], wbuffer, size) => size; + lfs_file_close(&lfs, &file[0]) => 0; + lfs_unmount(&lfs) => 0; + + lfs_mount(&lfs, &cfg) => 0; + snprintf((char*)buffer, sizeof(buffer), "file_%03d", i); + lfs_file_open(&lfs, &file[0], (char*)buffer, LFS_O_RDONLY) => 0; + size = 7; + snprintf((char*)wbuffer, size, "Hi %03d", i); + lfs_file_read(&lfs, &file[0], rbuffer, size) => size; + memcmp(wbuffer, rbuffer, size) => 0; lfs_file_close(&lfs, &file[0]) => 0; } lfs_unmount(&lfs) => 0; From 312326c4e47ed9bc19f0b120faf9d126a15c0bd1 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 24 Jul 2019 14:24:29 -0500 Subject: [PATCH 15/27] Added a better solution for large prog sizes A current limitation of the lfs tag is the 10-bit (1024) length field. This field is used to indicate padding for commits and effectively limits the size of commits to 1KiB. Because commits must be prog size aligned, this is a problem on devices with prog size > 1024. [---- 6KiB erase block ----] [-- 2KiB prog size --|-- 2KiB prog size --|-- 2KiB prog size --] [ 1KiB commit | ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ] This can be increased to 12-bit (4096), but for NAND devices this is still to small to completely solve the issue. The previous workaround was to just create unaligned commits. This can occur naturally if littlefs is used on portable media as the prog size does not have to be consistent on different drivers. If littlefs sees an unaligned commit, it treats the dir as unerased and must compact the dir if it creates any new commits. Unfortunately this isn't great. It effectively means that every small commit forced an erase on devices with prog size > 1024. This is pretty terrible. [---- 6KiB erase block ----] [-- 2KiB prog size --|-- 2KiB prog size --|-- 2KiB prog size --] [ 1KiB commit |------------------- wasted ---------------------] A different solution, implemented here, is to use multiple crc tags to pad the commit until the remaining space fits in the padding. This effectively looks like multiple empty commits and has a small runtime cost to parse these tags, but otherwise does no harm. [---- 6KiB erase block ----] [-- 2KiB prog size --|-- 2KiB prog size --|-- 2KiB prog size --] [ 1KiB commit | noop | 1KiB commit | noop | 1KiB commit | noop ] It was a bit tricky to implement, but now we can effectively support unlimited prog sizes since there's no limit to the number of commits in a block. found by kazink and joicetm --- lfs.c | 113 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 66 insertions(+), 47 deletions(-) diff --git a/lfs.c b/lfs.c index af3a5d7..a8724bb 100644 --- a/lfs.c +++ b/lfs.c @@ -1232,65 +1232,85 @@ static int lfs_dir_commitattr(lfs_t *lfs, struct lfs_commit *commit, static int lfs_dir_commitcrc(lfs_t *lfs, struct lfs_commit *commit) { // align to program units - lfs_off_t off = lfs_alignup(commit->off + 2*sizeof(uint32_t), + const lfs_off_t off1 = commit->off + sizeof(lfs_tag_t); + const lfs_off_t end = lfs_alignup(off1 + sizeof(uint32_t), lfs->cfg->prog_size); - // read erased state from next program unit - lfs_tag_t tag; - int err = lfs_bd_read(lfs, - NULL, &lfs->rcache, sizeof(tag), - commit->block, off, &tag, sizeof(tag)); - if (err && err != LFS_ERR_CORRUPT) { - return err; - } + // create crc tags to fill up remainder of commit, note that + // padding is not crcd, which lets fetches skip padding but + // makes committing a bit more complicated + while (commit->off < end) { + lfs_off_t off = commit->off + sizeof(lfs_tag_t); + lfs_off_t noff = lfs_min(end - off, 0x3fe) + off; + if (noff < end) { + noff = lfs_min(noff, end - 2*sizeof(uint32_t)); + } - // build crc tag - bool reset = ~lfs_frombe32(tag) >> 31; - tag = LFS_MKTAG(LFS_TYPE_CRC + reset, 0x3ff, - lfs_min(off - (commit->off+sizeof(lfs_tag_t)), 0x3fe)); + // read erased state from next program unit + lfs_tag_t tag = 0xffffffff; + int err = lfs_bd_read(lfs, + NULL, &lfs->rcache, sizeof(tag), + commit->block, noff, &tag, sizeof(tag)); + if (err && err != LFS_ERR_CORRUPT) { + return err; + } - // write out crc - uint32_t footer[2]; - footer[0] = lfs_tobe32(tag ^ commit->ptag); - commit->crc = lfs_crc(commit->crc, &footer[0], sizeof(footer[0])); - footer[1] = lfs_tole32(commit->crc); - err = lfs_bd_prog(lfs, - &lfs->pcache, &lfs->rcache, false, - commit->block, commit->off, &footer, sizeof(footer)); - if (err) { - return err; - } - commit->off += sizeof(tag)+lfs_tag_size(tag); - commit->ptag = tag ^ (reset << 31); + // build crc tag + bool reset = ~lfs_frombe32(tag) >> 31; + tag = LFS_MKTAG(LFS_TYPE_CRC + reset, 0x3ff, noff - off); - // flush buffers - err = lfs_bd_sync(lfs, &lfs->pcache, &lfs->rcache, false); - if (err) { - return err; - } - - // successful commit, check checksum to make sure - uint32_t crc = 0xffffffff; - lfs_size_t size = commit->off - lfs_tag_size(tag) - commit->begin; - for (lfs_off_t i = 0; i < size; i++) { - // leave it up to caching to make this efficient - uint8_t dat; - err = lfs_bd_read(lfs, - NULL, &lfs->rcache, size-i, - commit->block, commit->begin+i, &dat, 1); + // write out crc + uint32_t footer[2]; + footer[0] = lfs_tobe32(tag ^ commit->ptag); + commit->crc = lfs_crc(commit->crc, &footer[0], sizeof(footer[0])); + footer[1] = lfs_tole32(commit->crc); + err = lfs_bd_prog(lfs, + &lfs->pcache, &lfs->rcache, false, + commit->block, commit->off, &footer, sizeof(footer)); if (err) { return err; } - crc = lfs_crc(crc, &dat, 1); + commit->off += sizeof(tag)+lfs_tag_size(tag); + commit->ptag = tag ^ (reset << 31); + commit->crc = 0xffffffff; // reset crc for next "commit" } + // flush buffers + int err = lfs_bd_sync(lfs, &lfs->pcache, &lfs->rcache, false); if (err) { return err; } - if (crc != commit->crc) { - return LFS_ERR_CORRUPT; + // successful commit, check checksums to make sure + lfs_off_t off = commit->begin; + lfs_off_t noff = off1; + while (off < end) { + uint32_t crc = 0xffffffff; + for (lfs_off_t i = off; i < noff+sizeof(uint32_t); i++) { + // leave it up to caching to make this efficient + uint8_t dat; + err = lfs_bd_read(lfs, + NULL, &lfs->rcache, noff+sizeof(uint32_t)-i, + commit->block, i, &dat, 1); + if (err) { + return err; + } + + crc = lfs_crc(crc, &dat, 1); + } + + // detected write error? + if (crc != 0) { + return LFS_ERR_CORRUPT; + } + + // skip padding + off = lfs_min(end - noff, 0x3fe) + noff; + if (off < end) { + off = lfs_min(off, end - 2*sizeof(uint32_t)); + } + noff = off + sizeof(uint32_t); } return 0; @@ -1583,11 +1603,11 @@ static int lfs_dir_compact(lfs_t *lfs, } // successful compaction, swap dir pair to indicate most recent + LFS_ASSERT(commit.off % lfs->cfg->prog_size == 0); lfs_pair_swap(dir->pair); dir->count = end - begin; dir->off = commit.off; dir->etag = commit.ptag; - dir->erased = (dir->off % lfs->cfg->prog_size == 0); // note we able to have already handled move here if (lfs_gstate_hasmovehere(&lfs->gpending, dir->pair)) { lfs_gstate_xormove(&lfs->gpending, @@ -1758,10 +1778,9 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_mdir_t *dir, } // successful commit, update dir + LFS_ASSERT(commit.off % lfs->cfg->prog_size == 0); dir->off = commit.off; dir->etag = commit.ptag; - // workaround to handle prog_size >1024 - dir->erased = (dir->off % lfs->cfg->prog_size == 0); // note we able to have already handled move here if (lfs_gstate_hasmovehere(&lfs->gpending, dir->pair)) { From 19838371fb6e24ddbcec196b2269472f5eafef7f Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 26 Jul 2019 12:29:37 -0500 Subject: [PATCH 16/27] Fixed issue where sed buffering (QUIET=1) caused Travis timeout --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 185d8e5..640dd63 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ test: test_format test_dirs test_files test_seek test_truncate \ test_%: tests/test_%.sh ifdef QUIET - @./$< | sed -n '/^[-=]/p' + @./$< | sed -nu '/^[-=]/p' else ./$< endif From 51fabc672b43a6285bced7e6574989cfc203ebd9 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 26 Jul 2019 20:09:24 -0500 Subject: [PATCH 17/27] Switched to using hex for blocks and ids in debug output This is a minor quality of life change to help debugging, specifically when debugging test failures. Before, the test framework used hex, while the log output used decimal. This was slightly annoying to convert between. Why not output lengths/offset in hex? I don't have a big reason. I find it easier to reason about lengths in decimal and ids (such as addresses or block numbers) in hex. But this may just be me. --- emubd/lfs_emubd.c | 6 +++--- lfs.c | 32 ++++++++++++++++---------------- scripts/debug.py | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/emubd/lfs_emubd.c b/emubd/lfs_emubd.c index 943ddfb..2f729fb 100644 --- a/emubd/lfs_emubd.c +++ b/emubd/lfs_emubd.c @@ -151,7 +151,7 @@ void lfs_emubd_destroy(const struct lfs_config *cfg) { int lfs_emubd_read(const struct lfs_config *cfg, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) { - LFS_TRACE("lfs_emubd_read(%p, %"PRIu32", %"PRIu32", %p, %"PRIu32")", + LFS_TRACE("lfs_emubd_read(%p, 0x%"PRIx32", %"PRIu32", %p, %"PRIu32")", (void*)cfg, block, off, buffer, size); lfs_emubd_t *emu = cfg->context; uint8_t *data = buffer; @@ -204,7 +204,7 @@ int lfs_emubd_read(const struct lfs_config *cfg, lfs_block_t block, int lfs_emubd_prog(const struct lfs_config *cfg, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) { - LFS_TRACE("lfs_emubd_prog(%p, %"PRIu32", %"PRIu32", %p, %"PRIu32")", + LFS_TRACE("lfs_emubd_prog(%p, 0x%"PRIx32", %"PRIu32", %p, %"PRIu32")", (void*)cfg, block, off, buffer, size); lfs_emubd_t *emu = cfg->context; const uint8_t *data = buffer; @@ -276,7 +276,7 @@ int lfs_emubd_prog(const struct lfs_config *cfg, lfs_block_t block, } int lfs_emubd_erase(const struct lfs_config *cfg, lfs_block_t block) { - LFS_TRACE("lfs_emubd_erase(%p, %"PRIu32")", (void*)cfg, block); + LFS_TRACE("lfs_emubd_erase(%p, 0x%"PRIx32")", (void*)cfg, block); lfs_emubd_t *emu = cfg->context; // Check if erase is valid diff --git a/lfs.c b/lfs.c index f7235f6..0f16ed5 100644 --- a/lfs.c +++ b/lfs.c @@ -971,7 +971,7 @@ static lfs_stag_t lfs_dir_fetchmatch(lfs_t *lfs, dir->rev = revs[(r+1)%2]; } - LFS_ERROR("Corrupted dir pair at %"PRIu32" %"PRIu32, + LFS_ERROR("Corrupted dir pair at %"PRIx32" %"PRIx32, dir->pair[0], dir->pair[1]); return LFS_ERR_CORRUPT; } @@ -1607,12 +1607,12 @@ relocate: relocated = true; lfs_cache_drop(lfs, &lfs->pcache); if (!exhausted) { - LFS_DEBUG("Bad block at %"PRIu32, dir->pair[1]); + LFS_DEBUG("Bad block at %"PRIx32, dir->pair[1]); } // can't relocate superblock, filesystem is now frozen if (lfs_pair_cmp(oldpair, (const lfs_block_t[2]){0, 1}) == 0) { - LFS_WARN("Superblock %"PRIu32" has become unwritable", oldpair[1]); + LFS_WARN("Superblock %"PRIx32" has become unwritable", oldpair[1]); return LFS_ERR_NOSPC; } @@ -1630,7 +1630,7 @@ relocate: lfs->gdelta = (struct lfs_gstate){0}; } else { // update references if we relocated - LFS_DEBUG("Relocating %"PRIu32" %"PRIu32" to %"PRIu32" %"PRIu32, + LFS_DEBUG("Relocating %"PRIx32" %"PRIx32" -> %"PRIx32" %"PRIx32, oldpair[0], oldpair[1], dir->pair[0], dir->pair[1]); int err = lfs_fs_relocate(lfs, oldpair, dir->pair); if (err) { @@ -2236,7 +2236,7 @@ static int lfs_ctz_extend(lfs_t *lfs, } relocate: - LFS_DEBUG("Bad block at %"PRIu32, nblock); + LFS_DEBUG("Bad block at %"PRIx32, nblock); // just clear cache and try a new block lfs_cache_drop(lfs, pcache); @@ -2291,7 +2291,7 @@ static int lfs_ctz_traverse(lfs_t *lfs, int lfs_file_opencfg(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\", 0x%x, %p {" + 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); @@ -2442,7 +2442,7 @@ cleanup: int lfs_file_open(lfs_t *lfs, lfs_file_t *file, const char *path, int flags) { - LFS_TRACE("lfs_file_open(%p, %p, \"%s\", 0x%x)", + 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_opencfg(lfs, file, path, flags, &defaults); @@ -2534,7 +2534,7 @@ static int lfs_file_relocate(lfs_t *lfs, lfs_file_t *file) { return 0; relocate: - LFS_DEBUG("Bad block at %"PRIu32, nblock); + LFS_DEBUG("Bad block at %"PRIx32, nblock); // just clear cache and try a new block lfs_cache_drop(lfs, &lfs->pcache); @@ -2597,7 +2597,7 @@ static int lfs_file_flush(lfs_t *lfs, lfs_file_t *file) { break; relocate: - LFS_DEBUG("Bad block at %"PRIu32, file->block); + LFS_DEBUG("Bad block at %"PRIx32, file->block); err = lfs_file_relocate(lfs, file); if (err) { return err; @@ -3641,7 +3641,7 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) { lfs->gpending.tag += !lfs_tag_isvalid(lfs->gpending.tag); lfs->gstate = lfs->gpending; if (lfs_gstate_hasmove(&lfs->gstate)) { - LFS_DEBUG("Found move %"PRIu32" %"PRIu32" %"PRIu16, + LFS_DEBUG("Found move %"PRIx32" %"PRIx32" %"PRIx16, lfs->gstate.pair[0], lfs->gstate.pair[1], lfs_tag_id(lfs->gstate.tag)); @@ -3828,7 +3828,7 @@ static int lfs_fs_relocate(lfs_t *lfs, const lfs_block_t oldpair[2], lfs_block_t newpair[2]) { // update internal root if (lfs_pair_cmp(oldpair, lfs->root) == 0) { - LFS_DEBUG("Relocating root %"PRIu32" %"PRIu32, + LFS_DEBUG("Relocating root %"PRIx32" %"PRIx32, newpair[0], newpair[1]); lfs->root[0] = newpair[0]; lfs->root[1] = newpair[1]; @@ -3906,7 +3906,7 @@ static int lfs_fs_demove(lfs_t *lfs) { } // Fix bad moves - LFS_DEBUG("Fixing move %"PRIu32" %"PRIu32" %"PRIu16, + LFS_DEBUG("Fixing move %"PRIx32" %"PRIx32" %"PRIx16, lfs->gstate.pair[0], lfs->gstate.pair[1], lfs_tag_id(lfs->gstate.tag)); @@ -3954,7 +3954,7 @@ static int lfs_fs_deorphan(lfs_t *lfs) { if (tag == LFS_ERR_NOENT) { // we are an orphan - LFS_DEBUG("Fixing orphan %"PRIu32" %"PRIu32, + LFS_DEBUG("Fixing orphan %"PRIx32" %"PRIx32, pdir.tail[0], pdir.tail[1]); err = lfs_dir_drop(lfs, &pdir, &dir); @@ -3975,7 +3975,7 @@ static int lfs_fs_deorphan(lfs_t *lfs) { if (!lfs_pair_sync(pair, pdir.tail)) { // we have desynced - LFS_DEBUG("Fixing half-orphan %"PRIu32" %"PRIu32, + LFS_DEBUG("Fixing half-orphan %"PRIx32" %"PRIx32, pair[0], pair[1]); lfs_pair_tole32(pair); @@ -4238,7 +4238,7 @@ static int lfs1_dir_fetch(lfs_t *lfs, } if (!valid) { - LFS_ERROR("Corrupted dir pair at %" PRIu32 " %" PRIu32 , + LFS_ERROR("Corrupted dir pair at %" PRIx32 " %" PRIx32 , tpair[0], tpair[1]); return LFS_ERR_CORRUPT; } @@ -4600,7 +4600,7 @@ int lfs_migrate(lfs_t *lfs, const struct lfs_config *cfg) { // Copy over first block to thread into fs. Unfortunately // if this fails there is not much we can do. - LFS_DEBUG("Migrating %"PRIu32" %"PRIu32" -> %"PRIu32" %"PRIu32, + LFS_DEBUG("Migrating %"PRIx32" %"PRIx32" -> %"PRIx32" %"PRIx32, lfs->root[0], lfs->root[1], dir1.head[0], dir1.head[1]); err = lfs_bd_erase(lfs, dir1.head[1]); diff --git a/scripts/debug.py b/scripts/debug.py index f8c0484..ba7525d 100755 --- a/scripts/debug.py +++ b/scripts/debug.py @@ -95,7 +95,7 @@ def main(*blocks): print '%04x: %08x %-15s %3s %4s %-23s %-8s' % ( off, tag, typeof(type) + (' bad!' if iscrc and ~crc else ''), - id if id != 0x3ff else '.', + hex(id)[2:] if id != 0x3ff else '.', size if size != 0x3ff else 'x', ' '.join('%02x' % ord(c) for c in data[:8]), ''.join(c if c >= ' ' and c <= '~' else '.' for c in data[:8])) From 38a2a8d2a3d64e5219ec0babaf233ae9e8da577c Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sun, 28 Jul 2019 20:42:13 -0500 Subject: [PATCH 18/27] Minor improvement to documentation over block_cycles Suggested by haneefmubarak --- lfs.c | 10 +++++++--- lfs.h | 7 ++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lfs.c b/lfs.c index 0417202..3fe6389 100644 --- a/lfs.c +++ b/lfs.c @@ -3192,11 +3192,15 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) { LFS_ASSERT(4*lfs_npw2(0xffffffff / (lfs->cfg->block_size-2*4)) <= lfs->cfg->block_size); - // block_cycles = 0 is no longer supported, must either set a number - // of erase cycles before moving logs to another block (~500 suggested), - // or explicitly disable wear-leveling with -1. + // block_cycles = 0 is no longer supported. + // + // block_cycles is the number of erase cycles before littlefs evicts + // metadata logs as a part of wear leveling. Suggested values are in the + // range of 100-1000, or set block_cycles to -1 to disable block-level + // wear-leveling. LFS_ASSERT(lfs->cfg->block_cycles != 0); + // setup read cache if (lfs->cfg->read_buffer) { lfs->rcache.buffer = lfs->cfg->read_buffer; diff --git a/lfs.h b/lfs.h index 276b5a5..6abfcdb 100644 --- a/lfs.h +++ b/lfs.h @@ -190,9 +190,10 @@ struct lfs_config { // Number of erasable blocks on the device. lfs_size_t block_count; - // Number of erase cycles before we should move logs to another block. - // Suggested values are in the range 100-1000, with large values having - // better performance at the cost of less consistent wear distribution. + // Number of erase cycles before littlefs evicts metadata logs and moves + // the metadata to another block. Suggested values are in the + // range 100-1000, with large values having better performance at the cost + // of less consistent wear distribution. // // Set to -1 to disable block-level wear-leveling. int32_t block_cycles; From e8c023aab055a8892b8abc262d82f78a11108dc5 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sun, 28 Jul 2019 20:43:12 -0500 Subject: [PATCH 19/27] Changed FUSE branch to v2 (previously v2-alpha) --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index dcfedf6..ab69041 100644 --- a/.travis.yml +++ b/.travis.yml @@ -111,7 +111,7 @@ jobs: if: branch !~ -prefix$ install: - sudo apt-get install libfuse-dev - - git clone --depth 1 https://github.com/geky/littlefs-fuse -b v2-alpha + - git clone --depth 1 https://github.com/geky/littlefs-fuse -b v2 - fusermount -V - gcc --version before_script: @@ -146,7 +146,7 @@ jobs: if: branch !~ -prefix$ install: - sudo apt-get install libfuse-dev - - git clone --depth 1 https://github.com/geky/littlefs-fuse -b v2-alpha v2 + - git clone --depth 1 https://github.com/geky/littlefs-fuse -b v2 v2 - git clone --depth 1 https://github.com/geky/littlefs-fuse -b v1 v1 - fusermount -V - gcc --version From de5972699a3761d5602d8467df3f5f792bfb1b51 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Thu, 18 Jul 2019 19:43:49 -0500 Subject: [PATCH 20/27] Fixed license header in lfs.c Found by pabigot --- lfs.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/lfs.c b/lfs.c index c554135..d968cc9 100644 --- a/lfs.c +++ b/lfs.c @@ -1,19 +1,8 @@ /* * The little filesystem * - * Copyright (c) 2017 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright (c) 2017, Arm Limited. All rights reserved. + * SPDX-License-Identifier: BSD-3-Clause */ #include "lfs.h" #include "lfs_util.h" From 3806d8828504d303ba6a8e07656535d1e82808f9 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 3 Jul 2019 15:14:59 -0500 Subject: [PATCH 21/27] Fixed seek-related typos in lfs.h - lfs_file_rewind == lfs_file_seek(lfs, file, 0, LFS_SEEK_SET) - lfs_file_seek returns the _new_ position of the file --- lfs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lfs.h b/lfs.h index d09124b..504932d 100644 --- a/lfs.h +++ b/lfs.h @@ -528,7 +528,7 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, // Change the position of the file // // The change in position is determined by the offset and whence flag. -// Returns the old position of the file, or a negative error code on failure. +// Returns the new position of the file, or a negative error code on failure. lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file, lfs_soff_t off, int whence); @@ -545,7 +545,7 @@ lfs_soff_t lfs_file_tell(lfs_t *lfs, lfs_file_t *file); // Change the position of the file to the beginning of the file // -// Equivalent to lfs_file_seek(lfs, file, 0, LFS_SEEK_CUR) +// Equivalent to lfs_file_seek(lfs, file, 0, LFS_SEEK_SET) // Returns a negative error code on failure. int lfs_file_rewind(lfs_t *lfs, lfs_file_t *file); From 4ec442527247b5b534e302e3936491ad18337dbb Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 16 Jul 2019 15:23:42 -0500 Subject: [PATCH 22/27] Fixed overlapping memcpy in emubd Found by DanielLyubin --- emubd/lfs_emubd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emubd/lfs_emubd.c b/emubd/lfs_emubd.c index 712fcba..8c2c30b 100644 --- a/emubd/lfs_emubd.c +++ b/emubd/lfs_emubd.c @@ -215,7 +215,7 @@ int lfs_emubd_prog(const struct lfs_config *cfg, lfs_block_t block, // update history and stats if (block != emu->history.blocks[0]) { - memcpy(&emu->history.blocks[1], &emu->history.blocks[0], + memmove(&emu->history.blocks[1], &emu->history.blocks[0], sizeof(emu->history) - sizeof(emu->history.blocks[0])); emu->history.blocks[0] = block; } From 4850e01e14373d9808b78f3fb7833e26583744c1 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 24 Jul 2019 14:59:48 -0500 Subject: [PATCH 23/27] Changed rdonly/wronly mistakes to assert Previously these returned LFS_ERR_BADF. But attempting to modify a file opened read-only, or reading a write-only flie, is a user error and should not occur in normal use. Changing this to an assert allows the logic to be omitted if the user disables asserts to reduce the code footprint (not suggested unless the user really really knows what they're doing). --- lfs.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/lfs.c b/lfs.c index a535295..dd63677 100644 --- a/lfs.c +++ b/lfs.c @@ -2631,10 +2631,7 @@ lfs_ssize_t lfs_file_read(lfs_t *lfs, lfs_file_t *file, lfs_size_t nsize = size; LFS_ASSERT(file->flags & LFS_F_OPENED); - - if ((file->flags & 3) == LFS_O_WRONLY) { - return LFS_ERR_BADF; - } + LFS_ASSERT((file->flags & 3) != LFS_O_WRONLY); if (file->flags & LFS_F_WRITING) { // flush out any writes @@ -2706,10 +2703,7 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, lfs_size_t nsize = size; LFS_ASSERT(file->flags & LFS_F_OPENED); - - if ((file->flags & 3) == LFS_O_RDONLY) { - return LFS_ERR_BADF; - } + LFS_ASSERT((file->flags & 3) != LFS_O_RDONLY); if (file->flags & LFS_F_READING) { // drop any reads @@ -2857,10 +2851,7 @@ lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file, int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) { LFS_ASSERT(file->flags & LFS_F_OPENED); - - if ((file->flags & 3) == LFS_O_RDONLY) { - return LFS_ERR_BADF; - } + LFS_ASSERT((file->flags & 3) != LFS_O_RDONLY); if (size > LFS_FILE_MAX) { return LFS_ERR_INVAL; From 0d4c0b105cabc7dd76a9aaa3f82f655a7b35aa79 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 9 Jul 2019 17:51:15 -0500 Subject: [PATCH 24/27] Fixed issue where inline files were not cleaned up Due to the logging nature of metadata pairs, switching from inline files (type3 = 0x201) to CTZ skip-lists (type3 = 0x202) does not explicitly erase inline files, but instead leaves them up to compaction to omit. To save code size, this is handled by the same logic that deduplicates tags. Unfortunately, this wasn't working. Due to a relatively late change in v2 the struct's type field was changed to no longer be a part of determining a tag's "uniqueness". A part of this should have been the modification of directory traversal filtering to respect type-dependent uniqueness, but I missed this. The fix is to add in correct type-dependent filtering. Also there was some clean up necessary around removing delete tags during compaction and outlining files. Note that while this appears to conflict with the possibility of combining inline + ctz files, we still have the device-side-only LFS_TYPE_FROM tag that can be repurposed for 256 additional inline "chunks". Found by Johnxjj --- lfs.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/lfs.c b/lfs.c index dd63677..70f54f3 100644 --- a/lfs.c +++ b/lfs.c @@ -403,7 +403,7 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_mdir_t *dir, static int lfs_dir_compact(lfs_t *lfs, lfs_mdir_t *dir, const struct lfs_mattr *attrs, int attrcount, lfs_mdir_t *source, uint16_t begin, uint16_t end); -static int lfs_file_relocate(lfs_t *lfs, lfs_file_t *file); +static int lfs_file_outline(lfs_t *lfs, lfs_file_t *file); static int lfs_file_flush(lfs_t *lfs, lfs_file_t *file); static void lfs_fs_preporphans(lfs_t *lfs, int8_t orphans); static void lfs_fs_prepmove(lfs_t *lfs, @@ -619,11 +619,17 @@ static int lfs_dir_traverse_filter(void *p, lfs_tag_t *filtertag = p; (void)buffer; + // which mask depends on unique bit in tag structure + uint32_t mask = (tag & LFS_MKTAG(0x100, 0, 0)) + ? LFS_MKTAG(0x7ff, 0x3ff, 0) + : LFS_MKTAG(0x700, 0x3ff, 0); + // check for redundancy - uint32_t mask = LFS_MKTAG(0x7ff, 0x3ff, 0); if ((mask & tag) == (mask & *filtertag) || - (mask & tag) == (LFS_MKTAG(LFS_TYPE_DELETE, 0, 0) | - (LFS_MKTAG(0, 0x3ff, 0) & *filtertag))) { + lfs_tag_isdelete(*filtertag) || + (LFS_MKTAG(0x7ff, 0x3ff, 0) & tag) == ( + LFS_MKTAG(LFS_TYPE_DELETE, 0, 0) | + (LFS_MKTAG(0, 0x3ff, 0) & *filtertag))) { return true; } @@ -1632,11 +1638,7 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_mdir_t *dir, if (dir != &f->m && lfs_pair_cmp(f->m.pair, dir->pair) == 0 && f->type == LFS_TYPE_REG && (f->flags & LFS_F_INLINE) && f->ctz.size > lfs->cfg->cache_size) { - f->flags &= ~LFS_F_READING; - f->off = 0; - - lfs_alloc_ack(lfs); - int err = lfs_file_relocate(lfs, f); + int err = lfs_file_outline(lfs, f); if (err) { return err; } @@ -2471,7 +2473,6 @@ static int lfs_file_relocate(lfs_t *lfs, lfs_file_t *file) { lfs_cache_zero(lfs, &lfs->pcache); file->block = nblock; - file->flags &= ~LFS_F_INLINE; file->flags |= LFS_F_WRITING; return 0; @@ -2483,6 +2484,18 @@ relocate: } } +static int lfs_file_outline(lfs_t *lfs, lfs_file_t *file) { + file->off = file->pos; + lfs_alloc_ack(lfs); + int err = lfs_file_relocate(lfs, file); + if (err) { + return err; + } + + file->flags &= ~LFS_F_INLINE; + return 0; +} + static int lfs_file_flush(lfs_t *lfs, lfs_file_t *file) { LFS_ASSERT(file->flags & LFS_F_OPENED); @@ -2616,8 +2629,7 @@ int lfs_file_sync(lfs_t *lfs, lfs_file_t *file) { relocate: // inline file doesn't fit anymore - file->off = file->pos; - err = lfs_file_relocate(lfs, file); + err = lfs_file_outline(lfs, file); if (err) { file->flags |= LFS_F_ERRED; return err; @@ -2740,9 +2752,7 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, lfs_min(0x3fe, lfs_min( lfs->cfg->cache_size, lfs->cfg->block_size/8))) { // inline file doesn't fit anymore - file->off = file->pos; - lfs_alloc_ack(lfs); - int err = lfs_file_relocate(lfs, file); + int err = lfs_file_outline(lfs, file); if (err) { file->flags |= LFS_F_ERRED; return err; From e249854858dd28f263e96d96ac3e570b2d591a4a Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Mon, 29 Jul 2019 00:43:54 -0500 Subject: [PATCH 25/27] Removed dependency on uninitialized value in lfs_file_t struct --- lfs.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/lfs.c b/lfs.c index 627e048..0111a6c 100644 --- a/lfs.c +++ b/lfs.c @@ -2308,9 +2308,6 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file, (void*)lfs, (void*)file, path, flags, (void*)cfg, cfg->buffer, (void*)cfg->attrs, cfg->attr_count); - // do not allow open for already opened file - LFS_ASSERT(0 == (file->flags & LFS_F_OPENED)); - // deorphan if we haven't yet, needed at most once after poweron if ((flags & 3) != LFS_O_RDONLY) { int err = lfs_fs_forceconsistency(lfs); From 7872918ec89b23324345fc486163bcc1898fba76 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Mon, 29 Jul 2019 01:34:23 -0500 Subject: [PATCH 26/27] Fixed issue where lfs_migrate would relocate root and corrupt superblock Found during testing, the issue was with lfs_migrate in combination with wear leveling. Normally, we can expect lfs_migrate to be able to respect the user-configured block_cycles. It already has allocation information on which blocks are used by both v1 and v2, so it should be safe to relocate blocks as needed. However, this fell apart when root was relocated. If lfs_migrate found a root that needed migration, it would happily relocate the root. This would normally be fine, except relocating the root has a side-effect of needed to update the superblock. Which, during migration, is in a delicate state of containing both v1's and v2's superblocks in the same metadata pair. If the superblock ends up needing to compact, this would clobber the v1 superblock and corrupt the filesystem during migration. The best fix I could come up with is to specifically dissallow migrating the root directory during migration. Fortunately this is behind the LFS_MIGRATE macro, so the code cost for this check is not normally paid. --- lfs.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lfs.c b/lfs.c index 0111a6c..e7c4dae 100644 --- a/lfs.c +++ b/lfs.c @@ -1500,6 +1500,11 @@ static int lfs_dir_compact(lfs_t *lfs, end = begin; } } +#if LFS_MIGRATE + } else if (lfs_pair_cmp(dir->pair, lfs->root) == 0 && lfs->lfs1) { + // we can't relocate our root during migrations, as this would + // cause the superblock to get updated, which would clobber v1 +#endif } else { // we're writing too much, time to relocate exhausted = true; From db054684a67956c5b86101dd70018accf284be2f Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Mon, 29 Jul 2019 00:53:55 -0500 Subject: [PATCH 27/27] Bump version to v2.1 --- lfs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lfs.h b/lfs.h index 64d4f0a..04054e9 100644 --- a/lfs.h +++ b/lfs.h @@ -21,7 +21,7 @@ extern "C" // Software library version // Major (top-nibble), incremented on backwards incompatible changes // Minor (bottom-nibble), incremented on feature additions -#define LFS_VERSION 0x00020000 +#define LFS_VERSION 0x00020001 #define LFS_VERSION_MAJOR (0xffff & (LFS_VERSION >> 16)) #define LFS_VERSION_MINOR (0xffff & (LFS_VERSION >> 0))