Added asserts on geometry and updated config documentation

littlefs had an unwritten assumption that the block device's program
size would be a multiple of the read size, and the block size would
be a multiple of the program size. This has already caused confusion
for users. Added a note and assert to catch unexpected geometries
early.

Also found that the prog/erase functions indicated they must return
LFS_ERR_CORRUPT to catch bad blocks. This is no longer true as errors
are found by CRC.
This commit is contained in:
Christopher Haster
2018-01-11 11:56:09 -06:00
parent 472ccc4203
commit c2fab8fabb
2 changed files with 9 additions and 3 deletions

4
lfs.c
View File

@@ -1926,6 +1926,10 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
}
}
// check that program and read sizes are multiples of the block size
assert(lfs->cfg->prog_size % lfs->cfg->read_size == 0);
assert(lfs->cfg->block_size % lfs->cfg->prog_size == 0);
// check that the block size is large enough to fit ctz pointers
assert(4*lfs_npw2(0xffffffff / (lfs->cfg->block_size-2*4))
<= lfs->cfg->block_size);