Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit16ceb67

Browse files
authored
Merge pull request#1103 from littlefs-project/devel
Minor release: v2.11
2 parents8ed63b2 +8434536 commit16ceb67

File tree

14 files changed

+571
-51
lines changed

14 files changed

+571
-51
lines changed

‎.github/workflows/test.yml‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,22 @@ jobs:
374374
run:|
375375
CFLAGS="$CFLAGS -DLFS_NO_INTRINSICS" make test
376376
377+
test-shrink:
378+
runs-on:ubuntu-latest
379+
steps:
380+
-uses:actions/checkout@v4
381+
-name:install
382+
run:|
383+
# need a few things
384+
sudo apt-get update -qq
385+
sudo apt-get install -qq gcc python3 python3-pip
386+
pip3 install toml
387+
gcc --version
388+
python3 --version
389+
-name:test-no-intrinsics
390+
run:|
391+
CFLAGS="$CFLAGS -DLFS_SHRINKNONRELOCATING" make test
392+
377393
# run with all trace options enabled to at least make sure these
378394
# all compile
379395
test-yes-trace:
@@ -454,8 +470,7 @@ jobs:
454470
TESTFLAGS="$TESTFLAGS --valgrind --context=1024 -Gdefault -Pnone" \
455471
make test
456472
457-
# test that compilation is warning free under clang
458-
# run with Clang, mostly to check for Clang-specific warnings
473+
# compile/run with Clang, mostly to check for Clang-specific warnings
459474
test-clang:
460475
runs-on:ubuntu-latest
461476
steps:
@@ -469,12 +484,8 @@ jobs:
469484
python3 --version
470485
-name:test-clang
471486
run:|
472-
# override CFLAGS since Clang does not support -fcallgraph-info
473-
# and -ftrack-macro-expansions
474-
make \
475-
CC=clang \
476-
CFLAGS="$CFLAGS -MMD -g3 -I. -std=c99 -Wall -Wextra -pedantic" \
477-
test
487+
CC=clang \
488+
make test
478489
479490
# run benchmarks
480491
#

‎Makefile‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ VALGRIND ?= valgrind
1818
GDB ?= gdb
1919
PERF ?= perf
2020

21+
# guess clang or gcc (clang sometimes masquerades as gcc because of
22+
# course it does)
23+
ifneq ($(shell$(CC) --version | grep clang),)
24+
NO_GCC = 1
25+
endif
26+
2127
SRC ?=$(filter-out$(wildcard*.t.**.b.*),$(wildcard*.c))
2228
OBJ :=$(SRC:%.c=$(BUILDDIR)/%.o)
2329
DEP :=$(SRC:%.c=$(BUILDDIR)/%.d)
@@ -59,12 +65,15 @@ BENCH_PERF := $(BENCH_RUNNER:%=%.perf)
5965
BENCH_TRACE :=$(BENCH_RUNNER:%=%.trace)
6066
BENCH_CSV :=$(BENCH_RUNNER:%=%.csv)
6167

62-
CFLAGS += -fcallgraph-info=su
6368
CFLAGS += -g3
6469
CFLAGS += -I.
6570
CFLAGS += -std=c99 -Wall -Wextra -pedantic
6671
CFLAGS += -Wmissing-prototypes
72+
ifndefNO_GCC
73+
CFLAGS += -fcallgraph-info=su
6774
CFLAGS += -ftrack-macro-expansion=0
75+
endif
76+
6877
ifdefDEBUG
6978
CFLAGS += -O0
7079
else

‎lfs.c‎

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3932,7 +3932,9 @@ static int lfs_remove_(lfs_t *lfs, const char *path) {
39323932
}
39333933

