diff --git a/lfs.c b/lfs.c index e2f90ee..1ff4f90 100644 --- a/lfs.c +++ b/lfs.c @@ -6,6 +6,70 @@ */ #include "lfs.h" + +/// Configuration mapping /// +#ifdef LFS_STATICCFG +// direct config towards user defines +#define LFS_CFG_READ(lfs, block, off, buffer, size) \ + ((void)lfs, lfs_read(block, off, buffer, size)) +#define LFS_CFG_PROG(lfs, block, off, buffer, size) \ + ((void)lfs, lfs_prog(block, off, buffer, size)) +#define LFS_CFG_ERASE(lfs, block) \ + ((void)lfs, lfs_erase(block)) +#define LFS_CFG_SYNC(lfs) \ + ((void)lfs, lfs_sync()) +#define LFS_CFG_READ_SIZE(lfs) ((void)lfs, LFS_READ_SIZE) +#define LFS_CFG_PROG_SIZE(lfs) ((void)lfs, LFS_PROG_SIZE) +#define LFS_CFG_BLOCK_SIZE(lfs) ((void)lfs, LFS_BLOCK_SIZE) +#define LFS_CFG_BLOCK_COUNT(lfs) ((void)lfs, LFS_BLOCK_COUNT) +#define LFS_CFG_BLOCK_CYCLES(lfs) ((void)lfs, LFS_BLOCK_CYCLES) +#define LFS_CFG_CACHE_SIZE(lfs) ((void)lfs, LFS_CACHE_SIZE) +#define LFS_CFG_LOOKAHEAD_SIZE(lfs) ((void)lfs, LFS_LOOKAHEAD_SIZE) +#define LFS_CFG_READ_BUFFER(lfs) ((void)lfs, LFS_READ_BUFFER) +#define LFS_CFG_PROG_BUFFER(lfs) ((void)lfs, LFS_PROG_BUFFER) +#define LFS_CFG_LOOKAHEAD_BUFFER(lfs) ((void)lfs, LFS_LOOKAHEAD_BUFFER) +#define LFS_CFG_NAME_MAX(lfs) ((void)lfs, LFS_NAME_MAX) +#define LFS_CFG_FILE_MAX(lfs) ((void)lfs, LFS_FILE_MAX) +#define LFS_CFG_ATTR_MAX(lfs) ((void)lfs, LFS_ATTR_MAX) +#else +// direct config towards dynamic lfs_config struct +#define LFS_CFG_READ(lfs, block, off, buffer, size) \ + lfs->cfg->read(lfs->cfg, block, off, buffer, size) +#define LFS_CFG_PROG(lfs, block, off, buffer, size) \ + lfs->cfg->prog(lfs->cfg, block, off, buffer, size) +#define LFS_CFG_ERASE(lfs, block) \ + lfs->cfg->erase(lfs->cfg, block) +#define LFS_CFG_SYNC(lfs) \ + lfs->cfg->sync(lfs->cfg) +#define LFS_CFG_READ_SIZE(lfs) lfs->cfg->read_size +#define LFS_CFG_PROG_SIZE(lfs) lfs->cfg->prog_size +#define LFS_CFG_BLOCK_SIZE(lfs) lfs->cfg->block_size +#define LFS_CFG_BLOCK_COUNT(lfs) lfs->cfg->block_count +#define LFS_CFG_BLOCK_CYCLES(lfs) lfs->cfg->block_cycles +#define LFS_CFG_CACHE_SIZE(lfs) lfs->cfg->cache_size +#define LFS_CFG_LOOKAHEAD_SIZE(lfs) lfs->cfg->lookahead_size +#define LFS_CFG_READ_BUFFER(lfs) lfs->cfg->read_buffer +#define LFS_CFG_PROG_BUFFER(lfs) lfs->cfg->prog_buffer +#define LFS_CFG_LOOKAHEAD_BUFFER(lfs) lfs->cfg->lookahead_buffer +#define LFS_CFG_NAME_MAX(lfs) lfs->cfg->name_max +#define LFS_CFG_FILE_MAX(lfs) lfs->cfg->file_max +#define LFS_CFG_ATTR_MAX(lfs) lfs->cfg->attr_max +#endif + +#ifdef LFS_FILE_STATICCFG +// direct config towards user defines +#define LFS_FILE_CFG_BUFFER(file) LFS_FILE_BUFFER +#define LFS_FILE_CFG_ATTRS(file) LFS_FILE_ATTRS +#define LFS_FILE_CFG_ATTR_COUNT(file) LFS_FILE_ATTR_COUNT +#else +// direct config towards dynamic lfs_config struct +#define LFS_FILE_CFG_BUFFER(file) file->cfg->buffer +#define LFS_FILE_CFG_ATTRS(file) file->cfg->attrs +#define LFS_FILE_CFG_ATTR_COUNT(file) file->cfg->attr_count +#endif + + +/// Internal littlefs constants /// #define LFS_BLOCK_NULL ((lfs_block_t)-1) #define LFS_BLOCK_INLINE ((lfs_block_t)-2) @@ -19,7 +83,7 @@ static inline void lfs_cache_drop(lfs_t *lfs, lfs_cache_t *rcache) { static inline void lfs_cache_zero(lfs_t *lfs, lfs_cache_t *pcache) { // zero to avoid information leak - memset(pcache->buffer, 0xff, lfs->cfg->cache_size); + memset(pcache->buffer, 0xff, LFS_CFG_CACHE_SIZE(lfs)); pcache->block = LFS_BLOCK_NULL; } @@ -28,8 +92,8 @@ static int lfs_bd_read(lfs_t *lfs, lfs_block_t block, lfs_off_t off, void *buffer, lfs_size_t size) { uint8_t *data = buffer; - if (block >= lfs->cfg->block_count || - off+size > lfs->cfg->block_size) { + if (block >= LFS_CFG_BLOCK_COUNT(lfs) || + off+size > LFS_CFG_BLOCK_SIZE(lfs)) { return LFS_ERR_CORRUPT; } @@ -70,11 +134,11 @@ static int lfs_bd_read(lfs_t *lfs, diff = lfs_min(diff, rcache->off-off); } - if (size >= hint && off % lfs->cfg->read_size == 0 && - size >= lfs->cfg->read_size) { + if (size >= hint && off % LFS_CFG_READ_SIZE(lfs) == 0 && + size >= LFS_CFG_READ_SIZE(lfs)) { // bypass cache? - diff = lfs_aligndown(diff, lfs->cfg->read_size); - int err = lfs->cfg->read(lfs->cfg, block, off, data, diff); + diff = lfs_aligndown(diff, LFS_CFG_READ_SIZE(lfs)); + int err = LFS_CFG_READ(lfs, block, off, data, diff); if (err) { return err; } @@ -86,16 +150,16 @@ static int lfs_bd_read(lfs_t *lfs, } // load to cache, first condition can no longer fail - LFS_ASSERT(block < lfs->cfg->block_count); + LFS_ASSERT(block < LFS_CFG_BLOCK_COUNT(lfs)); rcache->block = block; - rcache->off = lfs_aligndown(off, lfs->cfg->read_size); + rcache->off = lfs_aligndown(off, LFS_CFG_READ_SIZE(lfs)); rcache->size = lfs_min( lfs_min( - lfs_alignup(off+hint, lfs->cfg->read_size), - lfs->cfg->block_size) + lfs_alignup(off+hint, LFS_CFG_READ_SIZE(lfs)), + LFS_CFG_BLOCK_SIZE(lfs)) - rcache->off, - lfs->cfg->cache_size); - int err = lfs->cfg->read(lfs->cfg, rcache->block, + LFS_CFG_CACHE_SIZE(lfs)); + int err = LFS_CFG_READ(lfs, rcache->block, rcache->off, rcache->buffer, rcache->size); LFS_ASSERT(err <= 0); if (err) { @@ -138,9 +202,9 @@ static int lfs_bd_cmp(lfs_t *lfs, static int lfs_bd_flush(lfs_t *lfs, lfs_cache_t *pcache, lfs_cache_t *rcache, bool validate) { if (pcache->block != LFS_BLOCK_NULL && pcache->block != LFS_BLOCK_INLINE) { - LFS_ASSERT(pcache->block < lfs->cfg->block_count); - lfs_size_t diff = lfs_alignup(pcache->size, lfs->cfg->prog_size); - int err = lfs->cfg->prog(lfs->cfg, pcache->block, + LFS_ASSERT(pcache->block < LFS_CFG_BLOCK_COUNT(lfs)); + lfs_size_t diff = lfs_alignup(pcache->size, LFS_CFG_PROG_SIZE(lfs)); + int err = LFS_CFG_PROG(lfs, pcache->block, pcache->off, pcache->buffer, diff); LFS_ASSERT(err <= 0); if (err) { @@ -177,7 +241,7 @@ static int lfs_bd_sync(lfs_t *lfs, return err; } - err = lfs->cfg->sync(lfs->cfg); + err = LFS_CFG_SYNC(lfs); LFS_ASSERT(err <= 0); return err; } @@ -187,16 +251,16 @@ static int lfs_bd_prog(lfs_t *lfs, lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) { const uint8_t *data = buffer; - LFS_ASSERT(block == LFS_BLOCK_INLINE || block < lfs->cfg->block_count); - LFS_ASSERT(off + size <= lfs->cfg->block_size); + LFS_ASSERT(block == LFS_BLOCK_INLINE || block < LFS_CFG_BLOCK_COUNT(lfs)); + LFS_ASSERT(off + size <= LFS_CFG_BLOCK_SIZE(lfs)); while (size > 0) { if (block == pcache->block && off >= pcache->off && - off < pcache->off + lfs->cfg->cache_size) { + off < pcache->off + LFS_CFG_CACHE_SIZE(lfs)) { // already fits in pcache? lfs_size_t diff = lfs_min(size, - lfs->cfg->cache_size - (off-pcache->off)); + LFS_CFG_CACHE_SIZE(lfs) - (off-pcache->off)); memcpy(&pcache->buffer[off-pcache->off], data, diff); data += diff; @@ -204,7 +268,7 @@ static int lfs_bd_prog(lfs_t *lfs, size -= diff; pcache->size = lfs_max(pcache->size, off - pcache->off); - if (pcache->size == lfs->cfg->cache_size) { + if (pcache->size == LFS_CFG_CACHE_SIZE(lfs)) { // eagerly flush out pcache if we fill up int err = lfs_bd_flush(lfs, pcache, rcache, validate); if (err) { @@ -221,7 +285,7 @@ static int lfs_bd_prog(lfs_t *lfs, // prepare pcache, first condition can no longer fail pcache->block = block; - pcache->off = lfs_aligndown(off, lfs->cfg->prog_size); + pcache->off = lfs_aligndown(off, LFS_CFG_PROG_SIZE(lfs)); pcache->size = 0; } @@ -229,8 +293,8 @@ 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); - int err = lfs->cfg->erase(lfs->cfg, block); + LFS_ASSERT(block < LFS_CFG_BLOCK_COUNT(lfs)); + int err = LFS_CFG_ERASE(lfs, block); LFS_ASSERT(err <= 0); return err; } @@ -442,7 +506,7 @@ static int lfs1_traverse(lfs_t *lfs, static int lfs_alloc_lookahead(void *p, lfs_block_t block) { lfs_t *lfs = (lfs_t*)p; lfs_block_t off = ((block - lfs->free.off) - + lfs->cfg->block_count) % lfs->cfg->block_count; + + LFS_CFG_BLOCK_COUNT(lfs)) % LFS_CFG_BLOCK_COUNT(lfs); if (off < lfs->free.size) { lfs->free.buffer[off / 32] |= 1U << (off % 32); @@ -452,13 +516,13 @@ static int lfs_alloc_lookahead(void *p, lfs_block_t block) { } static void lfs_alloc_ack(lfs_t *lfs) { - lfs->free.ack = lfs->cfg->block_count; + lfs->free.ack = LFS_CFG_BLOCK_COUNT(lfs); } // Invalidate the lookahead buffer. This is done during mounting and // failed traversals static void lfs_alloc_reset(lfs_t *lfs) { - lfs->free.off = lfs->seed % lfs->cfg->block_size; + lfs->free.off = lfs->seed % LFS_CFG_BLOCK_SIZE(lfs); lfs->free.size = 0; lfs->free.i = 0; lfs_alloc_ack(lfs); @@ -473,7 +537,7 @@ static int lfs_alloc(lfs_t *lfs, lfs_block_t *block) { if (!(lfs->free.buffer[off / 32] & (1U << (off % 32)))) { // found a free block - *block = (lfs->free.off + off) % lfs->cfg->block_count; + *block = (lfs->free.off + off) % LFS_CFG_BLOCK_COUNT(lfs); // eagerly find next off so an alloc ack can // discredit old lookahead blocks @@ -496,12 +560,12 @@ static int lfs_alloc(lfs_t *lfs, lfs_block_t *block) { } lfs->free.off = (lfs->free.off + lfs->free.size) - % lfs->cfg->block_count; - lfs->free.size = lfs_min(8*lfs->cfg->lookahead_size, lfs->free.ack); + % LFS_CFG_BLOCK_COUNT(lfs); + lfs->free.size = lfs_min(8*LFS_CFG_LOOKAHEAD_SIZE(lfs), lfs->free.ack); lfs->free.i = 0; // find mask of free blocks from tree - memset(lfs->free.buffer, 0, lfs->cfg->lookahead_size); + memset(lfs->free.buffer, 0, LFS_CFG_LOOKAHEAD_SIZE(lfs)); int err = lfs_fs_traverseraw(lfs, lfs_alloc_lookahead, lfs, true); if (err) { lfs_alloc_reset(lfs); @@ -585,7 +649,7 @@ static int lfs_dir_getread(lfs_t *lfs, const lfs_mdir_t *dir, lfs_tag_t gmask, lfs_tag_t gtag, lfs_off_t off, void *buffer, lfs_size_t size) { uint8_t *data = buffer; - if (off+size > lfs->cfg->block_size) { + if (off+size > LFS_CFG_BLOCK_SIZE(lfs)) { return LFS_ERR_CORRUPT; } @@ -628,9 +692,9 @@ static int lfs_dir_getread(lfs_t *lfs, const lfs_mdir_t *dir, // load to cache, first condition can no longer fail rcache->block = LFS_BLOCK_INLINE; - rcache->off = lfs_aligndown(off, lfs->cfg->read_size); - rcache->size = lfs_min(lfs_alignup(off+hint, lfs->cfg->read_size), - lfs->cfg->cache_size); + rcache->off = lfs_aligndown(off, LFS_CFG_READ_SIZE(lfs)); + rcache->size = lfs_min(lfs_alignup(off+hint, LFS_CFG_READ_SIZE(lfs)), + LFS_CFG_CACHE_SIZE(lfs)); int err = lfs_dir_getslice(lfs, dir, gmask, gtag, rcache->off, rcache->buffer, rcache->size); if (err < 0) { @@ -773,7 +837,8 @@ static lfs_stag_t lfs_dir_fetchmatch(lfs_t *lfs, // if either block address is invalid we return LFS_ERR_CORRUPT here, // otherwise later writes to the pair could fail - if (pair[0] >= lfs->cfg->block_count || pair[1] >= lfs->cfg->block_count) { + if (pair[0] >= LFS_CFG_BLOCK_COUNT(lfs) || + pair[1] >= LFS_CFG_BLOCK_COUNT(lfs)) { return LFS_ERR_CORRUPT; } @@ -819,7 +884,7 @@ static lfs_stag_t lfs_dir_fetchmatch(lfs_t *lfs, lfs_tag_t tag; off += lfs_tag_dsize(ptag); int err = lfs_bd_read(lfs, - NULL, &lfs->rcache, lfs->cfg->block_size, + NULL, &lfs->rcache, LFS_CFG_BLOCK_SIZE(lfs), dir->pair[0], off, &tag, sizeof(tag)); if (err) { if (err == LFS_ERR_CORRUPT) { @@ -836,9 +901,9 @@ static lfs_stag_t lfs_dir_fetchmatch(lfs_t *lfs, // next commit not yet programmed or we're not in valid range if (!lfs_tag_isvalid(tag)) { dir->erased = (lfs_tag_type1(ptag) == LFS_TYPE_CRC && - dir->off % lfs->cfg->prog_size == 0); + dir->off % LFS_CFG_PROG_SIZE(lfs) == 0); break; - } else if (off + lfs_tag_dsize(tag) > lfs->cfg->block_size) { + } else if (off + lfs_tag_dsize(tag) > LFS_CFG_BLOCK_SIZE(lfs)) { dir->erased = false; break; } @@ -849,7 +914,7 @@ static lfs_stag_t lfs_dir_fetchmatch(lfs_t *lfs, // check the crc attr uint32_t dcrc; err = lfs_bd_read(lfs, - NULL, &lfs->rcache, lfs->cfg->block_size, + NULL, &lfs->rcache, LFS_CFG_BLOCK_SIZE(lfs), dir->pair[0], off+sizeof(tag), &dcrc, sizeof(dcrc)); if (err) { if (err == LFS_ERR_CORRUPT) { @@ -890,7 +955,7 @@ static lfs_stag_t lfs_dir_fetchmatch(lfs_t *lfs, for (lfs_off_t j = sizeof(tag); j < lfs_tag_dsize(tag); j++) { uint8_t dat; err = lfs_bd_read(lfs, - NULL, &lfs->rcache, lfs->cfg->block_size, + NULL, &lfs->rcache, LFS_CFG_BLOCK_SIZE(lfs), dir->pair[0], off+j, &dat, 1); if (err) { if (err == LFS_ERR_CORRUPT) { @@ -923,7 +988,7 @@ static lfs_stag_t lfs_dir_fetchmatch(lfs_t *lfs, tempsplit = (lfs_tag_chunk(tag) & 1); err = lfs_bd_read(lfs, - NULL, &lfs->rcache, lfs->cfg->block_size, + NULL, &lfs->rcache, LFS_CFG_BLOCK_SIZE(lfs), dir->pair[0], off+sizeof(tag), &temptail, 8); if (err) { if (err == LFS_ERR_CORRUPT) { @@ -1264,7 +1329,7 @@ static int lfs_dir_commitcrc(lfs_t *lfs, struct lfs_commit *commit) { const uint32_t crc1 = commit->crc; // align to program units const lfs_off_t end = lfs_alignup(off1 + 2*sizeof(uint32_t), - lfs->cfg->prog_size); + LFS_CFG_PROG_SIZE(lfs)); // create crc tags to fill up remainder of commit, note that // padding is not crced, which lets fetches skip padding but @@ -1486,9 +1551,9 @@ static int lfs_dir_compact(lfs_t *lfs, // cleanup delete, and we cap at half a block to give room // for metadata updates. if (end - begin < 0xff && - size <= lfs_min(lfs->cfg->block_size - 36, - lfs_alignup(lfs->cfg->block_size/2, - lfs->cfg->prog_size))) { + size <= lfs_min(LFS_CFG_BLOCK_SIZE(lfs) - 36, + lfs_alignup(LFS_CFG_BLOCK_SIZE(lfs)/2, + LFS_CFG_PROG_SIZE(lfs)))) { break; } @@ -1502,7 +1567,7 @@ static int lfs_dir_compact(lfs_t *lfs, // if we fail to split, we may be able to overcompact, unless // we're too big for even the full block, in which case our // only option is to error - if (err == LFS_ERR_NOSPC && size <= lfs->cfg->block_size - 36) { + if (err == LFS_ERR_NOSPC && size <= LFS_CFG_BLOCK_SIZE(lfs) - 36) { break; } return err; @@ -1519,8 +1584,8 @@ static int lfs_dir_compact(lfs_t *lfs, // 1. block_cycles = 1, which would prevent relocations from terminating // 2. block_cycles = 2n, which, due to aliasing, would only ever relocate // one metadata block in the pair, effectively making this useless - if (lfs->cfg->block_cycles > 0 && - (dir->rev % ((lfs->cfg->block_cycles+1)|1) == 0)) { + if (LFS_CFG_BLOCK_CYCLES(lfs) > 0 && + (dir->rev % ((LFS_CFG_BLOCK_CYCLES(lfs)+1)|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, // should we expand? @@ -1531,7 +1596,7 @@ static int lfs_dir_compact(lfs_t *lfs, // do we have extra space? littlefs can't reclaim this space // by itself, so expand cautiously - if ((lfs_size_t)res < lfs->cfg->block_count/2) { + if ((lfs_size_t)res < LFS_CFG_BLOCK_COUNT(lfs)/2) { LFS_DEBUG("Expanding superblock at rev %"PRIu32, dir->rev); int err = lfs_dir_split(lfs, dir, attrs, attrcount, source, begin, end); @@ -1572,7 +1637,7 @@ static int lfs_dir_compact(lfs_t *lfs, .crc = 0xffffffff, .begin = 0, - .end = lfs->cfg->block_size - 8, + .end = LFS_CFG_BLOCK_SIZE(lfs) - 8, }; // erase block to write to @@ -1663,7 +1728,7 @@ 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_ASSERT(commit.off % LFS_CFG_PROG_SIZE(lfs) == 0); lfs_pair_swap(dir->pair); dir->count = end - begin; dir->off = commit.off; @@ -1722,7 +1787,7 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_mdir_t *dir, for (lfs_file_t *f = (lfs_file_t*)lfs->mlist; f; f = f->next) { 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->ctz.size > LFS_CFG_CACHE_SIZE(lfs)) { int err = lfs_file_outline(lfs, f); if (err) { return err; @@ -1780,7 +1845,7 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_mdir_t *dir, .crc = 0xffffffff, .begin = dir->off, - .end = lfs->cfg->block_size - 8, + .end = LFS_CFG_BLOCK_SIZE(lfs) - 8, }; // traverse attrs that need to be written out @@ -1836,7 +1901,7 @@ 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); + LFS_ASSERT(commit.off % LFS_CFG_PROG_SIZE(lfs) == 0); dir->off = commit.off; dir->etag = commit.ptag; // and update gstate @@ -2191,7 +2256,7 @@ int lfs_dir_rewind(lfs_t *lfs, lfs_dir_t *dir) { /// File index list operations /// static int lfs_ctz_index(lfs_t *lfs, lfs_off_t *off) { lfs_off_t size = *off; - lfs_off_t b = lfs->cfg->block_size - 2*4; + lfs_off_t b = LFS_CFG_BLOCK_SIZE(lfs) - 2*4; lfs_off_t i = size / b; if (i == 0) { return 0; @@ -2268,7 +2333,7 @@ static int lfs_ctz_extend(lfs_t *lfs, noff = noff + 1; // just copy out the last block if it is incomplete - if (noff != lfs->cfg->block_size) { + if (noff != LFS_CFG_BLOCK_SIZE(lfs)) { for (lfs_off_t i = 0; i < noff; i++) { uint8_t data; err = lfs_bd_read(lfs, @@ -2379,26 +2444,18 @@ static int lfs_ctz_traverse(lfs_t *lfs, /// Top level file operations /// -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\", %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); - +static int lfs_file_opencommon(lfs_t *lfs, lfs_file_t *file, + const char *path, int flags) { // 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; } } // setup simple file details int err; - file->cfg = cfg; file->flags = flags | LFS_F_OPENED; file->pos = 0; file->off = 0; @@ -2461,14 +2518,16 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file, lfs_ctz_fromle32(&file->ctz); } +#if !defined(LFS_FILE_STATICCFG) || LFS_FILE_ATTR_COUNT > 0 // fetch attrs - for (unsigned i = 0; i < file->cfg->attr_count; i++) { + for (unsigned i = 0; i < LFS_FILE_CFG_ATTR_COUNT(file); i++) { if ((file->flags & 3) != LFS_O_WRONLY) { lfs_stag_t res = lfs_dir_get(lfs, &file->m, LFS_MKTAG(0x7ff, 0x3ff, 0), - LFS_MKTAG(LFS_TYPE_USERATTR + file->cfg->attrs[i].type, - file->id, file->cfg->attrs[i].size), - file->cfg->attrs[i].buffer); + LFS_MKTAG( + LFS_TYPE_USERATTR + LFS_FILE_CFG_ATTRS(file)[i].type, + file->id, LFS_FILE_CFG_ATTRS(file)[i].size), + LFS_FILE_CFG_ATTRS(file)[i].buffer); if (res < 0 && res != LFS_ERR_NOENT) { err = res; goto cleanup; @@ -2476,7 +2535,7 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file, } if ((file->flags & 3) != LFS_O_RDONLY) { - if (file->cfg->attrs[i].size > lfs->attr_max) { + if (LFS_FILE_CFG_ATTRS(file)[i].size > lfs->attr_max) { err = LFS_ERR_NOSPC; goto cleanup; } @@ -2484,12 +2543,13 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file, file->flags |= LFS_F_DIRTY; } } +#endif // allocate buffer if needed - if (file->cfg->buffer) { - file->cache.buffer = file->cfg->buffer; + if (LFS_FILE_CFG_BUFFER(file)) { + file->cache.buffer = LFS_FILE_CFG_BUFFER(file); } else { - file->cache.buffer = lfs_malloc(lfs->cfg->cache_size); + file->cache.buffer = lfs_malloc(LFS_CFG_CACHE_SIZE(lfs)); if (!file->cache.buffer) { err = LFS_ERR_NOMEM; goto cleanup; @@ -2506,7 +2566,7 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file, file->flags |= LFS_F_INLINE; file->cache.block = file->ctz.head; file->cache.off = 0; - file->cache.size = lfs->cfg->cache_size; + file->cache.size = LFS_CFG_CACHE_SIZE(lfs); // don't always read (may be new/trunc file) if (file->ctz.size > 0) { @@ -2522,14 +2582,12 @@ 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; } @@ -2537,12 +2595,30 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file, const char *path, int flags) { LFS_TRACE("lfs_file_open(%p, %p, \"%s\", %x)", (void*)lfs, (void*)file, path, flags); +#ifndef LFS_FILE_STATICCFG static const struct lfs_file_config defaults = {0}; - int err = lfs_file_opencfg(lfs, file, path, flags, &defaults); + file->cfg = &defaults; +#endif + int err = lfs_file_opencommon(lfs, file, path, flags); LFS_TRACE("lfs_file_open -> %d", err); return err; } +#if !defined(LFS_FILE_STATICCFG) +int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file, + const char *path, int flags, + const struct lfs_file_config *cfg) { + 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); + file->cfg = cfg; + int err = lfs_file_opencommon(lfs, file, path, flags); + LFS_TRACE("lfs_file_opencfg -> %d", err); + return err; +} +#endif + int lfs_file_close(lfs_t *lfs, lfs_file_t *file) { LFS_TRACE("lfs_file_close(%p, %p)", (void*)lfs, (void*)file); LFS_ASSERT(file->flags & LFS_F_OPENED); @@ -2558,7 +2634,7 @@ int lfs_file_close(lfs_t *lfs, lfs_file_t *file) { } // clean up memory - if (!file->cfg->buffer) { + if (!LFS_FILE_CFG_BUFFER(file)) { lfs_free(file->cache.buffer); } @@ -2620,7 +2696,7 @@ static int lfs_file_relocate(lfs_t *lfs, lfs_file_t *file) { } // copy over new state of file - memcpy(file->cache.buffer, lfs->pcache.buffer, lfs->cfg->cache_size); + memcpy(file->cache.buffer, lfs->pcache.buffer, LFS_CFG_CACHE_SIZE(lfs)); file->cache.block = lfs->pcache.block; file->cache.off = lfs->pcache.off; file->cache.size = lfs->pcache.size; @@ -2773,7 +2849,7 @@ int lfs_file_sync(lfs_t *lfs, lfs_file_t *file) { err = lfs_dir_commit(lfs, &file->m, LFS_MKATTRS( {LFS_MKTAG(type, file->id, size), buffer}, {LFS_MKTAG(LFS_FROM_USERATTRS, file->id, - file->cfg->attr_count), file->cfg->attrs})); + LFS_FILE_CFG_ATTR_COUNT(file)), LFS_FILE_CFG_ATTRS(file)})); if (err) { file->flags |= LFS_F_ERRED; LFS_TRACE("lfs_file_sync -> %d", err); @@ -2818,7 +2894,7 @@ lfs_ssize_t lfs_file_read(lfs_t *lfs, lfs_file_t *file, while (nsize > 0) { // check if we need a new block if (!(file->flags & LFS_F_READING) || - file->off == lfs->cfg->block_size) { + file->off == LFS_CFG_BLOCK_SIZE(lfs)) { if (!(file->flags & LFS_F_INLINE)) { int err = lfs_ctz_find(lfs, NULL, &file->cache, file->ctz.head, file->ctz.size, @@ -2836,10 +2912,10 @@ lfs_ssize_t lfs_file_read(lfs_t *lfs, lfs_file_t *file, } // read as much as we can in current block - lfs_size_t diff = lfs_min(nsize, lfs->cfg->block_size - file->off); + lfs_size_t diff = lfs_min(nsize, LFS_CFG_BLOCK_SIZE(lfs) - file->off); if (file->flags & LFS_F_INLINE) { int err = lfs_dir_getread(lfs, &file->m, - NULL, &file->cache, lfs->cfg->block_size, + NULL, &file->cache, LFS_CFG_BLOCK_SIZE(lfs), LFS_MKTAG(0xfff, 0x1ff, 0), LFS_MKTAG(LFS_TYPE_INLINESTRUCT, file->id, 0), file->off, data, diff); @@ -2849,7 +2925,7 @@ lfs_ssize_t lfs_file_read(lfs_t *lfs, lfs_file_t *file, } } else { int err = lfs_bd_read(lfs, - NULL, &file->cache, lfs->cfg->block_size, + NULL, &file->cache, LFS_CFG_BLOCK_SIZE(lfs), file->block, file->off, data, diff); if (err) { LFS_TRACE("lfs_file_read -> %d", err); @@ -2913,7 +2989,7 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, if ((file->flags & LFS_F_INLINE) && lfs_max(file->pos+nsize, file->ctz.size) > lfs_min(0x3fe, lfs_min( - lfs->cfg->cache_size, lfs->cfg->block_size/8))) { + LFS_CFG_CACHE_SIZE(lfs), LFS_CFG_BLOCK_SIZE(lfs)/8))) { // inline file doesn't fit anymore int err = lfs_file_outline(lfs, file); if (err) { @@ -2926,7 +3002,7 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, while (nsize > 0) { // check if we need a new block if (!(file->flags & LFS_F_WRITING) || - file->off == lfs->cfg->block_size) { + file->off == LFS_CFG_BLOCK_SIZE(lfs)) { if (!(file->flags & LFS_F_INLINE)) { if (!(file->flags & LFS_F_WRITING) && file->pos > 0) { // find out which block we're extending from @@ -2962,7 +3038,7 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file, } // program as much as we can in current block - lfs_size_t diff = lfs_min(nsize, lfs->cfg->block_size - file->off); + lfs_size_t diff = lfs_min(nsize, LFS_CFG_BLOCK_SIZE(lfs) - file->off); while (true) { int err = lfs_bd_prog(lfs, &file->cache, &lfs->rcache, true, file->block, file->off, data, diff); @@ -3459,25 +3535,24 @@ int lfs_removeattr(lfs_t *lfs, const char *path, uint8_t type) { /// Filesystem operations /// -static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) { - lfs->cfg = cfg; +static int lfs_initcommon(lfs_t *lfs) { int err = 0; // validate that the lfs-cfg sizes were initiated properly before // performing any arithmetic logics with them - LFS_ASSERT(lfs->cfg->read_size != 0); - LFS_ASSERT(lfs->cfg->prog_size != 0); - LFS_ASSERT(lfs->cfg->cache_size != 0); + LFS_ASSERT(LFS_CFG_READ_SIZE(lfs) != 0); + LFS_ASSERT(LFS_CFG_PROG_SIZE(lfs) != 0); + LFS_ASSERT(LFS_CFG_CACHE_SIZE(lfs) != 0); // check that block size is a multiple of cache size is a multiple // of prog and read sizes - LFS_ASSERT(lfs->cfg->cache_size % lfs->cfg->read_size == 0); - LFS_ASSERT(lfs->cfg->cache_size % lfs->cfg->prog_size == 0); - LFS_ASSERT(lfs->cfg->block_size % lfs->cfg->cache_size == 0); + LFS_ASSERT(LFS_CFG_CACHE_SIZE(lfs) % LFS_CFG_READ_SIZE(lfs) == 0); + LFS_ASSERT(LFS_CFG_CACHE_SIZE(lfs) % LFS_CFG_PROG_SIZE(lfs) == 0); + LFS_ASSERT(LFS_CFG_BLOCK_SIZE(lfs) % LFS_CFG_CACHE_SIZE(lfs) == 0); // check that the block size is large enough to fit ctz pointers - LFS_ASSERT(4*lfs_npw2(0xffffffff / (lfs->cfg->block_size-2*4)) - <= lfs->cfg->block_size); + LFS_ASSERT(4*lfs_npw2(0xffffffff / (LFS_CFG_BLOCK_SIZE(lfs)-2*4)) + <= LFS_CFG_BLOCK_SIZE(lfs)); // block_cycles = 0 is no longer supported. // @@ -3485,14 +3560,14 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) { // 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); + LFS_ASSERT(LFS_CFG_BLOCK_CYCLES(lfs) != 0); // setup read cache - if (lfs->cfg->read_buffer) { - lfs->rcache.buffer = lfs->cfg->read_buffer; + if (LFS_CFG_READ_BUFFER(lfs)) { + lfs->rcache.buffer = LFS_CFG_READ_BUFFER(lfs); } else { - lfs->rcache.buffer = lfs_malloc(lfs->cfg->cache_size); + lfs->rcache.buffer = lfs_malloc(LFS_CFG_CACHE_SIZE(lfs)); if (!lfs->rcache.buffer) { err = LFS_ERR_NOMEM; goto cleanup; @@ -3500,10 +3575,10 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) { } // setup program cache - if (lfs->cfg->prog_buffer) { - lfs->pcache.buffer = lfs->cfg->prog_buffer; + if (LFS_CFG_PROG_BUFFER(lfs)) { + lfs->pcache.buffer = LFS_CFG_PROG_BUFFER(lfs); } else { - lfs->pcache.buffer = lfs_malloc(lfs->cfg->cache_size); + lfs->pcache.buffer = lfs_malloc(LFS_CFG_CACHE_SIZE(lfs)); if (!lfs->pcache.buffer) { err = LFS_ERR_NOMEM; goto cleanup; @@ -3515,13 +3590,13 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) { lfs_cache_zero(lfs, &lfs->pcache); // setup lookahead, must be multiple of 64-bits, 32-bit aligned - LFS_ASSERT(lfs->cfg->lookahead_size > 0); - LFS_ASSERT(lfs->cfg->lookahead_size % 8 == 0 && - (uintptr_t)lfs->cfg->lookahead_buffer % 4 == 0); - if (lfs->cfg->lookahead_buffer) { - lfs->free.buffer = lfs->cfg->lookahead_buffer; + LFS_ASSERT(LFS_CFG_LOOKAHEAD_SIZE(lfs) > 0); + LFS_ASSERT(LFS_CFG_LOOKAHEAD_SIZE(lfs) % 8 == 0 && + (uintptr_t)LFS_CFG_LOOKAHEAD_BUFFER(lfs) % 4 == 0); + if (LFS_CFG_LOOKAHEAD_BUFFER(lfs)) { + lfs->free.buffer = LFS_CFG_LOOKAHEAD_BUFFER(lfs); } else { - lfs->free.buffer = lfs_malloc(lfs->cfg->lookahead_size); + lfs->free.buffer = lfs_malloc(LFS_CFG_LOOKAHEAD_SIZE(lfs)); if (!lfs->free.buffer) { err = LFS_ERR_NOMEM; goto cleanup; @@ -3529,20 +3604,20 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) { } // check that the size limits are sane - LFS_ASSERT(lfs->cfg->name_max <= LFS_NAME_MAX); - lfs->name_max = lfs->cfg->name_max; + LFS_ASSERT(LFS_CFG_NAME_MAX(lfs) <= LFS_NAME_MAX); + lfs->name_max = LFS_CFG_NAME_MAX(lfs); if (!lfs->name_max) { lfs->name_max = LFS_NAME_MAX; } - LFS_ASSERT(lfs->cfg->file_max <= LFS_FILE_MAX); - lfs->file_max = lfs->cfg->file_max; + LFS_ASSERT(LFS_CFG_FILE_MAX(lfs) <= LFS_FILE_MAX); + lfs->file_max = LFS_CFG_FILE_MAX(lfs); if (!lfs->file_max) { lfs->file_max = LFS_FILE_MAX; } - LFS_ASSERT(lfs->cfg->attr_max <= LFS_ATTR_MAX); - lfs->attr_max = lfs->cfg->attr_max; + LFS_ASSERT(LFS_CFG_ATTR_MAX(lfs) <= LFS_ATTR_MAX); + lfs->attr_max = LFS_CFG_ATTR_MAX(lfs); if (!lfs->attr_max) { lfs->attr_max = LFS_ATTR_MAX; } @@ -3568,51 +3643,34 @@ cleanup: static int lfs_deinit(lfs_t *lfs) { // free allocated memory - if (!lfs->cfg->read_buffer) { + if (!LFS_CFG_READ_BUFFER(lfs)) { lfs_free(lfs->rcache.buffer); } - if (!lfs->cfg->prog_buffer) { + if (!LFS_CFG_PROG_BUFFER(lfs)) { lfs_free(lfs->pcache.buffer); } - if (!lfs->cfg->lookahead_buffer) { + if (!LFS_CFG_LOOKAHEAD_BUFFER(lfs)) { lfs_free(lfs->free.buffer); } return 0; } -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); +static int lfs_formatcommon(lfs_t *lfs) { int err = 0; { - err = lfs_init(lfs, cfg); + err = lfs_initcommon(lfs); if (err) { - LFS_TRACE("lfs_format -> %d", err); return err; } // create free lookahead - memset(lfs->free.buffer, 0, lfs->cfg->lookahead_size); + memset(lfs->free.buffer, 0, LFS_CFG_LOOKAHEAD_SIZE(lfs)); lfs->free.off = 0; - lfs->free.size = lfs_min(8*lfs->cfg->lookahead_size, - lfs->cfg->block_count); + lfs->free.size = lfs_min(8*LFS_CFG_LOOKAHEAD_SIZE(lfs), + LFS_CFG_BLOCK_COUNT(lfs)); lfs->free.i = 0; lfs_alloc_ack(lfs); @@ -3626,8 +3684,8 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) { // write one superblock lfs_superblock_t superblock = { .version = LFS_DISK_VERSION, - .block_size = lfs->cfg->block_size, - .block_count = lfs->cfg->block_count, + .block_size = LFS_CFG_BLOCK_SIZE(lfs), + .block_count = LFS_CFG_BLOCK_COUNT(lfs), .name_max = lfs->name_max, .file_max = lfs->file_max, .attr_max = lfs->attr_max, @@ -3660,12 +3718,21 @@ 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, " +#if defined(LFS_STATICCFG) +int lfs_format(lfs_t *lfs) { + LFS_TRACE("lfs_format(%p)", (void*)lfs); + int err = lfs_formatcommon(lfs); + LFS_TRACE("lfs_format -> %d", err); + return err; +} +#endif + +#if !defined(LFS_STATICCFG) +int lfs_formatcfg(lfs_t *lfs, const struct lfs_config *cfg) { + LFS_TRACE("lfs_formatcfg(%p, %p {.context=%p, " ".read=%p, .prog=%p, .erase=%p, .sync=%p, " ".read_size=%"PRIu32", .prog_size=%"PRIu32", " ".block_size=%"PRIu32", .block_count=%"PRIu32", " @@ -3681,9 +3748,16 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) { 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); + lfs->cfg = cfg; + int err = lfs_formatcommon(lfs); + LFS_TRACE("lfs_formatcfg -> %d", err); + return err; +} +#endif + +static int lfs_mountcommon(lfs_t *lfs) { + int err = lfs_initcommon(lfs); if (err) { - LFS_TRACE("lfs_mount -> %d", err); return err; } @@ -3691,7 +3765,7 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) { lfs_mdir_t dir = {.tail = {0, 1}}; lfs_block_t cycle = 0; while (!lfs_pair_isnull(dir.tail)) { - if (cycle >= lfs->cfg->block_count/2) { + if (cycle >= LFS_CFG_BLOCK_COUNT(lfs)/2) { // loop detected err = LFS_ERR_CORRUPT; goto cleanup; @@ -3799,14 +3873,48 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) { // setup free lookahead lfs_alloc_reset(lfs); - LFS_TRACE("lfs_mount -> %d", 0); + LFS_TRACE("lfs_mountcfg -> %d", 0); return 0; cleanup: lfs_unmount(lfs); + LFS_TRACE("lfs_mountcfg -> %d", err); + return err; +} + +#if defined(LFS_STATICCFG) +int lfs_mount(lfs_t *lfs) { + LFS_TRACE("lfs_mount(%p)", (void*)lfs); + int err = lfs_mountcommon(lfs); LFS_TRACE("lfs_mount -> %d", err); return err; } +#endif + +#if !defined(LFS_STATICCFG) +int lfs_mountcfg(lfs_t *lfs, const struct lfs_config *cfg) { + LFS_TRACE("lfs_mountcfg(%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); + lfs->cfg = cfg; + int err = lfs_mountcommon(lfs); + LFS_TRACE("lfs_mountcfg -> %d", err); + return err; +} +#endif int lfs_unmount(lfs_t *lfs) { LFS_TRACE("lfs_unmount(%p)", (void*)lfs); @@ -3838,7 +3946,7 @@ int lfs_fs_traverseraw(lfs_t *lfs, lfs_block_t cycle = 0; while (!lfs_pair_isnull(dir.tail)) { - if (cycle >= lfs->cfg->block_count/2) { + if (cycle >= LFS_CFG_BLOCK_COUNT(lfs)/2) { // loop detected return LFS_ERR_CORRUPT; } @@ -3929,7 +4037,7 @@ static int lfs_fs_pred(lfs_t *lfs, pdir->tail[1] = 1; lfs_block_t cycle = 0; while (!lfs_pair_isnull(pdir->tail)) { - if (cycle >= lfs->cfg->block_count/2) { + if (cycle >= LFS_CFG_BLOCK_COUNT(lfs)/2) { // loop detected return LFS_ERR_CORRUPT; } @@ -3962,7 +4070,7 @@ static int lfs_fs_parent_match(void *data, lfs_block_t child[2]; int err = lfs_bd_read(lfs, - &lfs->pcache, &lfs->rcache, lfs->cfg->block_size, + &lfs->pcache, &lfs->rcache, LFS_CFG_BLOCK_SIZE(lfs), disk->block, disk->off, &child, sizeof(child)); if (err) { return err; @@ -3979,7 +4087,7 @@ static lfs_stag_t lfs_fs_parent(lfs_t *lfs, const lfs_block_t pair[2], parent->tail[1] = 1; lfs_block_t cycle = 0; while (!lfs_pair_isnull(parent->tail)) { - if (cycle >= lfs->cfg->block_count/2) { + if (cycle >= LFS_CFG_BLOCK_COUNT(lfs)/2) { // loop detected return LFS_ERR_CORRUPT; } @@ -4421,7 +4529,7 @@ static int lfs1_dir_fetch(lfs_t *lfs, } if ((0x7fffffff & test.size) < sizeof(test)+4 || - (0x7fffffff & test.size) > lfs->cfg->block_size) { + (0x7fffffff & test.size) > LFS_CFG_BLOCK_SIZE(lfs)) { continue; } @@ -4600,11 +4708,10 @@ static int lfs1_moved(lfs_t *lfs, const void *e) { } /// Filesystem operations /// -static int lfs1_mount(lfs_t *lfs, struct lfs1 *lfs1, - const struct lfs_config *cfg) { +static int lfs1_mountcommon(lfs_t *lfs, struct lfs1 *lfs1) { int err = 0; { - err = lfs_init(lfs, cfg); + err = lfs_initcommont(lfs); if (err) { return err; } @@ -4668,27 +4775,10 @@ 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); +static int lfs_migratecommon(lfs_t *lfs) { struct lfs1 lfs1; - int err = lfs1_mount(lfs, &lfs1, cfg); + int err = lfs1_mountcommon(lfs, &lfs1); if (err) { - LFS_TRACE("lfs_migrate -> %d", err); return err; } @@ -4872,8 +4962,8 @@ int lfs_migrate(lfs_t *lfs, const struct lfs_config *cfg) { lfs_superblock_t superblock = { .version = LFS_DISK_VERSION, - .block_size = lfs->cfg->block_size, - .block_count = lfs->cfg->block_count, + .block_size = LFS_CFG_BLOCK_SIZE(lfs), + .block_count = LFS_CFG_BLOCK_COUNT(lfs), .name_max = lfs->name_max, .file_max = lfs->file_max, .attr_max = lfs->attr_max, @@ -4905,8 +4995,41 @@ int lfs_migrate(lfs_t *lfs, const struct lfs_config *cfg) { cleanup: lfs1_unmount(lfs); - LFS_TRACE("lfs_migrate -> %d", err); return err; } +#if defined(LFS_STATICCFG) +int lfs_migrate(lfs_t *lfs) { + LFS_TRACE("lfs_migrate(%p)", (void*)lfs); + int err = lfs_migratecommon(lfs); + LFS_TRACE("lfs_migrate -> %d", err); + return err; +} +#endif + +#if !defined(LFS_STATICCFG) +int lfs_migratecfg(lfs_t *lfs, const struct lfs_config *cfg) { + LFS_TRACE("lfs_migratecfg(%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); + lfs->cfg = cfg; + int err = lfs_migratecommon(lfs); + LFS_TRACE("lfs_migratecfg -> %d", err); + return err; +} +#endif + #endif diff --git a/lfs.h b/lfs.h index 52e01b3..445c355 100644 --- a/lfs.h +++ b/lfs.h @@ -125,6 +125,7 @@ enum lfs_whence_flags { }; +#if !defined(LFS_STATICCFG) // Configuration provided during initialization of the littlefs struct lfs_config { // Opaque user provided context that can be used to pass @@ -219,6 +220,99 @@ struct lfs_config { // LFS_ATTR_MAX when zero. lfs_size_t attr_max; }; +#else +// Static configuration if LFS_STATICCFG is defined, there are defaults +// for some of these, but some are required. For full documentation, see +// the lfs_config struct above. + +// Block device operations +int lfs_read(lfs_block_t block, + lfs_off_t off, void *buffer, lfs_size_t size); +int lfs_prog(lfs_block_t block, + lfs_off_t off, const void *buffer, lfs_size_t size); +int lfs_erase(lfs_block_t block); +int lfs_sync(void); + +// Required configuration +#ifndef LFS_READ_SIZE +#error "LFS_STATICCFG requires LFS_READ_SIZE" +#endif +#ifndef LFS_PROG_SIZE +#error "LFS_STATICCFG requires LFS_PROG_SIZE" +#endif +#ifndef LFS_BLOCK_SIZE +#error "LFS_STATICCFG requires LFS_BLOCK_SIZE" +#endif +#ifndef LFS_BLOCK_COUNT +#error "LFS_STATICCFG requires LFS_BLOCK_COUNT" +#endif +#ifndef LFS_BLOCK_CYCLES +#error "LFS_STATICCFG requires LFS_BLOCK_CYCLES" +#endif +#ifndef LFS_CACHE_SIZE +#error "LFS_STATICCFG requires LFS_CACHE_SIZE" +#endif +#ifndef LFS_LOOKAHEAD_SIZE +#error "LFS_STATICCFG requires LFS_LOOKAHEAD_SIZE" +#endif + +// Optional configuration +#ifndef LFS_READ_BUFFER +#define LFS_READ_BUFFER NULL +#endif +#ifndef LFS_PROG_BUFFER +#define LFS_PROG_BUFFER NULL +#endif +#ifndef LFS_LOOKAHEAD_BUFFER +#define LFS_LOOKAHEAD_BUFFER NULL +#endif +#ifndef LFS_NAME_MAX +#define LFS_NAME_MAX 0 +#endif +#ifndef LFS_FILE_MAX +#define LFS_FILE_MAX 0 +#endif +#ifndef LFS_ATTR_MAX +#define LFS_ATTR_MAX 0 +#endif +#endif + +#if !defined(LFS_FILE_STATICCFG) +// Optional configuration provided during lfs_file_opencfg +struct lfs_file_config { + // Optional statically allocated file buffer. Must be cache_size. + // By default lfs_malloc is used to allocate this buffer. + void *buffer; + + // Optional list of custom attributes related to the file. If the file + // is opened with read access, these attributes will be read from disk + // during the open call. If the file is opened with write access, the + // attributes will be written to disk every file sync or close. This + // write occurs atomically with update to the file's contents. + // + // Custom attributes are uniquely identified by an 8-bit type and limited + // to LFS_ATTR_MAX bytes. When read, if the stored attribute is smaller + // than the buffer, it will be padded with zeros. If the stored attribute + // is larger, then it will be silently truncated. If the attribute is not + // found, it will be created implicitly. + struct lfs_attr *attrs; + + // Number of custom attributes in the list + lfs_size_t attr_count; +}; +#else +// Static configuration if LFS_FILE_STATICCFG is defined. For full +// documentation, see the lfs_file_config struct above. +#ifndef LFS_FILE_BUFFER +#define LFS_FILE_BUFFER NULL +#endif +#ifndef LFS_FILE_ATTRS +#define LFS_FILE_ATTRS ((struct lfs_attr*)NULL) +#endif +#ifndef LFS_FILE_ATTR_COUNT +#define LFS_FILE_ATTR_COUNT 0 +#endif +#endif // File info structure struct lfs_info { @@ -249,29 +343,6 @@ struct lfs_attr { lfs_size_t size; }; -// Optional configuration provided during lfs_file_opencfg -struct lfs_file_config { - // Optional statically allocated file buffer. Must be cache_size. - // By default lfs_malloc is used to allocate this buffer. - void *buffer; - - // Optional list of custom attributes related to the file. If the file - // is opened with read access, these attributes will be read from disk - // during the open call. If the file is opened with write access, the - // attributes will be written to disk every file sync or close. This - // write occurs atomically with update to the file's contents. - // - // Custom attributes are uniquely identified by an 8-bit type and limited - // to LFS_ATTR_MAX bytes. When read, if the stored attribute is smaller - // than the buffer, it will be padded with zeros. If the stored attribute - // is larger, then it will be silently truncated. If the attribute is not - // found, it will be created implicitly. - struct lfs_attr *attrs; - - // Number of custom attributes in the list - lfs_size_t attr_count; -}; - /// internal littlefs data structures /// typedef struct lfs_cache { @@ -321,7 +392,9 @@ typedef struct lfs_file { lfs_off_t off; lfs_cache_t cache; +#ifndef LFS_FILE_STATICCFG const struct lfs_file_config *cfg; +#endif } lfs_file_t; typedef struct lfs_superblock { @@ -364,7 +437,9 @@ typedef struct lfs { uint32_t *buffer; } free; +#ifndef LFS_STATICCFG const struct lfs_config *cfg; +#endif lfs_size_t name_max; lfs_size_t file_max; lfs_size_t attr_max; @@ -377,16 +452,38 @@ typedef struct lfs { /// Filesystem functions /// -// Format a block device with the littlefs +#if defined(LFS_STATICCFG) +// Format a block device with littlefs +// +// Requires a littlefs object. This clobbers the littlefs object, and does +// not leave the filesystem mounted. +// +// Returns a negative error code on failure. +int lfs_format(lfs_t *lfs); +#endif + +#if !defined(LFS_STATICCFG) +// Format a block device with littlefs with per-filesystem configuration // // Requires a littlefs object and config struct. This clobbers the littlefs // object, and does not leave the filesystem mounted. The config struct must // be zeroed for defaults and backwards compatibility. // // Returns a negative error code on failure. -int lfs_format(lfs_t *lfs, const struct lfs_config *config); +int lfs_formatcfg(lfs_t *lfs, const struct lfs_config *config); +#endif -// Mounts a littlefs +#if defined(LFS_STATICCFG) +// Mounts littlefs +// +// Requires a littlefs object and static configuration. +// +// Returns a negative error code on failure. +int lfs_mount(lfs_t *lfs); +#endif + +#if !defined(LFS_STATICCFG) +// Mounts a littlefs with per-filesystem configuration // // Requires a littlefs object and config struct. Multiple filesystems // may be mounted simultaneously with multiple littlefs objects. Both @@ -394,7 +491,8 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *config); // be zeroed for defaults and backwards compatibility. // // Returns a negative error code on failure. -int lfs_mount(lfs_t *lfs, const struct lfs_config *config); +int lfs_mountcfg(lfs_t *lfs, const struct lfs_config *config); +#endif // Unmounts a littlefs // @@ -468,7 +566,8 @@ int lfs_removeattr(lfs_t *lfs, const char *path, uint8_t type); int lfs_file_open(lfs_t *lfs, lfs_file_t *file, const char *path, int flags); -// Open a file with extra configuration +#if !defined(LFS_FILE_STATICCFG) +// Open a file with per-file configuration // // The mode that the file is opened in is determined by the flags, which // are values from the enum lfs_open_flags that are bitwise-ored together. @@ -481,6 +580,7 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file, int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file, const char *path, int flags, const struct lfs_file_config *config); +#endif // Close a file // @@ -610,19 +710,34 @@ lfs_ssize_t lfs_fs_size(lfs_t *lfs); // Returns a negative error code on failure. int lfs_fs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data); -#ifdef LFS_MIGRATE +#if defined(LFS_MIGRATE) && defined(LFS_STATICCFG) // Attempts to migrate a previous version of littlefs // // Behaves similarly to the lfs_format function. Attempts to mount // the previous version of littlefs and update the filesystem so it can be // mounted with the current version of littlefs. // +// Requires a littlefs object. This clobbers the littlefs object, and does +// not leave the filesystem mounted. +// +// Returns a negative error code on failure. +int lfs_migrate(lfs_t *lfs, const struct lfs_config *cfg); +#endif + +#if defined(LFS_MIGRATE) && !defined(LFS_STATICCFG) +// Attempts to migrate a previous version of littlefs with per-filesystem +// configuration +// +// Behaves similarly to the lfs_format function. Attempts to mount +// the previous version of littlefs and update the filesystem so it can be +// mounted with the current version of littlefs. +// // Requires a littlefs object and config struct. This clobbers the littlefs // object, and does not leave the filesystem mounted. The config struct must // be zeroed for defaults and backwards compatibility. // // Returns a negative error code on failure. -int lfs_migrate(lfs_t *lfs, const struct lfs_config *cfg); +int lfs_migratecfg(lfs_t *lfs, const struct lfs_config *cfg); #endif diff --git a/tests/test_alloc.toml b/tests/test_alloc.toml index fa92da5..711560f 100644 --- a/tests/test_alloc.toml +++ b/tests/test_alloc.toml @@ -9,12 +9,12 @@ code = ''' const char *names[FILES] = {"bacon", "eggs", "pancakes"}; lfs_file_t files[FILES]; - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "breakfast") => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int n = 0; n < FILES; n++) { sprintf(path, "breakfast/%s", names[n]); lfs_file_open(&lfs, &files[n], path, @@ -31,7 +31,7 @@ code = ''' } lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int n = 0; n < FILES; n++) { sprintf(path, "breakfast/%s", names[n]); lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) => 0; @@ -51,13 +51,13 @@ define.SIZE = '(((LFS_BLOCK_SIZE-8)*(LFS_BLOCK_COUNT-6)) / FILES)' code = ''' const char *names[FILES] = {"bacon", "eggs", "pancakes"}; - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "breakfast") => 0; lfs_unmount(&lfs) => 0; for (int n = 0; n < FILES; n++) { - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; sprintf(path, "breakfast/%s", names[n]); lfs_file_open(&lfs, &file, path, LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0; @@ -70,7 +70,7 @@ code = ''' lfs_unmount(&lfs) => 0; } - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int n = 0; n < FILES; n++) { sprintf(path, "breakfast/%s", names[n]); lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) => 0; @@ -92,14 +92,14 @@ code = ''' const char *names[FILES] = {"bacon", "eggs", "pancakes"}; lfs_file_t files[FILES]; - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; for (int c = 0; c < CYCLES; c++) { - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "breakfast") => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int n = 0; n < FILES; n++) { sprintf(path, "breakfast/%s", names[n]); lfs_file_open(&lfs, &files[n], path, @@ -116,7 +116,7 @@ code = ''' } lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int n = 0; n < FILES; n++) { sprintf(path, "breakfast/%s", names[n]); lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) => 0; @@ -129,7 +129,7 @@ code = ''' } lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int n = 0; n < FILES; n++) { sprintf(path, "breakfast/%s", names[n]); lfs_remove(&lfs, path) => 0; @@ -146,15 +146,15 @@ define.CYCLES = [1, 10] code = ''' const char *names[FILES] = {"bacon", "eggs", "pancakes"}; - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; for (int c = 0; c < CYCLES; c++) { - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "breakfast") => 0; lfs_unmount(&lfs) => 0; for (int n = 0; n < FILES; n++) { - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; sprintf(path, "breakfast/%s", names[n]); lfs_file_open(&lfs, &file, path, LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0; @@ -167,7 +167,7 @@ code = ''' lfs_unmount(&lfs) => 0; } - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int n = 0; n < FILES; n++) { sprintf(path, "breakfast/%s", names[n]); lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) => 0; @@ -180,7 +180,7 @@ code = ''' } lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int n = 0; n < FILES; n++) { sprintf(path, "breakfast/%s", names[n]); lfs_remove(&lfs, path) => 0; @@ -192,8 +192,8 @@ code = ''' [[case]] # exhaustion test code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT); size = strlen("exhaustion"); memcpy(buffer, "exhaustion", size); @@ -216,7 +216,7 @@ code = ''' lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "exhaustion", LFS_O_RDONLY); size = strlen("exhaustion"); lfs_file_size(&lfs, &file) => size; @@ -229,8 +229,8 @@ code = ''' [[case]] # exhaustion wraparound test define.SIZE = '(((LFS_BLOCK_SIZE-8)*(LFS_BLOCK_COUNT-4)) / 3)' code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "padding", LFS_O_WRONLY | LFS_O_CREAT); size = strlen("buffering"); @@ -263,7 +263,7 @@ code = ''' lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "exhaustion", LFS_O_RDONLY); size = strlen("exhaustion"); lfs_file_size(&lfs, &file) => size; @@ -276,8 +276,8 @@ code = ''' [[case]] # dir exhaustion test code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // find out max file size lfs_mkdir(&lfs, "exhaustiondir") => 0; @@ -328,8 +328,8 @@ in = "lfs.c" define.LFS_ERASE_CYCLES = 0xffffffff define.LFS_BADBLOCK_BEHAVIOR = 'LFS_TESTBD_BADBLOCK_READERROR' code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // first fill to exhaustion to find available space lfs_file_open(&lfs, &file, "pacman", LFS_O_WRONLY | LFS_O_CREAT) => 0; strcpy((char*)buffer, "waka"); @@ -358,7 +358,7 @@ code = ''' lfs_unmount(&lfs) => 0; // remount to force an alloc scan - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // but mark the head of our file as a "bad block", this is force our // scan to bail early @@ -393,7 +393,7 @@ code = ''' lfs_unmount(&lfs) => 0; // check that the disk isn't hurt - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "pacman", LFS_O_RDONLY) => 0; strcpy((char*)buffer, "waka"); size = strlen("waka"); @@ -416,8 +416,8 @@ define.LFS_BLOCK_SIZE = 512 define.LFS_BLOCK_COUNT = 1024 if = 'LFS_BLOCK_SIZE == 512 && LFS_BLOCK_COUNT == 1024' code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // find out max file size lfs_mkdir(&lfs, "exhaustiondir") => 0; @@ -487,8 +487,8 @@ define.LFS_BLOCK_SIZE = 512 define.LFS_BLOCK_COUNT = 1024 if = 'LFS_BLOCK_SIZE == 512 && LFS_BLOCK_COUNT == 1024' code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // create one block hole for half a directory lfs_file_open(&lfs, &file, "bump", LFS_O_WRONLY | LFS_O_CREAT) => 0; @@ -510,7 +510,7 @@ code = ''' // remount to force reset of lookahead lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // open hole lfs_remove(&lfs, "bump") => 0; @@ -532,8 +532,8 @@ define.LFS_BLOCK_SIZE = 512 define.LFS_BLOCK_COUNT = 1024 if = 'LFS_BLOCK_SIZE == 512 && LFS_BLOCK_COUNT == 1024' code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // fill completely with two files lfs_file_open(&lfs, &file, "exhaustion1", @@ -560,7 +560,7 @@ code = ''' // remount to force reset of lookahead lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // rewrite one file lfs_file_open(&lfs, &file, "exhaustion1", @@ -597,8 +597,8 @@ define.LFS_BLOCK_SIZE = 512 define.LFS_BLOCK_COUNT = 1024 if = 'LFS_BLOCK_SIZE == 512 && LFS_BLOCK_COUNT == 1024' code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // fill completely with two files lfs_file_open(&lfs, &file, "exhaustion1", @@ -625,7 +625,7 @@ code = ''' // remount to force reset of lookahead lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // rewrite one file with a hole of one block lfs_file_open(&lfs, &file, "exhaustion1", diff --git a/tests/test_attrs.toml b/tests/test_attrs.toml index db8d0c7..f57a491 100644 --- a/tests/test_attrs.toml +++ b/tests/test_attrs.toml @@ -1,14 +1,14 @@ [[case]] # set/get attribute code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "hello") => 0; lfs_file_open(&lfs, &file, "hello/hello", LFS_O_WRONLY | LFS_O_CREAT) => 0; lfs_file_write(&lfs, &file, "hello", strlen("hello")) => strlen("hello"); lfs_file_close(&lfs, &file); lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; memset(buffer, 0, sizeof(buffer)); lfs_setattr(&lfs, "hello", 'A', "aaaa", 4) => 0; lfs_setattr(&lfs, "hello", 'B', "bbbbbb", 6) => 0; @@ -60,7 +60,7 @@ code = ''' lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&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; @@ -78,15 +78,15 @@ code = ''' [[case]] # set/get root attribute code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "hello") => 0; lfs_file_open(&lfs, &file, "hello/hello", LFS_O_WRONLY | LFS_O_CREAT) => 0; lfs_file_write(&lfs, &file, "hello", strlen("hello")) => strlen("hello"); lfs_file_close(&lfs, &file); lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; memset(buffer, 0, sizeof(buffer)); lfs_setattr(&lfs, "/", 'A', "aaaa", 4) => 0; lfs_setattr(&lfs, "/", 'B', "bbbbbb", 6) => 0; @@ -137,7 +137,7 @@ code = ''' lfs_getattr(&lfs, "/", 'C', buffer+10, 5) => 5; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; memset(buffer, 0, sizeof(buffer)); lfs_getattr(&lfs, "/", 'A', buffer, 4) => 4; lfs_getattr(&lfs, "/", 'B', buffer+4, 9) => 9; @@ -155,15 +155,15 @@ code = ''' [[case]] # set/get file attribute code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "hello") => 0; lfs_file_open(&lfs, &file, "hello/hello", LFS_O_WRONLY | LFS_O_CREAT) => 0; lfs_file_write(&lfs, &file, "hello", strlen("hello")) => strlen("hello"); lfs_file_close(&lfs, &file); lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; memset(buffer, 0, sizeof(buffer)); struct lfs_attr attrs1[] = { {'A', buffer, 4}, @@ -238,7 +238,7 @@ code = ''' lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; memset(buffer, 0, sizeof(buffer)); struct lfs_attr attrs3[] = { {'A', buffer, 4}, @@ -262,15 +262,15 @@ code = ''' [[case]] # deferred file attributes code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "hello") => 0; lfs_file_open(&lfs, &file, "hello/hello", LFS_O_WRONLY | LFS_O_CREAT) => 0; lfs_file_write(&lfs, &file, "hello", strlen("hello")) => strlen("hello"); lfs_file_close(&lfs, &file); lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_setattr(&lfs, "hello/hello", 'B', "fffffffff", 9) => 0; lfs_setattr(&lfs, "hello/hello", 'C', "ccccc", 5) => 0; diff --git a/tests/test_badblocks.toml b/tests/test_badblocks.toml index 06967a6..2fed0f6 100644 --- a/tests/test_badblocks.toml +++ b/tests/test_badblocks.toml @@ -19,9 +19,9 @@ code = ''' lfs_testbd_setwear(&cfg, badblock-1, 0) => 0; lfs_testbd_setwear(&cfg, badblock, 0xffffffff) => 0; - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int i = 1; i < 10; i++) { for (int j = 0; j < NAMEMULT; j++) { buffer[j] = '0'+i; @@ -46,7 +46,7 @@ code = ''' } lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int i = 1; i < 10; i++) { for (int j = 0; j < NAMEMULT; j++) { buffer[j] = '0'+i; @@ -93,9 +93,9 @@ code = ''' lfs_testbd_setwear(&cfg, i+2, 0xffffffff) => 0; } - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int i = 1; i < 10; i++) { for (int j = 0; j < NAMEMULT; j++) { buffer[j] = '0'+i; @@ -120,7 +120,7 @@ code = ''' } lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int i = 1; i < 10; i++) { for (int j = 0; j < NAMEMULT; j++) { buffer[j] = '0'+i; @@ -166,9 +166,9 @@ code = ''' lfs_testbd_setwear(&cfg, (2*i) + 2, 0xffffffff) => 0; } - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int i = 1; i < 10; i++) { for (int j = 0; j < NAMEMULT; j++) { buffer[j] = '0'+i; @@ -193,7 +193,7 @@ code = ''' } lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int i = 1; i < 10; i++) { for (int j = 0; j < NAMEMULT; j++) { buffer[j] = '0'+i; @@ -236,6 +236,6 @@ code = ''' lfs_testbd_setwear(&cfg, 0, 0xffffffff) => 0; lfs_testbd_setwear(&cfg, 1, 0xffffffff) => 0; - lfs_format(&lfs, &cfg) => LFS_ERR_NOSPC; - lfs_mount(&lfs, &cfg) => LFS_ERR_CORRUPT; + lfs_formatcfg(&lfs, &cfg) => LFS_ERR_NOSPC; + lfs_mountcfg(&lfs, &cfg) => LFS_ERR_CORRUPT; ''' diff --git a/tests/test_dirs.toml b/tests/test_dirs.toml index 270f4f8..218049a 100644 --- a/tests/test_dirs.toml +++ b/tests/test_dirs.toml @@ -1,7 +1,7 @@ [[case]] # root code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "/") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(info.type == LFS_TYPE_DIR); @@ -17,16 +17,16 @@ code = ''' [[case]] # many directory creation define.N = 'range(0, 100, 3)' code = ''' - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int i = 0; i < N; i++) { sprintf(path, "dir%03d", i); lfs_mkdir(&lfs, path) => 0; } lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "/") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(info.type == LFS_TYPE_DIR); @@ -48,16 +48,16 @@ code = ''' [[case]] # many directory removal define.N = 'range(3, 100, 11)' code = ''' - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int i = 0; i < N; i++) { sprintf(path, "removeme%03d", i); lfs_mkdir(&lfs, path) => 0; } lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "/") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(info.type == LFS_TYPE_DIR); @@ -75,14 +75,14 @@ code = ''' lfs_dir_close(&lfs, &dir) => 0; lfs_unmount(&lfs); - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int i = 0; i < N; i++) { sprintf(path, "removeme%03d", i); lfs_remove(&lfs, path) => 0; } lfs_unmount(&lfs); - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "/") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(info.type == LFS_TYPE_DIR); @@ -98,16 +98,16 @@ code = ''' [[case]] # many directory rename define.N = 'range(3, 100, 11)' code = ''' - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int i = 0; i < N; i++) { sprintf(path, "test%03d", i); lfs_mkdir(&lfs, path) => 0; } lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "/") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(info.type == LFS_TYPE_DIR); @@ -125,7 +125,7 @@ code = ''' lfs_dir_close(&lfs, &dir) => 0; lfs_unmount(&lfs); - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int i = 0; i < N; i++) { char oldpath[128]; char newpath[128]; @@ -135,7 +135,7 @@ code = ''' } lfs_unmount(&lfs); - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "/") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(info.type == LFS_TYPE_DIR); @@ -158,10 +158,10 @@ code = ''' define.N = [5, 11] reentrant = true code = ''' - err = lfs_mount(&lfs, &cfg); + err = lfs_mountcfg(&lfs, &cfg); if (err) { - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; } for (int i = 0; i < N; i++) { @@ -237,9 +237,9 @@ code = ''' [[case]] # file creation define.N = 'range(3, 100, 11)' code = ''' - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int i = 0; i < N; i++) { sprintf(path, "file%03d", i); lfs_file_open(&lfs, &file, path, @@ -248,7 +248,7 @@ code = ''' } lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "/") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(info.type == LFS_TYPE_DIR); @@ -270,9 +270,9 @@ code = ''' [[case]] # file removal define.N = 'range(0, 100, 3)' code = ''' - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int i = 0; i < N; i++) { sprintf(path, "removeme%03d", i); lfs_file_open(&lfs, &file, path, @@ -281,7 +281,7 @@ code = ''' } lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "/") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(info.type == LFS_TYPE_DIR); @@ -299,14 +299,14 @@ code = ''' lfs_dir_close(&lfs, &dir) => 0; lfs_unmount(&lfs); - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int i = 0; i < N; i++) { sprintf(path, "removeme%03d", i); lfs_remove(&lfs, path) => 0; } lfs_unmount(&lfs); - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "/") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(info.type == LFS_TYPE_DIR); @@ -322,9 +322,9 @@ code = ''' [[case]] # file rename define.N = 'range(0, 100, 3)' code = ''' - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int i = 0; i < N; i++) { sprintf(path, "test%03d", i); lfs_file_open(&lfs, &file, path, @@ -333,7 +333,7 @@ code = ''' } lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "/") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(info.type == LFS_TYPE_DIR); @@ -351,7 +351,7 @@ code = ''' lfs_dir_close(&lfs, &dir) => 0; lfs_unmount(&lfs); - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int i = 0; i < N; i++) { char oldpath[128]; char newpath[128]; @@ -361,7 +361,7 @@ code = ''' } lfs_unmount(&lfs); - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "/") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(info.type == LFS_TYPE_DIR); @@ -384,10 +384,10 @@ code = ''' define.N = [5, 25] reentrant = true code = ''' - err = lfs_mount(&lfs, &cfg); + err = lfs_mountcfg(&lfs, &cfg); if (err) { - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; } for (int i = 0; i < N; i++) { @@ -462,21 +462,21 @@ code = ''' [[case]] # nested directories code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "potato") => 0; lfs_file_open(&lfs, &file, "burito", LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&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; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "potato") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(strcmp(info.name, ".") == 0); @@ -498,21 +498,21 @@ code = ''' lfs_unmount(&lfs) => 0; // try removing? - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_remove(&lfs, "potato") => LFS_ERR_NOTEMPTY; lfs_unmount(&lfs) => 0; // try renaming? - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_rename(&lfs, "potato", "coldpotato") => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_rename(&lfs, "coldpotato", "warmpotato") => 0; lfs_rename(&lfs, "warmpotato", "hotpotato") => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_remove(&lfs, "potato") => LFS_ERR_NOENT; lfs_remove(&lfs, "coldpotato") => LFS_ERR_NOENT; lfs_remove(&lfs, "warmpotato") => LFS_ERR_NOENT; @@ -520,7 +520,7 @@ code = ''' lfs_unmount(&lfs) => 0; // try cross-directory renaming - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "coldpotato") => 0; lfs_rename(&lfs, "hotpotato/baked", "coldpotato/baked") => 0; lfs_rename(&lfs, "coldpotato", "hotpotato") => LFS_ERR_NOTEMPTY; @@ -536,7 +536,7 @@ code = ''' lfs_remove(&lfs, "hotpotato") => LFS_ERR_NOTEMPTY; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "hotpotato") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(strcmp(info.name, ".") == 0); @@ -558,7 +558,7 @@ code = ''' lfs_unmount(&lfs) => 0; // final remove - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_remove(&lfs, "hotpotato") => LFS_ERR_NOTEMPTY; lfs_remove(&lfs, "hotpotato/baked") => 0; lfs_remove(&lfs, "hotpotato") => LFS_ERR_NOTEMPTY; @@ -568,7 +568,7 @@ code = ''' lfs_remove(&lfs, "hotpotato") => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "/") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(strcmp(info.name, ".") == 0); @@ -587,8 +587,8 @@ code = ''' [[case]] # recursive remove define.N = [10, 100] code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "prickly-pear") => 0; for (int i = 0; i < N; i++) { sprintf(path, "prickly-pear/cactus%03d", i); @@ -611,7 +611,7 @@ code = ''' lfs_dir_close(&lfs, &dir) => 0; lfs_unmount(&lfs); - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_remove(&lfs, "prickly-pear") => LFS_ERR_NOTEMPTY; lfs_dir_open(&lfs, &dir, "prickly-pear") => 0; @@ -636,22 +636,22 @@ code = ''' lfs_remove(&lfs, "prickly-pear") => LFS_ERR_NOENT; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_remove(&lfs, "prickly-pear") => LFS_ERR_NOENT; lfs_unmount(&lfs) => 0; ''' [[case]] # other error cases code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "potato") => 0; lfs_file_open(&lfs, &file, "burito", LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "potato") => LFS_ERR_EXIST; lfs_mkdir(&lfs, "burito") => LFS_ERR_EXIST; @@ -696,7 +696,7 @@ code = ''' lfs_unmount(&lfs) => 0; // or on disk - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "/") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(info.type == LFS_TYPE_DIR); @@ -718,8 +718,8 @@ code = ''' [[case]] # directory seek define.COUNT = [4, 128, 132] code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "hello") => 0; for (int i = 0; i < COUNT; i++) { sprintf(path, "hello/kitty%03d", i); @@ -728,7 +728,7 @@ code = ''' lfs_unmount(&lfs) => 0; for (int j = 2; j < COUNT; j++) { - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "hello") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(strcmp(info.name, ".") == 0); @@ -779,8 +779,8 @@ code = ''' [[case]] # root seek define.COUNT = [4, 128, 132] code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int i = 0; i < COUNT; i++) { sprintf(path, "hi%03d", i); lfs_mkdir(&lfs, path) => 0; @@ -788,7 +788,7 @@ code = ''' lfs_unmount(&lfs) => 0; for (int j = 2; j < COUNT; j++) { - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "/") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(strcmp(info.name, ".") == 0); diff --git a/tests/test_entries.toml b/tests/test_entries.toml index 81e175f..c624559 100644 --- a/tests/test_entries.toml +++ b/tests/test_entries.toml @@ -10,8 +10,8 @@ code = ''' uint8_t wbuffer[1024]; uint8_t rbuffer[1024]; - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // write hi0 20 sprintf(path, "hi0"); size = 20; @@ -99,8 +99,8 @@ code = ''' uint8_t wbuffer[1024]; uint8_t rbuffer[1024]; - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // write hi0 20 sprintf(path, "hi0"); size = 20; @@ -188,8 +188,8 @@ code = ''' uint8_t wbuffer[1024]; uint8_t rbuffer[1024]; - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // write hi0 200 sprintf(path, "hi0"); size = 200; @@ -261,8 +261,8 @@ code = ''' uint8_t wbuffer[1024]; uint8_t rbuffer[1024]; - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // write hi0 200 sprintf(path, "hi0"); size = 200; @@ -350,8 +350,8 @@ code = ''' uint8_t wbuffer[1024]; uint8_t rbuffer[1024]; - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // write hi0 200 sprintf(path, "hi0"); size = 200; @@ -454,8 +454,8 @@ code = ''' uint8_t wbuffer[1024]; uint8_t rbuffer[1024]; - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // write hi0 200 sprintf(path, "hi0"); size = 200; @@ -549,9 +549,9 @@ code = ''' [[case]] # create too big code = ''' - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; memset(path, 'm', 200); path[200] = '\0'; @@ -574,9 +574,9 @@ code = ''' [[case]] # resize too big code = ''' - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; memset(path, 'm', 200); path[200] = '\0'; diff --git a/tests/test_evil.toml b/tests/test_evil.toml index 920d3a0..c631799 100644 --- a/tests/test_evil.toml +++ b/tests/test_evil.toml @@ -9,10 +9,11 @@ define.INVALSET = [0x3, 0x1, 0x2] in = "lfs.c" code = ''' // create littlefs - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; // change tail-pointer to invalid pointers - lfs_init(&lfs, &cfg) => 0; + lfs.cfg = &cfg; + lfs_initcommon(&lfs) => 0; lfs_mdir_t mdir; lfs_dir_fetch(&lfs, &mdir, (lfs_block_t[2]){0, 1}) => 0; lfs_dir_commit(&lfs, &mdir, LFS_MKATTRS( @@ -23,7 +24,7 @@ code = ''' lfs_deinit(&lfs) => 0; // test that mount fails gracefully - lfs_mount(&lfs, &cfg) => LFS_ERR_CORRUPT; + lfs_mountcfg(&lfs, &cfg) => LFS_ERR_CORRUPT; ''' [[case]] # invalid dir pointer test @@ -31,14 +32,15 @@ define.INVALSET = [0x3, 0x1, 0x2] in = "lfs.c" code = ''' // create littlefs - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; // make a dir - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "dir_here") => 0; lfs_unmount(&lfs) => 0; // change the dir pointer to be invalid - lfs_init(&lfs, &cfg) => 0; + lfs.cfg = &cfg; + lfs_initcommon(&lfs) => 0; lfs_mdir_t mdir; lfs_dir_fetch(&lfs, &mdir, (lfs_block_t[2]){0, 1}) => 0; // make sure id 1 == our directory @@ -57,7 +59,7 @@ code = ''' // test that accessing our bad dir fails, note there's a number // of ways to access the dir, some can fail, but some don't - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_stat(&lfs, "dir_here", &info) => 0; assert(strcmp(info.name, "dir_here") == 0); assert(info.type == LFS_TYPE_DIR); @@ -77,16 +79,17 @@ in = "lfs.c" define.SIZE = [10, 1000, 100000] # faked file size code = ''' // create littlefs - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; // make a file - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "file_here", LFS_O_WRONLY | LFS_O_CREAT) => 0; lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; // change the file pointer to be invalid - lfs_init(&lfs, &cfg) => 0; + lfs.cfg = &cfg; + lfs_initcommon(&lfs) => 0; lfs_mdir_t mdir; lfs_dir_fetch(&lfs, &mdir, (lfs_block_t[2]){0, 1}) => 0; // make sure id 1 == our file @@ -103,7 +106,7 @@ code = ''' // test that accessing our bad file fails, note there's a number // of ways to access the dir, some can fail, but some don't - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_stat(&lfs, "file_here", &info) => 0; assert(strcmp(info.name, "file_here") == 0); assert(info.type == LFS_TYPE_REG); @@ -125,9 +128,9 @@ define.SIZE = ['2*LFS_BLOCK_SIZE', '3*LFS_BLOCK_SIZE', '4*LFS_BLOCK_SIZE'] in = "lfs.c" code = ''' // create littlefs - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; // make a file - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "file_here", LFS_O_WRONLY | LFS_O_CREAT) => 0; for (int i = 0; i < SIZE; i++) { @@ -137,7 +140,8 @@ code = ''' lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; // change pointer in CTZ skip-list to be invalid - lfs_init(&lfs, &cfg) => 0; + lfs.cfg = &cfg; + lfs_initcommon(&lfs) => 0; lfs_mdir_t mdir; lfs_dir_fetch(&lfs, &mdir, (lfs_block_t[2]){0, 1}) => 0; // make sure id 1 == our file and get our CTZ structure @@ -164,7 +168,7 @@ code = ''' // test that accessing our bad file fails, note there's a number // of ways to access the dir, some can fail, but some don't - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_stat(&lfs, "file_here", &info) => 0; assert(strcmp(info.name, "file_here") == 0); assert(info.type == LFS_TYPE_REG); @@ -187,10 +191,11 @@ define.INVALSET = [0x3, 0x1, 0x2] in = "lfs.c" code = ''' // create littlefs - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; // create an invalid gstate - lfs_init(&lfs, &cfg) => 0; + lfs.cfg = &cfg; + lfs_initcommon(&lfs) => 0; lfs_mdir_t mdir; lfs_dir_fetch(&lfs, &mdir, (lfs_block_t[2]){0, 1}) => 0; lfs_fs_prepmove(&lfs, 1, (lfs_block_t [2]){ @@ -202,7 +207,7 @@ code = ''' // test that mount fails gracefully // mount may not fail, but our first alloc should fail when // we try to fix the gstate - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "should_fail") => LFS_ERR_CORRUPT; lfs_unmount(&lfs) => 0; ''' @@ -213,10 +218,11 @@ code = ''' in = "lfs.c" code = ''' // create littlefs - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; // change tail-pointer to point to ourself - lfs_init(&lfs, &cfg) => 0; + lfs.cfg = &cfg; + lfs_initcommon(&lfs) => 0; lfs_mdir_t mdir; lfs_dir_fetch(&lfs, &mdir, (lfs_block_t[2]){0, 1}) => 0; lfs_dir_commit(&lfs, &mdir, LFS_MKATTRS( @@ -225,20 +231,21 @@ code = ''' lfs_deinit(&lfs) => 0; // test that mount fails gracefully - lfs_mount(&lfs, &cfg) => LFS_ERR_CORRUPT; + lfs_mountcfg(&lfs, &cfg) => LFS_ERR_CORRUPT; ''' [[case]] # metadata-pair threaded-list 2-length loop test in = "lfs.c" code = ''' // create littlefs with child dir - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "child") => 0; lfs_unmount(&lfs) => 0; // find child - lfs_init(&lfs, &cfg) => 0; + lfs.cfg = &cfg; + lfs_initcommon(&lfs) => 0; lfs_mdir_t mdir; lfs_block_t pair[2]; lfs_dir_fetch(&lfs, &mdir, (lfs_block_t[2]){0, 1}) => 0; @@ -255,20 +262,21 @@ code = ''' lfs_deinit(&lfs) => 0; // test that mount fails gracefully - lfs_mount(&lfs, &cfg) => LFS_ERR_CORRUPT; + lfs_mountcfg(&lfs, &cfg) => LFS_ERR_CORRUPT; ''' [[case]] # metadata-pair threaded-list 1-length child loop test in = "lfs.c" code = ''' // create littlefs with child dir - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "child") => 0; lfs_unmount(&lfs) => 0; // find child - lfs_init(&lfs, &cfg) => 0; + lfs.cfg = &cfg; + lfs_initcommon(&lfs) => 0; lfs_mdir_t mdir; lfs_block_t pair[2]; lfs_dir_fetch(&lfs, &mdir, (lfs_block_t[2]){0, 1}) => 0; @@ -284,5 +292,5 @@ code = ''' lfs_deinit(&lfs) => 0; // test that mount fails gracefully - lfs_mount(&lfs, &cfg) => LFS_ERR_CORRUPT; + lfs_mountcfg(&lfs, &cfg) => LFS_ERR_CORRUPT; ''' diff --git a/tests/test_exhaustion.toml b/tests/test_exhaustion.toml index 569611c..c339d45 100644 --- a/tests/test_exhaustion.toml +++ b/tests/test_exhaustion.toml @@ -11,14 +11,14 @@ define.LFS_BADBLOCK_BEHAVIOR = [ ] define.FILES = 10 code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "roadrunner") => 0; lfs_unmount(&lfs) => 0; uint32_t cycle = 0; while (true) { - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (uint32_t i = 0; i < FILES; i++) { // chose name, roughly random seed, and random 2^n size sprintf(path, "roadrunner/test%d", i); @@ -71,7 +71,7 @@ code = ''' exhausted: // should still be readable - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (uint32_t i = 0; i < FILES; i++) { // check for errors sprintf(path, "roadrunner/test%d", i); @@ -96,11 +96,11 @@ define.LFS_BADBLOCK_BEHAVIOR = [ ] define.FILES = 10 code = ''' - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; uint32_t cycle = 0; while (true) { - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (uint32_t i = 0; i < FILES; i++) { // chose name, roughly random seed, and random 2^n size sprintf(path, "test%d", i); @@ -153,7 +153,7 @@ code = ''' exhausted: // should still be readable - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (uint32_t i = 0; i < FILES; i++) { // check for errors sprintf(path, "test%d", i); @@ -184,14 +184,14 @@ code = ''' (b < run_block_count[run]) ? 0 : LFS_ERASE_CYCLES) => 0; } - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "roadrunner") => 0; lfs_unmount(&lfs) => 0; uint32_t cycle = 0; while (true) { - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (uint32_t i = 0; i < FILES; i++) { // chose name, roughly random seed, and random 2^n size sprintf(path, "roadrunner/test%d", i); @@ -244,7 +244,7 @@ code = ''' exhausted: // should still be readable - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (uint32_t i = 0; i < FILES; i++) { // check for errors sprintf(path, "roadrunner/test%d", i); @@ -276,11 +276,11 @@ code = ''' (b < run_block_count[run]) ? 0 : LFS_ERASE_CYCLES) => 0; } - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; uint32_t cycle = 0; while (true) { - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (uint32_t i = 0; i < FILES; i++) { // chose name, roughly random seed, and random 2^n size sprintf(path, "test%d", i); @@ -333,7 +333,7 @@ code = ''' exhausted: // should still be readable - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (uint32_t i = 0; i < FILES; i++) { // check for errors sprintf(path, "test%d", i); @@ -358,14 +358,14 @@ define.CYCLES = 100 define.FILES = 10 if = 'LFS_BLOCK_CYCLES < CYCLES/10' code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "roadrunner") => 0; lfs_unmount(&lfs) => 0; uint32_t cycle = 0; while (cycle < CYCLES) { - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (uint32_t i = 0; i < FILES; i++) { // chose name, roughly random seed, and random 2^n size sprintf(path, "roadrunner/test%d", i); @@ -418,7 +418,7 @@ code = ''' exhausted: // should still be readable - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (uint32_t i = 0; i < FILES; i++) { // check for errors sprintf(path, "roadrunner/test%d", i); diff --git a/tests/test_files.toml b/tests/test_files.toml index 565e665..eedcd96 100644 --- a/tests/test_files.toml +++ b/tests/test_files.toml @@ -1,8 +1,8 @@ [[case]] # simple file test code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "hello", LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; size = strlen("Hello World!")+1; @@ -11,7 +11,7 @@ code = ''' lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "hello", LFS_O_RDONLY) => 0; lfs_file_read(&lfs, &file, buffer, size) => size; assert(strcmp((char*)buffer, "Hello World!") == 0); @@ -23,10 +23,10 @@ code = ''' define.SIZE = [32, 8192, 262144, 0, 7, 8193] define.CHUNKSIZE = [31, 16, 33, 1, 1023] code = ''' - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; // write - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "avacado", LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; srand(1); @@ -41,7 +41,7 @@ code = ''' lfs_unmount(&lfs) => 0; // read - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "avacado", LFS_O_RDONLY) => 0; lfs_file_size(&lfs, &file) => SIZE; srand(1); @@ -62,10 +62,10 @@ define.SIZE1 = [32, 8192, 131072, 0, 7, 8193] define.SIZE2 = [32, 8192, 131072, 0, 7, 8193] define.CHUNKSIZE = [31, 16, 1] code = ''' - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; // write - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "avacado", LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; srand(1); @@ -80,7 +80,7 @@ code = ''' lfs_unmount(&lfs) => 0; // read - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "avacado", LFS_O_RDONLY) => 0; lfs_file_size(&lfs, &file) => SIZE1; srand(1); @@ -96,7 +96,7 @@ code = ''' lfs_unmount(&lfs) => 0; // rewrite - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "avacado", LFS_O_WRONLY) => 0; srand(2); for (lfs_size_t i = 0; i < SIZE2; i += CHUNKSIZE) { @@ -110,7 +110,7 @@ code = ''' lfs_unmount(&lfs) => 0; // read - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "avacado", LFS_O_RDONLY) => 0; lfs_file_size(&lfs, &file) => lfs_max(SIZE1, SIZE2); srand(2); @@ -144,10 +144,10 @@ define.SIZE1 = [32, 8192, 131072, 0, 7, 8193] define.SIZE2 = [32, 8192, 131072, 0, 7, 8193] define.CHUNKSIZE = [31, 16, 1] code = ''' - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; // write - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "avacado", LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; srand(1); @@ -162,7 +162,7 @@ code = ''' lfs_unmount(&lfs) => 0; // read - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "avacado", LFS_O_RDONLY) => 0; lfs_file_size(&lfs, &file) => SIZE1; srand(1); @@ -178,7 +178,7 @@ code = ''' lfs_unmount(&lfs) => 0; // append - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "avacado", LFS_O_WRONLY | LFS_O_APPEND) => 0; srand(2); for (lfs_size_t i = 0; i < SIZE2; i += CHUNKSIZE) { @@ -192,7 +192,7 @@ code = ''' lfs_unmount(&lfs) => 0; // read - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "avacado", LFS_O_RDONLY) => 0; lfs_file_size(&lfs, &file) => SIZE1 + SIZE2; srand(1); @@ -221,10 +221,10 @@ define.SIZE1 = [32, 8192, 131072, 0, 7, 8193] define.SIZE2 = [32, 8192, 131072, 0, 7, 8193] define.CHUNKSIZE = [31, 16, 1] code = ''' - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; // write - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "avacado", LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; srand(1); @@ -239,7 +239,7 @@ code = ''' lfs_unmount(&lfs) => 0; // read - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "avacado", LFS_O_RDONLY) => 0; lfs_file_size(&lfs, &file) => SIZE1; srand(1); @@ -255,7 +255,7 @@ code = ''' lfs_unmount(&lfs) => 0; // truncate - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "avacado", LFS_O_WRONLY | LFS_O_TRUNC) => 0; srand(2); for (lfs_size_t i = 0; i < SIZE2; i += CHUNKSIZE) { @@ -269,7 +269,7 @@ code = ''' lfs_unmount(&lfs) => 0; // read - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "avacado", LFS_O_RDONLY) => 0; lfs_file_size(&lfs, &file) => SIZE2; srand(2); @@ -290,10 +290,10 @@ define.SIZE = [32, 0, 7, 2049] define.CHUNKSIZE = [31, 16, 65] reentrant = true code = ''' - err = lfs_mount(&lfs, &cfg); + err = lfs_mountcfg(&lfs, &cfg); if (err) { - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; } err = lfs_file_open(&lfs, &file, "avacado", LFS_O_RDONLY); @@ -344,10 +344,10 @@ define = [ ] reentrant = true code = ''' - err = lfs_mount(&lfs, &cfg); + err = lfs_mountcfg(&lfs, &cfg); if (err) { - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; } err = lfs_file_open(&lfs, &file, "avacado", LFS_O_RDONLY); @@ -406,9 +406,9 @@ code = ''' [[case]] # many files define.N = 300 code = ''' - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; // create N files of 7 bytes - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int i = 0; i < N; i++) { sprintf(path, "file_%03d", i); lfs_file_open(&lfs, &file, path, @@ -431,9 +431,9 @@ code = ''' [[case]] # many files with power cycle define.N = 300 code = ''' - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; // create N files of 7 bytes - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int i = 0; i < N; i++) { sprintf(path, "file_%03d", i); lfs_file_open(&lfs, &file, path, @@ -446,7 +446,7 @@ code = ''' lfs_unmount(&lfs) => 0; char rbuffer[1024]; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, path, LFS_O_RDONLY) => 0; lfs_file_read(&lfs, &file, rbuffer, size) => size; assert(strcmp(rbuffer, wbuffer) == 0); @@ -459,10 +459,10 @@ code = ''' define.N = 300 reentrant = true code = ''' - err = lfs_mount(&lfs, &cfg); + err = lfs_mountcfg(&lfs, &cfg); if (err) { - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; } // create N files of 7 bytes for (int i = 0; i < N; i++) { diff --git a/tests/test_interspersed.toml b/tests/test_interspersed.toml index 87a0578..bf2027f 100644 --- a/tests/test_interspersed.toml +++ b/tests/test_interspersed.toml @@ -5,8 +5,8 @@ define.FILES = [4, 10, 26] code = ''' lfs_file_t files[FILES]; const char alphas[] = "abcdefghijklmnopqrstuvwxyz"; - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int j = 0; j < FILES; j++) { sprintf(path, "%c", alphas[j]); lfs_file_open(&lfs, &files[j], path, @@ -64,8 +64,8 @@ define.SIZE = [10, 100] define.FILES = [4, 10, 26] code = ''' const char alphas[] = "abcdefghijklmnopqrstuvwxyz"; - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int j = 0; j < FILES; j++) { sprintf(path, "%c", alphas[j]); lfs_file_open(&lfs, &file, path, @@ -77,7 +77,7 @@ code = ''' } lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "zzz", LFS_O_WRONLY | LFS_O_CREAT) => 0; for (int j = 0; j < FILES; j++) { lfs_file_write(&lfs, &file, (const void*)"~", 1) => 1; @@ -115,8 +115,8 @@ code = ''' [[case]] # remove inconveniently test define.SIZE = [10, 100] code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_t files[3]; lfs_file_open(&lfs, &files[0], "e", LFS_O_WRONLY | LFS_O_CREAT) => 0; lfs_file_open(&lfs, &files[1], "f", LFS_O_WRONLY | LFS_O_CREAT) => 0; @@ -180,10 +180,10 @@ code = ''' lfs_file_t files[FILES]; const char alphas[] = "abcdefghijklmnopqrstuvwxyz"; - err = lfs_mount(&lfs, &cfg); + err = lfs_mountcfg(&lfs, &cfg); if (err) { - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; } for (int j = 0; j < FILES; j++) { diff --git a/tests/test_move.toml b/tests/test_move.toml index bb3b713..de62795 100644 --- a/tests/test_move.toml +++ b/tests/test_move.toml @@ -1,7 +1,7 @@ [[case]] # move file code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "a") => 0; lfs_mkdir(&lfs, "b") => 0; lfs_mkdir(&lfs, "c") => 0; @@ -13,11 +13,11 @@ code = ''' lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_rename(&lfs, "a/hello", "c/hello") => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "a") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(strcmp(info.name, ".") == 0); @@ -57,8 +57,8 @@ code = ''' [[case]] # noop move, yes this is legal code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "hi") => 0; lfs_rename(&lfs, "hi", "hi") => 0; lfs_mkdir(&lfs, "hi/hi") => 0; @@ -74,8 +74,8 @@ code = ''' [[case]] # move file corrupt source in = "lfs.c" code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "a") => 0; lfs_mkdir(&lfs, "b") => 0; lfs_mkdir(&lfs, "c") => 0; @@ -87,12 +87,12 @@ code = ''' lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_rename(&lfs, "a/hello", "c/hello") => 0; lfs_unmount(&lfs) => 0; // corrupt the source - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "a") => 0; lfs_block_t block = dir.m.pair[0]; lfs_dir_close(&lfs, &dir) => 0; @@ -108,7 +108,7 @@ code = ''' cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; cfg.sync(&cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "a") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(strcmp(info.name, ".") == 0); @@ -150,8 +150,8 @@ code = ''' in = "lfs.c" if = 'LFS_PROG_SIZE <= 0x3fe' # only works with one crc per commit code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "a") => 0; lfs_mkdir(&lfs, "b") => 0; lfs_mkdir(&lfs, "c") => 0; @@ -163,12 +163,12 @@ code = ''' lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_rename(&lfs, "a/hello", "c/hello") => 0; lfs_unmount(&lfs) => 0; // corrupt the source - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "a") => 0; lfs_block_t block = dir.m.pair[0]; lfs_dir_close(&lfs, &dir) => 0; @@ -185,7 +185,7 @@ code = ''' cfg.sync(&cfg) => 0; // corrupt the destination - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "c") => 0; block = dir.m.pair[0]; lfs_dir_close(&lfs, &dir) => 0; @@ -200,7 +200,7 @@ code = ''' cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; cfg.sync(&cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "a") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(strcmp(info.name, ".") == 0); @@ -242,8 +242,8 @@ code = ''' in = "lfs.c" if = 'LFS_PROG_SIZE <= 0x3fe' # only works with one crc per commit code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "a") => 0; lfs_mkdir(&lfs, "b") => 0; lfs_mkdir(&lfs, "c") => 0; @@ -255,12 +255,12 @@ code = ''' lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_rename(&lfs, "a/hello", "c/hello") => 0; lfs_unmount(&lfs) => 0; // corrupt the source - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "a") => 0; lfs_block_t block = dir.m.pair[0]; lfs_dir_close(&lfs, &dir) => 0; @@ -277,7 +277,7 @@ code = ''' cfg.sync(&cfg) => 0; // corrupt the destination - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "c") => 0; block = dir.m.pair[0]; lfs_dir_close(&lfs, &dir) => 0; @@ -293,11 +293,11 @@ code = ''' cfg.sync(&cfg) => 0; // continue move - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_rename(&lfs, "a/hello", "c/hello") => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "a") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(strcmp(info.name, ".") == 0); @@ -338,10 +338,10 @@ code = ''' [[case]] # simple reentrant move file reentrant = true code = ''' - err = lfs_mount(&lfs, &cfg); + err = lfs_mountcfg(&lfs, &cfg); if (err) { - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; } err = lfs_mkdir(&lfs, "a"); assert(!err || err == LFS_ERR_EXIST); @@ -354,7 +354,7 @@ code = ''' lfs_unmount(&lfs) => 0; while (true) { - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // there should never exist _2_ hello files int count = 0; if (lfs_stat(&lfs, "a/hello", &info) == 0) { @@ -384,7 +384,7 @@ code = ''' assert(count <= 1); lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; if (lfs_stat(&lfs, "a/hello", &info) == 0 && info.size > 0) { lfs_rename(&lfs, "a/hello", "b/hello") => 0; } else if (lfs_stat(&lfs, "b/hello", &info) == 0) { @@ -407,7 +407,7 @@ code = ''' lfs_unmount(&lfs) => 0; } - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "a") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(strcmp(info.name, ".") == 0); @@ -447,8 +447,8 @@ code = ''' [[case]] # move dir code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "a") => 0; lfs_mkdir(&lfs, "b") => 0; lfs_mkdir(&lfs, "c") => 0; @@ -459,11 +459,11 @@ code = ''' lfs_mkdir(&lfs, "a/hi/ohayo") => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_rename(&lfs, "a/hi", "c/hi") => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "a") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(strcmp(info.name, ".") == 0); @@ -513,8 +513,8 @@ code = ''' [[case]] # move dir corrupt source in = "lfs.c" code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "a") => 0; lfs_mkdir(&lfs, "b") => 0; lfs_mkdir(&lfs, "c") => 0; @@ -525,12 +525,12 @@ code = ''' lfs_mkdir(&lfs, "a/hi/ohayo") => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_rename(&lfs, "a/hi", "c/hi") => 0; lfs_unmount(&lfs) => 0; // corrupt the source - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "a") => 0; lfs_block_t block = dir.m.pair[0]; lfs_dir_close(&lfs, &dir) => 0; @@ -546,7 +546,7 @@ code = ''' cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; cfg.sync(&cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "a") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(strcmp(info.name, ".") == 0); @@ -597,8 +597,8 @@ code = ''' in = "lfs.c" if = 'LFS_PROG_SIZE <= 0x3fe' # only works with one crc per commit code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "a") => 0; lfs_mkdir(&lfs, "b") => 0; lfs_mkdir(&lfs, "c") => 0; @@ -609,12 +609,12 @@ code = ''' lfs_mkdir(&lfs, "a/hi/ohayo") => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_rename(&lfs, "a/hi", "c/hi") => 0; lfs_unmount(&lfs) => 0; // corrupt the source - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "a") => 0; lfs_block_t block = dir.m.pair[0]; lfs_dir_close(&lfs, &dir) => 0; @@ -631,7 +631,7 @@ code = ''' cfg.sync(&cfg) => 0; // corrupt the destination - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "c") => 0; block = dir.m.pair[0]; lfs_dir_close(&lfs, &dir) => 0; @@ -646,7 +646,7 @@ code = ''' cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; cfg.sync(&cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "a") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(strcmp(info.name, ".") == 0); @@ -697,8 +697,8 @@ code = ''' in = "lfs.c" if = 'LFS_PROG_SIZE <= 0x3fe' # only works with one crc per commit code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "a") => 0; lfs_mkdir(&lfs, "b") => 0; lfs_mkdir(&lfs, "c") => 0; @@ -709,12 +709,12 @@ code = ''' lfs_mkdir(&lfs, "a/hi/ohayo") => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_rename(&lfs, "a/hi", "c/hi") => 0; lfs_unmount(&lfs) => 0; // corrupt the source - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "a") => 0; lfs_block_t block = dir.m.pair[0]; lfs_dir_close(&lfs, &dir) => 0; @@ -731,7 +731,7 @@ code = ''' cfg.sync(&cfg) => 0; // corrupt the destination - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "c") => 0; block = dir.m.pair[0]; lfs_dir_close(&lfs, &dir) => 0; @@ -747,11 +747,11 @@ code = ''' cfg.sync(&cfg) => 0; // continue move - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_rename(&lfs, "a/hi", "c/hi") => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "a") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(strcmp(info.name, ".") == 0); @@ -801,10 +801,10 @@ code = ''' [[case]] # simple reentrant move dir reentrant = true code = ''' - err = lfs_mount(&lfs, &cfg); + err = lfs_mountcfg(&lfs, &cfg); if (err) { - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; } err = lfs_mkdir(&lfs, "a"); assert(!err || err == LFS_ERR_EXIST); @@ -817,7 +817,7 @@ code = ''' lfs_unmount(&lfs) => 0; while (true) { - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // there should never exist _2_ hi directories int count = 0; if (lfs_stat(&lfs, "a/hi", &info) == 0) { @@ -843,7 +843,7 @@ code = ''' assert(count <= 1); lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; if (lfs_stat(&lfs, "a/hi", &info) == 0) { lfs_rename(&lfs, "a/hi", "b/hi") => 0; } else if (lfs_stat(&lfs, "b/hi", &info) == 0) { @@ -868,7 +868,7 @@ code = ''' lfs_unmount(&lfs) => 0; } - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "a") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; assert(strcmp(info.name, ".") == 0); @@ -917,8 +917,8 @@ code = ''' [[case]] # move state stealing code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "a") => 0; lfs_mkdir(&lfs, "b") => 0; lfs_mkdir(&lfs, "c") => 0; @@ -930,17 +930,17 @@ code = ''' lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_rename(&lfs, "a/hello", "b/hello") => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_rename(&lfs, "b/hello", "c/hello") => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_rename(&lfs, "c/hello", "d/hello") => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "a/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; lfs_file_open(&lfs, &file, "b/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; lfs_file_open(&lfs, &file, "c/hello", LFS_O_RDONLY) => LFS_ERR_NOENT; @@ -954,12 +954,12 @@ code = ''' lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_remove(&lfs, "b") => 0; lfs_remove(&lfs, "c") => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_stat(&lfs, "a", &info) => 0; lfs_stat(&lfs, "b", &info) => LFS_ERR_NOENT; lfs_stat(&lfs, "c", &info) => LFS_ERR_NOENT; @@ -981,8 +981,8 @@ code = ''' # Other specific corner cases [[case]] # create + delete in same commit with neighbors code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // littlefs keeps files sorted, so we know the order these will be in lfs_file_open(&lfs, &file, "/1.move_me", @@ -1127,8 +1127,8 @@ code = ''' # Other specific corner cases [[case]] # create + delete + delete in same commit with neighbors code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // littlefs keeps files sorted, so we know the order these will be in lfs_file_open(&lfs, &file, "/1.move_me", @@ -1283,8 +1283,8 @@ code = ''' [[case]] # create + delete in different dirs with neighbors code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // littlefs keeps files sorted, so we know the order these will be in lfs_mkdir(&lfs, "/dir.1") => 0; @@ -1523,8 +1523,8 @@ in = "lfs.c" define.RELOCATIONS = 'range(0x3+1)' define.LFS_ERASE_CYCLES = 0xffffffff code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "/parent") => 0; lfs_mkdir(&lfs, "/parent/child") => 0; @@ -1660,8 +1660,8 @@ in = "lfs.c" define.RELOCATIONS = 'range(0x7+1)' define.LFS_ERASE_CYCLES = 0xffffffff code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "/parent") => 0; lfs_mkdir(&lfs, "/parent/child") => 0; diff --git a/tests/test_orphans.toml b/tests/test_orphans.toml index 241e273..e89f03c 100644 --- a/tests/test_orphans.toml +++ b/tests/test_orphans.toml @@ -2,8 +2,8 @@ in = "lfs.c" if = 'LFS_PROG_SIZE <= 0x3fe' # only works with one crc per commit code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "parent") => 0; lfs_mkdir(&lfs, "parent/orphan") => 0; lfs_mkdir(&lfs, "parent/child") => 0; @@ -13,7 +13,7 @@ code = ''' // corrupt the child's most recent commit, this should be the update // to the linked-list entry, which should orphan the orphan. Note this // makes a lot of assumptions about the remove operation. - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "parent/child") => 0; lfs_block_t block = dir.m.pair[0]; lfs_dir_close(&lfs, &dir) => 0; @@ -29,13 +29,13 @@ code = ''' cfg.prog(&cfg, block, 0, bbuffer, LFS_BLOCK_SIZE) => 0; cfg.sync(&cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_stat(&lfs, "parent/orphan", &info) => LFS_ERR_NOENT; lfs_stat(&lfs, "parent/child", &info) => 0; lfs_fs_size(&lfs) => 8; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_stat(&lfs, "parent/orphan", &info) => LFS_ERR_NOENT; lfs_stat(&lfs, "parent/child", &info) => 0; lfs_fs_size(&lfs) => 8; @@ -48,7 +48,7 @@ code = ''' lfs_fs_size(&lfs) => 8; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_stat(&lfs, "parent/orphan", &info) => LFS_ERR_NOENT; lfs_stat(&lfs, "parent/child", &info) => 0; lfs_stat(&lfs, "parent/otherchild", &info) => 0; @@ -66,10 +66,10 @@ define = [ {FILES=3, DEPTH=3, CYCLES=20}, ] code = ''' - err = lfs_mount(&lfs, &cfg); + err = lfs_mountcfg(&lfs, &cfg); if (err) { - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; } srand(1); diff --git a/tests/test_paths.toml b/tests/test_paths.toml index a7474c0..61f27b4 100644 --- a/tests/test_paths.toml +++ b/tests/test_paths.toml @@ -1,8 +1,8 @@ [[case]] # simple path test code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "tea") => 0; lfs_mkdir(&lfs, "tea/hottea") => 0; lfs_mkdir(&lfs, "tea/warmtea") => 0; @@ -23,8 +23,8 @@ code = ''' [[case]] # redundant slashes code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "tea") => 0; lfs_mkdir(&lfs, "tea/hottea") => 0; lfs_mkdir(&lfs, "tea/warmtea") => 0; @@ -47,8 +47,8 @@ code = ''' [[case]] # dot path test code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "tea") => 0; lfs_mkdir(&lfs, "tea/hottea") => 0; lfs_mkdir(&lfs, "tea/warmtea") => 0; @@ -73,8 +73,8 @@ code = ''' [[case]] # dot dot path test code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "tea") => 0; lfs_mkdir(&lfs, "tea/hottea") => 0; lfs_mkdir(&lfs, "tea/warmtea") => 0; @@ -103,8 +103,8 @@ code = ''' [[case]] # trailing dot path test code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "tea") => 0; lfs_mkdir(&lfs, "tea/hottea") => 0; lfs_mkdir(&lfs, "tea/warmtea") => 0; @@ -125,8 +125,8 @@ code = ''' [[case]] # leading dot path test code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, ".milk") => 0; lfs_stat(&lfs, ".milk", &info) => 0; strcmp(info.name, ".milk") => 0; @@ -137,8 +137,8 @@ code = ''' [[case]] # root dot dot path test code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "tea") => 0; lfs_mkdir(&lfs, "tea/hottea") => 0; lfs_mkdir(&lfs, "tea/warmtea") => 0; @@ -161,8 +161,8 @@ code = ''' [[case]] # invalid path tests code = ''' - lfs_format(&lfs, &cfg); - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg); + lfs_mountcfg(&lfs, &cfg) => 0; lfs_stat(&lfs, "dirt", &info) => LFS_ERR_NOENT; lfs_stat(&lfs, "dirt/ground", &info) => LFS_ERR_NOENT; lfs_stat(&lfs, "dirt/ground/earth", &info) => LFS_ERR_NOENT; @@ -182,8 +182,8 @@ code = ''' [[case]] # root operations code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_stat(&lfs, "/", &info) => 0; assert(strcmp(info.name, "/") == 0); assert(info.type == LFS_TYPE_DIR); @@ -198,8 +198,8 @@ code = ''' [[case]] # root representations code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_stat(&lfs, "/", &info) => 0; assert(strcmp(info.name, "/") == 0); assert(info.type == LFS_TYPE_DIR); @@ -223,8 +223,8 @@ code = ''' [[case]] # superblock conflict test code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_stat(&lfs, "littlefs", &info) => LFS_ERR_NOENT; lfs_remove(&lfs, "littlefs") => LFS_ERR_NOENT; @@ -239,8 +239,8 @@ code = ''' [[case]] # max path test code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "coffee") => 0; lfs_mkdir(&lfs, "coffee/hotcoffee") => 0; lfs_mkdir(&lfs, "coffee/warmcoffee") => 0; @@ -263,8 +263,8 @@ code = ''' [[case]] # really big path test code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_mkdir(&lfs, "coffee") => 0; lfs_mkdir(&lfs, "coffee/hotcoffee") => 0; lfs_mkdir(&lfs, "coffee/warmcoffee") => 0; diff --git a/tests/test_relocations.toml b/tests/test_relocations.toml index 71b1047..fb548dc 100644 --- a/tests/test_relocations.toml +++ b/tests/test_relocations.toml @@ -4,9 +4,9 @@ define.ITERATIONS = 20 define.COUNT = 10 define.LFS_BLOCK_CYCLES = [8, 1] code = ''' - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; // fill up filesystem so only ~16 blocks are left - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "padding", LFS_O_CREAT | LFS_O_WRONLY) => 0; memset(buffer, 0, 512); while (LFS_BLOCK_COUNT - lfs_fs_size(&lfs) > 16) { @@ -17,7 +17,7 @@ code = ''' lfs_mkdir(&lfs, "child") => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int j = 0; j < ITERATIONS; j++) { for (int i = 0; i < COUNT; i++) { sprintf(path, "child/test%03d_loooooooooooooooooong_name", i); @@ -47,7 +47,7 @@ code = ''' } lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_dir_open(&lfs, &dir, "child") => 0; lfs_dir_read(&lfs, &dir, &info) => 1; lfs_dir_read(&lfs, &dir, &info) => 1; @@ -70,9 +70,9 @@ define.ITERATIONS = 20 define.COUNT = 10 define.LFS_BLOCK_CYCLES = [8, 1] code = ''' - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; // fill up filesystem so only ~16 blocks are left - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "padding", LFS_O_CREAT | LFS_O_WRONLY) => 0; memset(buffer, 0, 512); while (LFS_BLOCK_COUNT - lfs_fs_size(&lfs) > 16) { @@ -83,7 +83,7 @@ code = ''' lfs_mkdir(&lfs, "child") => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int j = 0; j < ITERATIONS; j++) { for (int i = 0; i < COUNT; i++) { sprintf(path, "child/test%03d_loooooooooooooooooong_name", i); @@ -155,10 +155,10 @@ define = [ {FILES=3, DEPTH=3, CYCLES=20, LFS_BLOCK_CYCLES=1}, ] code = ''' - err = lfs_mount(&lfs, &cfg); + err = lfs_mountcfg(&lfs, &cfg); if (err) { - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; } srand(1); @@ -217,10 +217,10 @@ define = [ {FILES=3, DEPTH=3, CYCLES=20, LFS_BLOCK_CYCLES=1}, ] code = ''' - err = lfs_mount(&lfs, &cfg); + err = lfs_mountcfg(&lfs, &cfg); if (err) { - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; } srand(1); diff --git a/tests/test_seek.toml b/tests/test_seek.toml index 79d7728..e0b0ea9 100644 --- a/tests/test_seek.toml +++ b/tests/test_seek.toml @@ -9,8 +9,8 @@ define = [ {COUNT=4, SKIP=2}, ] code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "kitty", LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0; size = strlen("kittycatcat"); @@ -21,7 +21,7 @@ code = ''' lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "kitty", LFS_O_RDONLY) => 0; lfs_soff_t pos = -1; @@ -78,8 +78,8 @@ define = [ {COUNT=4, SKIP=2}, ] code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "kitty", LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0; size = strlen("kittycatcat"); @@ -90,7 +90,7 @@ code = ''' lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "kitty", LFS_O_RDWR) => 0; lfs_soff_t pos = -1; @@ -133,8 +133,8 @@ code = ''' define.COUNT = 132 define.OFFSETS = '"{512, 1020, 513, 1021, 511, 1019, 1441}"' code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "kitty", LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0; size = strlen("kittycatcat"); @@ -145,7 +145,7 @@ code = ''' lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "kitty", LFS_O_RDWR) => 0; size = strlen("hedgehoghog"); @@ -193,8 +193,8 @@ define = [ {COUNT=4, SKIP=3}, ] code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "kitty", LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0; size = strlen("kittycatcat"); @@ -204,7 +204,7 @@ code = ''' } lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "kitty", LFS_O_RDWR) => 0; size = strlen("kittycatcat"); @@ -241,8 +241,8 @@ code = ''' [[case]] # inline write and seek define.SIZE = [2, 4, 128, 132] code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "tinykitty", LFS_O_RDWR | LFS_O_CREAT) => 0; int j = 0; @@ -310,10 +310,10 @@ code = ''' define.COUNT = [4, 64, 128] reentrant = true code = ''' - err = lfs_mount(&lfs, &cfg); + err = lfs_mountcfg(&lfs, &cfg); if (err) { - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; } err = lfs_file_open(&lfs, &file, "kitty", LFS_O_RDONLY); assert(!err || err == LFS_ERR_NOENT); diff --git a/tests/test_superblocks.toml b/tests/test_superblocks.toml index 407c845..6998810 100644 --- a/tests/test_superblocks.toml +++ b/tests/test_superblocks.toml @@ -1,37 +1,37 @@ [[case]] # simple formatting test code = ''' - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; ''' [[case]] # mount/unmount code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_unmount(&lfs) => 0; ''' [[case]] # reentrant format reentrant = true code = ''' - err = lfs_mount(&lfs, &cfg); + err = lfs_mountcfg(&lfs, &cfg); if (err) { - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; } lfs_unmount(&lfs) => 0; ''' [[case]] # invalid mount code = ''' - lfs_mount(&lfs, &cfg) => LFS_ERR_CORRUPT; + lfs_mountcfg(&lfs, &cfg) => LFS_ERR_CORRUPT; ''' [[case]] # expanding superblock define.LFS_BLOCK_CYCLES = [32, 33, 1] define.N = [10, 100, 1000] code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (int i = 0; i < N; i++) { lfs_file_open(&lfs, &file, "dummy", LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; @@ -44,7 +44,7 @@ code = ''' lfs_unmount(&lfs) => 0; // one last check after power-cycle - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "dummy", LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0; lfs_file_close(&lfs, &file) => 0; @@ -58,9 +58,9 @@ code = ''' define.LFS_BLOCK_CYCLES = [32, 33, 1] define.N = [10, 100, 1000] code = ''' - lfs_format(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; for (int i = 0; i < N; i++) { - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; // remove lingering dummy? err = lfs_stat(&lfs, "dummy", &info); assert(err == 0 || (err == LFS_ERR_NOENT && i == 0)); @@ -80,7 +80,7 @@ code = ''' } // one last check after power-cycle - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_stat(&lfs, "dummy", &info) => 0; assert(strcmp(info.name, "dummy") == 0); assert(info.type == LFS_TYPE_REG); @@ -92,10 +92,10 @@ define.LFS_BLOCK_CYCLES = [2, 1] define.N = 24 reentrant = true code = ''' - err = lfs_mount(&lfs, &cfg); + err = lfs_mountcfg(&lfs, &cfg); if (err) { - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; } for (int i = 0; i < N; i++) { @@ -119,7 +119,7 @@ code = ''' lfs_unmount(&lfs) => 0; // one last check after power-cycle - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_stat(&lfs, "dummy", &info) => 0; assert(strcmp(info.name, "dummy") == 0); assert(info.type == LFS_TYPE_REG); diff --git a/tests/test_truncate.toml b/tests/test_truncate.toml index c11285b..38346e2 100644 --- a/tests/test_truncate.toml +++ b/tests/test_truncate.toml @@ -2,8 +2,8 @@ define.MEDIUMSIZE = [32, 2048] define.LARGESIZE = 8192 code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "baldynoop", LFS_O_WRONLY | LFS_O_CREAT) => 0; @@ -17,7 +17,7 @@ code = ''' lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "baldynoop", LFS_O_RDWR) => 0; lfs_file_size(&lfs, &file) => LARGESIZE; @@ -27,7 +27,7 @@ code = ''' lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "baldynoop", LFS_O_RDONLY) => 0; lfs_file_size(&lfs, &file) => MEDIUMSIZE; @@ -46,8 +46,8 @@ code = ''' define.MEDIUMSIZE = [32, 2048] define.LARGESIZE = 8192 code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "baldyread", LFS_O_WRONLY | LFS_O_CREAT) => 0; @@ -61,7 +61,7 @@ code = ''' lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "baldyread", LFS_O_RDWR) => 0; lfs_file_size(&lfs, &file) => LARGESIZE; @@ -78,7 +78,7 @@ code = ''' lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "baldyread", LFS_O_RDONLY) => 0; lfs_file_size(&lfs, &file) => MEDIUMSIZE; @@ -95,8 +95,8 @@ code = ''' [[case]] # write, truncate, and read code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "sequence", LFS_O_RDWR | LFS_O_CREAT | LFS_O_TRUNC) => 0; @@ -149,8 +149,8 @@ code = ''' define.MEDIUMSIZE = [32, 2048] define.LARGESIZE = 8192 code = ''' - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "baldywrite", LFS_O_WRONLY | LFS_O_CREAT) => 0; @@ -164,7 +164,7 @@ code = ''' lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "baldywrite", LFS_O_RDWR) => 0; lfs_file_size(&lfs, &file) => LARGESIZE; @@ -181,7 +181,7 @@ code = ''' lfs_file_close(&lfs, &file) => 0; lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; lfs_file_open(&lfs, &file, "baldywrite", LFS_O_RDONLY) => 0; lfs_file_size(&lfs, &file) => MEDIUMSIZE; @@ -202,10 +202,10 @@ define.MEDIUMSIZE = [32, 1024] define.LARGESIZE = 2048 reentrant = true code = ''' - err = lfs_mount(&lfs, &cfg); + err = lfs_mountcfg(&lfs, &cfg); if (err) { - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; } err = lfs_file_open(&lfs, &file, "baldy", LFS_O_RDONLY); assert(!err || err == LFS_ERR_NOENT); @@ -312,8 +312,8 @@ code = ''' const lfs_off_t *hotsizes = configs[CONFIG].hotsizes; const lfs_off_t *coldsizes = configs[CONFIG].coldsizes; - lfs_format(&lfs, &cfg) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_formatcfg(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (unsigned i = 0; i < COUNT; i++) { sprintf(path, "hairyhead%d", i); @@ -340,7 +340,7 @@ code = ''' lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (unsigned i = 0; i < COUNT; i++) { sprintf(path, "hairyhead%d", i); @@ -367,7 +367,7 @@ code = ''' lfs_unmount(&lfs) => 0; - lfs_mount(&lfs, &cfg) => 0; + lfs_mountcfg(&lfs, &cfg) => 0; for (unsigned i = 0; i < COUNT; i++) { sprintf(path, "hairyhead%d", i);