mirror of
https://github.com/eledio-devices/thirdparty-littlefs.git
synced 2025-11-01 16:14:13 +01:00
Compare commits
1 Commits
v1.6.2
...
sanity-tes
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1c15c1768 |
84
.travis.yml
84
.travis.yml
@@ -134,57 +134,53 @@ jobs:
|
||||
- STAGE=deploy
|
||||
- NAME=deploy
|
||||
script:
|
||||
# Find version defined in lfs.h
|
||||
# Update tag for version defined in lfs.h
|
||||
- LFS_VERSION=$(grep -ox '#define LFS_VERSION .*' lfs.h | cut -d ' ' -f3)
|
||||
- LFS_VERSION_MAJOR=$((0xffff & ($LFS_VERSION >> 16)))
|
||||
- LFS_VERSION_MINOR=$((0xffff & ($LFS_VERSION >> 0)))
|
||||
# Grab latests patch from repo tags, default to 0, needs finagling to get past github's pagination api
|
||||
- PREV_URL=https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs/tags/v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR.
|
||||
- PREV_URL=$(curl -u "$GEKY_BOT_RELEASES" "$PREV_URL" -I
|
||||
| sed -n '/^Link/{s/.*<\(.*\)>; rel="last"/\1/;p;q0};$q1'
|
||||
|| echo $PREV_URL)
|
||||
- LFS_VERSION_PATCH=$(curl -u "$GEKY_BOT_RELEASES" "$PREV_URL"
|
||||
| jq 'map(.ref | match("\\bv.*\\..*\\.(.*)$";"g")
|
||||
.captures[].string | tonumber) | max + 1'
|
||||
|| echo 0)
|
||||
# We have our new version
|
||||
- LFS_VERSION="v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR.$LFS_VERSION_PATCH"
|
||||
- echo "VERSION $LFS_VERSION"
|
||||
- LFS_VERSION="v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR"
|
||||
- echo "littlefs version $LFS_VERSION"
|
||||
- |
|
||||
# Check that we're the most recent commit
|
||||
CURRENT_COMMIT=$(curl -f -u "$GEKY_BOT_RELEASES" \
|
||||
https://api.github.com/repos/$TRAVIS_REPO_SLUG/commits/master \
|
||||
| jq -re '.sha')
|
||||
if [ "$TRAVIS_COMMIT" == "$CURRENT_COMMIT" ]
|
||||
curl -u $GEKY_BOT_RELEASES -X POST \
|
||||
https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs \
|
||||
-d "{
|
||||
\"ref\": \"refs/tags/$LFS_VERSION\",
|
||||
\"sha\": \"$TRAVIS_COMMIT\"
|
||||
}"
|
||||
- |
|
||||
curl -f -u $GEKY_BOT_RELEASES -X PATCH \
|
||||
https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs/tags/$LFS_VERSION \
|
||||
-d "{
|
||||
\"sha\": \"$TRAVIS_COMMIT\"
|
||||
}"
|
||||
# Create release notes from commits
|
||||
- LFS_PREV_VERSION="v$LFS_VERSION_MAJOR.$(($LFS_VERSION_MINOR-1))"
|
||||
- |
|
||||
if [ $(git tag -l "$LFS_PREV_VERSION") ]
|
||||
then
|
||||
# Create a simple tag
|
||||
curl -f -u "$GEKY_BOT_RELEASES" -X POST \
|
||||
https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs \
|
||||
curl -u $GEKY_BOT_RELEASES -X POST \
|
||||
https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases \
|
||||
-d "{
|
||||
\"ref\": \"refs/tags/$LFS_VERSION\",
|
||||
\"sha\": \"$TRAVIS_COMMIT\"
|
||||
\"tag_name\": \"$LFS_VERSION\",
|
||||
\"name\": \"$LFS_VERSION\"
|
||||
}"
|
||||
# Minor release?
|
||||
if [[ "$LFS_VERSION" == *.0 ]]
|
||||
then
|
||||
# Build release notes
|
||||
PREV=$(git tag --sort=-v:refname -l "v*.0" | head -1)
|
||||
if [ ! -z "$PREV" ]
|
||||
then
|
||||
echo "PREV $PREV"
|
||||
CHANGES=$'### Changes\n\n'$( \
|
||||
git log --oneline $PREV.. --grep='^Merge' --invert-grep)
|
||||
printf "CHANGES\n%s\n\n" "$CHANGES"
|
||||
fi
|
||||
# Create the release
|
||||
curl -f -u "$GEKY_BOT_RELEASES" -X POST \
|
||||
https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases \
|
||||
-d "{
|
||||
\"tag_name\": \"$LFS_VERSION\",
|
||||
\"name\": \"${LFS_VERSION%.0}\",
|
||||
\"body\": $(jq -sR '.' <<< "$CHANGES")
|
||||
}"
|
||||
fi
|
||||
RELEASE=$(
|
||||
curl -f -u $GEKY_BOT_RELEASES \
|
||||
https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases/tags/$LFS_VERSION
|
||||
)
|
||||
CHANGES=$(
|
||||
git log --oneline $LFS_PREV_VERSION.. --grep='^Merge' --invert-grep
|
||||
)
|
||||
curl -f -u $GEKY_BOT_RELEASES -X PATCH \
|
||||
https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases/$(
|
||||
jq -r '.id' <<< "$RELEASE"
|
||||
) \
|
||||
-d "$(
|
||||
jq -s '{
|
||||
"body": ((.[0] // "" | sub("(?<=\n)#+ Changes.*"; ""; "mi"))
|
||||
+ "### Changes\n\n" + .[1])
|
||||
}' <(jq '.body' <<< "$RELEASE") <(jq -sR '.' <<< "$CHANGES")
|
||||
)"
|
||||
fi
|
||||
|
||||
# Manage statuses
|
||||
|
||||
12
LICENSE.md
12
LICENSE.md
@@ -22,3 +22,15 @@ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
---
|
||||
|
||||
*Note*:
|
||||
Individual files contain the following tag instead of the full license text.
|
||||
|
||||
|
||||
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
This enables machine processing of license information based on the SPDX
|
||||
License Identifiers that are here available: http://spdx.org/licenses/
|
||||
|
||||
3
Makefile
3
Makefile
@@ -25,8 +25,7 @@ ifdef WORD
|
||||
override CFLAGS += -m$(WORD)
|
||||
endif
|
||||
override CFLAGS += -I.
|
||||
override CFLAGS += -std=c99 -Wall -pedantic
|
||||
override CFLAGS += -Wshadow -Wunused-parameter -Wjump-misses-init -Wsign-compare
|
||||
override CFLAGS += -std=c99 -Wall -pedantic -Wshadow -Wunused-parameter
|
||||
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
13
README.md
13
README.md
@@ -146,19 +146,6 @@ The tests assume a Linux environment and can be started with make:
|
||||
make test
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
The littlefs is provided under the [BSD-3-Clause](https://spdx.org/licenses/BSD-3-Clause.html)
|
||||
license. See [LICENSE.md](LICENSE.md) for more information. Contributions to
|
||||
this project are accepted under the same license.
|
||||
|
||||
Individual files contain the following tag instead of the full license text.
|
||||
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
This enables machine processing of license information based on the SPDX
|
||||
License Identifiers that are here available: http://spdx.org/licenses/
|
||||
|
||||
## Related projects
|
||||
|
||||
[Mbed OS](https://github.com/ARMmbed/mbed-os/tree/master/features/filesystem/littlefs) -
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
|
||||
// Block device emulated on existing filesystem
|
||||
@@ -47,24 +46,19 @@ int lfs_emubd_create(const struct lfs_config *cfg, const char *path) {
|
||||
|
||||
// Load stats to continue incrementing
|
||||
snprintf(emu->child, LFS_NAME_MAX, "stats");
|
||||
|
||||
FILE *f = fopen(emu->path, "r");
|
||||
if (!f && errno != ENOENT) {
|
||||
if (!f) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
if (errno == ENOENT) {
|
||||
memset(&emu->stats, 0x0, sizeof(emu->stats));
|
||||
} else {
|
||||
size_t res = fread(&emu->stats, sizeof(emu->stats), 1, f);
|
||||
if (res < 1) {
|
||||
return -errno;
|
||||
}
|
||||
size_t res = fread(&emu->stats, sizeof(emu->stats), 1, f);
|
||||
if (res < 1) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
err = fclose(f);
|
||||
if (err) {
|
||||
return -errno;
|
||||
}
|
||||
err = fclose(f);
|
||||
if (err) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -91,7 +85,7 @@ int lfs_emubd_read(const struct lfs_config *cfg, lfs_block_t block,
|
||||
memset(data, 0, size);
|
||||
|
||||
// Read data
|
||||
snprintf(emu->child, LFS_NAME_MAX, "%" PRIx32, block);
|
||||
snprintf(emu->child, LFS_NAME_MAX, "%x", block);
|
||||
|
||||
FILE *f = fopen(emu->path, "rb");
|
||||
if (!f && errno != ENOENT) {
|
||||
@@ -130,7 +124,7 @@ int lfs_emubd_prog(const struct lfs_config *cfg, lfs_block_t block,
|
||||
assert(block < cfg->block_count);
|
||||
|
||||
// Program data
|
||||
snprintf(emu->child, LFS_NAME_MAX, "%" PRIx32, block);
|
||||
snprintf(emu->child, LFS_NAME_MAX, "%x", block);
|
||||
|
||||
FILE *f = fopen(emu->path, "r+b");
|
||||
if (!f) {
|
||||
@@ -177,7 +171,7 @@ int lfs_emubd_erase(const struct lfs_config *cfg, lfs_block_t block) {
|
||||
assert(block < cfg->block_count);
|
||||
|
||||
// Erase the block
|
||||
snprintf(emu->child, LFS_NAME_MAX, "%" PRIx32, block);
|
||||
snprintf(emu->child, LFS_NAME_MAX, "%x", block);
|
||||
struct stat st;
|
||||
int err = stat(emu->path, &st);
|
||||
if (err && errno != ENOENT) {
|
||||
@@ -245,3 +239,4 @@ int lfs_emubd_sync(const struct lfs_config *cfg) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,11 +10,6 @@
|
||||
#include "lfs.h"
|
||||
#include "lfs_util.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
// Config options
|
||||
#ifndef LFS_EMUBD_READ_SIZE
|
||||
@@ -80,8 +75,4 @@ int lfs_emubd_erase(const struct lfs_config *cfg, lfs_block_t block);
|
||||
int lfs_emubd_sync(const struct lfs_config *cfg);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
363
lfs.c
363
lfs.c
@@ -7,8 +7,6 @@
|
||||
#include "lfs.h"
|
||||
#include "lfs_util.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
|
||||
/// Caching block device operations ///
|
||||
static int lfs_cache_read(lfs_t *lfs, lfs_cache_t *rcache,
|
||||
@@ -310,8 +308,7 @@ static int lfs_alloc(lfs_t *lfs, lfs_block_t *block) {
|
||||
|
||||
// check if we have looked at all blocks since last ack
|
||||
if (lfs->free.ack == 0) {
|
||||
LFS_WARN("No more free space %" PRIu32,
|
||||
lfs->free.i + lfs->free.off);
|
||||
LFS_WARN("No more free space %d", lfs->free.i + lfs->free.off);
|
||||
return LFS_ERR_NOSPC;
|
||||
}
|
||||
|
||||
@@ -417,14 +414,11 @@ static int lfs_dir_alloc(lfs_t *lfs, lfs_dir_t *dir) {
|
||||
// rather than clobbering one of the blocks we just pretend
|
||||
// the revision may be valid
|
||||
int err = lfs_bd_read(lfs, dir->pair[0], 0, &dir->d.rev, 4);
|
||||
if (err && err != LFS_ERR_CORRUPT) {
|
||||
dir->d.rev = lfs_fromle32(dir->d.rev);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (err != LFS_ERR_CORRUPT) {
|
||||
dir->d.rev = lfs_fromle32(dir->d.rev);
|
||||
}
|
||||
|
||||
// set defaults
|
||||
dir->d.rev += 1;
|
||||
dir->d.size = sizeof(dir->d)+4;
|
||||
@@ -448,9 +442,6 @@ static int lfs_dir_fetch(lfs_t *lfs,
|
||||
int err = lfs_bd_read(lfs, tpair[i], 0, &test, sizeof(test));
|
||||
lfs_dir_fromle32(&test);
|
||||
if (err) {
|
||||
if (err == LFS_ERR_CORRUPT) {
|
||||
continue;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -470,9 +461,6 @@ static int lfs_dir_fetch(lfs_t *lfs,
|
||||
err = lfs_bd_crc(lfs, tpair[i], sizeof(test),
|
||||
(0x7fffffff & test.size) - sizeof(test), &crc);
|
||||
if (err) {
|
||||
if (err == LFS_ERR_CORRUPT) {
|
||||
continue;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -490,8 +478,7 @@ static int lfs_dir_fetch(lfs_t *lfs,
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
LFS_ERROR("Corrupted dir pair at %" PRIu32 " %" PRIu32 ,
|
||||
tpair[0], tpair[1]);
|
||||
LFS_ERROR("Corrupted dir pair at %d %d", tpair[0], tpair[1]);
|
||||
return LFS_ERR_CORRUPT;
|
||||
}
|
||||
|
||||
@@ -614,7 +601,7 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_dir_t *dir,
|
||||
break;
|
||||
relocate:
|
||||
//commit was corrupted
|
||||
LFS_DEBUG("Bad block at %" PRIu32, dir->pair[0]);
|
||||
LFS_DEBUG("Bad block at %d", dir->pair[0]);
|
||||
|
||||
// drop caches and prepare to relocate block
|
||||
relocated = true;
|
||||
@@ -622,8 +609,7 @@ relocate:
|
||||
|
||||
// can't relocate superblock, filesystem is now frozen
|
||||
if (lfs_paircmp(oldpair, (const lfs_block_t[2]){0, 1}) == 0) {
|
||||
LFS_WARN("Superblock %" PRIu32 " has become unwritable",
|
||||
oldpair[0]);
|
||||
LFS_WARN("Superblock %d has become unwritable", oldpair[0]);
|
||||
return LFS_ERR_CORRUPT;
|
||||
}
|
||||
|
||||
@@ -636,7 +622,7 @@ relocate:
|
||||
|
||||
if (relocated) {
|
||||
// update references if we relocated
|
||||
LFS_DEBUG("Relocating %" PRIu32 " %" PRIu32 " to %" PRIu32 " %" PRIu32,
|
||||
LFS_DEBUG("Relocating %d %d to %d %d",
|
||||
oldpair[0], oldpair[1], dir->pair[0], dir->pair[1]);
|
||||
int err = lfs_relocate(lfs, oldpair, dir->pair);
|
||||
if (err) {
|
||||
@@ -1241,7 +1227,7 @@ static int lfs_ctz_extend(lfs_t *lfs,
|
||||
}
|
||||
|
||||
relocate:
|
||||
LFS_DEBUG("Bad block at %" PRIu32, nblock);
|
||||
LFS_DEBUG("Bad block at %d", nblock);
|
||||
|
||||
// just clear cache and try a new block
|
||||
lfs_cache_drop(lfs, &lfs->pcache);
|
||||
@@ -1291,9 +1277,8 @@ static int lfs_ctz_traverse(lfs_t *lfs,
|
||||
|
||||
|
||||
/// Top level file operations ///
|
||||
int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
|
||||
const char *path, int flags,
|
||||
const struct lfs_file_config *cfg) {
|
||||
int lfs_file_open(lfs_t *lfs, lfs_file_t *file,
|
||||
const char *path, int flags) {
|
||||
// deorphan if we haven't yet, needed at most once after poweron
|
||||
if ((flags & 3) != LFS_O_RDONLY && !lfs->deorphaned) {
|
||||
int err = lfs_deorphan(lfs);
|
||||
@@ -1333,7 +1318,6 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
|
||||
}
|
||||
|
||||
// setup file struct
|
||||
file->cfg = cfg;
|
||||
file->pair[0] = cwd.pair[0];
|
||||
file->pair[1] = cwd.pair[1];
|
||||
file->poff = entry.off;
|
||||
@@ -1351,10 +1335,7 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
|
||||
}
|
||||
|
||||
// allocate buffer if needed
|
||||
file->cache.block = 0xffffffff;
|
||||
if (file->cfg && file->cfg->buffer) {
|
||||
file->cache.buffer = file->cfg->buffer;
|
||||
} else if (lfs->cfg->file_buffer) {
|
||||
if (lfs->cfg->file_buffer) {
|
||||
if (lfs->files) {
|
||||
// already in use
|
||||
return LFS_ERR_NOMEM;
|
||||
@@ -1373,10 +1354,7 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
|
||||
}
|
||||
|
||||
// zero to avoid information leak
|
||||
lfs_cache_drop(lfs, &file->cache);
|
||||
if ((file->flags & 3) != LFS_O_RDONLY) {
|
||||
lfs_cache_zero(lfs, &file->cache);
|
||||
}
|
||||
lfs_cache_zero(lfs, &file->cache);
|
||||
|
||||
// add to list of files
|
||||
file->next = lfs->files;
|
||||
@@ -1385,11 +1363,6 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lfs_file_open(lfs_t *lfs, lfs_file_t *file,
|
||||
const char *path, int flags) {
|
||||
return lfs_file_opencfg(lfs, file, path, flags, NULL);
|
||||
}
|
||||
|
||||
int lfs_file_close(lfs_t *lfs, lfs_file_t *file) {
|
||||
int err = lfs_file_sync(lfs, file);
|
||||
|
||||
@@ -1402,7 +1375,7 @@ int lfs_file_close(lfs_t *lfs, lfs_file_t *file) {
|
||||
}
|
||||
|
||||
// clean up memory
|
||||
if (!(file->cfg && file->cfg->buffer) && !lfs->cfg->file_buffer) {
|
||||
if (!lfs->cfg->file_buffer) {
|
||||
lfs_free(file->cache.buffer);
|
||||
}
|
||||
|
||||
@@ -1411,7 +1384,7 @@ int lfs_file_close(lfs_t *lfs, lfs_file_t *file) {
|
||||
|
||||
static int lfs_file_relocate(lfs_t *lfs, lfs_file_t *file) {
|
||||
relocate:
|
||||
LFS_DEBUG("Bad block at %" PRIu32, file->block);
|
||||
LFS_DEBUG("Bad block at %d", file->block);
|
||||
|
||||
// just relocate what exists into new block
|
||||
lfs_block_t nblock;
|
||||
@@ -2019,21 +1992,6 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) {
|
||||
|
||||
|
||||
/// Filesystem operations ///
|
||||
static void lfs_deinit(lfs_t *lfs) {
|
||||
// free allocated memory
|
||||
if (!lfs->cfg->read_buffer) {
|
||||
lfs_free(lfs->rcache.buffer);
|
||||
}
|
||||
|
||||
if (!lfs->cfg->prog_buffer) {
|
||||
lfs_free(lfs->pcache.buffer);
|
||||
}
|
||||
|
||||
if (!lfs->cfg->lookahead_buffer) {
|
||||
lfs_free(lfs->free.buffer);
|
||||
}
|
||||
}
|
||||
|
||||
static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
lfs->cfg = cfg;
|
||||
|
||||
@@ -2043,7 +2001,7 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
} else {
|
||||
lfs->rcache.buffer = lfs_malloc(lfs->cfg->read_size);
|
||||
if (!lfs->rcache.buffer) {
|
||||
goto cleanup;
|
||||
return LFS_ERR_NOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2053,13 +2011,13 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
} else {
|
||||
lfs->pcache.buffer = lfs_malloc(lfs->cfg->prog_size);
|
||||
if (!lfs->pcache.buffer) {
|
||||
goto cleanup;
|
||||
return LFS_ERR_NOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
// zero to avoid information leaks
|
||||
lfs_cache_zero(lfs, &lfs->rcache);
|
||||
lfs_cache_zero(lfs, &lfs->pcache);
|
||||
lfs_cache_drop(lfs, &lfs->rcache);
|
||||
|
||||
// setup lookahead, round down to nearest 32-bits
|
||||
LFS_ASSERT(lfs->cfg->lookahead % 32 == 0);
|
||||
@@ -2069,7 +2027,7 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
} else {
|
||||
lfs->free.buffer = lfs_malloc(lfs->cfg->lookahead/8);
|
||||
if (!lfs->free.buffer) {
|
||||
goto cleanup;
|
||||
return LFS_ERR_NOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2089,160 +2047,155 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
lfs->deorphaned = false;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
lfs_deinit(lfs);
|
||||
return LFS_ERR_NOMEM;
|
||||
static int lfs_deinit(lfs_t *lfs) {
|
||||
// free allocated memory
|
||||
if (!lfs->cfg->read_buffer) {
|
||||
lfs_free(lfs->rcache.buffer);
|
||||
}
|
||||
|
||||
if (!lfs->cfg->prog_buffer) {
|
||||
lfs_free(lfs->pcache.buffer);
|
||||
}
|
||||
|
||||
if (!lfs->cfg->lookahead_buffer) {
|
||||
lfs_free(lfs->free.buffer);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
int err = 0;
|
||||
if (true) {
|
||||
err = lfs_init(lfs, cfg);
|
||||
if (err) {
|
||||
int err = lfs_init(lfs, cfg);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// create free lookahead
|
||||
memset(lfs->free.buffer, 0, lfs->cfg->lookahead/8);
|
||||
lfs->free.off = 0;
|
||||
lfs->free.size = lfs_min(lfs->cfg->lookahead, lfs->cfg->block_count);
|
||||
lfs->free.i = 0;
|
||||
lfs_alloc_ack(lfs);
|
||||
|
||||
// create superblock dir
|
||||
lfs_dir_t superdir;
|
||||
err = lfs_dir_alloc(lfs, &superdir);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// write root directory
|
||||
lfs_dir_t root;
|
||||
err = lfs_dir_alloc(lfs, &root);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = lfs_dir_commit(lfs, &root, NULL, 0);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
lfs->root[0] = root.pair[0];
|
||||
lfs->root[1] = root.pair[1];
|
||||
|
||||
// write superblocks
|
||||
lfs_superblock_t superblock = {
|
||||
.off = sizeof(superdir.d),
|
||||
.d.type = LFS_TYPE_SUPERBLOCK,
|
||||
.d.elen = sizeof(superblock.d) - sizeof(superblock.d.magic) - 4,
|
||||
.d.nlen = sizeof(superblock.d.magic),
|
||||
.d.version = LFS_DISK_VERSION,
|
||||
.d.magic = {"littlefs"},
|
||||
.d.block_size = lfs->cfg->block_size,
|
||||
.d.block_count = lfs->cfg->block_count,
|
||||
.d.root = {lfs->root[0], lfs->root[1]},
|
||||
};
|
||||
superdir.d.tail[0] = root.pair[0];
|
||||
superdir.d.tail[1] = root.pair[1];
|
||||
superdir.d.size = sizeof(superdir.d) + sizeof(superblock.d) + 4;
|
||||
|
||||
// write both pairs to be safe
|
||||
lfs_superblock_tole32(&superblock.d);
|
||||
bool valid = false;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
err = lfs_dir_commit(lfs, &superdir, (struct lfs_region[]){
|
||||
{sizeof(superdir.d), sizeof(superblock.d),
|
||||
&superblock.d, sizeof(superblock.d)}
|
||||
}, 1);
|
||||
if (err && err != LFS_ERR_CORRUPT) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// create free lookahead
|
||||
memset(lfs->free.buffer, 0, lfs->cfg->lookahead/8);
|
||||
lfs->free.off = 0;
|
||||
lfs->free.size = lfs_min(lfs->cfg->lookahead, lfs->cfg->block_count);
|
||||
lfs->free.i = 0;
|
||||
lfs_alloc_ack(lfs);
|
||||
|
||||
// create superblock dir
|
||||
lfs_dir_t superdir;
|
||||
err = lfs_dir_alloc(lfs, &superdir);
|
||||
if (err) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// write root directory
|
||||
lfs_dir_t root;
|
||||
err = lfs_dir_alloc(lfs, &root);
|
||||
if (err) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
err = lfs_dir_commit(lfs, &root, NULL, 0);
|
||||
if (err) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
lfs->root[0] = root.pair[0];
|
||||
lfs->root[1] = root.pair[1];
|
||||
|
||||
// write superblocks
|
||||
lfs_superblock_t superblock = {
|
||||
.off = sizeof(superdir.d),
|
||||
.d.type = LFS_TYPE_SUPERBLOCK,
|
||||
.d.elen = sizeof(superblock.d) - sizeof(superblock.d.magic) - 4,
|
||||
.d.nlen = sizeof(superblock.d.magic),
|
||||
.d.version = LFS_DISK_VERSION,
|
||||
.d.magic = {"littlefs"},
|
||||
.d.block_size = lfs->cfg->block_size,
|
||||
.d.block_count = lfs->cfg->block_count,
|
||||
.d.root = {lfs->root[0], lfs->root[1]},
|
||||
};
|
||||
superdir.d.tail[0] = root.pair[0];
|
||||
superdir.d.tail[1] = root.pair[1];
|
||||
superdir.d.size = sizeof(superdir.d) + sizeof(superblock.d) + 4;
|
||||
|
||||
// write both pairs to be safe
|
||||
lfs_superblock_tole32(&superblock.d);
|
||||
bool valid = false;
|
||||
for (int i = 0; i < 2; i++) {
|
||||
err = lfs_dir_commit(lfs, &superdir, (struct lfs_region[]){
|
||||
{sizeof(superdir.d), sizeof(superblock.d),
|
||||
&superblock.d, sizeof(superblock.d)}
|
||||
}, 1);
|
||||
if (err && err != LFS_ERR_CORRUPT) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
valid = valid || !err;
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
err = LFS_ERR_CORRUPT;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// sanity check that fetch works
|
||||
err = lfs_dir_fetch(lfs, &superdir, (const lfs_block_t[2]){0, 1});
|
||||
if (err) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
lfs_alloc_ack(lfs);
|
||||
valid = valid || !err;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
lfs_deinit(lfs);
|
||||
return err;
|
||||
if (!valid) {
|
||||
return LFS_ERR_CORRUPT;
|
||||
}
|
||||
|
||||
// sanity check that fetch works
|
||||
err = lfs_dir_fetch(lfs, &superdir, (const lfs_block_t[2]){0, 1});
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
lfs_alloc_ack(lfs);
|
||||
return lfs_deinit(lfs);
|
||||
}
|
||||
|
||||
int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
int err = 0;
|
||||
if (true) {
|
||||
err = lfs_init(lfs, cfg);
|
||||
int err = lfs_init(lfs, cfg);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// setup free lookahead
|
||||
lfs->free.off = 0;
|
||||
lfs->free.size = 0;
|
||||
lfs->free.i = 0;
|
||||
lfs_alloc_ack(lfs);
|
||||
|
||||
// load superblock
|
||||
lfs_dir_t dir;
|
||||
lfs_superblock_t superblock;
|
||||
err = lfs_dir_fetch(lfs, &dir, (const lfs_block_t[2]){0, 1});
|
||||
if (err && err != LFS_ERR_CORRUPT) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (!err) {
|
||||
err = lfs_bd_read(lfs, dir.pair[0], sizeof(dir.d),
|
||||
&superblock.d, sizeof(superblock.d));
|
||||
lfs_superblock_fromle32(&superblock.d);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// setup free lookahead
|
||||
lfs->free.off = 0;
|
||||
lfs->free.size = 0;
|
||||
lfs->free.i = 0;
|
||||
lfs_alloc_ack(lfs);
|
||||
|
||||
// load superblock
|
||||
lfs_dir_t dir;
|
||||
lfs_superblock_t superblock;
|
||||
err = lfs_dir_fetch(lfs, &dir, (const lfs_block_t[2]){0, 1});
|
||||
if (err && err != LFS_ERR_CORRUPT) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!err) {
|
||||
err = lfs_bd_read(lfs, dir.pair[0], sizeof(dir.d),
|
||||
&superblock.d, sizeof(superblock.d));
|
||||
lfs_superblock_fromle32(&superblock.d);
|
||||
if (err) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
lfs->root[0] = superblock.d.root[0];
|
||||
lfs->root[1] = superblock.d.root[1];
|
||||
}
|
||||
|
||||
if (err || memcmp(superblock.d.magic, "littlefs", 8) != 0) {
|
||||
LFS_ERROR("Invalid superblock at %d %d", 0, 1);
|
||||
err = LFS_ERR_CORRUPT;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
uint16_t major_version = (0xffff & (superblock.d.version >> 16));
|
||||
uint16_t minor_version = (0xffff & (superblock.d.version >> 0));
|
||||
if ((major_version != LFS_DISK_VERSION_MAJOR ||
|
||||
minor_version > LFS_DISK_VERSION_MINOR)) {
|
||||
LFS_ERROR("Invalid version %d.%d", major_version, minor_version);
|
||||
err = LFS_ERR_INVAL;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
return 0;
|
||||
lfs->root[0] = superblock.d.root[0];
|
||||
lfs->root[1] = superblock.d.root[1];
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if (err || memcmp(superblock.d.magic, "littlefs", 8) != 0) {
|
||||
LFS_ERROR("Invalid superblock at %d %d", 0, 1);
|
||||
return LFS_ERR_CORRUPT;
|
||||
}
|
||||
|
||||
lfs_deinit(lfs);
|
||||
return err;
|
||||
uint16_t major_version = (0xffff & (superblock.d.version >> 16));
|
||||
uint16_t minor_version = (0xffff & (superblock.d.version >> 0));
|
||||
if ((major_version != LFS_DISK_VERSION_MAJOR ||
|
||||
minor_version > LFS_DISK_VERSION_MINOR)) {
|
||||
LFS_ERROR("Invalid version %d.%d", major_version, minor_version);
|
||||
return LFS_ERR_INVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lfs_unmount(lfs_t *lfs) {
|
||||
lfs_deinit(lfs);
|
||||
return 0;
|
||||
return lfs_deinit(lfs);
|
||||
}
|
||||
|
||||
|
||||
@@ -2442,8 +2395,7 @@ static int lfs_relocate(lfs_t *lfs,
|
||||
|
||||
// update internal root
|
||||
if (lfs_paircmp(oldpair, lfs->root) == 0) {
|
||||
LFS_DEBUG("Relocating root %" PRIu32 " %" PRIu32,
|
||||
newpair[0], newpair[1]);
|
||||
LFS_DEBUG("Relocating root %d %d", newpair[0], newpair[1]);
|
||||
lfs->root[0] = newpair[0];
|
||||
lfs->root[1] = newpair[1];
|
||||
}
|
||||
@@ -2481,11 +2433,7 @@ int lfs_deorphan(lfs_t *lfs) {
|
||||
lfs_dir_t cwd = {.d.tail[0] = 0, .d.tail[1] = 1};
|
||||
|
||||
// iterate over all directory directory entries
|
||||
for (lfs_size_t i = 0; i < lfs->cfg->block_count; i++) {
|
||||
if (lfs_pairisnull(cwd.d.tail)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (!lfs_pairisnull(cwd.d.tail)) {
|
||||
int err = lfs_dir_fetch(lfs, &cwd, cwd.d.tail);
|
||||
if (err) {
|
||||
return err;
|
||||
@@ -2503,7 +2451,7 @@ int lfs_deorphan(lfs_t *lfs) {
|
||||
|
||||
if (!res) {
|
||||
// we are an orphan
|
||||
LFS_DEBUG("Found orphan %" PRIu32 " %" PRIu32,
|
||||
LFS_DEBUG("Found orphan %d %d",
|
||||
pdir.d.tail[0], pdir.d.tail[1]);
|
||||
|
||||
pdir.d.tail[0] = cwd.d.tail[0];
|
||||
@@ -2514,12 +2462,12 @@ int lfs_deorphan(lfs_t *lfs) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!lfs_pairsync(entry.d.u.dir, pdir.d.tail)) {
|
||||
// we have desynced
|
||||
LFS_DEBUG("Found desync %" PRIu32 " %" PRIu32,
|
||||
LFS_DEBUG("Found desync %d %d",
|
||||
entry.d.u.dir[0], entry.d.u.dir[1]);
|
||||
|
||||
pdir.d.tail[0] = entry.d.u.dir[0];
|
||||
@@ -2530,7 +2478,7 @@ int lfs_deorphan(lfs_t *lfs) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2554,14 +2502,14 @@ int lfs_deorphan(lfs_t *lfs) {
|
||||
}
|
||||
|
||||
if (moved) {
|
||||
LFS_DEBUG("Found move %" PRIu32 " %" PRIu32,
|
||||
LFS_DEBUG("Found move %d %d",
|
||||
entry.d.u.dir[0], entry.d.u.dir[1]);
|
||||
err = lfs_dir_remove(lfs, &cwd, &entry);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
} else {
|
||||
LFS_DEBUG("Found partial move %" PRIu32 " %" PRIu32,
|
||||
LFS_DEBUG("Found partial move %d %d",
|
||||
entry.d.u.dir[0], entry.d.u.dir[1]);
|
||||
entry.d.type &= ~0x80;
|
||||
err = lfs_dir_update(lfs, &cwd, &entry, NULL);
|
||||
@@ -2575,7 +2523,6 @@ int lfs_deorphan(lfs_t *lfs) {
|
||||
memcpy(&pdir, &cwd, sizeof(pdir));
|
||||
}
|
||||
|
||||
// If we reached here, we have more directory pairs than blocks in the
|
||||
// filesystem... So something must be horribly wrong
|
||||
return LFS_ERR_CORRUPT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
43
lfs.h
43
lfs.h
@@ -10,18 +10,13 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
/// Version info ///
|
||||
|
||||
// Software library version
|
||||
// Major (top-nibble), incremented on backwards incompatible changes
|
||||
// Minor (bottom-nibble), incremented on feature additions
|
||||
#define LFS_VERSION 0x00010006
|
||||
#define LFS_VERSION 0x00010004
|
||||
#define LFS_VERSION_MAJOR (0xffff & (LFS_VERSION >> 16))
|
||||
#define LFS_VERSION_MINOR (0xffff & (LFS_VERSION >> 0))
|
||||
|
||||
@@ -167,12 +162,6 @@ struct lfs_config {
|
||||
void *file_buffer;
|
||||
};
|
||||
|
||||
// Optional configuration provided during lfs_file_opencfg
|
||||
struct lfs_file_config {
|
||||
// Optional, statically allocated buffer for files. Must be program sized.
|
||||
// If NULL, malloc will be used by default.
|
||||
void *buffer;
|
||||
};
|
||||
|
||||
// File info structure
|
||||
struct lfs_info {
|
||||
@@ -220,7 +209,6 @@ typedef struct lfs_file {
|
||||
lfs_block_t head;
|
||||
lfs_size_t size;
|
||||
|
||||
const struct lfs_file_config *cfg;
|
||||
uint32_t flags;
|
||||
lfs_off_t pos;
|
||||
lfs_block_t block;
|
||||
@@ -288,8 +276,7 @@ typedef struct lfs {
|
||||
// Format a block device with the littlefs
|
||||
//
|
||||
// Requires a littlefs object and config struct. This clobbers the littlefs
|
||||
// object, and does not leave the filesystem mounted. The config struct must
|
||||
// be zeroed for defaults and backwards compatibility.
|
||||
// object, and does not leave the filesystem mounted.
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
int lfs_format(lfs_t *lfs, const struct lfs_config *config);
|
||||
@@ -298,8 +285,7 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *config);
|
||||
//
|
||||
// Requires a littlefs object and config struct. Multiple filesystems
|
||||
// may be mounted simultaneously with multiple littlefs objects. Both
|
||||
// lfs and config must be allocated while mounted. The config struct must
|
||||
// be zeroed for defaults and backwards compatibility.
|
||||
// lfs and config must be allocated while mounted.
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
int lfs_mount(lfs_t *lfs, const struct lfs_config *config);
|
||||
@@ -337,27 +323,14 @@ int lfs_stat(lfs_t *lfs, const char *path, struct lfs_info *info);
|
||||
|
||||
// Open a file
|
||||
//
|
||||
// The mode that the file is opened in is determined by the flags, which
|
||||
// are values from the enum lfs_open_flags that are bitwise-ored together.
|
||||
// The mode that the file is opened in is determined
|
||||
// by the flags, which are values from the enum lfs_open_flags
|
||||
// that are bitwise-ored together.
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
int lfs_file_open(lfs_t *lfs, lfs_file_t *file,
|
||||
const char *path, int flags);
|
||||
|
||||
// Open a file with extra configuration
|
||||
//
|
||||
// The mode that the file is opened in is determined by the flags, which
|
||||
// are values from the enum lfs_open_flags that are bitwise-ored together.
|
||||
//
|
||||
// The config struct provides additional config options per file as described
|
||||
// above. The config struct must be allocated while the file is open, and the
|
||||
// config struct must be zeroed for defaults and backwards compatibility.
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
|
||||
const char *path, int flags,
|
||||
const struct lfs_file_config *config);
|
||||
|
||||
// Close a file
|
||||
//
|
||||
// Any pending writes are written out to storage as though
|
||||
@@ -487,8 +460,4 @@ int lfs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data);
|
||||
int lfs_deorphan(lfs_t *lfs);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -34,11 +34,6 @@
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
// Macros, may be replaced by system specific wrappers. Arguments to these
|
||||
// macros must not have side-effects as the macros can be removed for a smaller
|
||||
@@ -178,9 +173,5 @@ static inline void lfs_free(void *p) {
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -32,18 +32,18 @@ lfs_alloc_singleproc() {
|
||||
tests/test.py << TEST
|
||||
const char *names[] = {"bacon", "eggs", "pancakes"};
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
for (unsigned n = 0; n < sizeof(names)/sizeof(names[0]); n++) {
|
||||
for (int n = 0; n < sizeof(names)/sizeof(names[0]); n++) {
|
||||
sprintf((char*)buffer, "$1/%s", names[n]);
|
||||
lfs_file_open(&lfs, &file[n], (char*)buffer,
|
||||
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0;
|
||||
}
|
||||
for (unsigned n = 0; n < sizeof(names)/sizeof(names[0]); n++) {
|
||||
for (int n = 0; n < sizeof(names)/sizeof(names[0]); n++) {
|
||||
size = strlen(names[n]);
|
||||
for (int i = 0; i < $SIZE; i++) {
|
||||
lfs_file_write(&lfs, &file[n], names[n], size) => size;
|
||||
}
|
||||
}
|
||||
for (unsigned n = 0; n < sizeof(names)/sizeof(names[0]); n++) {
|
||||
for (int n = 0; n < sizeof(names)/sizeof(names[0]); n++) {
|
||||
lfs_file_close(&lfs, &file[n]) => 0;
|
||||
}
|
||||
lfs_unmount(&lfs) => 0;
|
||||
|
||||
@@ -301,7 +301,7 @@ tests/test.py << TEST
|
||||
size = strlen("hedgehoghog");
|
||||
const lfs_soff_t offsets[] = {512, 1020, 513, 1021, 511, 1019};
|
||||
|
||||
for (unsigned i = 0; i < sizeof(offsets) / sizeof(offsets[0]); i++) {
|
||||
for (int i = 0; i < sizeof(offsets) / sizeof(offsets[0]); i++) {
|
||||
lfs_soff_t off = offsets[i];
|
||||
memcpy(buffer, "hedgehoghog", size);
|
||||
lfs_file_seek(&lfs, &file[0], off, LFS_SEEK_SET) => off;
|
||||
|
||||
@@ -23,14 +23,14 @@ tests/test.py << TEST
|
||||
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
|
||||
for (unsigned i = 0; i < sizeof(startsizes)/sizeof(startsizes[0]); i++) {
|
||||
for (int i = 0; i < sizeof(startsizes)/sizeof(startsizes[0]); i++) {
|
||||
sprintf((char*)buffer, "hairyhead%d", i);
|
||||
lfs_file_open(&lfs, &file[0], (const char*)buffer,
|
||||
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_TRUNC) => 0;
|
||||
|
||||
strcpy((char*)buffer, "hair");
|
||||
size = strlen((char*)buffer);
|
||||
for (lfs_off_t j = 0; j < startsizes[i]; j += size) {
|
||||
for (int j = 0; j < startsizes[i]; j += size) {
|
||||
lfs_file_write(&lfs, &file[0], buffer, size) => size;
|
||||
}
|
||||
lfs_file_size(&lfs, &file[0]) => startsizes[i];
|
||||
@@ -55,13 +55,13 @@ tests/test.py << TEST
|
||||
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
|
||||
for (unsigned i = 0; i < sizeof(startsizes)/sizeof(startsizes[0]); i++) {
|
||||
for (int i = 0; i < sizeof(startsizes)/sizeof(startsizes[0]); i++) {
|
||||
sprintf((char*)buffer, "hairyhead%d", i);
|
||||
lfs_file_open(&lfs, &file[0], (const char*)buffer, LFS_O_RDWR) => 0;
|
||||
lfs_file_size(&lfs, &file[0]) => hotsizes[i];
|
||||
|
||||
size = strlen("hair");
|
||||
lfs_off_t j = 0;
|
||||
int j = 0;
|
||||
for (; j < startsizes[i] && j < hotsizes[i]; j += size) {
|
||||
lfs_file_read(&lfs, &file[0], buffer, size) => size;
|
||||
memcmp(buffer, "hair", size) => 0;
|
||||
@@ -87,13 +87,13 @@ tests/test.py << TEST
|
||||
|
||||
lfs_mount(&lfs, &cfg) => 0;
|
||||
|
||||
for (unsigned i = 0; i < sizeof(startsizes)/sizeof(startsizes[0]); i++) {
|
||||
for (int i = 0; i < sizeof(startsizes)/sizeof(startsizes[0]); i++) {
|
||||
sprintf((char*)buffer, "hairyhead%d", i);
|
||||
lfs_file_open(&lfs, &file[0], (const char*)buffer, LFS_O_RDONLY) => 0;
|
||||
lfs_file_size(&lfs, &file[0]) => coldsizes[i];
|
||||
|
||||
size = strlen("hair");
|
||||
lfs_off_t j = 0;
|
||||
int j = 0;
|
||||
for (; j < startsizes[i] && j < hotsizes[i] && j < coldsizes[i];
|
||||
j += size) {
|
||||
lfs_file_read(&lfs, &file[0], buffer, size) => size;
|
||||
|
||||
Reference in New Issue
Block a user