From b63237555b88502e45ff151f5f726ca3650dfdab Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Mon, 1 Dec 2025 15:21:37 -0600 Subject: [PATCH] rattrs: Brought back LFS3_FROM_LLEB128 This was originally dropped because it's not strictly necessary, little-leb128s (28-bits) can always be encoded with the default leb128 encoder (31-bits). But it is useful if only for the assert. Note this matches lfs3_data_readlleb128, which was never dropped, and is useful for decreasing decoder DSIZEs. Maybe it makes sense to drop both of these in the future, especially if we start running into from-field pressure. But for now, this assert is useful for ensuring disk compatibility with little 4-byte leb128s. --- Surprisingly no code cost, at least by default (code alignment?). Though it did add 4 bytes to the gbmap build (so yes, probably code alignment): code stack ctx before: 35316 2176 660 after: 35316 (+0.0%) 2176 (+0.0%) 660 (+0.0%) code stack ctx gbmap before: 38168 2192 772 gbmap after: 38172 (+0.0%) 2192 (+0.0%) 772 (+0.0%) --- lfs3.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/lfs3.c b/lfs3.c index 63111ee8..d54eaa5f 100644 --- a/lfs3.c +++ b/lfs3.c @@ -1894,16 +1894,17 @@ enum lfs3_from { LFS3_FROM_LE32 = 4, LFS3_FROM_LEB128 = 5, - LFS3_FROM_NAME = 6, + LFS3_FROM_LLEB128 = 6, + LFS3_FROM_NAME = 7, - LFS3_FROM_ECKSUM = 7, - LFS3_FROM_BRANCH = 8, + LFS3_FROM_ECKSUM = 8, + LFS3_FROM_BRANCH = 9, - LFS3_FROM_BPTR = 9, - LFS3_FROM_BTREE = 10, - LFS3_FROM_SHRUB = 11, - LFS3_FROM_MPTR = 12, - LFS3_FROM_GEOMETRY = 13, + LFS3_FROM_BPTR = 10, + LFS3_FROM_BTREE = 11, + LFS3_FROM_SHRUB = 12, + LFS3_FROM_MPTR = 13, + LFS3_FROM_GEOMETRY = 14, }; typedef uint8_t lfs3_from_t; @@ -3295,6 +3296,10 @@ static int lfs3_rbyd_appendrattr_(lfs3_t *lfs3, lfs3_rbyd_t *rbyd, lfs3_data_t data; uint8_t buf[LFS3_LEB128_DSIZE]; } leb128; + struct { + lfs3_data_t data; + uint8_t buf[LFS3_LLEB128_DSIZE]; + } lleb128; struct { lfs3_data_t datas[2]; uint8_t buf[LFS3_LEB128_DSIZE]; @@ -3373,10 +3378,13 @@ static int lfs3_rbyd_appendrattr_(lfs3_t *lfs3, lfs3_rbyd_t *rbyd, datas = &ctx.u.le32.data; data_count = 1; - // leb128? - } else if (from == LFS3_FROM_LEB128) { + // leb128? little-leb128? + } else if (from == LFS3_FROM_LEB128 + || from == LFS3_FROM_LLEB128) { // leb128s should not exceed 31-bits LFS3_ASSERT(args[0] <= 0x7fffffff); + // little-leb128s should not exceed 28-bits + LFS3_ASSERT(from != LFS3_FROM_LLEB128 || args[0] <= 0x0fffffff); ctx.u.leb128.data = lfs3_data_fromleb128(args[0], ctx.u.leb128.buf); datas = &ctx.u.leb128.data; @@ -15897,7 +15905,7 @@ static int lfs3_formatinited(lfs3_t *lfs3) { *r++ = LFS3_RATTR_ARG(lfs3_wcompat(lfs3)); *r++ = LFS3_RATTR(2, LFS3_TAG_GEOMETRY, 0, LFS3_FROM_GEOMETRY); *r++ = LFS3_RATTR_ARG(&geometry); - *r++ = LFS3_RATTR(2, LFS3_TAG_NAMELIMIT, 0, LFS3_FROM_LEB128); + *r++ = LFS3_RATTR(2, LFS3_TAG_NAMELIMIT, 0, LFS3_FROM_LLEB128); *r++ = LFS3_RATTR_ARG(lfs3->name_limit); *r++ = LFS3_RATTR(2, LFS3_TAG_FILELIMIT, 0, LFS3_FROM_LEB128); *r++ = LFS3_RATTR_ARG(lfs3->file_limit);