(Re)implemented lfsr_fs_gc
This just provides a simple, easy-to-call, wrapper over the new
traversal API:
int lfsr_fs_gc(lfs_t *lfs, uint32_t flags);
The main difference from its previous incarnation, is that lfsr_fs_gc
now takes a flags argument to indicate exactly what gc operations to
perform. This gives the user more control, and may also make the API
more robust towards adding new features:
LFS_GC_MTREEONLY = 0x0010, // Only traverse the mtree
LFS_GC_MKCONSISTENT = 0x0020, // Make the filesystem consistent
LFS_GC_LOOKAHEAD = 0x0040, // Populate lookahead buffer
LFS_GC_COMPACT = 0x0080, // Compact metadata logs
LFS_GC_CKMETA = 0x0100, // Check metadata checksums
LFS_GC_CKDATA = 0x0200, // Check metadata + data checksums
LFS_GC_REPAIRMETA+ = 0x0400, // Repair metadata blocks
LFS_GC_REPAIRDATA+ = 0x0800, // Repair metadata + data blocks
+ Planned
Alternatively, gc_flags could have been added as a config option. But
making gc_flags a function argument matches other flag APIs (open
mainly), and is slightly more flexible in that it allows a system to do
different gc operations in different system states (though this could
also be accomplished with the hypothetical lfsr_fs_gccfg, which would
probably be good to add anyways).
Worst case, defining a system-wide define that you always pass to
lfsr_fs_gc accomplishes roughly the same thing.
---
This adds a bit more code, mainly to check if we actually need to
traverse, and to make sure traversals accomplish all of the requested
work.
code stack
before: 35448 2680
after: 35708 (+0.7%) 2672 (-0.3%)
Curiously it also saved a bit of stack, which is a bit silly given this
commit is purely code addition. Apparently something in lfs_alloc and
lfsr_fs_gc is shared, getting uninlined, and messing with the stack
measurement. lfs_alloc is quite sensitive to stack changes after all.
This commit is contained in:
@@ -183,6 +183,19 @@ enum lfs_traversal_flags {
|
||||
LFS_F_MUTATED = 0x4000, // Filesystem modified by traversal
|
||||
};
|
||||
|
||||
// GC flags
|
||||
enum lfs_gc_flags {
|
||||
LFS_GC_MTREEONLY = 0x0010, // Only traverse the mtree
|
||||
LFS_GC_MKCONSISTENT = 0x0020, // Make the filesystem consistent
|
||||
LFS_GC_LOOKAHEAD = 0x0040, // Populate lookahead buffer
|
||||
LFS_GC_COMPACT = 0x0080, // Compact metadata logs
|
||||
LFS_GC_CKMETA = 0x0100, // Check metadata checksums
|
||||
LFS_GC_CKDATA = 0x0200, // Check metadata + data checksums
|
||||
// TODO
|
||||
// LFS_GC_REPAIRMETA = 0x0400, // Repair metadata blocks
|
||||
// LFS_GC_REPAIRDATA = 0x0800, // Repair metadata + data blocks
|
||||
};
|
||||
|
||||
|
||||
// Configuration provided during initialization of the littlefs
|
||||
struct lfs_config {
|
||||
@@ -1114,6 +1127,20 @@ lfs_ssize_t lfsr_fs_size(lfs_t *lfs);
|
||||
int lfsr_fs_mkconsistent(lfs_t *lfs);
|
||||
#endif
|
||||
|
||||
#ifndef LFS_READONLY
|
||||
// Attempt any janitorial work that may be pending.
|
||||
//
|
||||
// The exact janitorial work depends on the provided flags. Note that most
|
||||
// of this work can also be accomplished incrementally via
|
||||
// lfsr_traversal_read.
|
||||
//
|
||||
// Calling this function is not required, but may allow the offloading of
|
||||
// expensive janitorial work to a less time-critical code path.
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
int lfsr_fs_gc(lfs_t *lfs, uint32_t flags);
|
||||
#endif
|
||||
|
||||
#ifndef LFS_READONLY
|
||||
// Change the number of blocks used by the filesystem
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user