forked from Imagelibrary/littlefs
Compare commits
11 Commits
v2.8.0
...
tighter-ml
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b93cd18bf5 | ||
|
|
3513ff1afc | ||
|
|
8a22bd6e67 | ||
|
|
9b82db72d8 | ||
|
|
99b84ee3db | ||
|
|
e91a29d2b5 | ||
|
|
b9b95ab4bc | ||
|
|
10bcff1af8 | ||
|
|
c733d9ec57 | ||
|
|
8f3f32d1f3 | ||
|
|
92fc780f71 |
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -112,7 +112,7 @@ jobs:
|
||||
table[$i,$j]=$c_camel
|
||||
((j+=1))
|
||||
|
||||
for s in code stack struct
|
||||
for s in code stack structs
|
||||
do
|
||||
f=sizes/thumb${c:+-$c}.$s.csv
|
||||
[ -e $f ] && table[$i,$j]=$( \
|
||||
|
||||
@@ -59,7 +59,7 @@ This leaves us with three major requirements for an embedded filesystem.
|
||||
RAM to temporarily store filesystem metadata.
|
||||
|
||||
For ROM, this means we need to keep our design simple and reuse code paths
|
||||
were possible. For RAM we have a stronger requirement, all RAM usage is
|
||||
where possible. For RAM we have a stronger requirement, all RAM usage is
|
||||
bounded. This means RAM usage does not grow as the filesystem changes in
|
||||
size or number of files. This creates a unique challenge as even presumably
|
||||
simple operations, such as traversing the filesystem, become surprisingly
|
||||
@@ -626,7 +626,7 @@ log₂_n_ pointers that skip to different preceding elements of the
|
||||
skip-list.
|
||||
|
||||
The name comes from heavy use of the [CTZ instruction][wikipedia-ctz], which
|
||||
lets us calculate the power-of-two factors efficiently. For a give block _n_,
|
||||
lets us calculate the power-of-two factors efficiently. For a given block _n_,
|
||||
that block contains ctz(_n_)+1 pointers.
|
||||
|
||||
```
|
||||
|
||||
3
Makefile
3
Makefile
@@ -63,6 +63,7 @@ CFLAGS += -fcallgraph-info=su
|
||||
CFLAGS += -g3
|
||||
CFLAGS += -I.
|
||||
CFLAGS += -std=c99 -Wall -Wextra -pedantic
|
||||
CFLAGS += -Wmissing-prototypes
|
||||
CFLAGS += -ftrack-macro-expansion=0
|
||||
ifdef DEBUG
|
||||
CFLAGS += -O0
|
||||
@@ -354,6 +355,7 @@ summary-diff sizes-diff: $(OBJ) $(CI)
|
||||
|
||||
## Build the test-runner
|
||||
.PHONY: test-runner build-test
|
||||
test-runner build-test: CFLAGS+=-Wno-missing-prototypes
|
||||
ifndef NO_COV
|
||||
test-runner build-test: CFLAGS+=--coverage
|
||||
endif
|
||||
@@ -405,6 +407,7 @@ testmarks-diff: $(TEST_CSV)
|
||||
|
||||
## Build the bench-runner
|
||||
.PHONY: bench-runner build-bench
|
||||
bench-runner build-bench: CFLAGS+=-Wno-missing-prototypes
|
||||
ifdef YES_COV
|
||||
bench-runner build-bench: CFLAGS+=--coverage
|
||||
endif
|
||||
|
||||
28
lfs.c
28
lfs.c
@@ -505,6 +505,7 @@ static bool lfs_mlist_isopen(struct lfs_mlist *head,
|
||||
#endif
|
||||
|
||||
static void lfs_mlist_remove(lfs_t *lfs, struct lfs_mlist *mlist) {
|
||||
LFS_ASSERT(lfs_mlist_isopen(lfs->mlist, mlist));
|
||||
for (struct lfs_mlist **p = &lfs->mlist; *p; p = &(*p)->next) {
|
||||
if (*p == mlist) {
|
||||
*p = (*p)->next;
|
||||
@@ -514,6 +515,7 @@ static void lfs_mlist_remove(lfs_t *lfs, struct lfs_mlist *mlist) {
|
||||
}
|
||||
|
||||
static void lfs_mlist_append(lfs_t *lfs, struct lfs_mlist *mlist) {
|
||||
LFS_ASSERT(!lfs_mlist_isopen(lfs->mlist, mlist));
|
||||
mlist->next = lfs->mlist;
|
||||
lfs->mlist = mlist;
|
||||
}
|
||||
@@ -2151,9 +2153,11 @@ static int lfs_dir_splittingcompact(lfs_t *lfs, lfs_mdir_t *dir,
|
||||
return size;
|
||||
}
|
||||
|
||||
// do we have extra space? littlefs can't reclaim this space
|
||||
// by itself, so expand cautiously
|
||||
if ((lfs_size_t)size < lfs->block_count/2) {
|
||||
// littlefs cannot reclaim expanded superblocks, so expand cautiously
|
||||
//
|
||||
// if our filesystem is more than ~88% full, don't expand, this is
|
||||
// somewhat arbitrary
|
||||
if (lfs->block_count - size > lfs->block_count/8) {
|
||||
LFS_DEBUG("Expanding superblock at rev %"PRIu32, dir->rev);
|
||||
int err = lfs_dir_split(lfs, dir, attrs, attrcount,
|
||||
source, begin, end);
|
||||
@@ -3030,8 +3034,7 @@ static int lfs_file_rawopencfg(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)) {
|
||||
err = tag;
|
||||
goto cleanup;
|
||||
return tag;
|
||||
}
|
||||
|
||||
// get id, add to list of mdirs to catch update changes
|
||||
@@ -4999,7 +5002,7 @@ static int lfs_fs_forceconsistency(lfs_t *lfs) {
|
||||
#endif
|
||||
|
||||
#ifndef LFS_READONLY
|
||||
int lfs_fs_rawmkconsistent(lfs_t *lfs) {
|
||||
static int lfs_fs_rawmkconsistent(lfs_t *lfs) {
|
||||
// lfs_fs_forceconsistency does most of the work here
|
||||
int err = lfs_fs_forceconsistency(lfs);
|
||||
if (err) {
|
||||
@@ -5046,7 +5049,7 @@ static lfs_ssize_t lfs_fs_rawsize(lfs_t *lfs) {
|
||||
}
|
||||
|
||||
#ifndef LFS_READONLY
|
||||
int lfs_fs_rawgrow(lfs_t *lfs, lfs_size_t block_count) {
|
||||
static int lfs_fs_rawgrow(lfs_t *lfs, lfs_size_t block_count) {
|
||||
// shrinking is not supported
|
||||
LFS_ASSERT(block_count >= lfs->block_count);
|
||||
|
||||
@@ -5927,7 +5930,6 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file, const char *path, int flags) {
|
||||
}
|
||||
LFS_TRACE("lfs_file_open(%p, %p, \"%s\", %x)",
|
||||
(void*)lfs, (void*)file, path, flags);
|
||||
LFS_ASSERT(!lfs_mlist_isopen(lfs->mlist, (struct lfs_mlist*)file));
|
||||
|
||||
err = lfs_file_rawopen(lfs, file, path, flags);
|
||||
|
||||
@@ -5948,7 +5950,6 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
|
||||
".buffer=%p, .attrs=%p, .attr_count=%"PRIu32"})",
|
||||
(void*)lfs, (void*)file, path, flags,
|
||||
(void*)cfg, cfg->buffer, (void*)cfg->attrs, cfg->attr_count);
|
||||
LFS_ASSERT(!lfs_mlist_isopen(lfs->mlist, (struct lfs_mlist*)file));
|
||||
|
||||
err = lfs_file_rawopencfg(lfs, file, path, flags, cfg);
|
||||
|
||||
@@ -5963,7 +5964,6 @@ int lfs_file_close(lfs_t *lfs, lfs_file_t *file) {
|
||||
return err;
|
||||
}
|
||||
LFS_TRACE("lfs_file_close(%p, %p)", (void*)lfs, (void*)file);
|
||||
LFS_ASSERT(lfs_mlist_isopen(lfs->mlist, (struct lfs_mlist*)file));
|
||||
|
||||
err = lfs_file_rawclose(lfs, file);
|
||||
|
||||
@@ -5979,7 +5979,6 @@ int lfs_file_sync(lfs_t *lfs, lfs_file_t *file) {
|
||||
return err;
|
||||
}
|
||||
LFS_TRACE("lfs_file_sync(%p, %p)", (void*)lfs, (void*)file);
|
||||
LFS_ASSERT(lfs_mlist_isopen(lfs->mlist, (struct lfs_mlist*)file));
|
||||
|
||||
err = lfs_file_rawsync(lfs, file);
|
||||
|
||||
@@ -5997,7 +5996,6 @@ lfs_ssize_t lfs_file_read(lfs_t *lfs, lfs_file_t *file,
|
||||
}
|
||||
LFS_TRACE("lfs_file_read(%p, %p, %p, %"PRIu32")",
|
||||
(void*)lfs, (void*)file, buffer, size);
|
||||
LFS_ASSERT(lfs_mlist_isopen(lfs->mlist, (struct lfs_mlist*)file));
|
||||
|
||||
lfs_ssize_t res = lfs_file_rawread(lfs, file, buffer, size);
|
||||
|
||||
@@ -6015,7 +6013,6 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file,
|
||||
}
|
||||
LFS_TRACE("lfs_file_write(%p, %p, %p, %"PRIu32")",
|
||||
(void*)lfs, (void*)file, buffer, size);
|
||||
LFS_ASSERT(lfs_mlist_isopen(lfs->mlist, (struct lfs_mlist*)file));
|
||||
|
||||
lfs_ssize_t res = lfs_file_rawwrite(lfs, file, buffer, size);
|
||||
|
||||
@@ -6033,7 +6030,6 @@ lfs_soff_t lfs_file_seek(lfs_t *lfs, lfs_file_t *file,
|
||||
}
|
||||
LFS_TRACE("lfs_file_seek(%p, %p, %"PRId32", %d)",
|
||||
(void*)lfs, (void*)file, off, whence);
|
||||
LFS_ASSERT(lfs_mlist_isopen(lfs->mlist, (struct lfs_mlist*)file));
|
||||
|
||||
lfs_soff_t res = lfs_file_rawseek(lfs, file, off, whence);
|
||||
|
||||
@@ -6050,7 +6046,6 @@ int lfs_file_truncate(lfs_t *lfs, lfs_file_t *file, lfs_off_t size) {
|
||||
}
|
||||
LFS_TRACE("lfs_file_truncate(%p, %p, %"PRIu32")",
|
||||
(void*)lfs, (void*)file, size);
|
||||
LFS_ASSERT(lfs_mlist_isopen(lfs->mlist, (struct lfs_mlist*)file));
|
||||
|
||||
err = lfs_file_rawtruncate(lfs, file, size);
|
||||
|
||||
@@ -6066,7 +6061,6 @@ lfs_soff_t lfs_file_tell(lfs_t *lfs, lfs_file_t *file) {
|
||||
return err;
|
||||
}
|
||||
LFS_TRACE("lfs_file_tell(%p, %p)", (void*)lfs, (void*)file);
|
||||
LFS_ASSERT(lfs_mlist_isopen(lfs->mlist, (struct lfs_mlist*)file));
|
||||
|
||||
lfs_soff_t res = lfs_file_rawtell(lfs, file);
|
||||
|
||||
@@ -6095,7 +6089,6 @@ lfs_soff_t lfs_file_size(lfs_t *lfs, lfs_file_t *file) {
|
||||
return err;
|
||||
}
|
||||
LFS_TRACE("lfs_file_size(%p, %p)", (void*)lfs, (void*)file);
|
||||
LFS_ASSERT(lfs_mlist_isopen(lfs->mlist, (struct lfs_mlist*)file));
|
||||
|
||||
lfs_soff_t res = lfs_file_rawsize(lfs, file);
|
||||
|
||||
@@ -6126,7 +6119,6 @@ int lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path) {
|
||||
return err;
|
||||
}
|
||||
LFS_TRACE("lfs_dir_open(%p, %p, \"%s\")", (void*)lfs, (void*)dir, path);
|
||||
LFS_ASSERT(!lfs_mlist_isopen(lfs->mlist, (struct lfs_mlist*)dir));
|
||||
|
||||
err = lfs_dir_rawopen(lfs, dir, path);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user