Moved info flags to overlap with traversal flags
We just have too many flags! Mount flags specifically are already close
to filling up with the currently planned features.
Fortunately the info flags, used internally to track filesystem state,
are never needed at the same time as the traversal flags which specify
one-time traversals during lfsr_mount. So we can move these to overlap
and free up quite a bit more space:
8 8 8 8
.----++----++----++----.
.----..-..-..----------.
o_flags: |type||f||t|| o |
|----||-|:-:'--.-.-----'
|----||-|:-:---:-:-----.
d_flags: |type||f|: : : : |
|----||-|:-:---:-:-----'
|----||-|:-'--..-..----.
t_flags: |type||f|| t ||f||tstt|
'----''-'|----|'-''----'
.--------|----|:-:-----.
gc_flags: | | t |: : |
'--------|----|:-:-----'
.-------.|----|.-------.
f_flags: | m || t || f |
|-------||----|'-------'
|-------||----|:-:.----.
m_flags: | m || t ||o|| m |
|-------|'----'|-||----|
|-------|.----.|-||----|
i_flags: | m || i ||o|| m |
'-------''----''-''----'
The only downside is a bit more masking and not having this info
available when debugging.
The overlap is also convenient for lfsr_fs_gc and lets us remove some
shifts, which humorously perfectly canceled out the added cost of the
masks:
code stack
before: 36416 2616
after: 36416 (+0.0%) 2616 (+0.0%)
This commit is contained in:
@@ -13156,6 +13156,17 @@ static int lfs_deinit(lfs_t *lfs);
|
||||
// initialize littlefs state, assert on bad configuration
|
||||
static int lfs_init(lfs_t *lfs, uint32_t flags,
|
||||
const struct lfs_config *cfg) {
|
||||
// unknown flags?
|
||||
LFS_ASSERT((flags & ~(
|
||||
LFS_M_RDWR
|
||||
| LFS_M_RDONLY
|
||||
| LFS_M_FLUSH
|
||||
| LFS_M_SYNC
|
||||
| LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, 0)
|
||||
| LFS_IFDEF_CKFETCHES(LFS_M_CKFETCHES, 0)
|
||||
| LFS_IFDEF_CKPARITY(LFS_M_CKPARITY, 0)
|
||||
| LFS_IFDEF_CKCKSUMS(LFS_M_CKCKSUMS, 0))) == 0);
|
||||
|
||||
// TODO this all needs to be cleaned up
|
||||
lfs->cfg = cfg;
|
||||
int err = 0;
|
||||
@@ -13974,7 +13985,17 @@ int lfsr_mount(lfs_t *lfs, uint32_t flags,
|
||||
LFS_ASSERT(!lfsr_t_ismtreeonly(flags) || !lfsr_t_islookahead(flags));
|
||||
LFS_ASSERT(!lfsr_t_ismtreeonly(flags) || !lfsr_t_isckdata(flags));
|
||||
|
||||
int err = lfs_init(lfs, flags, cfg);
|
||||
int err = lfs_init(lfs,
|
||||
flags & (
|
||||
LFS_M_RDWR
|
||||
| LFS_M_RDONLY
|
||||
| LFS_M_FLUSH
|
||||
| LFS_M_SYNC
|
||||
| LFS_IFDEF_CKPROGS(LFS_M_CKPROGS, 0)
|
||||
| LFS_IFDEF_CKFETCHES(LFS_M_CKFETCHES, 0)
|
||||
| LFS_IFDEF_CKPARITY(LFS_M_CKPARITY, 0)
|
||||
| LFS_IFDEF_CKCKSUMS(LFS_M_CKCKSUMS, 0)),
|
||||
cfg);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
@@ -14123,7 +14144,14 @@ int lfsr_format(lfs_t *lfs, uint32_t flags,
|
||||
// some flags don't make sense when only traversing the mtree
|
||||
LFS_ASSERT(!lfsr_t_ismtreeonly(flags) || !lfsr_t_isckdata(flags));
|
||||
|
||||
int err = lfs_init(lfs, flags, cfg);
|
||||
int err = lfs_init(lfs,
|
||||
flags & (
|
||||
LFS_F_RDWR
|
||||
| LFS_IFDEF_CKPROGS(LFS_F_CKPROGS, 0)
|
||||
| LFS_IFDEF_CKFETCHES(LFS_F_CKFETCHES, 0)
|
||||
| LFS_IFDEF_CKPARITY(LFS_F_CKPARITY, 0)
|
||||
| LFS_IFDEF_CKCKSUMS(LFS_F_CKCKSUMS, 0)),
|
||||
cfg);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
@@ -14444,9 +14472,9 @@ int lfsr_fs_gc(lfs_t *lfs, lfs_soff_t steps, uint32_t flags) {
|
||||
|
||||
// do we have any pending work?
|
||||
uint32_t pending = flags & (
|
||||
((lfs->flags & (
|
||||
(lfs->flags & (
|
||||
LFS_I_HASORPHANS
|
||||
| LFS_I_UNCOMPACTED)) >> 12)
|
||||
| LFS_I_UNCOMPACTED))
|
||||
| ((lfsr_fs_canlookahead(lfs)) ? LFS_GC_LOOKAHEAD : 0)
|
||||
| LFS_GC_CKMETA
|
||||
| LFS_GC_CKDATA);
|
||||
@@ -14509,9 +14537,9 @@ int lfsr_fs_gc(lfs_t *lfs, lfs_soff_t steps, uint32_t flags) {
|
||||
|
||||
// clear any pending flags we make progress on
|
||||
pending &= (
|
||||
((lfs->flags & (
|
||||
(lfs->flags & (
|
||||
LFS_I_HASORPHANS
|
||||
| LFS_I_UNCOMPACTED)) >> 12)
|
||||
| LFS_I_UNCOMPACTED))
|
||||
| ((lfsr_fs_canlookahead(lfs)) ? LFS_GC_LOOKAHEAD : 0)
|
||||
// only consider our filesystem checked if we
|
||||
// weren't mutated
|
||||
|
||||
@@ -215,15 +215,15 @@ enum lfs_type {
|
||||
#endif
|
||||
|
||||
#define LFS_I_INCONSISTENT \
|
||||
0x01000000 // Filesystem needs mkconsistent to write
|
||||
0x00001000 // Filesystem needs mkconsistent to write
|
||||
#define LFS_I_CANLOOKAHEAD \
|
||||
0x02000000 // Lookahead buffer is not full
|
||||
0x00002000 // Lookahead buffer is not full
|
||||
#define LFS_I_UNCOMPACTED \
|
||||
0x08000000 // Filesystem may have uncompacted metadata
|
||||
0x00008000 // Filesystem may have uncompacted metadata
|
||||
|
||||
// internally used flags, don't use these
|
||||
#define LFS_I_HASORPHANS \
|
||||
0x01000000 // Filesystem may have untracked orphans
|
||||
0x00001000 // Filesystem may have untracked orphans
|
||||
|
||||
|
||||
// Block types
|
||||
|
||||
Reference in New Issue
Block a user