Compare commits

...

12 Commits

Author SHA1 Message Date
geky-bot
445381645f Generated v2 prefixes 2025-09-29 21:24:05 +00:00
Christopher Haster
adad0fbbcf
Merge pull request #1140 from tjko/littlefs-toy
Add littlefs-toy to the related projects section.
2025-09-29 15:10:55 -05:00
Christopher Haster
ed127050bb
Merge pull request #1137 from dschendt/dschendt-fix-dir-count
fix: compact when dir count hits 0x3ff
2025-09-29 15:10:42 -05:00
Christopher Haster
ec26996631
Merge pull request #1134 from elupus/patch-2
fix: add missing return causing uninitialized reads
2025-09-29 15:10:26 -05:00
Christopher Haster
17ab6e92f7
Merge pull request #1133 from elupus/patch-1
fix: false uninitialized read warning
2025-09-29 15:10:10 -05:00
Christopher Haster
4cd2bfc2c1 Fixed inverted dir->count check logic
Curiously, the logic from 48bd2bf was incorrect, and would allow a
commit to be tried if erased _or_ dir->count was at risk of overflow.

That is clearly wrong, we should only try to commit if both conditions
are met...

Found again by dschendt
2025-09-25 15:24:33 -05:00
Christopher Haster
f24ff9fb25 Moved dir->count check before commit, limited to < 0xff
This matches the logic originally implemented in 48bd2bf, which was lost
during the big no-recursion refactor 84da4c0.

Other notes:

- Checking >= 0xff matches the split logic during compaction (line
  2158):

    end - split < 0xff

- Grouping dir->erased || dir->count >= 0xff together makes it clear
  these share a common code path.

- Checking for dir->count >= 0xff early avoids committing >8-bit ids to
  disk.

  The cat may already be out-of-the bag on this one, but opening the id
  space up to the full 10-bits should probably be on a non-patch
  release.

Found by dschendt
2025-09-25 13:03:42 -05:00
Timo Kokkonen
f5b2226a80 Add littlefs-toy to the related projects section. 2025-09-15 17:32:05 -07:00
David
172a186fa9 compact when dir count hits 0x3ff 2025-09-02 19:36:10 -04:00
Joakim Plate
8b75de74c9
fix: add missing return causing uninitialized reads
If lfs_bd_read fails, lfs_fcrc_fromle32 will read uninitialized memory, and hasfcrc will be set to true.

This may end up in a "working" state later due to crcs not matching. but it's hard to follow if that woud be the case.
2025-08-12 17:03:40 +02:00
Joakim Plate
11cecd079c
fix: also assert inside lfs_bd_read 2025-08-12 16:29:31 +02:00
Joakim Plate
8c7b6b26e6
fix: false uninitialized read warning
Add asserts on file system reads to make sure
no positive values are returned, which would
make assumptions on error checks invalid.

This fixes clang tidy warnings on uninitialized
reads in uses of lfs_dir_get where only negative
returns are considered errors.
2025-08-12 14:56:29 +02:00
2 changed files with 11 additions and 2 deletions

View File

@ -267,7 +267,11 @@ License Identifiers that are here available: http://spdx.org/licenses/
to create images of the filesystem on your PC. Check if littlefs will fit
your needs, create images for a later download to the target memory or
inspect the content of a binary image of the target memory.
- [littlefs-toy] - A command-line tool for creating and working with littlefs
images. Uses syntax similar to tar command for ease of use. Supports working
on littlefs images embedded inside another file (firmware image, etc).
- [littlefs2-rust] - A Rust wrapper for littlefs. This project allows you
to use littlefs in a Rust-friendly API, reaping the benefits of Rust's memory
safety and other guarantees.
@ -321,6 +325,7 @@ License Identifiers that are here available: http://spdx.org/licenses/
[littlefs-js]: https://github.com/geky/littlefs-js
[littlefs-js-demo]:http://littlefs.geky.net/demo.html
[littlefs-python]: https://pypi.org/project/littlefs-python/
[littlefs-toy]: https://github.com/tjko/littlefs-toy
[littlefs2-rust]: https://crates.io/crates/littlefs2
[nim-littlefs]: https://github.com/Graveflo/nim-littlefs
[chamelon]: https://github.com/yomimono/chamelon

6
lfs2.c
View File

@ -93,6 +93,7 @@ static int lfs2_bd_read(lfs2_t *lfs2,
// bypass cache?
diff = lfs2_aligndown(diff, lfs2->cfg->read_size);
int err = lfs2->cfg->read(lfs2->cfg, block, off, data, diff);
LFS2_ASSERT(err <= 0);
if (err) {
return err;
}
@ -739,6 +740,7 @@ static lfs2_stag_t lfs2_dir_getslice(lfs2_t *lfs2, const lfs2_mdir_t *dir,
int err = lfs2_bd_read(lfs2,
NULL, &lfs2->rcache, sizeof(ntag),
dir->pair[0], off, &ntag, sizeof(ntag));
LFS2_ASSERT(err <= 0);
if (err) {
return err;
}
@ -767,6 +769,7 @@ static lfs2_stag_t lfs2_dir_getslice(lfs2_t *lfs2, const lfs2_mdir_t *dir,
err = lfs2_bd_read(lfs2,
NULL, &lfs2->rcache, diff,
dir->pair[0], off+sizeof(tag)+goff, gbuffer, diff);
LFS2_ASSERT(err <= 0);
if (err) {
return err;
}
@ -1279,6 +1282,7 @@ static lfs2_stag_t lfs2_dir_fetchmatch(lfs2_t *lfs2,
if (err == LFS2_ERR_CORRUPT) {
break;
}
return err;
}
lfs2_fcrc_fromle32(&fcrc);
@ -2264,7 +2268,7 @@ static int lfs2_dir_relocatingcommit(lfs2_t *lfs2, lfs2_mdir_t *dir,
}
}
if (dir->erased) {
if (dir->erased && dir->count < 0xff) {
// try to commit
struct lfs2_commit commit = {
.block = dir->pair[0],