From d18633e4e8c096d810e541d9b6eb0fda746f63d4 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sun, 14 Jul 2024 01:19:21 -0500 Subject: [PATCH] Tweaked lfsr_fs_gc to imply LFS_GC_MTREEONLY based on flags LFS_GC_MTREEONLY is a rather niche/littlefs-specific flag, and we probably shouldn't expect users to know when to use it. So now we automatically switch to LFS_GC_MTREEONLY mode in lfsr_fs_gc if it is sufficient for accomplishing all pending gc work. Though currently the only traversal that can be LFS_GC_MTREEONLY is LFS_GC_MKCONSISTENT... Note that LFS_GC_MTREEONLY can still be explicitly provided, as it does change the behavior of LFS_GC_COMPACT and LFS_GC_CKMETA (and combining LFS_GC_MTREEONLY with LFS_GC_LOOKAHEAD/LFS_GC_CKDATA still asserts). This adds a bit of code: code stack before: 35728 2672 after: 35740 (+0.0%) 2672 (+0.0%) --- lfs.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lfs.c b/lfs.c index d407c12c..dc768324 100644 --- a/lfs.c +++ b/lfs.c @@ -12895,13 +12895,21 @@ int lfsr_fs_gc(lfs_t *lfs, uint32_t flags) { return 0; } + // do we really need a full traversal? + if (!(lfsr_t_islookahead(flags) + || lfsr_t_iscompact(flags) + || lfsr_t_isckmeta(flags) + || lfsr_t_isckdata(flags))) { + flags |= LFS_GC_MTREEONLY; + } + // existing traversal? if (lfsr_omdir_isopen(lfs, &lfs->gc.o.o)) { - // note that we mask out flags! if you change flags mid-traversal, - // the result is equivalent to the worst-case set of flags + // note that we mask flags (except mtreeonly)! if you change flags + // mid-traversal, the result is equivalent to the worst-case set + // of flags lfs->gc.o.o.flags &= ( - ~LFS_GC_MTREEONLY - & ~LFS_GC_MKCONSISTENT + ~LFS_GC_MKCONSISTENT & ~LFS_GC_LOOKAHEAD & ~LFS_GC_COMPACT & ~LFS_GC_CKMETA