39343934
lfs->mlist=dir.next;
3935-
if (lfs_tag_type3(tag)==LFS_TYPE_DIR) {
3935+
if (lfs_gstate_hasorphans(&lfs->gstate)) {
3936+
LFS_ASSERT(lfs_tag_type3(tag)==LFS_TYPE_DIR);
3937+
39363938
// fix orphan
39373939
err=lfs_fs_preporphans(lfs,-1);
39383940
if (err) {
@@ -4076,8 +4078,10 @@ static int lfs_rename_(lfs_t *lfs, const char *oldpath, const char *newpath) {
40764078
}
40774079

40784080
lfs->mlist=prevdir.next;
4079-
if (prevtag!=LFS_ERR_NOENT
4080-
&&lfs_tag_type3(prevtag)==LFS_TYPE_DIR) {
4081+
if (lfs_gstate_hasorphans(&lfs->gstate)) {
4082+
LFS_ASSERT(prevtag!=LFS_ERR_NOENT
4083+
&&lfs_tag_type3(prevtag)==LFS_TYPE_DIR);
4084+
40814085
// fix orphan
40824086
err=lfs_fs_preporphans(lfs,-1);
40834087
if (err) {
@@ -5233,40 +5237,64 @@ static int lfs_fs_gc_(lfs_t *lfs) {
52335237
#endif
52345238

52355239
#ifndefLFS_READONLY
5240+
#ifdefLFS_SHRINKNONRELOCATING
5241+
staticintlfs_shrink_checkblock(void*data,lfs_block_tblock) {
5242+
lfs_size_tthreshold=*((lfs_size_t*)data);
5243+
if (block >=threshold) {
5244+
returnLFS_ERR_NOTEMPTY;
5245+
}
5246+
return0;
5247+
}
5248+
#endif
5249+
52365250
staticintlfs_fs_grow_(lfs_t*lfs,lfs_size_tblock_count) {
5237-
// shrinking is not supported
5238-
LFS_ASSERT(block_count >=lfs->block_count);
5251+
interr;
52395252

5240-
if (block_count>lfs->block_count) {
5241-
lfs->block_count=block_count;
5253+
if (block_count==lfs->block_count) {
5254+
return0;
5255+
}
52425256

5243-
// fetch the root
5244-
lfs_mdir_troot;
5245-
interr=lfs_dir_fetch(lfs,&root,lfs->root);
5257+
5258+
#ifndefLFS_SHRINKNONRELOCATING
5259+
// shrinking is not supported
5260+
LFS_ASSERT(block_count >=lfs->block_count);
5261+
#endif
5262+
#ifdefLFS_SHRINKNONRELOCATING
5263+
if (block_count<lfs->block_count) {
5264+
err=lfs_fs_traverse_(lfs,lfs_shrink_checkblock,&block_count, true);
52465265
if (err) {
52475266
returnerr;
52485267
}
5268+
}
5269+
#endif
52495270

5250-
// update the superblock
5251-
lfs_superblock_tsuperblock;
5252-
lfs_stag_ttag=lfs_dir_get(lfs,&root,LFS_MKTAG(0x7ff,0x3ff,0),
5253-
LFS_MKTAG(LFS_TYPE_INLINESTRUCT,0,sizeof(superblock)),
5254-
&superblock);
5255-
if (tag<0) {
5256-
returntag;
5257-
}
5258-
lfs_superblock_fromle32(&superblock);
5271+
lfs->block_count=block_count;
52595272

5260-
superblock.block_count=lfs->block_count;
5273+
// fetch the root
5274+
lfs_mdir_troot;
5275+
err=lfs_dir_fetch(lfs,&root,lfs->root);
5276+
if (err) {
5277+
returnerr;
5278+
}
52615279

5262-
lfs_superblock_tole32(&superblock);
5263-
err=lfs_dir_commit(lfs,&root,LFS_MKATTRS(
5264-
{tag,&superblock}));
5265-
if (err) {
5266-
returnerr;
5267-
}
5280+
// update the superblock
5281+
lfs_superblock_tsuperblock;
5282+
lfs_stag_ttag=lfs_dir_get(lfs,&root,LFS_MKTAG(0x7ff,0x3ff,0),
5283+
LFS_MKTAG(LFS_TYPE_INLINESTRUCT,0,sizeof(superblock)),
5284+
&superblock);
5285+
if (tag<0) {
5286+
returntag;
52685287
}
5288+
lfs_superblock_fromle32(&superblock);
5289+
5290+
superblock.block_count=lfs->block_count;
52695291

5292+
lfs_superblock_tole32(&superblock);
5293+
err=lfs_dir_commit(lfs,&root,LFS_MKATTRS(
5294+
{tag,&superblock}));
5295+
if (err) {
5296+
returnerr;
5297+
}
52705298
return0;
52715299
}
52725300
#endif

‎lfs.h‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extern "C"
2121
// Software library version
2222
// Major (top-nibble), incremented on backwards incompatible changes
2323
// Minor (bottom-nibble), incremented on feature additions
24-
#defineLFS_VERSION0x0002000a
24+
#defineLFS_VERSION0x0002000b
2525
#defineLFS_VERSION_MAJOR (0xffff & (LFS_VERSION >> 16))
2626
#defineLFS_VERSION_MINOR (0xffff & (LFS_VERSION >> 0))
2727

@@ -766,7 +766,11 @@ int lfs_fs_gc(lfs_t *lfs);
766766
// Grows the filesystem to a new size, updating the superblock with the new
767767
// block count.
768768
//
769-
// Note: This is irreversible.
769+
// If LFS_SHRINKNONRELOCATING is defined, this function will also accept
770+
// block_counts smaller than the current configuration, after checking
771+
// that none of the blocks that are being removed are in use.
772+
// Note that littlefs's pseudorandom block allocation means that
773+
// this is very unlikely to work in the general case.
770774
//
771775
// Returns a negative error code on failure.
772776
intlfs_fs_grow(lfs_t*lfs,lfs_size_tblock_count);

‎lfs_util.h‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ static inline uint32_t lfs_fromle32(uint32_t a) {
195195
(defined(__BYTE_ORDER__)&& defined(__ORDER_BIG_ENDIAN__)&&__BYTE_ORDER__==__ORDER_BIG_ENDIAN__))
196196
return__builtin_bswap32(a);
197197
#else
198-
return (((uint8_t*)&a)[0] <<0) |
199-
(((uint8_t*)&a)[1] <<8) |
200-
(((uint8_t*)&a)[2] <<16) |
201-
(((uint8_t*)&a)[3] <<24);
198+
return ((uint32_t)((uint8_t*)&a)[0] <<0) |
199+
((uint32_t)((uint8_t*)&a)[1] <<8) |
200+
((uint32_t)((uint8_t*)&a)[2] <<16) |
201+
((uint32_t)((uint8_t*)&a)[3] <<24);
202202
#endif
203203
}
204204

@@ -218,10 +218,10 @@ static inline uint32_t lfs_frombe32(uint32_t a) {
218218
(defined(__BYTE_ORDER__)&& defined(__ORDER_BIG_ENDIAN__)&&__BYTE_ORDER__==__ORDER_BIG_ENDIAN__)
219219
returna;
220220
#else
221-
return (((uint8_t*)&a)[0] <<24) |
222-
(((uint8_t*)&a)[1] <<16) |
223-
(((uint8_t*)&a)[2] <<8) |
224-
(((uint8_t*)&a)[3] <<0);
221+
return ((uint32_t)((uint8_t*)&a)[0] <<24) |
222+
((uint32_t)((uint8_t*)&a)[1] <<16) |
223+
((uint32_t)((uint8_t*)&a)[2] <<8) |
224+
((uint32_t)((uint8_t*)&a)[3] <<0);
225225
#endif
226226
}
227227

@@ -231,8 +231,8 @@ static inline uint32_t lfs_tobe32(uint32_t a) {
231231

232232
// Calculate CRC-32 with polynomial = 0x04c11db7
233233
#ifdefLFS_CRC
234-
uint32_tlfs_crc(uint32_tcrc,constvoid*buffer,size_tsize) {
235-
returnLFS_CRC(crc,buffer,size)
234+
staticinlineuint32_tlfs_crc(uint32_tcrc,constvoid*buffer,size_tsize) {
235+
returnLFS_CRC(crc,buffer,size);
236236
}
237237
#else
238238
uint32_tlfs_crc(uint32_tcrc,constvoid*buffer,size_tsize);

‎runners/bench_runner.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,13 @@ typedef struct bench_id {
123123

124124

125125
// bench suites are linked into a custom ld section
126+
#if defined(__APPLE__)
127+
externstructbench_suite__start__bench_suites __asm("section$start$__DATA$_bench_suites");
128+
externstructbench_suite__stop__bench_suites __asm("section$end$__DATA$_bench_suites");
129+
#else
126130
externstructbench_suite__start__bench_suites;
127131
externstructbench_suite__stop__bench_suites;
132+
#endif
128133

129134
conststructbench_suite*bench_suites=&__start__bench_suites;
130135
#defineBENCH_SUITE_COUNT \

‎runners/test_runner.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,13 @@ typedef struct test_id {
136136

137137

138138
// test suites are linked into a custom ld section
139+
#if defined(__APPLE__)
140+
externstructtest_suite__start__test_suites __asm("section$start$__DATA$_test_suites");
141+
externstructtest_suite__stop__test_suites __asm("section$end$__DATA$_test_suites");
142+
#else
139143
externstructtest_suite__start__test_suites;
140144
externstructtest_suite__stop__test_suites;
145+
#endif
141146

142147
conststructtest_suite*test_suites=&__start__test_suites;
143148
#defineTEST_SUITE_COUNT \

‎scripts/bench.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,15 @@ def write_case_functions(f, suite, case):
404404
f.writeln()
405405

406406
# create suite struct
407-
#
407+
f.writeln('#if defined(__APPLE__)')
408+
f.writeln('__attribute__((section("__DATA,_bench_suites")))')
409+
f.writeln('#else')
408410
# note we place this in the custom bench_suites section with
409411
# minimum alignment, otherwise GCC ups the alignment to
410412
# 32-bytes for some reason
411413
f.writeln('__attribute__((section("_bench_suites"), '
412414
'aligned(1)))')
415+
f.writeln('#endif')
413416
f.writeln('const struct bench_suite __bench__%s__suite = {'
414417
%suite.name)
415418
f.writeln(4*' '+'.name = "%s",'%suite.name)

‎scripts/changeprefix.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def changefile(from_prefix, to_prefix, from_path, to_path, *,
7373
shutil.copystat(from_path,to_path)
7474

7575
ifto_path_temp:
76-
os.rename(to_path,from_path)
76+
shutil.move(to_path,from_path)
7777
eliffrom_path!='-':
7878
os.remove(from_path)
7979

‎scripts/test.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,15 @@ def write_case_functions(f, suite, case):
412412
f.writeln()
413413

414414
# create suite struct
415-
#
415+
f.writeln('#if defined(__APPLE__)')
416+
f.writeln('__attribute__((section("__DATA,_test_suites")))')
417+
f.writeln('#else')
416418
# note we place this in the custom test_suites section with
417419
# minimum alignment, otherwise GCC ups the alignment to
418420
# 32-bytes for some reason
419421
f.writeln('__attribute__((section("_test_suites"), '
420422
'aligned(1)))')
423+
f.writeln('#endif')
421424
f.writeln('const struct test_suite __test__%s__suite = {'
422425
%suite.name)
423426
f.writeln(4*' '+'.name = "%s",'%suite.name)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp