Commit Graph

973 Commits

Author SHA1 Message Date
Christopher Haster d3375f1cef Merge pull request #1180 from ChaserTlss/master
lfs: guard null callbacks in lfs_dir_fetchmatch
2026-03-24 17:26:08 -05:00
Christopher Haster 24d23dda83 Merge pull request #1172 from ThaChoppahIsLookinSharp/fix/emu-block-readme
Fix broken link on README.md for emu device
2026-03-24 17:25:53 -05:00
Christopher Haster 58eaa9836e Merge pull request #1161 from amubiera/size-t-warnings
Fixes for 'Implicit conversion loses integer precision' warnings.
2026-03-24 17:25:43 -05:00
Christopher Haster 87d5f61d3e Merge pull request #1156 from amgross/minor_typo
Fix comment typo and -> an
2026-03-24 17:25:31 -05:00
daimiao chen fd5e7f6253 Using LFS_ASSERT instead of an runtime check.
Remove NULL check from condition and assert callback is valid.
2026-03-09 19:09:15 -05:00
Daimiao Chen 2311cd785a Guard null callbacks in lfs_dir_fetchmatch
lfs_dir_fetch relies on an impossible tag match to avoid calling a
NULL callback. Add an explicit cb != NULL check in the match path
so future refactors don’t risk a NULL function-pointer call.
2026-03-09 19:09:06 -05:00
Daniel Lamana 74f32c83ac Fix broken link on README.md for emu device 2025-11-25 12:07:09 +01:00
Amilcar Ubiera dbe96d0326 Fixes for 'Implicit conversion loses integer precision' warnings. 2025-11-11 09:15:20 -05:00
aryeg b062c88a08 Fix comment typo and -> an 2025-10-19 08:35:05 +03:00
Christopher Haster adad0fbbcf Merge pull request #1140 from tjko/littlefs-toy
Add littlefs-toy to the related projects section.
v2.11.2
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
Christopher Haster 8e251dd675 Merge pull request #1110 from Ryan-CW-Code/perf_gc
perf: gc might try to populate the lookahead buffer each time
v2.11.1
2025-06-30 11:39:17 -05:00
Christopher Haster 25b9a4af85 Merge pull request #1109 from Ryan-CW-Code/never_read
refactor: value stored to 'diff' is never read
2025-06-30 11:39:05 -05:00
Christopher Haster 2acf939a00 Merge pull request #1106 from littlefs-project/fix-make-build-dep
make: Add missing BUILD_DEP include
2025-06-30 11:38:56 -05:00
ryancw d5a86fd28d style: format code, limit to 80 columns. 2025-06-03 09:46:59 +08:00
ryancw 2349ac8c96 perf: gc might try to populate the lookahead buffer each time 2025-05-28 10:23:47 +08:00
ryancw 0755b00c21 refactor: value stored to 'diff' is never read 2025-05-27 20:00:29 +08:00
Christopher Haster 8365bbb7a2 make: Added missing BUILD_DEP include
This was preventing bench modifications from triggering relevant
bench-runner rebuilds.
2025-05-15 13:38:31 -05:00
Christopher Haster 16ceb67934 Merge pull request #1103 from littlefs-project/devel
Minor release: v2.11
v2.11.0
2025-05-14 20:45:44 -05:00
Christopher Haster 8434536f0a Bumped minor version to v2.11 2025-05-13 13:18:31 -05:00
Christopher Haster 523319b685 Merge pull request #1104 from DvdGiessen/os-rename-between-filesystems
use shutil.move instead of os.rename to move file
2025-05-13 13:17:53 -05:00
Daniël van de Giessen ba250a3075 use shutil.move instead of os.rename to move file
This prevents a "OSError: [Errno 18] Invalid cross-device link" if the temporary
file was created on different filesystem (such as a tmpfs mount).
2025-05-13 13:15:21 +02:00
Christopher Haster 8c458fa6bd Merge pull request #1094 from sosthene-nitrokey/shrink-fs
Add support for shrinking a filesystem
2025-05-13 00:45:32 -05:00
Christopher Haster 3149201ae5 Merge pull request #1091 from yamt/mach-o
adapt the linker sections usage to mach-o
2025-05-13 00:45:02 -05:00
Christopher Haster 6a43f3cdc3 Merge pull request #1090 from yamt/clang
drop a few unsupported CFLAGS for clang
2025-05-13 00:44:46 -05:00
Christopher Haster d73fb8ef3c Merge pull request #1099 from littlefs-project/fix-remove-double-deorphan
Fix double deorphan caused by relocation mid dir remove
2025-05-13 00:44:26 -05:00
Christopher Haster c1bf7cee84 Merge pull request #1100 from selimkeles/fix/bitshift_overflow
fix: added uint32_t cast to the bitshift places
2025-05-13 00:44:05 -05:00
Christopher Haster b26bf3494c Merge pull request #1095 from DvdGiessen/lfs_crc
lfs_crc should be static if LFS_CRC is defined
2025-05-13 00:43:24 -05:00
Christopher Haster 0115cf6b74 gha: Dropped explicit CFLAGS from clang testing in CI
Thanks to yamt, GCC-specific flags should now be disabled if compiling
with clang. Dropping the explicit flags also doubles as a test that the
NO_GCC inference works.
2025-05-07 23:45:29 -05:00
Christopher Haster bff4dfd1b1 Added NO_GCC to allow users to explicitly disable GCC-specific flags
This is the same as the implicit Clang => NO_GCC behavior introduced by
yamt, but with an explicit variable that can be assigned by users using
other, non-gcc, compilers:

  $ NO_GCC=1 make

