forked from Imagelibrary/littlefs
Compare commits
96 Commits
fix-expand
...
devel
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e251dd675 | ||
|
|
25b9a4af85 | ||
|
|
2acf939a00 | ||
|
|
d5a86fd28d | ||
|
|
2349ac8c96 | ||
|
|
0755b00c21 | ||
|
|
8365bbb7a2 | ||
|
|
16ceb67934 | ||
|
|
8434536f0a | ||
|
|
523319b685 | ||
|
|
ba250a3075 | ||
|
|
8c458fa6bd | ||
|
|
3149201ae5 | ||
|
|
6a43f3cdc3 | ||
|
|
d73fb8ef3c | ||
|
|
c1bf7cee84 | ||
|
|
b26bf3494c | ||
|
|
0115cf6b74 | ||
|
|
bff4dfd1b1 | ||
|
|
edaaaf88ea | ||
|
|
7d79423972 | ||
|
|
7782d3dfa3 | ||
|
|
f4a1bb328a | ||
|
|
9b8f802b43 | ||
|
|
a3d6bec5f0 | ||
|
|
0634d13e07 | ||
|
|
2105e502c5 | ||
|
|
b823728420 | ||
|
|
0d861b7916 | ||
|
|
26bee8ad36 | ||
|
|
8ed63b27be | ||
|
|
a666730044 | ||
|
|
47e738b788 | ||
|
|
81b0db0cdc | ||
|
|
63ab1ffb65 | ||
|
|
ca1081e7c4 | ||
|
|
76027f1502 | ||
|
|
61a1b0b496 | ||
|
|
ffafb9cbb1 | ||
|
|
5281a20f6c | ||
|
|
f55520380d | ||
|
|
936919d134 | ||
|
|
d2c3a47627 | ||
|
|
0320e7db0e | ||
|
|
caba4f31df | ||
|
|
152d03043c | ||
|
|
8d01895b32 | ||
|
|
0494ce7169 | ||
|
|
366100b140 | ||
|
|
630a0d87c2 | ||
|
|
3d0386489b | ||
|
|
b8e4433b34 | ||
|
|
dae656aa53 | ||
|
|
469c863c18 | ||
|
|
215613e41f | ||
|
|
2fcecc8894 | ||
|
|
78f9a5fcd3 | ||
|
|
83fe41b605 | ||
|
|
d7a911923b | ||
|
|
2ba4280a5e | ||
|
|
c961e1fe66 | ||
|
|
bd01a4c0ee | ||
|
|
999ef6656f | ||
|
|
b735c8fd7f | ||
|
|
30947054d4 | ||
|
|
80ca1ea300 | ||
|
|
815f0d85a5 | ||
|
|
dc92dec6d3 | ||
|
|
a6035071be | ||
|
|
232e736aae | ||
|
|
0de0389c6f | ||
|
|
1407db9556 | ||
|
|
ea431bd6ae | ||
|
|
2d62d2f4c9 | ||
|
|
1f82c0f27f | ||
|
|
a2c2e49e6b | ||
|
|
abaec45652 | ||
|
|
f1c430e779 | ||
|
|
4a845be0be | ||
|
|
e1636d05ab | ||
|
|
b78afe2518 | ||
|
|
798073c2a7 | ||
|
|
7db9e1663a | ||
|
|
2c4b262c35 | ||
|
|
72a4b57f4e | ||
|
|
6e7269890a | ||
|
|
ac207586ba | ||
|
|
d01280e649 | ||
|
|
6e52140d51 | ||
|
|
0bbb8bc88b | ||
|
|
78082336e7 | ||
|
|
8336ecd203 | ||
|
|
68d28b5114 | ||
|
|
1bc14933b7 | ||
|
|
01b6a47ea8 | ||
|
|
749a45650f |
29
.github/workflows/release.yml
vendored
29
.github/workflows/release.yml
vendored
@@ -20,7 +20,7 @@ jobs:
|
||||
github.event.workflow_run.head_sha == github.sha}}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{github.event.workflow_run.head_sha}}
|
||||
# need workflow access since we push branches
|
||||
@@ -30,26 +30,29 @@ jobs:
|
||||
fetch-depth: 0
|
||||
|
||||
# try to get results from tests
|
||||
- uses: dawidd6/action-download-artifact@v2
|
||||
- uses: actions/download-artifact@v4
|
||||
continue-on-error: true
|
||||
with:
|
||||
workflow: ${{github.event.workflow_run.name}}
|
||||
run_id: ${{github.event.workflow_run.id}}
|
||||
name: sizes
|
||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||
run-id: ${{github.event.workflow_run.id}}
|
||||
pattern: '{sizes,sizes-*}'
|
||||
merge-multiple: true
|
||||
path: sizes
|
||||
- uses: dawidd6/action-download-artifact@v2
|
||||
- uses: actions/download-artifact@v4
|
||||
continue-on-error: true
|
||||
with:
|
||||
workflow: ${{github.event.workflow_run.name}}
|
||||
run_id: ${{github.event.workflow_run.id}}
|
||||
name: cov
|
||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||
run-id: ${{github.event.workflow_run.id}}
|
||||
pattern: '{cov,cov-*}'
|
||||
merge-multiple: true
|
||||
path: cov
|
||||
- uses: dawidd6/action-download-artifact@v2
|
||||
- uses: actions/download-artifact@v4
|
||||
continue-on-error: true
|
||||
with:
|
||||
workflow: ${{github.event.workflow_run.name}}
|
||||
run_id: ${{github.event.workflow_run.id}}
|
||||
name: bench
|
||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||
run-id: ${{github.event.workflow_run.id}}
|
||||
pattern: '{bench,bench-*}'
|
||||
merge-multiple: true
|
||||
path: bench
|
||||
|
||||
- name: find-version
|
||||
|
||||
18
.github/workflows/status.yml
vendored
18
.github/workflows/status.yml
vendored
@@ -13,12 +13,13 @@ jobs:
|
||||
status:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: dawidd6/action-download-artifact@v2
|
||||
- uses: actions/download-artifact@v4
|
||||
continue-on-error: true
|
||||
with:
|
||||
workflow: ${{github.event.workflow_run.name}}
|
||||
run_id: ${{github.event.workflow_run.id}}
|
||||
name: status
|
||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||
run-id: ${{github.event.workflow_run.id}}
|
||||
pattern: '{status,status-*}'
|
||||
merge-multiple: true
|
||||
path: status
|
||||
- name: update-status
|
||||
continue-on-error: true
|
||||
@@ -67,12 +68,13 @@ jobs:
|
||||
|
||||
steps:
|
||||
# generated comment?
|
||||
- uses: dawidd6/action-download-artifact@v2
|
||||
- uses: actions/download-artifact@v4
|
||||
continue-on-error: true
|
||||
with:
|
||||
workflow: ${{github.event.workflow_run.name}}
|
||||
run_id: ${{github.event.workflow_run.id}}
|
||||
name: comment
|
||||
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||
run-id: ${{github.event.workflow_run.id}}
|
||||
pattern: '{comment,comment-*}'
|
||||
merge-multiple: true
|
||||
path: comment
|
||||
- name: update-comment
|
||||
continue-on-error: true
|
||||
|
||||
121
.github/workflows/test.yml
vendored
121
.github/workflows/test.yml
vendored
@@ -21,7 +21,7 @@ jobs:
|
||||
arch: [x86_64, thumb, mips, powerpc]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- name: install
|
||||
run: |
|
||||
# need a few things
|
||||
@@ -235,9 +235,9 @@ jobs:
|
||||
|
||||
# create size statuses
|
||||
- name: upload-sizes
|
||||
uses: actions/upload-artifact@v2
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: sizes
|
||||
name: sizes-${{matrix.arch}}
|
||||
path: sizes
|
||||
- name: status-sizes
|
||||
run: |
|
||||
@@ -273,16 +273,16 @@ jobs:
|
||||
}' | tee status/$(basename $f .csv).json
|
||||
done
|
||||
- name: upload-status-sizes
|
||||
uses: actions/upload-artifact@v2
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: status
|
||||
name: status-sizes-${{matrix.arch}}
|
||||
path: status
|
||||
retention-days: 1
|
||||
|
||||
# create cov statuses
|
||||
- name: upload-cov
|
||||
if: ${{matrix.arch == 'x86_64'}}
|
||||
uses: actions/upload-artifact@v2
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: cov
|
||||
path: cov
|
||||
@@ -317,11 +317,11 @@ jobs:
|
||||
target_step: env.STEP,
|
||||
}' | tee status/$(basename $f .csv)-$s.json
|
||||
done
|
||||
- name: upload-status-sizes
|
||||
- name: upload-status-cov
|
||||
if: ${{matrix.arch == 'x86_64'}}
|
||||
uses: actions/upload-artifact@v2
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: status
|
||||
name: status-cov
|
||||
path: status
|
||||
retention-days: 1
|
||||
|
||||
@@ -336,7 +336,7 @@ jobs:
|
||||
pls: [1, 2]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- name: install
|
||||
run: |
|
||||
# need a few things
|
||||
@@ -361,7 +361,7 @@ jobs:
|
||||
test-no-intrinsics:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- name: install
|
||||
run: |
|
||||
# need a few things
|
||||
@@ -374,11 +374,50 @@ jobs:
|
||||
run: |
|
||||
CFLAGS="$CFLAGS -DLFS_NO_INTRINSICS" make test
|
||||
|
||||
test-shrink:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: install
|
||||
run: |
|
||||
# need a few things
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get install -qq gcc python3 python3-pip
|
||||
pip3 install toml
|
||||
gcc --version
|
||||
python3 --version
|
||||
- name: test-no-intrinsics
|
||||
run: |
|
||||
CFLAGS="$CFLAGS -DLFS_SHRINKNONRELOCATING" make test
|
||||
|
||||
# run with all trace options enabled to at least make sure these
|
||||
# all compile
|
||||
test-yes-trace:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: install
|
||||
run: |
|
||||
# need a few things
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get install -qq gcc python3 python3-pip
|
||||
pip3 install toml
|
||||
gcc --version
|
||||
python3 --version
|
||||
- name: test-yes-trace
|
||||
run: |
|
||||
CFLAGS="$CFLAGS \
|
||||
-DLFS_YES_TRACE \
|
||||
-DLFS_RAMBD_YES_TRACE \
|
||||
-DLFS_FILEBD_YES_TRACE \
|
||||
-DLFS_RAMBD_YES_TRACE" \
|
||||
make test
|
||||
|
||||
# run LFS_MULTIVERSION tests
|
||||
test-multiversion:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- name: install
|
||||
run: |
|
||||
# need a few things
|
||||
@@ -395,7 +434,7 @@ jobs:
|
||||
test-lfs2_0:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- name: install
|
||||
run: |
|
||||
# need a few things
|
||||
@@ -414,7 +453,7 @@ jobs:
|
||||
test-valgrind:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- name: install
|
||||
run: |
|
||||
# need a few things
|
||||
@@ -431,12 +470,11 @@ jobs:
|
||||
TESTFLAGS="$TESTFLAGS --valgrind --context=1024 -Gdefault -Pnone" \
|
||||
make test
|
||||
|
||||
# test that compilation is warning free under clang
|
||||
# run with Clang, mostly to check for Clang-specific warnings
|
||||
# compile/run with Clang, mostly to check for Clang-specific warnings
|
||||
test-clang:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- name: install
|
||||
run: |
|
||||
# need a few things
|
||||
@@ -446,12 +484,8 @@ jobs:
|
||||
python3 --version
|
||||
- name: test-clang
|
||||
run: |
|
||||
# override CFLAGS since Clang does not support -fcallgraph-info
|
||||
# and -ftrack-macro-expansions
|
||||
make \
|
||||
CC=clang \
|
||||
CFLAGS="$CFLAGS -MMD -g3 -I. -std=c99 -Wall -Wextra -pedantic" \
|
||||
test
|
||||
CC=clang \
|
||||
make test
|
||||
|
||||
# run benchmarks
|
||||
#
|
||||
@@ -459,7 +493,7 @@ jobs:
|
||||
bench:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- name: install
|
||||
run: |
|
||||
# need a few things
|
||||
@@ -491,7 +525,7 @@ jobs:
|
||||
|
||||
# create bench statuses
|
||||
- name: upload-bench
|
||||
uses: actions/upload-artifact@v2
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: bench
|
||||
path: bench
|
||||
@@ -525,9 +559,9 @@ jobs:
|
||||
}' | tee status/$(basename $f .csv)-$s.json
|
||||
done
|
||||
- name: upload-status-bench
|
||||
uses: actions/upload-artifact@v2
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: status
|
||||
name: status-bench
|
||||
path: status
|
||||
retention-days: 1
|
||||
|
||||
@@ -535,10 +569,10 @@ jobs:
|
||||
test-compat:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
if: ${{github.event_name == 'pull_request'}}
|
||||
# checkout the current pr target into lfsp
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
if: ${{github.event_name == 'pull_request'}}
|
||||
with:
|
||||
ref: ${{github.event.pull_request.base.ref}}
|
||||
@@ -572,7 +606,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{!endsWith(github.ref, '-prefix')}}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- name: install
|
||||
run: |
|
||||
# need a few things
|
||||
@@ -582,7 +616,7 @@ jobs:
|
||||
gcc --version
|
||||
python3 --version
|
||||
fusermount -V
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
repository: littlefs-project/littlefs-fuse
|
||||
ref: v2
|
||||
@@ -622,7 +656,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{!endsWith(github.ref, '-prefix')}}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
- name: install
|
||||
run: |
|
||||
# need a few things
|
||||
@@ -632,12 +666,12 @@ jobs:
|
||||
gcc --version
|
||||
python3 --version
|
||||
fusermount -V
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
repository: littlefs-project/littlefs-fuse
|
||||
ref: v2
|
||||
path: v2
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
repository: littlefs-project/littlefs-fuse
|
||||
ref: v1
|
||||
@@ -694,7 +728,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [test, bench]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v4
|
||||
if: ${{github.event_name == 'pull_request'}}
|
||||
- name: install
|
||||
if: ${{github.event_name == 'pull_request'}}
|
||||
@@ -704,23 +738,26 @@ jobs:
|
||||
pip3 install toml
|
||||
gcc --version
|
||||
python3 --version
|
||||
- uses: actions/download-artifact@v2
|
||||
- uses: actions/download-artifact@v4
|
||||
if: ${{github.event_name == 'pull_request'}}
|
||||
continue-on-error: true
|
||||
with:
|
||||
name: sizes
|
||||
pattern: '{sizes,sizes-*}'
|
||||
merge-multiple: true
|
||||
path: sizes
|
||||
- uses: actions/download-artifact@v2
|
||||
- uses: actions/download-artifact@v4
|
||||
if: ${{github.event_name == 'pull_request'}}
|
||||
continue-on-error: true
|
||||
with:
|
||||
name: cov
|
||||
pattern: '{cov,cov-*}'
|
||||
merge-multiple: true
|
||||
path: cov
|
||||
- uses: actions/download-artifact@v2
|
||||
- uses: actions/download-artifact@v4
|
||||
if: ${{github.event_name == 'pull_request'}}
|
||||
continue-on-error: true
|
||||
with:
|
||||
name: bench
|
||||
pattern: '{bench,bench-*}'
|
||||
merge-multiple: true
|
||||
path: bench
|
||||
|
||||
# try to find results from tests
|
||||
@@ -862,7 +899,7 @@ jobs:
|
||||
body: $comment,
|
||||
}' | tee comment/comment.json
|
||||
- name: upload-comment
|
||||
uses: actions/upload-artifact@v2
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: comment
|
||||
path: comment
|
||||
|
||||
12
Makefile
12
Makefile
@@ -18,6 +18,12 @@ VALGRIND ?= valgrind
|
||||
GDB ?= gdb
|
||||
PERF ?= perf
|
||||
|
||||
# guess clang or gcc (clang sometimes masquerades as gcc because of
|
||||
# course it does)
|
||||
ifneq ($(shell $(CC) --version | grep clang),)
|
||||
NO_GCC = 1
|
||||
endif
|
||||
|
||||
SRC ?= $(filter-out $(wildcard *.t.* *.b.*),$(wildcard *.c))
|
||||
OBJ := $(SRC:%.c=$(BUILDDIR)/%.o)
|
||||
DEP := $(SRC:%.c=$(BUILDDIR)/%.d)
|
||||
@@ -59,12 +65,15 @@ BENCH_PERF := $(BENCH_RUNNER:%=%.perf)
|
||||
BENCH_TRACE := $(BENCH_RUNNER:%=%.trace)
|
||||
BENCH_CSV := $(BENCH_RUNNER:%=%.csv)
|
||||
|
||||
CFLAGS += -fcallgraph-info=su
|
||||
CFLAGS += -g3
|
||||
CFLAGS += -I.
|
||||
CFLAGS += -std=c99 -Wall -Wextra -pedantic
|
||||
CFLAGS += -Wmissing-prototypes
|
||||
ifndef NO_GCC
|
||||
CFLAGS += -fcallgraph-info=su
|
||||
CFLAGS += -ftrack-macro-expansion=0
|
||||
endif
|
||||
|
||||
ifdef DEBUG
|
||||
CFLAGS += -O0
|
||||
else
|
||||
@@ -466,6 +475,7 @@ benchmarks-diff: $(BENCH_CSV)
|
||||
# rules
|
||||
-include $(DEP)
|
||||
-include $(TEST_DEP)
|
||||
-include $(BENCH_DEP)
|
||||
.SUFFIXES:
|
||||
.SECONDARY:
|
||||
|
||||
|
||||
87
README.md
87
README.md
@@ -199,6 +199,47 @@ The tests assume a Linux environment and can be started with make:
|
||||
make test
|
||||
```
|
||||
|
||||
Tests are implemented in C in the .toml files found in the `tests` directory.
|
||||
When developing a feature or fixing a bug, it is frequently useful to run a
|
||||
single test case or suite of tests:
|
||||
|
||||
``` bash
|
||||
./scripts/test.py -l runners/test_runner # list available test suites
|
||||
./scripts/test.py -L runners/test_runner test_dirs # list available test cases
|
||||
./scripts/test.py runners/test_runner test_dirs # run a specific test suite
|
||||
```
|
||||
|
||||
If an assert fails in a test, test.py will try to print information about the
|
||||
failure:
|
||||
|
||||
``` bash
|
||||
tests/test_dirs.toml:1:failure: test_dirs_root:1g12gg2 (PROG_SIZE=16, ERASE_SIZE=512) failed
|
||||
tests/test_dirs.toml:5:assert: assert failed with 0, expected eq 42
|
||||
lfs_mount(&lfs, cfg) => 42;
|
||||
```
|
||||
|
||||
This includes the test id, which can be passed to test.py to run only that
|
||||
specific test permutation:
|
||||
|
||||
``` bash
|
||||
./scripts/test.py runners/test_runner test_dirs_root:1g12gg2 # run a specific test permutation
|
||||
./scripts/test.py runners/test_runner test_dirs_root:1g12gg2 --gdb # drop into gdb on failure
|
||||
```
|
||||
|
||||
Some other flags that may be useful:
|
||||
|
||||
```bash
|
||||
./scripts/test.py runners/test_runner -b -j # run tests in parallel
|
||||
./scripts/test.py runners/test_runner -v -O- # redirect stdout to stdout
|
||||
./scripts/test.py runners/test_runner -ddisk # capture resulting disk image
|
||||
```
|
||||
|
||||
See `-h/--help` for a full list of available flags:
|
||||
|
||||
``` bash
|
||||
./scripts/test.py --help
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
The littlefs is provided under the [BSD-3-Clause] license. See
|
||||
@@ -231,11 +272,31 @@ License Identifiers that are here available: http://spdx.org/licenses/
|
||||
to use littlefs in a Rust-friendly API, reaping the benefits of Rust's memory
|
||||
safety and other guarantees.
|
||||
|
||||
- [nim-littlefs] - A Nim wrapper and API for littlefs. Includes a fuse
|
||||
implementation based on [littlefs-fuse]
|
||||
|
||||
- [chamelon] - A pure-OCaml implementation of (most of) littlefs, designed for
|
||||
use with the MirageOS library operating system project. It is interoperable
|
||||
with the reference implementation, with some caveats.
|
||||
|
||||
- [littlefs-disk-img-viewer] - A memory-efficient web application for viewing
|
||||
littlefs disk images in your web browser.
|
||||
|
||||
- [mklfs] - A command line tool built by the [Lua RTOS] guys for making
|
||||
littlefs images from a host PC. Supports Windows, Mac OS, and Linux.
|
||||
- [mklfs] - A command line tool for creating littlefs images. Used in the Lua
|
||||
RTOS ecosystem.
|
||||
|
||||
- [mklittlefs] - A command line tool for creating littlefs images. Used in the
|
||||
ESP8266 and RP2040 ecosystem.
|
||||
|
||||
- [pico-littlefs-usb] - An interface for littlefs that emulates a FAT12
|
||||
filesystem over USB. Allows mounting littlefs on a host PC without additional
|
||||
drivers.
|
||||
|
||||
- [ramcrc32bd] - An example block device using littlefs's 32-bit CRC for
|
||||
error-correction.
|
||||
|
||||
- [ramrsbd] - An example block device using Reed-Solomon codes for
|
||||
error-correction.
|
||||
|
||||
- [Mbed OS] - The easiest way to get started with littlefs is to jump into Mbed
|
||||
which already has block device drivers for most forms of embedded storage.
|
||||
@@ -254,27 +315,23 @@ License Identifiers that are here available: http://spdx.org/licenses/
|
||||
for microcontroller-scale devices. Due to limitations of FAT it can't provide
|
||||
power-loss resilience, but it does allow easy interop with PCs.
|
||||
|
||||
- [chamelon] - A pure-OCaml implementation of (most of) littlefs, designed for
|
||||
use with the MirageOS library operating system project. It is interoperable
|
||||
with the reference implementation, with some caveats.
|
||||
|
||||
- [nim-littlefs] - A Nim wrapper and API for littlefs. Includes a fuse
|
||||
implementation based on [littlefs-fuse]
|
||||
|
||||
[BSD-3-Clause]: https://spdx.org/licenses/BSD-3-Clause.html
|
||||
[littlefs-disk-img-viewer]: https://github.com/tniessen/littlefs-disk-img-viewer
|
||||
[littlefs-fuse]: https://github.com/geky/littlefs-fuse
|
||||
[FUSE]: https://github.com/libfuse/libfuse
|
||||
[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/
|
||||
[littlefs2-rust]: https://crates.io/crates/littlefs2
|
||||
[nim-littlefs]: https://github.com/Graveflo/nim-littlefs
|
||||
[chamelon]: https://github.com/yomimono/chamelon
|
||||
[littlefs-disk-img-viewer]: https://github.com/tniessen/littlefs-disk-img-viewer
|
||||
[mklfs]: https://github.com/whitecatboard/Lua-RTOS-ESP32/tree/master/components/mklfs/src
|
||||
[Lua RTOS]: https://github.com/whitecatboard/Lua-RTOS-ESP32
|
||||
[mklittlefs]: https://github.com/earlephilhower/mklittlefs
|
||||
[pico-littlefs-usb]: https://github.com/oyama/pico-littlefs-usb
|
||||
[ramcrc32bd]: https://github.com/geky/ramcrc32bd
|
||||
[ramrsbd]: https://github.com/geky/ramrsbd
|
||||
[Mbed OS]: https://github.com/armmbed/mbed-os
|
||||
[LittleFileSystem]: https://os.mbed.com/docs/mbed-os/latest/apis/littlefilesystem.html
|
||||
[SPIFFS]: https://github.com/pellepl/spiffs
|
||||
[Dhara]: https://github.com/dlbeer/dhara
|
||||
[ChaN's FatFs]: http://elm-chan.org/fsw/ff/00index_e.html
|
||||
[littlefs-python]: https://pypi.org/project/littlefs-python/
|
||||
[littlefs2-rust]: https://crates.io/crates/littlefs2
|
||||
[chamelon]: https://github.com/yomimono/chamelon
|
||||
[nim-littlefs]: https://github.com/Graveflo/nim-littlefs
|
||||
|
||||
@@ -133,7 +133,7 @@ int lfs_filebd_prog(const struct lfs_config *cfg, lfs_block_t block,
|
||||
|
||||
int lfs_filebd_erase(const struct lfs_config *cfg, lfs_block_t block) {
|
||||
LFS_FILEBD_TRACE("lfs_filebd_erase(%p, 0x%"PRIx32" (%"PRIu32"))",
|
||||
(void*)cfg, block, ((lfs_file_t*)cfg->context)->cfg->erase_size);
|
||||
(void*)cfg, block, ((lfs_filebd_t*)cfg->context)->cfg->erase_size);
|
||||
lfs_filebd_t *bd = cfg->context;
|
||||
|
||||
// check if erase is valid
|
||||
|
||||
377
lfs.c
377
lfs.c
@@ -282,6 +282,21 @@ static int lfs_bd_erase(lfs_t *lfs, lfs_block_t block) {
|
||||
|
||||
|
||||
/// Small type-level utilities ///
|
||||
|
||||
// some operations on paths
|
||||
static inline lfs_size_t lfs_path_namelen(const char *path) {
|
||||
return strcspn(path, "/");
|
||||
}
|
||||
|
||||
static inline bool lfs_path_islast(const char *path) {
|
||||
lfs_size_t namelen = lfs_path_namelen(path);
|
||||
return path[namelen + strspn(path + namelen, "/")] == '\0';
|
||||
}
|
||||
|
||||
static inline bool lfs_path_isdir(const char *path) {
|
||||
return path[lfs_path_namelen(path)] != '\0';
|
||||
}
|
||||
|
||||
// operations on block pairs
|
||||
static inline void lfs_pair_swap(lfs_block_t pair[2]) {
|
||||
lfs_block_t t = pair[0];
|
||||
@@ -389,18 +404,15 @@ struct lfs_diskoff {
|
||||
|
||||
// operations on global state
|
||||
static inline void lfs_gstate_xor(lfs_gstate_t *a, const lfs_gstate_t *b) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
((uint32_t*)a)[i] ^= ((const uint32_t*)b)[i];
|
||||
}
|
||||
a->tag ^= b->tag;
|
||||
a->pair[0] ^= b->pair[0];
|
||||
a->pair[1] ^= b->pair[1];
|
||||
}
|
||||
|
||||
static inline bool lfs_gstate_iszero(const lfs_gstate_t *a) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (((uint32_t*)a)[i] != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return a->tag == 0
|
||||
&& a->pair[0] == 0
|
||||
&& a->pair[1] == 0;
|
||||
}
|
||||
|
||||
#ifndef LFS_READONLY
|
||||
@@ -688,7 +700,7 @@ static int lfs_alloc(lfs_t *lfs, lfs_block_t *block) {
|
||||
if (lfs->lookahead.ckpoint <= 0) {
|
||||
LFS_ERROR("No more free space 0x%"PRIx32,
|
||||
(lfs->lookahead.start + lfs->lookahead.next)
|
||||
% lfs->cfg->block_count);
|
||||
% lfs->block_count);
|
||||
return LFS_ERR_NOSPC;
|
||||
}
|
||||
|
||||
@@ -816,9 +828,6 @@ static int lfs_dir_getread(lfs_t *lfs, const lfs_mdir_t *dir,
|
||||
size -= diff;
|
||||
continue;
|
||||
}
|
||||
|
||||
// rcache takes priority
|
||||
diff = lfs_min(diff, rcache->off-off);
|
||||
}
|
||||
|
||||
// load to cache, first condition can no longer fail
|
||||
@@ -1461,32 +1470,46 @@ static int lfs_dir_find_match(void *data,
|
||||
return LFS_CMP_EQ;
|
||||
}
|
||||
|
||||
// lfs_dir_find tries to set path and id even if file is not found
|
||||
//
|
||||
// returns:
|
||||
// - 0 if file is found
|
||||
// - LFS_ERR_NOENT if file or parent is not found
|
||||
// - LFS_ERR_NOTDIR if parent is not a dir
|
||||
static lfs_stag_t lfs_dir_find(lfs_t *lfs, lfs_mdir_t *dir,
|
||||
const char **path, uint16_t *id) {
|
||||
// we reduce path to a single name if we can find it
|
||||
const char *name = *path;
|
||||
if (id) {
|
||||
*id = 0x3ff;
|
||||
}
|
||||
|
||||
// default to root dir
|
||||
lfs_stag_t tag = LFS_MKTAG(LFS_TYPE_DIR, 0x3ff, 0);
|
||||
dir->tail[0] = lfs->root[0];
|
||||
dir->tail[1] = lfs->root[1];
|
||||
|
||||
// empty paths are not allowed
|
||||
if (*name == '\0') {
|
||||
return LFS_ERR_INVAL;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
nextname:
|
||||
// skip slashes
|
||||
name += strspn(name, "/");
|
||||
// skip slashes if we're a directory
|
||||
if (lfs_tag_type3(tag) == LFS_TYPE_DIR) {
|
||||
name += strspn(name, "/");
|
||||
}
|
||||
lfs_size_t namelen = strcspn(name, "/");
|
||||
|
||||
// skip '.' and root '..'
|
||||
if ((namelen == 1 && memcmp(name, ".", 1) == 0) ||
|
||||
(namelen == 2 && memcmp(name, "..", 2) == 0)) {
|
||||
// skip '.'
|
||||
if (namelen == 1 && memcmp(name, ".", 1) == 0) {
|
||||
name += namelen;
|
||||
goto nextname;
|
||||
}
|
||||
|
||||
// error on unmatched '..', trying to go above root?
|
||||
if (namelen == 2 && memcmp(name, "..", 2) == 0) {
|
||||
return LFS_ERR_INVAL;
|
||||
}
|
||||
|
||||
// skip if matched by '..' in name
|
||||
const char *suffix = name + namelen;
|
||||
lfs_size_t sufflen;
|
||||
@@ -1498,7 +1521,9 @@ nextname:
|
||||
break;
|
||||
}
|
||||
|
||||
if (sufflen == 2 && memcmp(suffix, "..", 2) == 0) {
|
||||
if (sufflen == 1 && memcmp(suffix, ".", 1) == 0) {
|
||||
// noop
|
||||
} else if (sufflen == 2 && memcmp(suffix, "..", 2) == 0) {
|
||||
depth -= 1;
|
||||
if (depth == 0) {
|
||||
name = suffix + sufflen;
|
||||
@@ -1512,14 +1537,14 @@ nextname:
|
||||
}
|
||||
|
||||
// found path
|
||||
if (name[0] == '\0') {
|
||||
if (*name == '\0') {
|
||||
return tag;
|
||||
}
|
||||
|
||||
// update what we've found so far
|
||||
*path = name;
|
||||
|
||||
// only continue if we hit a directory
|
||||
// only continue if we're a directory
|
||||
if (lfs_tag_type3(tag) != LFS_TYPE_DIR) {
|
||||
return LFS_ERR_NOTDIR;
|
||||
}
|
||||
@@ -1539,8 +1564,7 @@ nextname:
|
||||
tag = lfs_dir_fetchmatch(lfs, dir, dir->tail,
|
||||
LFS_MKTAG(0x780, 0, 0),
|
||||
LFS_MKTAG(LFS_TYPE_NAME, 0, namelen),
|
||||
// are we last name?
|
||||
(strchr(name, '/') == NULL) ? id : NULL,
|
||||
id,
|
||||
lfs_dir_find_match, &(struct lfs_dir_find_match){
|
||||
lfs, name, namelen});
|
||||
if (tag < 0) {
|
||||
@@ -2128,13 +2152,14 @@ static int lfs_dir_splittingcompact(lfs_t *lfs, lfs_mdir_t *dir,
|
||||
// And we cap at half a block to avoid degenerate cases with
|
||||
// nearly-full metadata blocks.
|
||||
//
|
||||
lfs_size_t metadata_max = (lfs->cfg->metadata_max)
|
||||
? lfs->cfg->metadata_max
|
||||
: lfs->cfg->block_size;
|
||||
if (end - split < 0xff
|
||||
&& size <= lfs_min(
|
||||
lfs->cfg->block_size - 40,
|
||||
metadata_max - 40,
|
||||
lfs_alignup(
|
||||
(lfs->cfg->metadata_max
|
||||
? lfs->cfg->metadata_max
|
||||
: lfs->cfg->block_size)/2,
|
||||
metadata_max/2,
|
||||
lfs->cfg->prog_size))) {
|
||||
break;
|
||||
}
|
||||
@@ -2338,7 +2363,8 @@ fixmlist:;
|
||||
if (d->m.pair != pair) {
|
||||
for (int i = 0; i < attrcount; i++) {
|
||||
if (lfs_tag_type3(attrs[i].tag) == LFS_TYPE_DELETE &&
|
||||
d->id == lfs_tag_id(attrs[i].tag)) {
|
||||
d->id == lfs_tag_id(attrs[i].tag) &&
|
||||
d->type != LFS_TYPE_DIR) {
|
||||
d->m.pair[0] = LFS_BLOCK_NULL;
|
||||
d->m.pair[1] = LFS_BLOCK_NULL;
|
||||
} else if (lfs_tag_type3(attrs[i].tag) == LFS_TYPE_DELETE &&
|
||||
@@ -2527,7 +2553,7 @@ static int lfs_dir_orphaningcommit(lfs_t *lfs, lfs_mdir_t *dir,
|
||||
if (err != LFS_ERR_NOENT) {
|
||||
if (lfs_gstate_hasorphans(&lfs->gstate)) {
|
||||
// next step, clean up orphans
|
||||
err = lfs_fs_preporphans(lfs, -hasparent);
|
||||
err = lfs_fs_preporphans(lfs, -(int8_t)hasparent);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
@@ -2603,12 +2629,12 @@ static int lfs_mkdir_(lfs_t *lfs, const char *path) {
|
||||
cwd.next = lfs->mlist;
|
||||
uint16_t id;
|
||||
err = lfs_dir_find(lfs, &cwd.m, &path, &id);
|
||||
if (!(err == LFS_ERR_NOENT && id != 0x3ff)) {
|
||||
if (!(err == LFS_ERR_NOENT && lfs_path_islast(path))) {
|
||||
return (err < 0) ? err : LFS_ERR_EXIST;
|
||||
}
|
||||
|
||||
// check that name fits
|
||||
lfs_size_t nlen = strlen(path);
|
||||
lfs_size_t nlen = lfs_path_namelen(path);
|
||||
if (nlen > lfs->name_max) {
|
||||
return LFS_ERR_NAMETOOLONG;
|
||||
}
|
||||
@@ -3057,7 +3083,7 @@ static int lfs_file_opencfg_(lfs_t *lfs, lfs_file_t *file,
|
||||
|
||||
// allocate entry for file if it doesn't exist
|
||||
lfs_stag_t tag = lfs_dir_find(lfs, &file->m, &path, &file->id);
|
||||
if (tag < 0 && !(tag == LFS_ERR_NOENT && file->id != 0x3ff)) {
|
||||
if (tag < 0 && !(tag == LFS_ERR_NOENT && lfs_path_islast(path))) {
|
||||
err = tag;
|
||||
goto cleanup;
|
||||
}
|
||||
@@ -3077,8 +3103,14 @@ static int lfs_file_opencfg_(lfs_t *lfs, lfs_file_t *file,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// don't allow trailing slashes
|
||||
if (lfs_path_isdir(path)) {
|
||||
err = LFS_ERR_NOTDIR;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// check that name fits
|
||||
lfs_size_t nlen = strlen(path);
|
||||
lfs_size_t nlen = lfs_path_namelen(path);
|
||||
if (nlen > lfs->name_max) {
|
||||
err = LFS_ERR_NAMETOOLONG;
|
||||
goto cleanup;
|
||||
@@ -3664,22 +3696,16 @@ static lfs_ssize_t lfs_file_write_(lfs_t *lfs, lfs_file_t *file,
|
||||
static lfs_soff_t lfs_file_seek_(lfs_t *lfs, lfs_file_t *file,
|
||||
lfs_soff_t off, int whence) {
|
||||
// find new pos
|
||||
//
|
||||
// fortunately for us, littlefs is limited to 31-bit file sizes, so we
|
||||
// don't have to worry too much about integer overflow
|
||||
lfs_off_t npos = file->pos;
|
||||
if (whence == LFS_SEEK_SET) {
|
||||
npos = off;
|
||||
} else if (whence == LFS_SEEK_CUR) {
|
||||
if ((lfs_soff_t)file->pos + off < 0) {
|
||||
return LFS_ERR_INVAL;
|
||||
} else {
|
||||
npos = file->pos + off;
|
||||
}
|
||||
npos = file->pos + (lfs_off_t)off;
|
||||
} else if (whence == LFS_SEEK_END) {
|
||||
lfs_soff_t res = lfs_file_size_(lfs, file) + off;
|
||||
if (res < 0) {
|
||||
return LFS_ERR_INVAL;
|
||||
} else {
|
||||
npos = res;
|
||||
}
|
||||
npos = (lfs_off_t)lfs_file_size_(lfs, file) + (lfs_off_t)off;
|
||||
}
|
||||
|
||||
if (npos > lfs->file_max) {
|
||||
@@ -3694,13 +3720,8 @@ static lfs_soff_t lfs_file_seek_(lfs_t *lfs, lfs_file_t *file,
|
||||
|
||||
// if we're only reading and our new offset is still in the file's cache
|
||||
// we can avoid flushing and needing to reread the data
|
||||
if (
|
||||
#ifndef LFS_READONLY
|
||||
!(file->flags & LFS_F_WRITING)
|
||||
#else
|
||||
true
|
||||
#endif
|
||||
) {
|
||||
if ((file->flags & LFS_F_READING)
|
||||
&& file->off != lfs->cfg->block_size) {
|
||||
int oindex = lfs_ctz_index(lfs, &(lfs_off_t){file->pos});
|
||||
lfs_off_t noff = npos;
|
||||
int nindex = lfs_ctz_index(lfs, &noff);
|
||||
@@ -3842,6 +3863,12 @@ static int lfs_stat_(lfs_t *lfs, const char *path, struct lfs_info *info) {
|
||||
return (int)tag;
|
||||
}
|
||||
|
||||
// only allow trailing slashes on dirs
|
||||
if (strchr(path, '/') != NULL
|
||||
&& lfs_tag_type3(tag) != LFS_TYPE_DIR) {
|
||||
return LFS_ERR_NOTDIR;
|
||||
}
|
||||
|
||||
return lfs_dir_getinfo(lfs, &cwd, lfs_tag_id(tag), info);
|
||||
}
|
||||
|
||||
@@ -3902,7 +3929,9 @@ static int lfs_remove_(lfs_t *lfs, const char *path) {
|
||||
}
|
||||
|
||||
lfs->mlist = dir.next;
|
||||
if (lfs_tag_type3(tag) == LFS_TYPE_DIR) {
|
||||
if (lfs_gstate_hasorphans(&lfs->gstate)) {
|
||||
LFS_ASSERT(lfs_tag_type3(tag) == LFS_TYPE_DIR);
|
||||
|
||||
// fix orphan
|
||||
err = lfs_fs_preporphans(lfs, -1);
|
||||
if (err) {
|
||||
@@ -3944,7 +3973,7 @@ static int lfs_rename_(lfs_t *lfs, const char *oldpath, const char *newpath) {
|
||||
uint16_t newid;
|
||||
lfs_stag_t prevtag = lfs_dir_find(lfs, &newcwd, &newpath, &newid);
|
||||
if ((prevtag < 0 || lfs_tag_id(prevtag) == 0x3ff) &&
|
||||
!(prevtag == LFS_ERR_NOENT && newid != 0x3ff)) {
|
||||
!(prevtag == LFS_ERR_NOENT && lfs_path_islast(newpath))) {
|
||||
return (prevtag < 0) ? (int)prevtag : LFS_ERR_INVAL;
|
||||
}
|
||||
|
||||
@@ -3955,8 +3984,14 @@ static int lfs_rename_(lfs_t *lfs, const char *oldpath, const char *newpath) {
|
||||
struct lfs_mlist prevdir;
|
||||
prevdir.next = lfs->mlist;
|
||||
if (prevtag == LFS_ERR_NOENT) {
|
||||
// if we're a file, don't allow trailing slashes
|
||||
if (lfs_path_isdir(newpath)
|
||||
&& lfs_tag_type3(oldtag) != LFS_TYPE_DIR) {
|
||||
return LFS_ERR_NOTDIR;
|
||||
}
|
||||
|
||||
// check that name fits
|
||||
lfs_size_t nlen = strlen(newpath);
|
||||
lfs_size_t nlen = lfs_path_namelen(newpath);
|
||||
if (nlen > lfs->name_max) {
|
||||
return LFS_ERR_NAMETOOLONG;
|
||||
}
|
||||
@@ -4016,7 +4051,8 @@ static int lfs_rename_(lfs_t *lfs, const char *oldpath, const char *newpath) {
|
||||
{LFS_MKTAG_IF(prevtag != LFS_ERR_NOENT,
|
||||
LFS_TYPE_DELETE, newid, 0), NULL},
|
||||
{LFS_MKTAG(LFS_TYPE_CREATE, newid, 0), NULL},
|
||||
{LFS_MKTAG(lfs_tag_type3(oldtag), newid, strlen(newpath)), newpath},
|
||||
{LFS_MKTAG(lfs_tag_type3(oldtag),
|
||||
newid, lfs_path_namelen(newpath)), newpath},
|
||||
{LFS_MKTAG(LFS_FROM_MOVE, newid, lfs_tag_id(oldtag)), &oldcwd},
|
||||
{LFS_MKTAG_IF(samepair,
|
||||
LFS_TYPE_DELETE, newoldid, 0), NULL}));
|
||||
@@ -4039,8 +4075,10 @@ static int lfs_rename_(lfs_t *lfs, const char *oldpath, const char *newpath) {
|
||||
}
|
||||
|
||||
lfs->mlist = prevdir.next;
|
||||
if (prevtag != LFS_ERR_NOENT
|
||||
&& lfs_tag_type3(prevtag) == LFS_TYPE_DIR) {
|
||||
if (lfs_gstate_hasorphans(&lfs->gstate)) {
|
||||
LFS_ASSERT(prevtag != LFS_ERR_NOENT
|
||||
&& lfs_tag_type3(prevtag) == LFS_TYPE_DIR);
|
||||
|
||||
// fix orphan
|
||||
err = lfs_fs_preporphans(lfs, -1);
|
||||
if (err) {
|
||||
@@ -4173,6 +4211,14 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
// which littlefs currently does not support
|
||||
LFS_ASSERT((bool)0x80000000);
|
||||
|
||||
// check that the required io functions are provided
|
||||
LFS_ASSERT(lfs->cfg->read != NULL);
|
||||
#ifndef LFS_READONLY
|
||||
LFS_ASSERT(lfs->cfg->prog != NULL);
|
||||
LFS_ASSERT(lfs->cfg->erase != NULL);
|
||||
LFS_ASSERT(lfs->cfg->sync != NULL);
|
||||
#endif
|
||||
|
||||
// validate that the lfs-cfg sizes were initiated properly before
|
||||
// performing any arithmetic logics with them
|
||||
LFS_ASSERT(lfs->cfg->read_size != 0);
|
||||
@@ -4209,6 +4255,15 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
LFS_ASSERT(lfs->cfg->compact_thresh == (lfs_size_t)-1
|
||||
|| lfs->cfg->compact_thresh <= lfs->cfg->block_size);
|
||||
|
||||
// check that metadata_max is a multiple of read_size and prog_size,
|
||||
// and a factor of the block_size
|
||||
LFS_ASSERT(!lfs->cfg->metadata_max
|
||||
|| lfs->cfg->metadata_max % lfs->cfg->read_size == 0);
|
||||
LFS_ASSERT(!lfs->cfg->metadata_max
|
||||
|| lfs->cfg->metadata_max % lfs->cfg->prog_size == 0);
|
||||
LFS_ASSERT(!lfs->cfg->metadata_max
|
||||
|| lfs->cfg->block_size % lfs->cfg->metadata_max == 0);
|
||||
|
||||
// setup read cache
|
||||
if (lfs->cfg->read_buffer) {
|
||||
lfs->rcache.buffer = lfs->cfg->read_buffer;
|
||||
@@ -4396,6 +4451,30 @@ cleanup:
|
||||
}
|
||||
#endif
|
||||
|
||||
struct lfs_tortoise_t {
|
||||
lfs_block_t pair[2];
|
||||
lfs_size_t i;
|
||||
lfs_size_t period;
|
||||
};
|
||||
|
||||
static int lfs_tortoise_detectcycles(
|
||||
const lfs_mdir_t *dir, struct lfs_tortoise_t *tortoise) {
|
||||
// detect cycles with Brent's algorithm
|
||||
if (lfs_pair_issync(dir->tail, tortoise->pair)) {
|
||||
LFS_WARN("Cycle detected in tail list");
|
||||
return LFS_ERR_CORRUPT;
|
||||
}
|
||||
if (tortoise->i == tortoise->period) {
|
||||
tortoise->pair[0] = dir->tail[0];
|
||||
tortoise->pair[1] = dir->tail[1];
|
||||
tortoise->i = 0;
|
||||
tortoise->period *= 2;
|
||||
}
|
||||
tortoise->i += 1;
|
||||
|
||||
return LFS_ERR_OK;
|
||||
}
|
||||
|
||||
static int lfs_mount_(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
int err = lfs_init(lfs, cfg);
|
||||
if (err) {
|
||||
@@ -4404,23 +4483,16 @@ static int lfs_mount_(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
|
||||
// scan directory blocks for superblock and any global updates
|
||||
lfs_mdir_t dir = {.tail = {0, 1}};
|
||||
lfs_block_t tortoise[2] = {LFS_BLOCK_NULL, LFS_BLOCK_NULL};
|
||||
lfs_size_t tortoise_i = 1;
|
||||
lfs_size_t tortoise_period = 1;
|
||||
struct lfs_tortoise_t tortoise = {
|
||||
.pair = {LFS_BLOCK_NULL, LFS_BLOCK_NULL},
|
||||
.i = 1,
|
||||
.period = 1,
|
||||
};
|
||||
while (!lfs_pair_isnull(dir.tail)) {
|
||||
// detect cycles with Brent's algorithm
|
||||
if (lfs_pair_issync(dir.tail, tortoise)) {
|
||||
LFS_WARN("Cycle detected in tail list");
|
||||
err = LFS_ERR_CORRUPT;
|
||||
err = lfs_tortoise_detectcycles(&dir, &tortoise);
|
||||
if (err < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
if (tortoise_i == tortoise_period) {
|
||||
tortoise[0] = dir.tail[0];
|
||||
tortoise[1] = dir.tail[1];
|
||||
tortoise_i = 0;
|
||||
tortoise_period *= 2;
|
||||
}
|
||||
tortoise_i += 1;
|
||||
|
||||
// fetch next block in tail list
|
||||
lfs_stag_t tag = lfs_dir_fetchmatch(lfs, &dir, dir.tail,
|
||||
@@ -4633,22 +4705,17 @@ int lfs_fs_traverse_(lfs_t *lfs,
|
||||
}
|
||||
#endif
|
||||
|
||||
lfs_block_t tortoise[2] = {LFS_BLOCK_NULL, LFS_BLOCK_NULL};
|
||||
lfs_size_t tortoise_i = 1;
|
||||
lfs_size_t tortoise_period = 1;
|
||||
struct lfs_tortoise_t tortoise = {
|
||||
.pair = {LFS_BLOCK_NULL, LFS_BLOCK_NULL},
|
||||
.i = 1,
|
||||
.period = 1,
|
||||
};
|
||||
int err = LFS_ERR_OK;
|
||||
while (!lfs_pair_isnull(dir.tail)) {
|
||||
// detect cycles with Brent's algorithm
|
||||
if (lfs_pair_issync(dir.tail, tortoise)) {
|
||||
LFS_WARN("Cycle detected in tail list");
|
||||
err = lfs_tortoise_detectcycles(&dir, &tortoise);
|
||||
if (err < 0) {
|
||||
return LFS_ERR_CORRUPT;
|
||||
}
|
||||
if (tortoise_i == tortoise_period) {
|
||||
tortoise[0] = dir.tail[0];
|
||||
tortoise[1] = dir.tail[1];
|
||||
tortoise_i = 0;
|
||||
tortoise_period *= 2;
|
||||
}
|
||||
tortoise_i += 1;
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
int err = cb(data, dir.tail[i]);
|
||||
@@ -4727,22 +4794,17 @@ static int lfs_fs_pred(lfs_t *lfs,
|
||||
// iterate over all directory directory entries
|
||||
pdir->tail[0] = 0;
|
||||
pdir->tail[1] = 1;
|
||||
lfs_block_t tortoise[2] = {LFS_BLOCK_NULL, LFS_BLOCK_NULL};
|
||||
lfs_size_t tortoise_i = 1;
|
||||
lfs_size_t tortoise_period = 1;
|
||||
struct lfs_tortoise_t tortoise = {
|
||||
.pair = {LFS_BLOCK_NULL, LFS_BLOCK_NULL},
|
||||
.i = 1,
|
||||
.period = 1,
|
||||
};
|
||||
int err = LFS_ERR_OK;
|
||||
while (!lfs_pair_isnull(pdir->tail)) {
|
||||
// detect cycles with Brent's algorithm
|
||||
if (lfs_pair_issync(pdir->tail, tortoise)) {
|
||||
LFS_WARN("Cycle detected in tail list");
|
||||
err = lfs_tortoise_detectcycles(pdir, &tortoise);
|
||||
if (err < 0) {
|
||||
return LFS_ERR_CORRUPT;
|
||||
}
|
||||
if (tortoise_i == tortoise_period) {
|
||||
tortoise[0] = pdir->tail[0];
|
||||
tortoise[1] = pdir->tail[1];
|
||||
tortoise_i = 0;
|
||||
tortoise_period *= 2;
|
||||
}
|
||||
tortoise_i += 1;
|
||||
|
||||
if (lfs_pair_cmp(pdir->tail, pair) == 0) {
|
||||
return 0;
|
||||
@@ -4792,22 +4854,17 @@ static lfs_stag_t lfs_fs_parent(lfs_t *lfs, const lfs_block_t pair[2],
|
||||
// use fetchmatch with callback to find pairs
|
||||
parent->tail[0] = 0;
|
||||
parent->tail[1] = 1;
|
||||
lfs_block_t tortoise[2] = {LFS_BLOCK_NULL, LFS_BLOCK_NULL};
|
||||
lfs_size_t tortoise_i = 1;
|
||||
lfs_size_t tortoise_period = 1;
|
||||
struct lfs_tortoise_t tortoise = {
|
||||
.pair = {LFS_BLOCK_NULL, LFS_BLOCK_NULL},
|
||||
.i = 1,
|
||||
.period = 1,
|
||||
};
|
||||
int err = LFS_ERR_OK;
|
||||
while (!lfs_pair_isnull(parent->tail)) {
|
||||
// detect cycles with Brent's algorithm
|
||||
if (lfs_pair_issync(parent->tail, tortoise)) {
|
||||
LFS_WARN("Cycle detected in tail list");
|
||||
return LFS_ERR_CORRUPT;
|
||||
err = lfs_tortoise_detectcycles(parent, &tortoise);
|
||||
if (err < 0) {
|
||||
return err;
|
||||
}
|
||||
if (tortoise_i == tortoise_period) {
|
||||
tortoise[0] = parent->tail[0];
|
||||
tortoise[1] = parent->tail[1];
|
||||
tortoise_i = 0;
|
||||
tortoise_period *= 2;
|
||||
}
|
||||
tortoise_i += 1;
|
||||
|
||||
lfs_stag_t tag = lfs_dir_fetchmatch(lfs, parent, parent->tail,
|
||||
LFS_MKTAG(0x7ff, 0, 0x3ff),
|
||||
@@ -5165,7 +5222,9 @@ static int lfs_fs_gc_(lfs_t *lfs) {
|
||||
}
|
||||
|
||||
// try to populate the lookahead buffer, unless it's already full
|
||||
if (lfs->lookahead.size < 8*lfs->cfg->lookahead_size) {
|
||||
if (lfs->lookahead.size < lfs_min(
|
||||
8 * lfs->cfg->lookahead_size,
|
||||
lfs->block_count)) {
|
||||
err = lfs_alloc_scan(lfs);
|
||||
if (err) {
|
||||
return err;
|
||||
@@ -5177,40 +5236,64 @@ static int lfs_fs_gc_(lfs_t *lfs) {
|
||||
#endif
|
||||
|
||||
#ifndef LFS_READONLY
|
||||
#ifdef LFS_SHRINKNONRELOCATING
|
||||
static int lfs_shrink_checkblock(void *data, lfs_block_t block) {
|
||||
lfs_size_t threshold = *((lfs_size_t*)data);
|
||||
if (block >= threshold) {
|
||||
return LFS_ERR_NOTEMPTY;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int lfs_fs_grow_(lfs_t *lfs, lfs_size_t block_count) {
|
||||
int err;
|
||||
|
||||
if (block_count == lfs->block_count) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifndef LFS_SHRINKNONRELOCATING
|
||||
// shrinking is not supported
|
||||
LFS_ASSERT(block_count >= lfs->block_count);
|
||||
|
||||
if (block_count > lfs->block_count) {
|
||||
lfs->block_count = block_count;
|
||||
|
||||
// fetch the root
|
||||
lfs_mdir_t root;
|
||||
int err = lfs_dir_fetch(lfs, &root, lfs->root);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// update the superblock
|
||||
lfs_superblock_t superblock;
|
||||
lfs_stag_t tag = lfs_dir_get(lfs, &root, LFS_MKTAG(0x7ff, 0x3ff, 0),
|
||||
LFS_MKTAG(LFS_TYPE_INLINESTRUCT, 0, sizeof(superblock)),
|
||||
&superblock);
|
||||
if (tag < 0) {
|
||||
return tag;
|
||||
}
|
||||
lfs_superblock_fromle32(&superblock);
|
||||
|
||||
superblock.block_count = lfs->block_count;
|
||||
|
||||
lfs_superblock_tole32(&superblock);
|
||||
err = lfs_dir_commit(lfs, &root, LFS_MKATTRS(
|
||||
{tag, &superblock}));
|
||||
#endif
|
||||
#ifdef LFS_SHRINKNONRELOCATING
|
||||
if (block_count < lfs->block_count) {
|
||||
err = lfs_fs_traverse_(lfs, lfs_shrink_checkblock, &block_count, true);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
lfs->block_count = block_count;
|
||||
|
||||
// fetch the root
|
||||
lfs_mdir_t root;
|
||||
err = lfs_dir_fetch(lfs, &root, lfs->root);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// update the superblock
|
||||
lfs_superblock_t superblock;
|
||||
lfs_stag_t tag = lfs_dir_get(lfs, &root, LFS_MKTAG(0x7ff, 0x3ff, 0),
|
||||
LFS_MKTAG(LFS_TYPE_INLINESTRUCT, 0, sizeof(superblock)),
|
||||
&superblock);
|
||||
if (tag < 0) {
|
||||
return tag;
|
||||
}
|
||||
lfs_superblock_fromle32(&superblock);
|
||||
|
||||
superblock.block_count = lfs->block_count;
|
||||
|
||||
lfs_superblock_tole32(&superblock);
|
||||
err = lfs_dir_commit(lfs, &root, LFS_MKATTRS(
|
||||
{tag, &superblock}));
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -5890,7 +5973,7 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
".read=%p, .prog=%p, .erase=%p, .sync=%p, "
|
||||
".read_size=%"PRIu32", .prog_size=%"PRIu32", "
|
||||
".block_size=%"PRIu32", .block_count=%"PRIu32", "
|
||||
".block_cycles=%"PRIu32", .cache_size=%"PRIu32", "
|
||||
".block_cycles=%"PRId32", .cache_size=%"PRIu32", "
|
||||
".lookahead_size=%"PRIu32", .read_buffer=%p, "
|
||||
".prog_buffer=%p, .lookahead_buffer=%p, "
|
||||
".name_max=%"PRIu32", .file_max=%"PRIu32", "
|
||||
@@ -5920,7 +6003,7 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
".read=%p, .prog=%p, .erase=%p, .sync=%p, "
|
||||
".read_size=%"PRIu32", .prog_size=%"PRIu32", "
|
||||
".block_size=%"PRIu32", .block_count=%"PRIu32", "
|
||||
".block_cycles=%"PRIu32", .cache_size=%"PRIu32", "
|
||||
".block_cycles=%"PRId32", .cache_size=%"PRIu32", "
|
||||
".lookahead_size=%"PRIu32", .read_buffer=%p, "
|
||||
".prog_buffer=%p, .lookahead_buffer=%p, "
|
||||
".name_max=%"PRIu32", .file_max=%"PRIu32", "
|
||||
@@ -6057,7 +6140,7 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file, const char *path, int flags) {
|
||||
return err;
|
||||
}
|
||||
LFS_TRACE("lfs_file_open(%p, %p, \"%s\", %x)",
|
||||
(void*)lfs, (void*)file, path, flags);
|
||||
(void*)lfs, (void*)file, path, (unsigned)flags);
|
||||
LFS_ASSERT(!lfs_mlist_isopen(lfs->mlist, (struct lfs_mlist*)file));
|
||||
|
||||
err = lfs_file_open_(lfs, file, path, flags);
|
||||
@@ -6077,7 +6160,7 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
|
||||
}
|
||||
LFS_TRACE("lfs_file_opencfg(%p, %p, \"%s\", %x, %p {"
|
||||
".buffer=%p, .attrs=%p, .attr_count=%"PRIu32"})",
|
||||
(void*)lfs, (void*)file, path, flags,
|
||||
(void*)lfs, (void*)file, path, (unsigned)flags,
|
||||
(void*)cfg, cfg->buffer, (void*)cfg->attrs, cfg->attr_count);
|
||||
LFS_ASSERT(!lfs_mlist_isopen(lfs->mlist, (struct lfs_mlist*)file));
|
||||
|
||||
@@ -6230,7 +6313,7 @@ lfs_soff_t lfs_file_size(lfs_t *lfs, lfs_file_t *file) {
|
||||
|
||||
lfs_soff_t res = lfs_file_size_(lfs, file);
|
||||
|
||||
LFS_TRACE("lfs_file_size -> %"PRId32, res);
|
||||
LFS_TRACE("lfs_file_size -> %"PRIu32, res);
|
||||
LFS_UNLOCK(lfs->cfg);
|
||||
return res;
|
||||
}
|
||||
@@ -6439,7 +6522,7 @@ int lfs_migrate(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
".read=%p, .prog=%p, .erase=%p, .sync=%p, "
|
||||
".read_size=%"PRIu32", .prog_size=%"PRIu32", "
|
||||
".block_size=%"PRIu32", .block_count=%"PRIu32", "
|
||||
".block_cycles=%"PRIu32", .cache_size=%"PRIu32", "
|
||||
".block_cycles=%"PRId32", .cache_size=%"PRIu32", "
|
||||
".lookahead_size=%"PRIu32", .read_buffer=%p, "
|
||||
".prog_buffer=%p, .lookahead_buffer=%p, "
|
||||
".name_max=%"PRIu32", .file_max=%"PRIu32", "
|
||||
|
||||
24
lfs.h
24
lfs.h
@@ -21,7 +21,7 @@ extern "C"
|
||||
// Software library version
|
||||
// Major (top-nibble), incremented on backwards incompatible changes
|
||||
// Minor (bottom-nibble), incremented on feature additions
|
||||
#define LFS_VERSION 0x00020009
|
||||
#define LFS_VERSION 0x0002000b
|
||||
#define LFS_VERSION_MAJOR (0xffff & (LFS_VERSION >> 16))
|
||||
#define LFS_VERSION_MINOR (0xffff & (LFS_VERSION >> 0))
|
||||
|
||||
@@ -59,7 +59,8 @@ typedef uint32_t lfs_block_t;
|
||||
#endif
|
||||
|
||||
// Maximum size of custom attributes in bytes, may be redefined, but there is
|
||||
// no real benefit to using a smaller LFS_ATTR_MAX. Limited to <= 1022.
|
||||
// no real benefit to using a smaller LFS_ATTR_MAX. Limited to <= 1022. Stored
|
||||
// in superblock and must be respected by other littlefs drivers.
|
||||
#ifndef LFS_ATTR_MAX
|
||||
#define LFS_ATTR_MAX 1022
|
||||
#endif
|
||||
@@ -203,7 +204,8 @@ struct lfs_config {
|
||||
// program sizes.
|
||||
lfs_size_t block_size;
|
||||
|
||||
// Number of erasable blocks on the device.
|
||||
// Number of erasable blocks on the device. Defaults to block_count stored
|
||||
// on disk when zero.
|
||||
lfs_size_t block_count;
|
||||
|
||||
// Number of erase cycles before littlefs evicts metadata logs and moves
|
||||
@@ -252,18 +254,18 @@ struct lfs_config {
|
||||
|
||||
// Optional upper limit on length of file names in bytes. No downside for
|
||||
// larger names except the size of the info struct which is controlled by
|
||||
// the LFS_NAME_MAX define. Defaults to LFS_NAME_MAX when zero. Stored in
|
||||
// superblock and must be respected by other littlefs drivers.
|
||||
// the LFS_NAME_MAX define. Defaults to LFS_NAME_MAX or name_max stored on
|
||||
// disk when zero.
|
||||
lfs_size_t name_max;
|
||||
|
||||
// Optional upper limit on files in bytes. No downside for larger files
|
||||
// but must be <= LFS_FILE_MAX. Defaults to LFS_FILE_MAX when zero. Stored
|
||||
// in superblock and must be respected by other littlefs drivers.
|
||||
// but must be <= LFS_FILE_MAX. Defaults to LFS_FILE_MAX or file_max stored
|
||||
// on disk when zero.
|
||||
lfs_size_t file_max;
|
||||
|
||||
// Optional upper limit on custom attributes in bytes. No downside for
|
||||
// larger attributes size but must be <= LFS_ATTR_MAX. Defaults to
|
||||
// LFS_ATTR_MAX when zero.
|
||||
// LFS_ATTR_MAX or attr_max stored on disk when zero.
|
||||
lfs_size_t attr_max;
|
||||
|
||||
// Optional upper limit on total space given to metadata pairs in bytes. On
|
||||
@@ -764,7 +766,11 @@ int lfs_fs_gc(lfs_t *lfs);
|
||||
// Grows the filesystem to a new size, updating the superblock with the new
|
||||
// block count.
|
||||
//
|
||||
// Note: This is irreversible.
|
||||
// If LFS_SHRINKNONRELOCATING is defined, this function will also accept
|
||||
// block_counts smaller than the current configuration, after checking
|
||||
// that none of the blocks that are being removed are in use.
|
||||
// Note that littlefs's pseudorandom block allocation means that
|
||||
// this is very unlikely to work in the general case.
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
int lfs_fs_grow(lfs_t *lfs, lfs_size_t block_count);
|
||||
|
||||
42
lfs_util.h
42
lfs_util.h
@@ -8,6 +8,9 @@
|
||||
#ifndef LFS_UTIL_H
|
||||
#define LFS_UTIL_H
|
||||
|
||||
#define LFS_STRINGIZE(x) LFS_STRINGIZE2(x)
|
||||
#define LFS_STRINGIZE2(x) #x
|
||||
|
||||
// Users can override lfs_util.h with their own configuration by defining
|
||||
// LFS_CONFIG as a header file to include (-DLFS_CONFIG=lfs_config.h).
|
||||
//
|
||||
@@ -15,11 +18,26 @@
|
||||
// provided by the config file. To start, I would suggest copying lfs_util.h
|
||||
// and modifying as needed.
|
||||
#ifdef LFS_CONFIG
|
||||
#define LFS_STRINGIZE(x) LFS_STRINGIZE2(x)
|
||||
#define LFS_STRINGIZE2(x) #x
|
||||
#include LFS_STRINGIZE(LFS_CONFIG)
|
||||
#else
|
||||
|
||||
// Alternatively, users can provide a header file which defines
|
||||
// macros and other things consumed by littlefs.
|
||||
//
|
||||
// For example, provide my_defines.h, which contains
|
||||
// something like:
|
||||
//
|
||||
// #include <stddef.h>
|
||||
// extern void *my_malloc(size_t sz);
|
||||
// #define LFS_MALLOC(sz) my_malloc(sz)
|
||||
//
|
||||
// And build littlefs with the header by defining LFS_DEFINES.
|
||||
// (-DLFS_DEFINES=my_defines.h)
|
||||
|
||||
#ifdef LFS_DEFINES
|
||||
#include LFS_STRINGIZE(LFS_DEFINES)
|
||||
#endif
|
||||
|
||||
// System includes
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
@@ -177,10 +195,10 @@ static inline uint32_t lfs_fromle32(uint32_t a) {
|
||||
(defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
|
||||
return __builtin_bswap32(a);
|
||||
#else
|
||||
return (((uint8_t*)&a)[0] << 0) |
|
||||
(((uint8_t*)&a)[1] << 8) |
|
||||
(((uint8_t*)&a)[2] << 16) |
|
||||
(((uint8_t*)&a)[3] << 24);
|
||||
return ((uint32_t)((uint8_t*)&a)[0] << 0) |
|
||||
((uint32_t)((uint8_t*)&a)[1] << 8) |
|
||||
((uint32_t)((uint8_t*)&a)[2] << 16) |
|
||||
((uint32_t)((uint8_t*)&a)[3] << 24);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -200,10 +218,10 @@ static inline uint32_t lfs_frombe32(uint32_t a) {
|
||||
(defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
|
||||
return a;
|
||||
#else
|
||||
return (((uint8_t*)&a)[0] << 24) |
|
||||
(((uint8_t*)&a)[1] << 16) |
|
||||
(((uint8_t*)&a)[2] << 8) |
|
||||
(((uint8_t*)&a)[3] << 0);
|
||||
return ((uint32_t)((uint8_t*)&a)[0] << 24) |
|
||||
((uint32_t)((uint8_t*)&a)[1] << 16) |
|
||||
((uint32_t)((uint8_t*)&a)[2] << 8) |
|
||||
((uint32_t)((uint8_t*)&a)[3] << 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -213,8 +231,8 @@ static inline uint32_t lfs_tobe32(uint32_t a) {
|
||||
|
||||
// Calculate CRC-32 with polynomial = 0x04c11db7
|
||||
#ifdef LFS_CRC
|
||||
uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size) {
|
||||
return LFS_CRC(crc, buffer, size)
|
||||
static inline uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size) {
|
||||
return LFS_CRC(crc, buffer, size);
|
||||
}
|
||||
#else
|
||||
uint32_t lfs_crc(uint32_t crc, const void *buffer, size_t size);
|
||||
|
||||
@@ -123,8 +123,13 @@ typedef struct bench_id {
|
||||
|
||||
|
||||
// bench suites are linked into a custom ld section
|
||||
#if defined(__APPLE__)
|
||||
extern struct bench_suite __start__bench_suites __asm("section$start$__DATA$_bench_suites");
|
||||
extern struct bench_suite __stop__bench_suites __asm("section$end$__DATA$_bench_suites");
|
||||
#else
|
||||
extern struct bench_suite __start__bench_suites;
|
||||
extern struct bench_suite __stop__bench_suites;
|
||||
#endif
|
||||
|
||||
const struct bench_suite *bench_suites = &__start__bench_suites;
|
||||
#define BENCH_SUITE_COUNT \
|
||||
@@ -1322,6 +1327,7 @@ void perm_run(
|
||||
.cache_size = CACHE_SIZE,
|
||||
.lookahead_size = LOOKAHEAD_SIZE,
|
||||
.compact_thresh = COMPACT_THRESH,
|
||||
.metadata_max = METADATA_MAX,
|
||||
.inline_max = INLINE_MAX,
|
||||
};
|
||||
|
||||
|
||||
@@ -96,12 +96,13 @@ intmax_t bench_define(size_t define);
|
||||
#define CACHE_SIZE_i 6
|
||||
#define LOOKAHEAD_SIZE_i 7
|
||||
#define COMPACT_THRESH_i 8
|
||||
#define INLINE_MAX_i 9
|
||||
#define BLOCK_CYCLES_i 10
|
||||
#define ERASE_VALUE_i 11
|
||||
#define ERASE_CYCLES_i 12
|
||||
#define BADBLOCK_BEHAVIOR_i 13
|
||||
#define POWERLOSS_BEHAVIOR_i 14
|
||||
#define METADATA_MAX_i 9
|
||||
#define INLINE_MAX_i 10
|
||||
#define BLOCK_CYCLES_i 11
|
||||
#define ERASE_VALUE_i 12
|
||||
#define ERASE_CYCLES_i 13
|
||||
#define BADBLOCK_BEHAVIOR_i 14
|
||||
#define POWERLOSS_BEHAVIOR_i 15
|
||||
|
||||
#define READ_SIZE bench_define(READ_SIZE_i)
|
||||
#define PROG_SIZE bench_define(PROG_SIZE_i)
|
||||
@@ -112,6 +113,7 @@ intmax_t bench_define(size_t define);
|
||||
#define CACHE_SIZE bench_define(CACHE_SIZE_i)
|
||||
#define LOOKAHEAD_SIZE bench_define(LOOKAHEAD_SIZE_i)
|
||||
#define COMPACT_THRESH bench_define(COMPACT_THRESH_i)
|
||||
#define METADATA_MAX bench_define(METADATA_MAX_i)
|
||||
#define INLINE_MAX bench_define(INLINE_MAX_i)
|
||||
#define BLOCK_CYCLES bench_define(BLOCK_CYCLES_i)
|
||||
#define ERASE_VALUE bench_define(ERASE_VALUE_i)
|
||||
@@ -129,6 +131,7 @@ intmax_t bench_define(size_t define);
|
||||
BENCH_DEF(CACHE_SIZE, lfs_max(64,lfs_max(READ_SIZE,PROG_SIZE))) \
|
||||
BENCH_DEF(LOOKAHEAD_SIZE, 16) \
|
||||
BENCH_DEF(COMPACT_THRESH, 0) \
|
||||
BENCH_DEF(METADATA_MAX, 0) \
|
||||
BENCH_DEF(INLINE_MAX, 0) \
|
||||
BENCH_DEF(BLOCK_CYCLES, -1) \
|
||||
BENCH_DEF(ERASE_VALUE, 0xff) \
|
||||
@@ -137,7 +140,7 @@ intmax_t bench_define(size_t define);
|
||||
BENCH_DEF(POWERLOSS_BEHAVIOR, LFS_EMUBD_POWERLOSS_NOOP)
|
||||
|
||||
#define BENCH_GEOMETRY_DEFINE_COUNT 4
|
||||
#define BENCH_IMPLICIT_DEFINE_COUNT 15
|
||||
#define BENCH_IMPLICIT_DEFINE_COUNT 16
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -136,8 +136,13 @@ typedef struct test_id {
|
||||
|
||||
|
||||
// test suites are linked into a custom ld section
|
||||
#if defined(__APPLE__)
|
||||
extern struct test_suite __start__test_suites __asm("section$start$__DATA$_test_suites");
|
||||
extern struct test_suite __stop__test_suites __asm("section$end$__DATA$_test_suites");
|
||||
#else
|
||||
extern struct test_suite __start__test_suites;
|
||||
extern struct test_suite __stop__test_suites;
|
||||
#endif
|
||||
|
||||
const struct test_suite *test_suites = &__start__test_suites;
|
||||
#define TEST_SUITE_COUNT \
|
||||
@@ -1347,6 +1352,7 @@ static void run_powerloss_none(
|
||||
.cache_size = CACHE_SIZE,
|
||||
.lookahead_size = LOOKAHEAD_SIZE,
|
||||
.compact_thresh = COMPACT_THRESH,
|
||||
.metadata_max = METADATA_MAX,
|
||||
.inline_max = INLINE_MAX,
|
||||
#ifdef LFS_MULTIVERSION
|
||||
.disk_version = DISK_VERSION,
|
||||
@@ -1425,6 +1431,7 @@ static void run_powerloss_linear(
|
||||
.cache_size = CACHE_SIZE,
|
||||
.lookahead_size = LOOKAHEAD_SIZE,
|
||||
.compact_thresh = COMPACT_THRESH,
|
||||
.metadata_max = METADATA_MAX,
|
||||
.inline_max = INLINE_MAX,
|
||||
#ifdef LFS_MULTIVERSION
|
||||
.disk_version = DISK_VERSION,
|
||||
@@ -1520,6 +1527,7 @@ static void run_powerloss_log(
|
||||
.cache_size = CACHE_SIZE,
|
||||
.lookahead_size = LOOKAHEAD_SIZE,
|
||||
.compact_thresh = COMPACT_THRESH,
|
||||
.metadata_max = METADATA_MAX,
|
||||
.inline_max = INLINE_MAX,
|
||||
#ifdef LFS_MULTIVERSION
|
||||
.disk_version = DISK_VERSION,
|
||||
@@ -1613,6 +1621,7 @@ static void run_powerloss_cycles(
|
||||
.cache_size = CACHE_SIZE,
|
||||
.lookahead_size = LOOKAHEAD_SIZE,
|
||||
.compact_thresh = COMPACT_THRESH,
|
||||
.metadata_max = METADATA_MAX,
|
||||
.inline_max = INLINE_MAX,
|
||||
#ifdef LFS_MULTIVERSION
|
||||
.disk_version = DISK_VERSION,
|
||||
@@ -1804,6 +1813,7 @@ static void run_powerloss_exhaustive(
|
||||
.cache_size = CACHE_SIZE,
|
||||
.lookahead_size = LOOKAHEAD_SIZE,
|
||||
.compact_thresh = COMPACT_THRESH,
|
||||
.metadata_max = METADATA_MAX,
|
||||
.inline_max = INLINE_MAX,
|
||||
#ifdef LFS_MULTIVERSION
|
||||
.disk_version = DISK_VERSION,
|
||||
|
||||
@@ -89,13 +89,14 @@ intmax_t test_define(size_t define);
|
||||
#define CACHE_SIZE_i 6
|
||||
#define LOOKAHEAD_SIZE_i 7
|
||||
#define COMPACT_THRESH_i 8
|
||||
#define INLINE_MAX_i 9
|
||||
#define BLOCK_CYCLES_i 10
|
||||
#define ERASE_VALUE_i 11
|
||||
#define ERASE_CYCLES_i 12
|
||||
#define BADBLOCK_BEHAVIOR_i 13
|
||||
#define POWERLOSS_BEHAVIOR_i 14
|
||||
#define DISK_VERSION_i 15
|
||||
#define METADATA_MAX_i 9
|
||||
#define INLINE_MAX_i 10
|
||||
#define BLOCK_CYCLES_i 11
|
||||
#define ERASE_VALUE_i 12
|
||||
#define ERASE_CYCLES_i 13
|
||||
#define BADBLOCK_BEHAVIOR_i 14
|
||||
#define POWERLOSS_BEHAVIOR_i 15
|
||||
#define DISK_VERSION_i 16
|
||||
|
||||
#define READ_SIZE TEST_DEFINE(READ_SIZE_i)
|
||||
#define PROG_SIZE TEST_DEFINE(PROG_SIZE_i)
|
||||
@@ -106,6 +107,7 @@ intmax_t test_define(size_t define);
|
||||
#define CACHE_SIZE TEST_DEFINE(CACHE_SIZE_i)
|
||||
#define LOOKAHEAD_SIZE TEST_DEFINE(LOOKAHEAD_SIZE_i)
|
||||
#define COMPACT_THRESH TEST_DEFINE(COMPACT_THRESH_i)
|
||||
#define METADATA_MAX TEST_DEFINE(METADATA_MAX_i)
|
||||
#define INLINE_MAX TEST_DEFINE(INLINE_MAX_i)
|
||||
#define BLOCK_CYCLES TEST_DEFINE(BLOCK_CYCLES_i)
|
||||
#define ERASE_VALUE TEST_DEFINE(ERASE_VALUE_i)
|
||||
@@ -124,6 +126,7 @@ intmax_t test_define(size_t define);
|
||||
TEST_DEF(CACHE_SIZE, lfs_max(64,lfs_max(READ_SIZE,PROG_SIZE))) \
|
||||
TEST_DEF(LOOKAHEAD_SIZE, 16) \
|
||||
TEST_DEF(COMPACT_THRESH, 0) \
|
||||
TEST_DEF(METADATA_MAX, 0) \
|
||||
TEST_DEF(INLINE_MAX, 0) \
|
||||
TEST_DEF(BLOCK_CYCLES, -1) \
|
||||
TEST_DEF(ERASE_VALUE, 0xff) \
|
||||
@@ -133,7 +136,7 @@ intmax_t test_define(size_t define);
|
||||
TEST_DEF(DISK_VERSION, 0)
|
||||
|
||||
#define TEST_GEOMETRY_DEFINE_COUNT 4
|
||||
#define TEST_IMPLICIT_DEFINE_COUNT 16
|
||||
#define TEST_IMPLICIT_DEFINE_COUNT 17
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -404,12 +404,15 @@ def compile(bench_paths, **args):
|
||||
f.writeln()
|
||||
|
||||
# create suite struct
|
||||
#
|
||||
f.writeln('#if defined(__APPLE__)')
|
||||
f.writeln('__attribute__((section("__DATA,_bench_suites")))')
|
||||
f.writeln('#else')
|
||||
# note we place this in the custom bench_suites section with
|
||||
# minimum alignment, otherwise GCC ups the alignment to
|
||||
# 32-bytes for some reason
|
||||
f.writeln('__attribute__((section("_bench_suites"), '
|
||||
'aligned(1)))')
|
||||
f.writeln('#endif')
|
||||
f.writeln('const struct bench_suite __bench__%s__suite = {'
|
||||
% suite.name)
|
||||
f.writeln(4*' '+'.name = "%s",' % suite.name)
|
||||
|
||||
@@ -73,7 +73,7 @@ def changefile(from_prefix, to_prefix, from_path, to_path, *,
|
||||
shutil.copystat(from_path, to_path)
|
||||
|
||||
if to_path_temp:
|
||||
os.rename(to_path, from_path)
|
||||
shutil.move(to_path, from_path)
|
||||
elif from_path != '-':
|
||||
os.remove(from_path)
|
||||
|
||||
|
||||
@@ -35,10 +35,10 @@ LEXEMES = {
|
||||
'assert': ['assert'],
|
||||
'arrow': ['=>'],
|
||||
'string': [r'"(?:\\.|[^"])*"', r"'(?:\\.|[^'])\'"],
|
||||
'paren': ['\(', '\)'],
|
||||
'paren': [r'\(', r'\)'],
|
||||
'cmp': CMP.keys(),
|
||||
'logic': ['\&\&', '\|\|'],
|
||||
'sep': [':', ';', '\{', '\}', ','],
|
||||
'logic': [r'\&\&', r'\|\|'],
|
||||
'sep': [':', ';', r'\{', r'\}', ','],
|
||||
'op': ['->'], # specifically ops that conflict with cmp
|
||||
}
|
||||
|
||||
@@ -86,6 +86,13 @@ def write_header(f, limit=LIMIT):
|
||||
f.writeln("}")
|
||||
f.writeln()
|
||||
f.writeln("__attribute__((unused))")
|
||||
f.writeln("static void __pretty_assert_print_ptr(")
|
||||
f.writeln(" const void *v, size_t size) {")
|
||||
f.writeln(" (void)size;")
|
||||
f.writeln(" printf(\"%p\", v);")
|
||||
f.writeln("}")
|
||||
f.writeln()
|
||||
f.writeln("__attribute__((unused))")
|
||||
f.writeln("static void __pretty_assert_print_mem(")
|
||||
f.writeln(" const void *v, size_t size) {")
|
||||
f.writeln(" const uint8_t *v_ = v;")
|
||||
@@ -183,6 +190,23 @@ def write_header(f, limit=LIMIT):
|
||||
f.writeln(" _rh, strlen(_rh)); \\")
|
||||
f.writeln(" } \\")
|
||||
f.writeln("} while (0)")
|
||||
for op, cmp in sorted(CMP.items()):
|
||||
# Only EQ and NE are supported when compared to NULL.
|
||||
if cmp not in ['eq', 'ne']:
|
||||
continue
|
||||
f.writeln("#define __PRETTY_ASSERT_PTR_%s(lh, rh) do { \\"
|
||||
% cmp.upper())
|
||||
f.writeln(" const void *_lh = (const void*)(uintptr_t)lh; \\")
|
||||
f.writeln(" const void *_rh = (const void*)(uintptr_t)rh; \\")
|
||||
f.writeln(" if (!(_lh %s _rh)) { \\" % op)
|
||||
f.writeln(" __pretty_assert_fail( \\")
|
||||
f.writeln(" __FILE__, __LINE__, \\")
|
||||
f.writeln(" __pretty_assert_print_ptr, \"%s\", \\"
|
||||
% cmp)
|
||||
f.writeln(" (const void*){_lh}, 0, \\")
|
||||
f.writeln(" (const void*){_rh}, 0); \\")
|
||||
f.writeln(" } \\")
|
||||
f.writeln("} while (0)")
|
||||
f.writeln()
|
||||
f.writeln()
|
||||
|
||||
@@ -301,6 +325,8 @@ def p_assert(p):
|
||||
cmp = p.expect('cmp') ; p.accept('ws')
|
||||
rh = p_expr(p) ; p.accept('ws')
|
||||
p.expect(')')
|
||||
if rh == 'NULL' or lh == 'NULL':
|
||||
return mkassert('ptr', CMP[cmp], lh, rh)
|
||||
return mkassert('int', CMP[cmp], lh, rh)
|
||||
except ParseFailure:
|
||||
p.pop(state)
|
||||
|
||||
@@ -102,9 +102,9 @@ class TestCase:
|
||||
# the runner itself.
|
||||
for v_ in csplit(v):
|
||||
m = re.search(r'\brange\b\s*\('
|
||||
'(?P<start>[^,\s]*)'
|
||||
'\s*(?:,\s*(?P<stop>[^,\s]*)'
|
||||
'\s*(?:,\s*(?P<step>[^,\s]*)\s*)?)?\)',
|
||||
r'(?P<start>[^,\s]*)'
|
||||
r'\s*(?:,\s*(?P<stop>[^,\s]*)'
|
||||
r'\s*(?:,\s*(?P<step>[^,\s]*)\s*)?)?\)',
|
||||
v_)
|
||||
if m:
|
||||
start = (int(m.group('start'), 0)
|
||||
@@ -163,8 +163,8 @@ class TestSuite:
|
||||
code_linenos = []
|
||||
for i, line in enumerate(f):
|
||||
match = re.match(
|
||||
'(?P<case>\[\s*cases\s*\.\s*(?P<name>\w+)\s*\])'
|
||||
'|' '(?P<code>code\s*=)',
|
||||
r'(?P<case>\[\s*cases\s*\.\s*(?P<name>\w+)\s*\])'
|
||||
r'|' r'(?P<code>code\s*=)',
|
||||
line)
|
||||
if match and match.group('case'):
|
||||
case_linenos.append((i+1, match.group('name')))
|
||||
@@ -412,12 +412,15 @@ def compile(test_paths, **args):
|
||||
f.writeln()
|
||||
|
||||
# create suite struct
|
||||
#
|
||||
f.writeln('#if defined(__APPLE__)')
|
||||
f.writeln('__attribute__((section("__DATA,_test_suites")))')
|
||||
f.writeln('#else')
|
||||
# note we place this in the custom test_suites section with
|
||||
# minimum alignment, otherwise GCC ups the alignment to
|
||||
# 32-bytes for some reason
|
||||
f.writeln('__attribute__((section("_test_suites"), '
|
||||
'aligned(1)))')
|
||||
f.writeln('#endif')
|
||||
f.writeln('const struct test_suite __test__%s__suite = {'
|
||||
% suite.name)
|
||||
f.writeln(4*' '+'.name = "%s",' % suite.name)
|
||||
@@ -602,9 +605,9 @@ def find_perms(runner_, ids=[], **args):
|
||||
errors='replace',
|
||||
close_fds=False)
|
||||
pattern = re.compile(
|
||||
'^(?P<case>[^\s]+)'
|
||||
'\s+(?P<flags>[^\s]+)'
|
||||
'\s+(?P<filtered>\d+)/(?P<perms>\d+)')
|
||||
r'^(?P<case>[^\s]+)'
|
||||
r'\s+(?P<flags>[^\s]+)'
|
||||
r'\s+(?P<filtered>\d+)/(?P<perms>\d+)')
|
||||
# skip the first line
|
||||
for line in it.islice(proc.stdout, 1, None):
|
||||
m = pattern.match(line)
|
||||
@@ -632,8 +635,8 @@ def find_perms(runner_, ids=[], **args):
|
||||
errors='replace',
|
||||
close_fds=False)
|
||||
pattern = re.compile(
|
||||
'^(?P<case>[^\s]+)'
|
||||
'\s+(?P<path>[^:]+):(?P<lineno>\d+)')
|
||||
r'^(?P<case>[^\s]+)'
|
||||
r'\s+(?P<path>[^:]+):(?P<lineno>\d+)')
|
||||
# skip the first line
|
||||
for line in it.islice(proc.stdout, 1, None):
|
||||
m = pattern.match(line)
|
||||
@@ -676,8 +679,8 @@ def find_path(runner_, id, **args):
|
||||
errors='replace',
|
||||
close_fds=False)
|
||||
pattern = re.compile(
|
||||
'^(?P<case>[^\s]+)'
|
||||
'\s+(?P<path>[^:]+):(?P<lineno>\d+)')
|
||||
r'^(?P<case>[^\s]+)'
|
||||
r'\s+(?P<path>[^:]+):(?P<lineno>\d+)')
|
||||
# skip the first line
|
||||
for line in it.islice(proc.stdout, 1, None):
|
||||
m = pattern.match(line)
|
||||
@@ -706,7 +709,7 @@ def find_defines(runner_, id, **args):
|
||||
errors='replace',
|
||||
close_fds=False)
|
||||
defines = co.OrderedDict()
|
||||
pattern = re.compile('^(?P<define>\w+)=(?P<value>.+)')
|
||||
pattern = re.compile(r'^(?P<define>\w+)=(?P<value>.+)')
|
||||
for line in proc.stdout:
|
||||
m = pattern.match(line)
|
||||
if m:
|
||||
@@ -781,12 +784,12 @@ def run_stage(name, runner_, ids, stdout_, trace_, output_, **args):
|
||||
failures = []
|
||||
killed = False
|
||||
|
||||
pattern = re.compile('^(?:'
|
||||
'(?P<op>running|finished|skipped|powerloss) '
|
||||
'(?P<id>(?P<case>[^:]+)[^\s]*)'
|
||||
'|' '(?P<path>[^:]+):(?P<lineno>\d+):(?P<op_>assert):'
|
||||
' *(?P<message>.*)'
|
||||
')$')
|
||||
pattern = re.compile(r'^(?:'
|
||||
r'(?P<op>running|finished|skipped|powerloss) '
|
||||
r'(?P<id>(?P<case>[^:]+)[^\s]*)'
|
||||
r'|' r'(?P<path>[^:]+):(?P<lineno>\d+):(?P<op_>assert):'
|
||||
r' *(?P<message>.*)'
|
||||
r')$')
|
||||
locals = th.local()
|
||||
children = set()
|
||||
|
||||
|
||||
@@ -8,17 +8,22 @@ defines.FILES = 3
|
||||
defines.SIZE = '(((BLOCK_SIZE-8)*(BLOCK_COUNT-6)) / FILES)'
|
||||
defines.GC = [false, true]
|
||||
defines.COMPACT_THRESH = ['-1', '0', 'BLOCK_SIZE/2']
|
||||
defines.INFER_BC = [false, true]
|
||||
code = '''
|
||||
const char *names[] = {"bacon", "eggs", "pancakes"};
|
||||
lfs_file_t files[FILES];
|
||||
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
struct lfs_config cfg_ = *cfg;
|
||||
if (INFER_BC) {
|
||||
cfg_.block_count = 0;
|
||||
}
|
||||
lfs_mount(&lfs, &cfg_) => 0;
|
||||
lfs_mkdir(&lfs, "breakfast") => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg_) => 0;
|
||||
for (int n = 0; n < FILES; n++) {
|
||||
char path[1024];
|
||||
sprintf(path, "breakfast/%s", names[n]);
|
||||
@@ -39,7 +44,7 @@ code = '''
|
||||
}
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg_) => 0;
|
||||
for (int n = 0; n < FILES; n++) {
|
||||
char path[1024];
|
||||
sprintf(path, "breakfast/%s", names[n]);
|
||||
@@ -62,17 +67,22 @@ defines.FILES = 3
|
||||
defines.SIZE = '(((BLOCK_SIZE-8)*(BLOCK_COUNT-6)) / FILES)'
|
||||
defines.GC = [false, true]
|
||||
defines.COMPACT_THRESH = ['-1', '0', 'BLOCK_SIZE/2']
|
||||
defines.INFER_BC = [false, true]
|
||||
code = '''
|
||||
const char *names[] = {"bacon", "eggs", "pancakes"};
|
||||
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
struct lfs_config cfg_ = *cfg;
|
||||
if (INFER_BC) {
|
||||
cfg_.block_count = 0;
|
||||
}
|
||||
lfs_mount(&lfs, &cfg_) => 0;
|
||||
lfs_mkdir(&lfs, "breakfast") => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
for (int n = 0; n < FILES; n++) {
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg_) => 0;
|
||||
char path[1024];
|
||||
sprintf(path, "breakfast/%s", names[n]);
|
||||
lfs_file_t file;
|
||||
@@ -91,7 +101,7 @@ code = '''
|
||||
lfs_unmount(&lfs) => 0;
|
||||
}
|
||||
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg_) => 0;
|
||||
for (int n = 0; n < FILES; n++) {
|
||||
char path[1024];
|
||||
sprintf(path, "breakfast/%s", names[n]);
|
||||
@@ -113,19 +123,24 @@ code = '''
|
||||
defines.FILES = 3
|
||||
defines.SIZE = '(((BLOCK_SIZE-8)*(BLOCK_COUNT-6)) / FILES)'
|
||||
defines.CYCLES = [1, 10]
|
||||
defines.INFER_BC = [false, true]
|
||||
code = '''
|
||||
const char *names[] = {"bacon", "eggs", "pancakes"};
|
||||
lfs_file_t files[FILES];
|
||||
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
struct lfs_config cfg_ = *cfg;
|
||||
if (INFER_BC) {
|
||||
cfg_.block_count = 0;
|
||||
}
|
||||
|
||||
for (int c = 0; c < CYCLES; c++) {
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg_) => 0;
|
||||
lfs_mkdir(&lfs, "breakfast") => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg_) => 0;
|
||||
for (int n = 0; n < FILES; n++) {
|
||||
char path[1024];
|
||||
sprintf(path, "breakfast/%s", names[n]);
|
||||
@@ -143,7 +158,7 @@ code = '''
|
||||
}
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg_) => 0;
|
||||
for (int n = 0; n < FILES; n++) {
|
||||
char path[1024];
|
||||
sprintf(path, "breakfast/%s", names[n]);
|
||||
@@ -159,7 +174,7 @@ code = '''
|
||||
}
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg_) => 0;
|
||||
for (int n = 0; n < FILES; n++) {
|
||||
char path[1024];
|
||||
sprintf(path, "breakfast/%s", names[n]);
|
||||
@@ -175,19 +190,24 @@ code = '''
|
||||
defines.FILES = 3
|
||||
defines.SIZE = '(((BLOCK_SIZE-8)*(BLOCK_COUNT-6)) / FILES)'
|
||||
defines.CYCLES = [1, 10]
|
||||
defines.INFER_BC = [false, true]
|
||||
code = '''
|
||||
const char *names[] = {"bacon", "eggs", "pancakes"};
|
||||
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
struct lfs_config cfg_ = *cfg;
|
||||
if (INFER_BC) {
|
||||
cfg_.block_count = 0;
|
||||
}
|
||||
|
||||
for (int c = 0; c < CYCLES; c++) {
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg_) => 0;
|
||||
lfs_mkdir(&lfs, "breakfast") => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
for (int n = 0; n < FILES; n++) {
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg_) => 0;
|
||||
char path[1024];
|
||||
sprintf(path, "breakfast/%s", names[n]);
|
||||
lfs_file_t file;
|
||||
@@ -232,10 +252,15 @@ code = '''
|
||||
|
||||
# exhaustion test
|
||||
[cases.test_alloc_exhaustion]
|
||||
defines.INFER_BC = [false, true]
|
||||
code = '''
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
struct lfs_config cfg_ = *cfg;
|
||||
if (INFER_BC) {
|
||||
cfg_.block_count = 0;
|
||||
}
|
||||
lfs_mount(&lfs, &cfg_) => 0;
|
||||
lfs_file_t file;
|
||||
lfs_file_open(&lfs, &file, "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
|
||||
size_t size = strlen("exhaustion");
|
||||
@@ -263,7 +288,7 @@ code = '''
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg_) => 0;
|
||||
lfs_file_open(&lfs, &file, "exhaustion", LFS_O_RDONLY);
|
||||
size = strlen("exhaustion");
|
||||
lfs_file_size(&lfs, &file) => size;
|
||||
@@ -276,10 +301,15 @@ code = '''
|
||||
# exhaustion wraparound test
|
||||
[cases.test_alloc_exhaustion_wraparound]
|
||||
defines.SIZE = '(((BLOCK_SIZE-8)*(BLOCK_COUNT-4)) / 3)'
|
||||
defines.INFER_BC = [false, true]
|
||||
code = '''
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
struct lfs_config cfg_ = *cfg;
|
||||
if (INFER_BC) {
|
||||
cfg_.block_count = 0;
|
||||
}
|
||||
lfs_mount(&lfs, &cfg_) => 0;
|
||||
|
||||
lfs_file_t file;
|
||||
lfs_file_open(&lfs, &file, "padding", LFS_O_WRONLY | LFS_O_CREAT);
|
||||
@@ -317,7 +347,7 @@ code = '''
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, &cfg_) => 0;
|
||||
lfs_file_open(&lfs, &file, "exhaustion", LFS_O_RDONLY);
|
||||
size = strlen("exhaustion");
|
||||
lfs_file_size(&lfs, &file) => size;
|
||||
@@ -330,10 +360,15 @@ code = '''
|
||||
|
||||
# dir exhaustion test
|
||||
[cases.test_alloc_dir_exhaustion]
|
||||
defines.INFER_BC = [false, true]
|
||||
code = '''
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
struct lfs_config cfg_ = *cfg;
|
||||
if (INFER_BC) {
|
||||
cfg_.block_count = 0;
|
||||
}
|
||||
lfs_mount(&lfs, &cfg_) => 0;
|
||||
|
||||
// find out max file size
|
||||
lfs_mkdir(&lfs, "exhaustiondir") => 0;
|
||||
|
||||
@@ -725,6 +725,82 @@ code = '''
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
[cases.test_dirs_remove_read]
|
||||
defines.N = 10
|
||||
if = 'N < BLOCK_COUNT/2'
|
||||
code = '''
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_mkdir(&lfs, "prickly-pear") => 0;
|
||||
for (int i = 0; i < N; i++) {
|
||||
char path[1024];
|
||||
sprintf(path, "prickly-pear/cactus%03d", i);
|
||||
lfs_mkdir(&lfs, path) => 0;
|
||||
}
|
||||
lfs_dir_t dir;
|
||||
lfs_dir_open(&lfs, &dir, "prickly-pear") => 0;
|
||||
struct lfs_info info;
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
assert(info.type == LFS_TYPE_DIR);
|
||||
assert(strcmp(info.name, ".") == 0);
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
assert(info.type == LFS_TYPE_DIR);
|
||||
assert(strcmp(info.name, "..") == 0);
|
||||
for (int i = 0; i < N; i++) {
|
||||
char path[1024];
|
||||
sprintf(path, "cactus%03d", i);
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
assert(info.type == LFS_TYPE_DIR);
|
||||
assert(strcmp(info.name, path) == 0);
|
||||
}
|
||||
lfs_dir_read(&lfs, &dir, &info) => 0;
|
||||
lfs_dir_close(&lfs, &dir) => 0;
|
||||
lfs_unmount(&lfs);
|
||||
|
||||
for (lfs_size_t k = 0; k < N; k++) {
|
||||
for (lfs_size_t j = 0; j < N; j++) {
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_dir_open(&lfs, &dir, "prickly-pear") => 0;
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
assert(info.type == LFS_TYPE_DIR);
|
||||
assert(strcmp(info.name, ".") == 0);
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
assert(info.type == LFS_TYPE_DIR);
|
||||
assert(strcmp(info.name, "..") == 0);
|
||||
// iterate over dirs < j
|
||||
for (unsigned i = 0; i < j; i++) {
|
||||
char path[1024];
|
||||
sprintf(path, "cactus%03d", i);
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
assert(info.type == LFS_TYPE_DIR);
|
||||
assert(strcmp(info.name, path) == 0);
|
||||
}
|
||||
|
||||
// remove k while iterating
|
||||
char path[1024];
|
||||
sprintf(path, "prickly-pear/cactus%03d", k);
|
||||
lfs_remove(&lfs, path) => 0;
|
||||
|
||||
// iterate over dirs >= j
|
||||
for (unsigned i = j; i < ((k >= j) ? N-1 : N); i++) {
|
||||
char path[1024];
|
||||
sprintf(path, "cactus%03d", (k >= j && i >= k) ? i+1 : i);
|
||||
lfs_dir_read(&lfs, &dir, &info) => 1;
|
||||
assert(info.type == LFS_TYPE_DIR);
|
||||
assert(strcmp(info.name, path) == 0);
|
||||
}
|
||||
lfs_dir_read(&lfs, &dir, &info) => 0;
|
||||
lfs_dir_close(&lfs, &dir) => 0;
|
||||
|
||||
// recreate k
|
||||
sprintf(path, "prickly-pear/cactus%03d", k);
|
||||
lfs_mkdir(&lfs, path) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
}
|
||||
}
|
||||
'''
|
||||
|
||||
[cases.test_dirs_other_errors]
|
||||
code = '''
|
||||
lfs_t lfs;
|
||||
|
||||
@@ -207,7 +207,8 @@ code = '''
|
||||
[cases.test_orphans_reentrant]
|
||||
reentrant = true
|
||||
# TODO fix this case, caused by non-DAG trees
|
||||
if = '!(DEPTH == 3 && CACHE_SIZE != 64)'
|
||||
# NOTE the second condition is required
|
||||
if = '!(DEPTH == 3 && CACHE_SIZE != 64) && 2*FILES < BLOCK_COUNT'
|
||||
defines = [
|
||||
{FILES=6, DEPTH=1, CYCLES=20},
|
||||
{FILES=26, DEPTH=1, CYCLES=20},
|
||||
@@ -271,3 +272,69 @@ code = '''
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
# non-reentrant testing for orphans, this is the same as reentrant
|
||||
# testing, but we test way more states than we could under powerloss
|
||||
[cases.test_orphans_nonreentrant]
|
||||
# TODO fix this case, caused by non-DAG trees
|
||||
# NOTE the second condition is required
|
||||
if = '!(DEPTH == 3 && CACHE_SIZE != 64) && 2*FILES < BLOCK_COUNT'
|
||||
defines = [
|
||||
{FILES=6, DEPTH=1, CYCLES=2000},
|
||||
{FILES=26, DEPTH=1, CYCLES=2000},
|
||||
{FILES=3, DEPTH=3, CYCLES=2000},
|
||||
]
|
||||
code = '''
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
|
||||
uint32_t prng = 1;
|
||||
const char alpha[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
for (unsigned i = 0; i < CYCLES; i++) {
|
||||
// create random path
|
||||
char full_path[256];
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
sprintf(&full_path[2*d], "/%c", alpha[TEST_PRNG(&prng) % FILES]);
|
||||
}
|
||||
|
||||
// if it does not exist, we create it, else we destroy
|
||||
struct lfs_info info;
|
||||
int res = lfs_stat(&lfs, full_path, &info);
|
||||
if (res == LFS_ERR_NOENT) {
|
||||
// create each directory in turn, ignore if dir already exists
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
char path[1024];
|
||||
strcpy(path, full_path);
|
||||
path[2*d+2] = '\0';
|
||||
int err = lfs_mkdir(&lfs, path);
|
||||
assert(!err || err == LFS_ERR_EXIST);
|
||||
}
|
||||
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
char path[1024];
|
||||
strcpy(path, full_path);
|
||||
path[2*d+2] = '\0';
|
||||
lfs_stat(&lfs, path, &info) => 0;
|
||||
assert(strcmp(info.name, &path[2*d+1]) == 0);
|
||||
assert(info.type == LFS_TYPE_DIR);
|
||||
}
|
||||
} else {
|
||||
// is valid dir?
|
||||
assert(strcmp(info.name, &full_path[2*(DEPTH-1)+1]) == 0);
|
||||
assert(info.type == LFS_TYPE_DIR);
|
||||
|
||||
// try to delete path in reverse order, ignore if dir is not empty
|
||||
for (int d = DEPTH-1; d >= 0; d--) {
|
||||
char path[1024];
|
||||
strcpy(path, full_path);
|
||||
path[2*d+2] = '\0';
|
||||
int err = lfs_remove(&lfs, path);
|
||||
assert(!err || err == LFS_ERR_NOTEMPTY);
|
||||
}
|
||||
|
||||
lfs_stat(&lfs, full_path, &info) => LFS_ERR_NOENT;
|
||||
}
|
||||
}
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -341,3 +341,171 @@ code = '''
|
||||
}
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
# non-reentrant testing for orphans, this is the same as reentrant
|
||||
# testing, but we test way more states than we could under powerloss
|
||||
[cases.test_relocations_nonreentrant]
|
||||
# TODO fix this case, caused by non-DAG trees
|
||||
# NOTE the second condition is required
|
||||
if = '!(DEPTH == 3 && CACHE_SIZE != 64) && 2*FILES < BLOCK_COUNT'
|
||||
defines = [
|
||||
{FILES=6, DEPTH=1, CYCLES=2000, BLOCK_CYCLES=1},
|
||||
{FILES=26, DEPTH=1, CYCLES=2000, BLOCK_CYCLES=1},
|
||||
{FILES=3, DEPTH=3, CYCLES=2000, BLOCK_CYCLES=1},
|
||||
]
|
||||
code = '''
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
|
||||
uint32_t prng = 1;
|
||||
const char alpha[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
for (unsigned i = 0; i < CYCLES; i++) {
|
||||
// create random path
|
||||
char full_path[256];
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
sprintf(&full_path[2*d], "/%c", alpha[TEST_PRNG(&prng) % FILES]);
|
||||
}
|
||||
|
||||
// if it does not exist, we create it, else we destroy
|
||||
struct lfs_info info;
|
||||
int res = lfs_stat(&lfs, full_path, &info);
|
||||
if (res == LFS_ERR_NOENT) {
|
||||
// create each directory in turn, ignore if dir already exists
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
char path[1024];
|
||||
strcpy(path, full_path);
|
||||
path[2*d+2] = '\0';
|
||||
int err = lfs_mkdir(&lfs, path);
|
||||
assert(!err || err == LFS_ERR_EXIST);
|
||||
}
|
||||
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
char path[1024];
|
||||
strcpy(path, full_path);
|
||||
path[2*d+2] = '\0';
|
||||
lfs_stat(&lfs, path, &info) => 0;
|
||||
assert(strcmp(info.name, &path[2*d+1]) == 0);
|
||||
assert(info.type == LFS_TYPE_DIR);
|
||||
}
|
||||
} else {
|
||||
// is valid dir?
|
||||
assert(strcmp(info.name, &full_path[2*(DEPTH-1)+1]) == 0);
|
||||
assert(info.type == LFS_TYPE_DIR);
|
||||
|
||||
// try to delete path in reverse order, ignore if dir is not empty
|
||||
for (unsigned d = DEPTH-1; d+1 > 0; d--) {
|
||||
char path[1024];
|
||||
strcpy(path, full_path);
|
||||
path[2*d+2] = '\0';
|
||||
int err = lfs_remove(&lfs, path);
|
||||
assert(!err || err == LFS_ERR_NOTEMPTY);
|
||||
}
|
||||
|
||||
lfs_stat(&lfs, full_path, &info) => LFS_ERR_NOENT;
|
||||
}
|
||||
}
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
# non-reentrant testing for relocations, but now with random renames!
|
||||
[cases.test_relocations_nonreentrant_renames]
|
||||
# TODO fix this case, caused by non-DAG trees
|
||||
# NOTE the second condition is required
|
||||
if = '!(DEPTH == 3 && CACHE_SIZE != 64) && 2*FILES < BLOCK_COUNT'
|
||||
defines = [
|
||||
{FILES=6, DEPTH=1, CYCLES=2000, BLOCK_CYCLES=1},
|
||||
{FILES=26, DEPTH=1, CYCLES=2000, BLOCK_CYCLES=1},
|
||||
{FILES=3, DEPTH=3, CYCLES=2000, BLOCK_CYCLES=1},
|
||||
]
|
||||
code = '''
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
|
||||
uint32_t prng = 1;
|
||||
const char alpha[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
for (unsigned i = 0; i < CYCLES; i++) {
|
||||
// create random path
|
||||
char full_path[256];
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
sprintf(&full_path[2*d], "/%c", alpha[TEST_PRNG(&prng) % FILES]);
|
||||
}
|
||||
|
||||
// if it does not exist, we create it, else we destroy
|
||||
struct lfs_info info;
|
||||
int res = lfs_stat(&lfs, full_path, &info);
|
||||
assert(!res || res == LFS_ERR_NOENT);
|
||||
if (res == LFS_ERR_NOENT) {
|
||||
// create each directory in turn, ignore if dir already exists
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
char path[1024];
|
||||
strcpy(path, full_path);
|
||||
path[2*d+2] = '\0';
|
||||
int err = lfs_mkdir(&lfs, path);
|
||||
assert(!err || err == LFS_ERR_EXIST);
|
||||
}
|
||||
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
char path[1024];
|
||||
strcpy(path, full_path);
|
||||
path[2*d+2] = '\0';
|
||||
lfs_stat(&lfs, path, &info) => 0;
|
||||
assert(strcmp(info.name, &path[2*d+1]) == 0);
|
||||
assert(info.type == LFS_TYPE_DIR);
|
||||
}
|
||||
} else {
|
||||
assert(strcmp(info.name, &full_path[2*(DEPTH-1)+1]) == 0);
|
||||
assert(info.type == LFS_TYPE_DIR);
|
||||
|
||||
// create new random path
|
||||
char new_path[256];
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
sprintf(&new_path[2*d], "/%c", alpha[TEST_PRNG(&prng) % FILES]);
|
||||
}
|
||||
|
||||
// if new path does not exist, rename, otherwise destroy
|
||||
res = lfs_stat(&lfs, new_path, &info);
|
||||
assert(!res || res == LFS_ERR_NOENT);
|
||||
if (res == LFS_ERR_NOENT) {
|
||||
// stop once some dir is renamed
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
char path[1024];
|
||||
strcpy(&path[2*d], &full_path[2*d]);
|
||||
path[2*d+2] = '\0';
|
||||
strcpy(&path[128+2*d], &new_path[2*d]);
|
||||
path[128+2*d+2] = '\0';
|
||||
int err = lfs_rename(&lfs, path, path+128);
|
||||
assert(!err || err == LFS_ERR_NOTEMPTY);
|
||||
if (!err) {
|
||||
strcpy(path, path+128);
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned d = 0; d < DEPTH; d++) {
|
||||
char path[1024];
|
||||
strcpy(path, new_path);
|
||||
path[2*d+2] = '\0';
|
||||
lfs_stat(&lfs, path, &info) => 0;
|
||||
assert(strcmp(info.name, &path[2*d+1]) == 0);
|
||||
assert(info.type == LFS_TYPE_DIR);
|
||||
}
|
||||
|
||||
lfs_stat(&lfs, full_path, &info) => LFS_ERR_NOENT;
|
||||
} else {
|
||||
// try to delete path in reverse order,
|
||||
// ignore if dir is not empty
|
||||
for (unsigned d = DEPTH-1; d+1 > 0; d--) {
|
||||
char path[1024];
|
||||
strcpy(path, full_path);
|
||||
path[2*d+2] = '\0';
|
||||
int err = lfs_remove(&lfs, path);
|
||||
assert(!err || err == LFS_ERR_NOTEMPTY);
|
||||
}
|
||||
|
||||
lfs_stat(&lfs, full_path, &info) => LFS_ERR_NOENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
@@ -137,6 +137,130 @@ code = '''
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
# boundary seek and reads
|
||||
[cases.test_seek_boundary_read]
|
||||
defines.COUNT = 132
|
||||
code = '''
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_file_t file;
|
||||
lfs_file_open(&lfs, &file, "kitty",
|
||||
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
|
||||
size_t size = strlen("kittycatcat");
|
||||
uint8_t buffer[1024];
|
||||
memcpy(buffer, "kittycatcat", size);
|
||||
for (int j = 0; j < COUNT; j++) {
|
||||
lfs_file_write(&lfs, &file, buffer, size);
|
||||
}
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_file_open(&lfs, &file, "kitty", LFS_O_RDONLY) => 0;
|
||||
|
||||
size = strlen("kittycatcat");
|
||||
const lfs_soff_t offsets[] = {
|
||||
512,
|
||||
1024-4,
|
||||
512+1,
|
||||
1024-4+1,
|
||||
512-1,
|
||||
1024-4-1,
|
||||
|
||||
512-strlen("kittycatcat"),
|
||||
1024-4-strlen("kittycatcat"),
|
||||
512-strlen("kittycatcat")+1,
|
||||
1024-4-strlen("kittycatcat")+1,
|
||||
512-strlen("kittycatcat")-1,
|
||||
1024-4-strlen("kittycatcat")-1,
|
||||
|
||||
strlen("kittycatcat")*(COUNT-2)-1,
|
||||
};
|
||||
|
||||
for (unsigned i = 0; i < sizeof(offsets) / sizeof(offsets[0]); i++) {
|
||||
lfs_soff_t off = offsets[i];
|
||||
// read @ offset
|
||||
lfs_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
|
||||
lfs_file_read(&lfs, &file, buffer, size) => size;
|
||||
memcmp(buffer,
|
||||
&"kittycatcatkittycatcat"[off % strlen("kittycatcat")],
|
||||
size) => 0;
|
||||
// read after
|
||||
lfs_file_seek(&lfs, &file, off+strlen("kittycatcat")+1, LFS_SEEK_SET)
|
||||
=> off+strlen("kittycatcat")+1;
|
||||
lfs_file_read(&lfs, &file, buffer, size) => size;
|
||||
memcmp(buffer,
|
||||
&"kittycatcatkittycatcat"[(off+1) % strlen("kittycatcat")],
|
||||
size) => 0;
|
||||
// read before
|
||||
lfs_file_seek(&lfs, &file, off-strlen("kittycatcat")-1, LFS_SEEK_SET)
|
||||
=> off-strlen("kittycatcat")-1;
|
||||
lfs_file_read(&lfs, &file, buffer, size) => size;
|
||||
memcmp(buffer,
|
||||
&"kittycatcatkittycatcat"[(off-1) % strlen("kittycatcat")],
|
||||
size) => 0;
|
||||
|
||||
// read @ 0
|
||||
lfs_file_seek(&lfs, &file, 0, LFS_SEEK_SET) => 0;
|
||||
lfs_file_read(&lfs, &file, buffer, size) => size;
|
||||
memcmp(buffer, "kittycatcat", size) => 0;
|
||||
|
||||
// read @ offset
|
||||
lfs_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
|
||||
lfs_file_read(&lfs, &file, buffer, size) => size;
|
||||
memcmp(buffer,
|
||||
&"kittycatcatkittycatcat"[off % strlen("kittycatcat")],
|
||||
size) => 0;
|
||||
// read after
|
||||
lfs_file_seek(&lfs, &file, off+strlen("kittycatcat")+1, LFS_SEEK_SET)
|
||||
=> off+strlen("kittycatcat")+1;
|
||||
lfs_file_read(&lfs, &file, buffer, size) => size;
|
||||
memcmp(buffer,
|
||||
&"kittycatcatkittycatcat"[(off+1) % strlen("kittycatcat")],
|
||||
size) => 0;
|
||||
// read before
|
||||
lfs_file_seek(&lfs, &file, off-strlen("kittycatcat")-1, LFS_SEEK_SET)
|
||||
=> off-strlen("kittycatcat")-1;
|
||||
lfs_file_read(&lfs, &file, buffer, size) => size;
|
||||
memcmp(buffer,
|
||||
&"kittycatcatkittycatcat"[(off-1) % strlen("kittycatcat")],
|
||||
size) => 0;
|
||||
|
||||
// sync
|
||||
lfs_file_sync(&lfs, &file) => 0;
|
||||
|
||||
// read @ 0
|
||||
lfs_file_seek(&lfs, &file, 0, LFS_SEEK_SET) => 0;
|
||||
lfs_file_read(&lfs, &file, buffer, size) => size;
|
||||
memcmp(buffer, "kittycatcat", size) => 0;
|
||||
|
||||
// read @ offset
|
||||
lfs_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
|
||||
lfs_file_read(&lfs, &file, buffer, size) => size;
|
||||
memcmp(buffer,
|
||||
&"kittycatcatkittycatcat"[off % strlen("kittycatcat")],
|
||||
size) => 0;
|
||||
// read after
|
||||
lfs_file_seek(&lfs, &file, off+strlen("kittycatcat")+1, LFS_SEEK_SET)
|
||||
=> off+strlen("kittycatcat")+1;
|
||||
lfs_file_read(&lfs, &file, buffer, size) => size;
|
||||
memcmp(buffer,
|
||||
&"kittycatcatkittycatcat"[(off+1) % strlen("kittycatcat")],
|
||||
size) => 0;
|
||||
// read before
|
||||
lfs_file_seek(&lfs, &file, off-strlen("kittycatcat")-1, LFS_SEEK_SET)
|
||||
=> off-strlen("kittycatcat")-1;
|
||||
lfs_file_read(&lfs, &file, buffer, size) => size;
|
||||
memcmp(buffer,
|
||||
&"kittycatcatkittycatcat"[(off-1) % strlen("kittycatcat")],
|
||||
size) => 0;
|
||||
}
|
||||
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
# boundary seek and writes
|
||||
[cases.test_seek_boundary_write]
|
||||
defines.COUNT = 132
|
||||
@@ -160,31 +284,54 @@ code = '''
|
||||
lfs_file_open(&lfs, &file, "kitty", LFS_O_RDWR) => 0;
|
||||
|
||||
size = strlen("hedgehoghog");
|
||||
const lfs_soff_t offsets[] = {512, 1020, 513, 1021, 511, 1019, 1441};
|
||||
const lfs_soff_t offsets[] = {
|
||||
512,
|
||||
1024-4,
|
||||
512+1,
|
||||
1024-4+1,
|
||||
512-1,
|
||||
1024-4-1,
|
||||
|
||||
512-strlen("kittycatcat"),
|
||||
1024-4-strlen("kittycatcat"),
|
||||
512-strlen("kittycatcat")+1,
|
||||
1024-4-strlen("kittycatcat")+1,
|
||||
512-strlen("kittycatcat")-1,
|
||||
1024-4-strlen("kittycatcat")-1,
|
||||
|
||||
strlen("kittycatcat")*(COUNT-2)-1,
|
||||
};
|
||||
|
||||
for (unsigned i = 0; i < sizeof(offsets) / sizeof(offsets[0]); i++) {
|
||||
lfs_soff_t off = offsets[i];
|
||||
// write @ offset
|
||||
memcpy(buffer, "hedgehoghog", size);
|
||||
lfs_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
|
||||
lfs_file_write(&lfs, &file, buffer, size) => size;
|
||||
|
||||
// read @ offset
|
||||
lfs_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
|
||||
lfs_file_read(&lfs, &file, buffer, size) => size;
|
||||
memcmp(buffer, "hedgehoghog", size) => 0;
|
||||
|
||||
// read @ 0
|
||||
lfs_file_seek(&lfs, &file, 0, LFS_SEEK_SET) => 0;
|
||||
lfs_file_read(&lfs, &file, buffer, size) => size;
|
||||
memcmp(buffer, "kittycatcat", size) => 0;
|
||||
|
||||
// read @ offset
|
||||
lfs_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
|
||||
lfs_file_read(&lfs, &file, buffer, size) => size;
|
||||
memcmp(buffer, "hedgehoghog", size) => 0;
|
||||
|
||||
lfs_file_sync(&lfs, &file) => 0;
|
||||
|
||||
// read @ 0
|
||||
lfs_file_seek(&lfs, &file, 0, LFS_SEEK_SET) => 0;
|
||||
lfs_file_read(&lfs, &file, buffer, size) => size;
|
||||
memcmp(buffer, "kittycatcat", size) => 0;
|
||||
|
||||
// read @ offset
|
||||
lfs_file_seek(&lfs, &file, off, LFS_SEEK_SET) => off;
|
||||
lfs_file_read(&lfs, &file, buffer, size) => size;
|
||||
memcmp(buffer, "hedgehoghog", size) => 0;
|
||||
@@ -405,3 +552,111 @@ code = '''
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
|
||||
# test possible overflow/underflow conditions
|
||||
#
|
||||
# note these need -fsanitize=undefined to consistently detect
|
||||
# overflow/underflow conditions
|
||||
|
||||
[cases.test_seek_filemax]
|
||||
code = '''
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_file_t file;
|
||||
lfs_file_open(&lfs, &file, "kitty",
|
||||
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
|
||||
uint8_t buffer[1024];
|
||||
strcpy((char*)buffer, "kittycatcat");
|
||||
size_t size = strlen((char*)buffer);
|
||||
lfs_file_write(&lfs, &file, buffer, size) => size;
|
||||
|
||||
// seek with LFS_SEEK_SET
|
||||
lfs_file_seek(&lfs, &file, LFS_FILE_MAX, LFS_SEEK_SET) => LFS_FILE_MAX;
|
||||
|
||||
// seek with LFS_SEEK_CUR
|
||||
lfs_file_seek(&lfs, &file, 0, LFS_SEEK_CUR) => LFS_FILE_MAX;
|
||||
|
||||
// the file hasn't changed size, so seek end takes us back to the offset=0
|
||||
lfs_file_seek(&lfs, &file, +10, LFS_SEEK_END) => size+10;
|
||||
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
[cases.test_seek_underflow]
|
||||
code = '''
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_file_t file;
|
||||
lfs_file_open(&lfs, &file, "kitty",
|
||||
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
|
||||
uint8_t buffer[1024];
|
||||
strcpy((char*)buffer, "kittycatcat");
|
||||
size_t size = strlen((char*)buffer);
|
||||
lfs_file_write(&lfs, &file, buffer, size) => size;
|
||||
|
||||
// underflow with LFS_SEEK_CUR, should error
|
||||
lfs_file_seek(&lfs, &file, -(size+10), LFS_SEEK_CUR) => LFS_ERR_INVAL;
|
||||
lfs_file_seek(&lfs, &file, -LFS_FILE_MAX, LFS_SEEK_CUR) => LFS_ERR_INVAL;
|
||||
lfs_file_seek(&lfs, &file, -(size+LFS_FILE_MAX), LFS_SEEK_CUR)
|
||||
=> LFS_ERR_INVAL;
|
||||
|
||||
// underflow with LFS_SEEK_END, should error
|
||||
lfs_file_seek(&lfs, &file, -(size+10), LFS_SEEK_END) => LFS_ERR_INVAL;
|
||||
lfs_file_seek(&lfs, &file, -LFS_FILE_MAX, LFS_SEEK_END) => LFS_ERR_INVAL;
|
||||
lfs_file_seek(&lfs, &file, -(size+LFS_FILE_MAX), LFS_SEEK_END)
|
||||
=> LFS_ERR_INVAL;
|
||||
|
||||
// file pointer should not have changed
|
||||
lfs_file_tell(&lfs, &file) => size;
|
||||
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
[cases.test_seek_overflow]
|
||||
code = '''
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_file_t file;
|
||||
lfs_file_open(&lfs, &file, "kitty",
|
||||
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
|
||||
uint8_t buffer[1024];
|
||||
strcpy((char*)buffer, "kittycatcat");
|
||||
size_t size = strlen((char*)buffer);
|
||||
lfs_file_write(&lfs, &file, buffer, size) => size;
|
||||
|
||||
// seek to LFS_FILE_MAX
|
||||
lfs_file_seek(&lfs, &file, LFS_FILE_MAX, LFS_SEEK_SET) => LFS_FILE_MAX;
|
||||
|
||||
// overflow with LFS_SEEK_CUR, should error
|
||||
lfs_file_seek(&lfs, &file, +10, LFS_SEEK_CUR) => LFS_ERR_INVAL;
|
||||
lfs_file_seek(&lfs, &file, +LFS_FILE_MAX, LFS_SEEK_CUR) => LFS_ERR_INVAL;
|
||||
|
||||
// LFS_SEEK_SET/END don't care about the current file position, but we can
|
||||
// still overflow with a large offset
|
||||
|
||||
// overflow with LFS_SEEK_SET, should error
|
||||
lfs_file_seek(&lfs, &file,
|
||||
+((uint32_t)LFS_FILE_MAX+10),
|
||||
LFS_SEEK_SET) => LFS_ERR_INVAL;
|
||||
lfs_file_seek(&lfs, &file,
|
||||
+((uint32_t)LFS_FILE_MAX+(uint32_t)LFS_FILE_MAX),
|
||||
LFS_SEEK_SET) => LFS_ERR_INVAL;
|
||||
|
||||
// overflow with LFS_SEEK_END, should error
|
||||
lfs_file_seek(&lfs, &file, +(LFS_FILE_MAX-size+10), LFS_SEEK_END)
|
||||
=> LFS_ERR_INVAL;
|
||||
lfs_file_seek(&lfs, &file, +(LFS_FILE_MAX-size+LFS_FILE_MAX), LFS_SEEK_END)
|
||||
=> LFS_ERR_INVAL;
|
||||
|
||||
// file pointer should not have changed
|
||||
lfs_file_tell(&lfs, &file) => LFS_FILE_MAX;
|
||||
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
109
tests/test_shrink.toml
Normal file
109
tests/test_shrink.toml
Normal file
@@ -0,0 +1,109 @@
|
||||
# simple shrink
|
||||
[cases.test_shrink_simple]
|
||||
defines.BLOCK_COUNT = [10, 15, 20]
|
||||
defines.AFTER_BLOCK_COUNT = [5, 10, 15, 19]
|
||||
|
||||
if = "AFTER_BLOCK_COUNT <= BLOCK_COUNT"
|
||||
code = '''
|
||||
#ifdef LFS_SHRINKNONRELOCATING
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_fs_grow(&lfs, AFTER_BLOCK_COUNT) => 0;
|
||||
lfs_unmount(&lfs);
|
||||
if (BLOCK_COUNT != AFTER_BLOCK_COUNT) {
|
||||
lfs_mount(&lfs, cfg) => LFS_ERR_INVAL;
|
||||
}
|
||||
lfs_t lfs2 = lfs;
|
||||
struct lfs_config cfg2 = *cfg;
|
||||
cfg2.block_count = AFTER_BLOCK_COUNT;
|
||||
lfs2.cfg = &cfg2;
|
||||
lfs_mount(&lfs2, &cfg2) => 0;
|
||||
lfs_unmount(&lfs2) => 0;
|
||||
#endif
|
||||
'''
|
||||
|
||||
# shrinking full
|
||||
[cases.test_shrink_full]
|
||||
defines.BLOCK_COUNT = [10, 15, 20]
|
||||
defines.AFTER_BLOCK_COUNT = [5, 7, 10, 12, 15, 17, 20]
|
||||
defines.FILES_COUNT = [7, 8, 9, 10]
|
||||
if = "AFTER_BLOCK_COUNT <= BLOCK_COUNT && FILES_COUNT + 2 < BLOCK_COUNT"
|
||||
code = '''
|
||||
#ifdef LFS_SHRINKNONRELOCATING
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
// create FILES_COUNT files of BLOCK_SIZE - 50 bytes (to avoid inlining)
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
for (int i = 0; i < FILES_COUNT + 1; i++) {
|
||||
lfs_file_t file;
|
||||
char path[1024];
|
||||
sprintf(path, "file_%03d", i);
|
||||
lfs_file_open(&lfs, &file, path,
|
||||
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
|
||||
char wbuffer[BLOCK_SIZE];
|
||||
memset(wbuffer, 'b', BLOCK_SIZE);
|
||||
// Ensure one block is taken per file, but that files are not inlined.
|
||||
lfs_size_t size = BLOCK_SIZE - 0x40;
|
||||
sprintf(wbuffer, "Hi %03d", i);
|
||||
lfs_file_write(&lfs, &file, wbuffer, size) => size;
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
}
|
||||
|
||||
int err = lfs_fs_grow(&lfs, AFTER_BLOCK_COUNT);
|
||||
if (err == 0) {
|
||||
for (int i = 0; i < FILES_COUNT + 1; i++) {
|
||||
lfs_file_t file;
|
||||
char path[1024];
|
||||
sprintf(path, "file_%03d", i);
|
||||
lfs_file_open(&lfs, &file, path,
|
||||
LFS_O_RDONLY ) => 0;
|
||||
lfs_size_t size = BLOCK_SIZE - 0x40;
|
||||
char wbuffer[size];
|
||||
char wbuffer_ref[size];
|
||||
// Ensure one block is taken per file, but that files are not inlined.
|
||||
memset(wbuffer_ref, 'b', size);
|
||||
sprintf(wbuffer_ref, "Hi %03d", i);
|
||||
lfs_file_read(&lfs, &file, wbuffer, BLOCK_SIZE) => size;
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
for (lfs_size_t j = 0; j < size; j++) {
|
||||
wbuffer[j] => wbuffer_ref[j];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
assert(err == LFS_ERR_NOTEMPTY);
|
||||
}
|
||||
|
||||
lfs_unmount(&lfs) => 0;
|
||||
if (err == 0 ) {
|
||||
if ( AFTER_BLOCK_COUNT != BLOCK_COUNT ) {
|
||||
lfs_mount(&lfs, cfg) => LFS_ERR_INVAL;
|
||||
}
|
||||
|
||||
lfs_t lfs2 = lfs;
|
||||
struct lfs_config cfg2 = *cfg;
|
||||
cfg2.block_count = AFTER_BLOCK_COUNT;
|
||||
lfs2.cfg = &cfg2;
|
||||
lfs_mount(&lfs2, &cfg2) => 0;
|
||||
for (int i = 0; i < FILES_COUNT + 1; i++) {
|
||||
lfs_file_t file;
|
||||
char path[1024];
|
||||
sprintf(path, "file_%03d", i);
|
||||
lfs_file_open(&lfs2, &file, path,
|
||||
LFS_O_RDONLY ) => 0;
|
||||
lfs_size_t size = BLOCK_SIZE - 0x40;
|
||||
char wbuffer[size];
|
||||
char wbuffer_ref[size];
|
||||
// Ensure one block is taken per file, but that files are not inlined.
|
||||
memset(wbuffer_ref, 'b', size);
|
||||
sprintf(wbuffer_ref, "Hi %03d", i);
|
||||
lfs_file_read(&lfs2, &file, wbuffer, BLOCK_SIZE) => size;
|
||||
lfs_file_close(&lfs2, &file) => 0;
|
||||
for (lfs_size_t j = 0; j < size; j++) {
|
||||
wbuffer[j] => wbuffer_ref[j];
|
||||
}
|
||||
}
|
||||
lfs_unmount(&lfs2);
|
||||
}
|
||||
#endif
|
||||
'''
|
||||
@@ -523,3 +523,138 @@ code = '''
|
||||
assert(memcmp(buffer, "hello!", 6) == 0);
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
|
||||
# mount and grow the filesystem
|
||||
[cases.test_superblocks_shrink]
|
||||
defines.BLOCK_COUNT = 'ERASE_COUNT'
|
||||
defines.BLOCK_COUNT_2 = ['ERASE_COUNT/2', 'ERASE_COUNT/4', '2']
|
||||
defines.KNOWN_BLOCK_COUNT = [true, false]
|
||||
code = '''
|
||||
#ifdef LFS_SHRINKNONRELOCATING
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
|
||||
if (KNOWN_BLOCK_COUNT) {
|
||||
cfg->block_count = BLOCK_COUNT;
|
||||
} else {
|
||||
cfg->block_count = 0;
|
||||
}
|
||||
|
||||
// mount with block_size < erase_size
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
struct lfs_fsinfo fsinfo;
|
||||
lfs_fs_stat(&lfs, &fsinfo) => 0;
|
||||
assert(fsinfo.block_size == BLOCK_SIZE);
|
||||
assert(fsinfo.block_count == BLOCK_COUNT);
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
// same size is a noop
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_fs_grow(&lfs, BLOCK_COUNT) => 0;
|
||||
lfs_fs_stat(&lfs, &fsinfo) => 0;
|
||||
assert(fsinfo.block_size == BLOCK_SIZE);
|
||||
assert(fsinfo.block_count == BLOCK_COUNT);
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_fs_stat(&lfs, &fsinfo) => 0;
|
||||
assert(fsinfo.block_size == BLOCK_SIZE);
|
||||
assert(fsinfo.block_count == BLOCK_COUNT);
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
// grow to new size
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_fs_grow(&lfs, BLOCK_COUNT_2) => 0;
|
||||
lfs_fs_stat(&lfs, &fsinfo) => 0;
|
||||
assert(fsinfo.block_size == BLOCK_SIZE);
|
||||
assert(fsinfo.block_count == BLOCK_COUNT_2);
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
if (KNOWN_BLOCK_COUNT) {
|
||||
cfg->block_count = BLOCK_COUNT_2;
|
||||
} else {
|
||||
cfg->block_count = 0;
|
||||
}
|
||||
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_fs_stat(&lfs, &fsinfo) => 0;
|
||||
assert(fsinfo.block_size == BLOCK_SIZE);
|
||||
assert(fsinfo.block_count == BLOCK_COUNT_2);
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
// mounting with the previous size should fail
|
||||
cfg->block_count = BLOCK_COUNT;
|
||||
lfs_mount(&lfs, cfg) => LFS_ERR_INVAL;
|
||||
|
||||
if (KNOWN_BLOCK_COUNT) {
|
||||
cfg->block_count = BLOCK_COUNT_2;
|
||||
} else {
|
||||
cfg->block_count = 0;
|
||||
}
|
||||
|
||||
// same size is a noop
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_fs_grow(&lfs, BLOCK_COUNT_2) => 0;
|
||||
lfs_fs_stat(&lfs, &fsinfo) => 0;
|
||||
assert(fsinfo.block_size == BLOCK_SIZE);
|
||||
assert(fsinfo.block_count == BLOCK_COUNT_2);
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_fs_stat(&lfs, &fsinfo) => 0;
|
||||
assert(fsinfo.block_size == BLOCK_SIZE);
|
||||
assert(fsinfo.block_count == BLOCK_COUNT_2);
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
// do some work
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_fs_stat(&lfs, &fsinfo) => 0;
|
||||
assert(fsinfo.block_size == BLOCK_SIZE);
|
||||
assert(fsinfo.block_count == BLOCK_COUNT_2);
|
||||
lfs_file_t file;
|
||||
lfs_file_open(&lfs, &file, "test",
|
||||
LFS_O_CREAT | LFS_O_EXCL | LFS_O_WRONLY) => 0;
|
||||
lfs_file_write(&lfs, &file, "hello!", 6) => 6;
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
lfs_fs_stat(&lfs, &fsinfo) => 0;
|
||||
assert(fsinfo.block_size == BLOCK_SIZE);
|
||||
assert(fsinfo.block_count == BLOCK_COUNT_2);
|
||||
lfs_file_open(&lfs, &file, "test", LFS_O_RDONLY) => 0;
|
||||
uint8_t buffer[256];
|
||||
lfs_file_read(&lfs, &file, buffer, sizeof(buffer)) => 6;
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
assert(memcmp(buffer, "hello!", 6) == 0);
|
||||
lfs_unmount(&lfs) => 0;
|
||||
#endif
|
||||
'''
|
||||
|
||||
# test that metadata_max does not cause problems for superblock compaction
|
||||
[cases.test_superblocks_metadata_max]
|
||||
defines.METADATA_MAX = [
|
||||
'lfs_max(512, PROG_SIZE)',
|
||||
'lfs_max(BLOCK_SIZE/2, PROG_SIZE)',
|
||||
'BLOCK_SIZE'
|
||||
]
|
||||
defines.N = [10, 100, 1000]
|
||||
code = '''
|
||||
lfs_t lfs;
|
||||
lfs_format(&lfs, cfg) => 0;
|
||||
lfs_mount(&lfs, cfg) => 0;
|
||||
for (int i = 0; i < N; i++) {
|
||||
lfs_file_t file;
|
||||
char name[256];
|
||||
sprintf(name, "hello%03x", i);
|
||||
lfs_file_open(&lfs, &file, name,
|
||||
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
|
||||
lfs_file_close(&lfs, &file) => 0;
|
||||
struct lfs_info info;
|
||||
lfs_stat(&lfs, name, &info) => 0;
|
||||
assert(strcmp(info.name, name) == 0);
|
||||
assert(info.type == LFS_TYPE_REG);
|
||||
}
|
||||
lfs_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
Reference in New Issue
Block a user