Adopted lazy geometry encoding
- LFSR_TAG_GEOMETRY ---> lfsr_data_fromgeometry
Not much to say about this one, LFSR_TAG_GEOMETRY is a bit of an
outlier.
I did consider deduplicating with the mptr encoder, but decided that
would be too hacky, and create problems for future metadata redundancy
things.
Still saves code though, which is nice:
code stack ctx
before: 35632 2440 636
after: 35580 (-0.1%) 2440 (+0.0%) 636 (+0.0%)
This commit is contained in:
@@ -3449,6 +3449,9 @@ static int lfsr_rbyd_appendtag(lfs_t *lfs, lfsr_rbyd_t *rbyd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// needed in lfsr_rbyd_appendrattr_
|
// needed in lfsr_rbyd_appendrattr_
|
||||||
|
typedef struct lfsr_geometry lfsr_geometry_t;
|
||||||
|
static lfsr_data_t lfsr_data_fromgeometry(const lfsr_geometry_t *geometry,
|
||||||
|
uint8_t buffer[static LFSR_GEOMETRY_DSIZE]);
|
||||||
static lfsr_data_t lfsr_data_frombptr(const lfsr_bptr_t *bptr,
|
static lfsr_data_t lfsr_data_frombptr(const lfsr_bptr_t *bptr,
|
||||||
uint8_t buffer[static LFSR_BPTR_DSIZE]);
|
uint8_t buffer[static LFSR_BPTR_DSIZE]);
|
||||||
static lfsr_data_t lfsr_data_fromshrub(const lfsr_shrub_t *shrub,
|
static lfsr_data_t lfsr_data_fromshrub(const lfsr_shrub_t *shrub,
|
||||||
@@ -3473,6 +3476,8 @@ static int lfsr_rbyd_appendrattr_(lfs_t *lfs, lfsr_rbyd_t *rbyd,
|
|||||||
LFSR_LE32_DSIZE,
|
LFSR_LE32_DSIZE,
|
||||||
LFS_MAX(
|
LFS_MAX(
|
||||||
LFSR_LEB128_DSIZE,
|
LFSR_LEB128_DSIZE,
|
||||||
|
LFS_MAX(
|
||||||
|
LFSR_GEOMETRY_DSIZE,
|
||||||
LFS_MAX(
|
LFS_MAX(
|
||||||
LFSR_BPTR_DSIZE,
|
LFSR_BPTR_DSIZE,
|
||||||
LFS_MAX(
|
LFS_MAX(
|
||||||
@@ -3481,7 +3486,7 @@ static int lfsr_rbyd_appendrattr_(lfs_t *lfs, lfsr_rbyd_t *rbyd,
|
|||||||
LFSR_BTREE_DSIZE,
|
LFSR_BTREE_DSIZE,
|
||||||
LFS_MAX(
|
LFS_MAX(
|
||||||
LFSR_MPTR_DSIZE,
|
LFSR_MPTR_DSIZE,
|
||||||
LFSR_ECKSUM_DSIZE))))))];
|
LFSR_ECKSUM_DSIZE)))))))];
|
||||||
switch (lfsr_rattr_dtag(rattr)) {
|
switch (lfsr_rattr_dtag(rattr)) {
|
||||||
// le32?
|
// le32?
|
||||||
case LFSR_TAG_RCOMPAT:;
|
case LFSR_TAG_RCOMPAT:;
|
||||||
@@ -3505,6 +3510,14 @@ static int lfsr_rbyd_appendrattr_(lfs_t *lfs, lfsr_rbyd_t *rbyd,
|
|||||||
data_count = size;
|
data_count = size;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// geometry?
|
||||||
|
case LFSR_TAG_GEOMETRY:;
|
||||||
|
data = lfsr_data_fromgeometry(rattr.u.etc, buf);
|
||||||
|
size = lfsr_data_size(data);
|
||||||
|
datas = buf;
|
||||||
|
data_count = size;
|
||||||
|
break;
|
||||||
|
|
||||||
// bptr?
|
// bptr?
|
||||||
case LFSR_TAG_BLOCK:;
|
case LFSR_TAG_BLOCK:;
|
||||||
case LFSR_TAG_SHRUB | LFSR_TAG_BLOCK:;
|
case LFSR_TAG_SHRUB | LFSR_TAG_BLOCK:;
|
||||||
@@ -13310,10 +13323,10 @@ static inline int lfsr_data_readocompat(lfs_t *lfs, lfsr_data_t *data,
|
|||||||
// disk geometry
|
// disk geometry
|
||||||
//
|
//
|
||||||
// note these are stored minus 1 to avoid overflow issues
|
// note these are stored minus 1 to avoid overflow issues
|
||||||
typedef struct lfsr_geometry {
|
struct lfsr_geometry {
|
||||||
lfs_off_t block_size;
|
lfs_off_t block_size;
|
||||||
lfs_off_t block_count;
|
lfs_off_t block_count;
|
||||||
} lfsr_geometry_t;
|
};
|
||||||
|
|
||||||
// geometry on-disk encoding
|
// geometry on-disk encoding
|
||||||
static lfsr_data_t lfsr_data_fromgeometry(const lfsr_geometry_t *geometry,
|
static lfsr_data_t lfsr_data_fromgeometry(const lfsr_geometry_t *geometry,
|
||||||
@@ -13841,7 +13854,6 @@ static int lfsr_formatinited(lfs_t *lfs) {
|
|||||||
// - our magic string, "littlefs"
|
// - our magic string, "littlefs"
|
||||||
// - any format-time configuration
|
// - any format-time configuration
|
||||||
// - the root's bookmark tag, which reserves did = 0 for the root
|
// - the root's bookmark tag, which reserves did = 0 for the root
|
||||||
uint8_t geometry_buf[LFSR_GEOMETRY_DSIZE];
|
|
||||||
err = lfsr_rbyd_appendrattrs(lfs, &rbyd, -1, -1, -1, LFSR_RATTRS(
|
err = lfsr_rbyd_appendrattrs(lfs, &rbyd, -1, -1, -1, LFSR_RATTRS(
|
||||||
LFSR_RATTR(
|
LFSR_RATTR(
|
||||||
LFSR_TAG_MAGIC, 0,
|
LFSR_TAG_MAGIC, 0,
|
||||||
@@ -13857,13 +13869,11 @@ static int lfsr_formatinited(lfs_t *lfs) {
|
|||||||
LFSR_RATTR_LE32__(
|
LFSR_RATTR_LE32__(
|
||||||
LFSR_TAG_WCOMPAT, 0,
|
LFSR_TAG_WCOMPAT, 0,
|
||||||
LFSR_WCOMPAT_COMPAT),
|
LFSR_WCOMPAT_COMPAT),
|
||||||
LFSR_RATTR(
|
LFSR_RATTR__(
|
||||||
LFSR_TAG_GEOMETRY, 0,
|
LFSR_TAG_GEOMETRY, 0,
|
||||||
LFSR_DATA_GEOMETRY(
|
|
||||||
(&(lfsr_geometry_t){
|
(&(lfsr_geometry_t){
|
||||||
lfs->cfg->block_size,
|
lfs->cfg->block_size,
|
||||||
lfs->cfg->block_count}),
|
lfs->cfg->block_count}), LFSR_GEOMETRY_DSIZE),
|
||||||
geometry_buf)),
|
|
||||||
LFSR_RATTR_LEB128__(
|
LFSR_RATTR_LEB128__(
|
||||||
LFSR_TAG_NAMELIMIT, 0,
|
LFSR_TAG_NAMELIMIT, 0,
|
||||||
lfs->name_limit),
|
lfs->name_limit),
|
||||||
@@ -14386,15 +14396,12 @@ int lfsr_fs_grow(lfs_t *lfs, lfs_size_t block_count_) {
|
|||||||
|
|
||||||
// update our on-disk config
|
// update our on-disk config
|
||||||
lfs_alloc_ckpoint(lfs);
|
lfs_alloc_ckpoint(lfs);
|
||||||
uint8_t geometry_buf[LFSR_GEOMETRY_DSIZE];
|
|
||||||
int err = lfsr_mdir_commit(lfs, &lfs->mroot, LFSR_RATTRS(
|
int err = lfsr_mdir_commit(lfs, &lfs->mroot, LFSR_RATTRS(
|
||||||
LFSR_RATTR(
|
LFSR_RATTR__(
|
||||||
LFSR_TAG_GEOMETRY, 0,
|
LFSR_TAG_GEOMETRY, 0,
|
||||||
LFSR_DATA_GEOMETRY(
|
|
||||||
(&(lfsr_geometry_t){
|
(&(lfsr_geometry_t){
|
||||||
lfs->cfg->block_size,
|
lfs->cfg->block_size,
|
||||||
block_count_}),
|
block_count_}), LFSR_GEOMETRY_DSIZE)));
|
||||||
geometry_buf))));
|
|
||||||
if (err) {
|
if (err) {
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-10
@@ -995,15 +995,12 @@ code = '''
|
|||||||
// note we're messing around with internals to do this! this
|
// note we're messing around with internals to do this! this
|
||||||
// is not a user API
|
// is not a user API
|
||||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||||
uint8_t geometry_buf[LFSR_GEOMETRY_DSIZE];
|
|
||||||
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_RATTRS(
|
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_RATTRS(
|
||||||
LFSR_RATTR(
|
LFSR_RATTR__(
|
||||||
LFSR_TAG_GEOMETRY, 0,
|
LFSR_TAG_GEOMETRY, 0,
|
||||||
LFSR_DATA_GEOMETRY(
|
|
||||||
(&(lfsr_geometry_t){
|
(&(lfsr_geometry_t){
|
||||||
INC_BLOCK_SIZE,
|
INC_BLOCK_SIZE,
|
||||||
BLOCK_COUNT}),
|
BLOCK_COUNT}), LFSR_GEOMETRY_DSIZE))) => 0;
|
||||||
geometry_buf)))) => 0;
|
|
||||||
lfsr_unmount(&lfs) => 0;
|
lfsr_unmount(&lfs) => 0;
|
||||||
|
|
||||||
// mount should now fail
|
// mount should now fail
|
||||||
@@ -1025,15 +1022,12 @@ code = '''
|
|||||||
// note we're messing around with internals to do this! this
|
// note we're messing around with internals to do this! this
|
||||||
// is not a user API
|
// is not a user API
|
||||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||||
uint8_t geometry_buf[LFSR_GEOMETRY_DSIZE];
|
|
||||||
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_RATTRS(
|
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_RATTRS(
|
||||||
LFSR_RATTR(
|
LFSR_RATTR__(
|
||||||
LFSR_TAG_GEOMETRY, 0,
|
LFSR_TAG_GEOMETRY, 0,
|
||||||
LFSR_DATA_GEOMETRY(
|
|
||||||
(&(lfsr_geometry_t){
|
(&(lfsr_geometry_t){
|
||||||
BLOCK_SIZE,
|
BLOCK_SIZE,
|
||||||
INC_BLOCK_COUNT}),
|
INC_BLOCK_COUNT}), LFSR_GEOMETRY_DSIZE))) => 0;
|
||||||
geometry_buf)))) => 0;
|
|
||||||
lfsr_unmount(&lfs) => 0;
|
lfsr_unmount(&lfs) => 0;
|
||||||
|
|
||||||
// mount should now fail
|
// mount should now fail
|
||||||
|
|||||||
Reference in New Issue
Block a user