Note, stack measurements are currently GCC specific:

  $ NO_GCC=1 make stack
  ... snip ...
  FileNotFoundError: [Errno 2] No such file or directory: 'lfs.ci'
  make: *** [Makefile:494: lfs.stack.csv] Error 1
2025-05-07 23:40:25 -05:00
Sosthène Guédon edaaaf88ea Apply review comments 2025-05-07 10:38:43 +02:00
Sosthène Guédon 7d79423972 Rename SHRINKIFCHEAP to SHRINKNONRELOCATING 2025-05-07 10:34:24 +02:00
Sosthène Guédon 7782d3dfa3 Mention that shrinking is unlikely to work 2025-05-06 11:00:29 +02:00
selim.keles f4a1bb328a fix: added uint32_t cast to the bitshift places
In 16 bit and 8 bit architectures, overflow and underflow issues were occuring while using functions lfs_frombe32 and lfs_fromle32
2025-05-05 13:38:05 +03:00
Sosthène Guédon 9b8f802b43 fixup! Add support for shrinking a filesystem 2025-05-05 11:37:39 +02:00
Christopher Haster a3d6bec5f0 Fixed a double deorphan caused by relocation mid dir remove
Long story short: There is a specific case where removing a directory
can trigger a deorphan pass, but lfs_remove did not check for this,
would try to clean up the (already cleaned) directory orphan, and
trigger an assert:

  lfs.c:4890:assert: assert failed with false, expected eq true
      LFS_ASSERT(lfs_tag_size(lfs->gstate.tag) > 0x000 || orphans >= 0);

The specific case being a remove commit that triggers a relocation that
creates an orphan.

This is also possible in lfs_rename, but only if you're renaming a
directory that implies a remove, which is a pretty rare operation.

---

This was probably an oversight introduced in the non-recursive commit
logic rework.

Fortunately the fix is to just check if we even have an orphan before
trying to remove it. We can rely on this instead of the file type, so
this fix shouldn't even increase the code size.

Found and root-caused by Hugh-Baoa
2025-05-03 18:13:19 -05:00
Christopher Haster 0634d13e07 tests: Added non-reentrant variants of orphan/relocation tests
These are the same as the related reentrant variants, but by opting out
of powerloss testing, we can test a much larger number of states without
having to worry about the impact on powerloss testing runtime.

Bumped CYCLES from 20 -> 2000.

This reveals an orphan remove bug found by Hugh-Baoa.
2025-05-03 17:15:26 -05:00
Sosthène Guédon 2105e502c5 Add support for shrinking a filesystem
This PR adds a new `lfs_fs_shrink`, which functions similarly to
`lfs_fs_grow`, but supports reducing the block count.

This functions first checks that none of the removed block are in use.
If it is the case, it will fail.
2025-04-17 10:07:37 +02:00
Daniël van de Giessen b823728420 lfs_crc should be static if LFS_CRC is defined 2025-04-16 18:17:21 +02:00
YAMAMOTO Takashi 0d861b7916 adapt the linker sections usage to mach-o
"make test" on macOS:

```
using runner: ./runners/test_runner
found 19 suites, 188 cases, 11242/11770 permutations

running test_alloc: 12/12 cases, 207/207 perms
running test_attrs: 4/4 cases, 20/20 perms
running test_badblocks: 4/4 cases, 300/300 perms
running test_bd: 5/5 cases, 85/85 perms
running test_compat: 17/17 cases, 205/205 perms
running test_dirs: 15/15 cases, 450/450 perms, 1756pls!
running test_entries: 8/8 cases, 32/32 perms
running test_evil: 8/8 cases, 105/105 perms
running test_exhaustion: 5/5 cases, 85/85 perms
running test_files: 10/10 cases, 7155/7155 perms, 9410pls!
running test_interspersed: 4/4 cases, 190/190 perms, 2835pls!
running test_move: 17/17 cases, 161/161 perms, 157pls!
running test_orphans: 6/6 cases, 50/50 perms, 846pls!
running test_paths: 33/33 cases, 325/325 perms
running test_powerloss: 2/2 cases, 21/21 perms
running test_relocations: 4/4 cases, 68/68 perms, 1612pls!
running test_seek: 10/10 cases, 195/195 perms, 1050pls!
running test_superblocks: 17/17 cases, 318/318 perms, 1437pls!
running test_truncate: 7/7 cases, 1270/1270 perms, 9691pls!

done: 11242/11242 passed, 0/11242 failed, 28794pls!, in 585.76s
```
2025-04-07 16:20:23 +09:00
YAMAMOTO Takashi 26bee8ad36 drop a few unsupported CFLAGS for clang 2025-04-07 16:06:01 +09:00