From ce6cbc3c7794ae9a3e6cde1a2703a977c735aeb8 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sat, 29 Nov 2025 21:56:16 -0600 Subject: [PATCH] rattrs: Allowed LFS3_RATTR_TAIL as alternate rattr-list terminator LFS3_tag_RATTRS, now LFS3_tag_TAIL, is a bit funny in that it only supports tail-recursive rattrs. The whole point of littlefs is bounded-RAM after all. And if we know LFS3_tag_TAIL will terminate an rattr-list, why bother with an additional LFS3_tag_NULL? Like LFS3_RATTR_NULL, LFS3_RATTR_TAIL sets length=0 to indicate the end of the rattr-lists. Saves a bit of code: code stack ctx before: 35324 2176 660 after: 35316 (-0.0%) 2176 (+0.0%) 660 (+0.0%) code stack ctx gbmap before: 38156 2192 772 gbmap after: 38148 (-0.0%) 2192 (+0.0%) 772 (+0.0%) --- lfs3.c | 14 +++++++------- lfs3.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lfs3.c b/lfs3.c index c708f970..b39902eb 100644 --- a/lfs3.c +++ b/lfs3.c @@ -1945,6 +1945,9 @@ typedef uint8_t lfs3_count_t; // null rattr terminates rattr lists #define LFS3_RATTR_NULL ((lfs3_rattr_t)0) +// alternatively, a tail rattr tail-recurses into another rattr list +#define LFS3_RATTR_TAIL LFS3_RATTR(0, LFS3_tag_TAIL, 0) + // create an attribute list #define LFS3_RATTRS(...) ((const lfs3_rattr_t[]){__VA_ARGS__}) @@ -8265,9 +8268,7 @@ static int lfs3_mdir_commit___(lfs3_t *lfs3, lfs3_mdir_t *mdir_, LFS3_ASSERT(!(r > rattrs && lfs3_rattr_isinsert(r))); // rattr lists can be chained, but only tail-recursively - if (lfs3_rattr_tag(r) == LFS3_tag_RATTRS) { - // must be the last tag - LFS3_ASSERT(!*lfs3_rattr_next(r, NULL)); + if (lfs3_rattr_tag(r) == LFS3_tag_TAIL) { const lfs3_rattr_t *rattrs_ = (const lfs3_rattr_t*)lfs3_rattr_arg(r, 0); @@ -9285,10 +9286,9 @@ static int lfs3_mdir_commit_(lfs3_t *lfs3, lfs3_mdir_t *mdir, LFS3_RATTR_ARG(&mtree_), // were we committing to the mroot? include any -1 rattrs (mdir->mid <= -1) - ? LFS3_RATTR(2, LFS3_tag_RATTRS, 0) - : LFS3_RATTR(2, LFS3_TAG_NULL, 0), - LFS3_RATTR_ARG(rattrs), - LFS3_RATTR_NULL)); + ? LFS3_RATTR_TAIL + : LFS3_RATTR_NULL, + LFS3_RATTR_ARG(rattrs))); if (err) { LFS3_ASSERT(err != LFS3_ERR_RANGE); goto failed; diff --git a/lfs3.h b/lfs3.h index ab77b7de..a0e3d64c 100644 --- a/lfs3.h +++ b/lfs3.h @@ -829,7 +829,7 @@ enum lfs3_tag { // in-device only tags, these should never get written to disk LFS3_tag_INTERNAL = 0x0000, - LFS3_tag_RATTRS = 0x0001, + LFS3_tag_TAIL = 0x0001, LFS3_tag_SHRUBCOMMIT = 0x0002, LFS3_tag_GRMPUSH = 0x0003, LFS3_tag_MOVE = 0x0004,