mirror of
https://github.com/eledio-devices/thirdparty-littlefs.git
synced 2025-11-02 08:48:29 +01:00
Compare commits
38 Commits
v1.2
...
inline-fil
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21ef0b7169 | ||
|
|
fec133dfba | ||
|
|
9b4530f8de | ||
|
|
3a12b40fff | ||
|
|
12aa4bde06 | ||
|
|
09c7df83db | ||
|
|
5387f52de5 | ||
|
|
c5b11d2a62 | ||
|
|
66cdab8327 | ||
|
|
8aba03d25f | ||
|
|
9064fa6dbb | ||
|
|
fcc5c764e4 | ||
|
|
37f799d8a2 | ||
|
|
04b1103de1 | ||
|
|
87df75d009 | ||
|
|
1ea3d04d9c | ||
|
|
126f6d334e | ||
|
|
385b74944d | ||
|
|
3a10f5c29b | ||
|
|
96cca2f5b6 | ||
|
|
32f43462ea | ||
|
|
efc634f3ed | ||
|
|
2f7adc3461 | ||
|
|
e934a22c3a | ||
|
|
5937fd79dd | ||
|
|
58f3bb1f08 | ||
|
|
f72f6d6a05 | ||
|
|
5c4ee2109d | ||
|
|
155224600a | ||
|
|
9ee112a7cb | ||
|
|
d9c36371e7 | ||
|
|
1476181bd1 | ||
|
|
b2124a5ae5 | ||
|
|
949015ad52 | ||
|
|
67daf9e2c5 | ||
|
|
a3fd2d4d6d | ||
|
|
a0a55fb9e5 | ||
|
|
4f08424b51 |
292
.travis.yml
292
.travis.yml
@@ -1,107 +1,223 @@
|
|||||||
|
# Environment variables
|
||||||
env:
|
env:
|
||||||
|
global:
|
||||||
- CFLAGS=-Werror
|
- CFLAGS=-Werror
|
||||||
|
|
||||||
|
# Common test script
|
||||||
script:
|
script:
|
||||||
# make sure example can at least compile
|
# make sure example can at least compile
|
||||||
- sed -n '/``` c/,/```/{/```/d; p;}' README.md > test.c &&
|
- sed -n '/``` c/,/```/{/```/d; p;}' README.md > test.c &&
|
||||||
make all size CFLAGS+="
|
make all CFLAGS+="
|
||||||
-Duser_provided_block_device_read=NULL
|
-Duser_provided_block_device_read=NULL
|
||||||
-Duser_provided_block_device_prog=NULL
|
-Duser_provided_block_device_prog=NULL
|
||||||
-Duser_provided_block_device_erase=NULL
|
-Duser_provided_block_device_erase=NULL
|
||||||
-Duser_provided_block_device_sync=NULL
|
-Duser_provided_block_device_sync=NULL
|
||||||
-include stdio.h"
|
-include stdio.h"
|
||||||
|
|
||||||
# run tests
|
# run tests
|
||||||
- make test QUIET=1
|
- make test QUIET=1
|
||||||
|
|
||||||
# run tests with a few different configurations
|
# run tests with a few different configurations
|
||||||
- make test QUIET=1 CFLAGS+="-DLFS_READ_SIZE=1 -DLFS_PROG_SIZE=1"
|
- make test QUIET=1 CFLAGS+="-DLFS_READ_SIZE=1 -DLFS_PROG_SIZE=1"
|
||||||
- make test QUIET=1 CFLAGS+="-DLFS_READ_SIZE=512 -DLFS_PROG_SIZE=512"
|
- make test QUIET=1 CFLAGS+="-DLFS_READ_SIZE=512 -DLFS_PROG_SIZE=512"
|
||||||
- make test QUIET=1 CFLAGS+="-DLFS_BLOCK_COUNT=1023 -DLFS_LOOKAHEAD=2048"
|
- make test QUIET=1 CFLAGS+="-DLFS_BLOCK_COUNT=1023 -DLFS_LOOKAHEAD=2048"
|
||||||
|
|
||||||
|
- make clean test QUIET=1 CFLAGS+="-DLFS_NO_INTRINSICS"
|
||||||
|
|
||||||
|
# compile and find the code size with the smallest configuration
|
||||||
|
- make clean size
|
||||||
|
OBJ="$(ls lfs*.o | tr '\n' ' ')"
|
||||||
|
CFLAGS+="-DLFS_NO{ASSERT,DEBUG,WARN,ERROR}"
|
||||||
|
| tee sizes
|
||||||
|
|
||||||
|
# update status if we succeeded, compare with master if possible
|
||||||
|
- |
|
||||||
|
if [ "$TRAVIS_TEST_RESULT" -eq 0 ]
|
||||||
|
then
|
||||||
|
CURR=$(tail -n1 sizes | awk '{print $1}')
|
||||||
|
PREV=$(curl https://api.github.com/repos/$TRAVIS_REPO_SLUG/status/master \
|
||||||
|
| jq -re "select(.sha != \"$TRAVIS_COMMIT\")
|
||||||
|
| .statuses[] | select(.context == \"$STAGE/$NAME\").description
|
||||||
|
| capture(\"code size is (?<size>[0-9]+)\").size" \
|
||||||
|
|| echo 0)
|
||||||
|
|
||||||
|
STATUS="Passed, code size is ${CURR}B"
|
||||||
|
if [ "$PREV" -ne 0 ]
|
||||||
|
then
|
||||||
|
STATUS="$STATUS ($(python -c "print '%+.2f' % (100*($CURR-$PREV)/$PREV.0)")%)"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# CI matrix
|
||||||
|
jobs:
|
||||||
|
include:
|
||||||
|
# native testing
|
||||||
|
- stage: test
|
||||||
|
env:
|
||||||
|
- STAGE=test
|
||||||
|
- NAME=littlefs-x86
|
||||||
|
|
||||||
|
# cross-compile with ARM (thumb mode)
|
||||||
|
- stage: test
|
||||||
|
env:
|
||||||
|
- STAGE=test
|
||||||
|
- NAME=littlefs-arm
|
||||||
|
- CC="arm-linux-gnueabi-gcc --static -mthumb"
|
||||||
|
- EXEC="qemu-arm"
|
||||||
|
install:
|
||||||
|
- sudo apt-get install gcc-arm-linux-gnueabi qemu-user
|
||||||
|
- arm-linux-gnueabi-gcc --version
|
||||||
|
- qemu-arm -version
|
||||||
|
|
||||||
|
# cross-compile with PowerPC
|
||||||
|
- stage: test
|
||||||
|
env:
|
||||||
|
- STAGE=test
|
||||||
|
- NAME=littlefs-powerpc
|
||||||
|
- CC="powerpc-linux-gnu-gcc --static"
|
||||||
|
- EXEC="qemu-ppc"
|
||||||
|
install:
|
||||||
|
- sudo apt-get install gcc-powerpc-linux-gnu qemu-user
|
||||||
|
- powerpc-linux-gnu-gcc --version
|
||||||
|
- qemu-ppc -version
|
||||||
|
|
||||||
|
# cross-compile with MIPS
|
||||||
|
- stage: test
|
||||||
|
env:
|
||||||
|
- STAGE=test
|
||||||
|
- NAME=littlefs-mips
|
||||||
|
- CC="mips-linux-gnu-gcc --static"
|
||||||
|
- EXEC="qemu-mips"
|
||||||
|
install:
|
||||||
|
- sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu/ xenial main universe"
|
||||||
|
- sudo apt-get -qq update
|
||||||
|
- sudo apt-get install gcc-mips-linux-gnu qemu-user
|
||||||
|
- mips-linux-gnu-gcc --version
|
||||||
|
- qemu-mips -version
|
||||||
|
|
||||||
# self-host with littlefs-fuse for fuzz test
|
# self-host with littlefs-fuse for fuzz test
|
||||||
- make -C littlefs-fuse
|
- stage: test
|
||||||
|
env:
|
||||||
|
- STAGE=test
|
||||||
|
- NAME=littlefs-fuse
|
||||||
|
install:
|
||||||
|
- sudo apt-get install libfuse-dev
|
||||||
|
- git clone --depth 1 https://github.com/geky/littlefs-fuse
|
||||||
|
- fusermount -V
|
||||||
|
- gcc --version
|
||||||
|
before_script:
|
||||||
|
# setup disk for littlefs-fuse
|
||||||
|
- rm -rf littlefs-fuse/littlefs/*
|
||||||
|
- cp -r $(git ls-tree --name-only HEAD) littlefs-fuse/littlefs
|
||||||
|
|
||||||
- littlefs-fuse/lfs --format /dev/loop0
|
- mkdir mount
|
||||||
- littlefs-fuse/lfs /dev/loop0 mount
|
- sudo chmod a+rw /dev/loop0
|
||||||
|
- dd if=/dev/zero bs=512 count=2048 of=disk
|
||||||
|
- losetup /dev/loop0 disk
|
||||||
|
script:
|
||||||
|
# self-host test
|
||||||
|
- make -C littlefs-fuse
|
||||||
|
|
||||||
- ls mount
|
- littlefs-fuse/lfs --format /dev/loop0
|
||||||
- mkdir mount/littlefs
|
- littlefs-fuse/lfs /dev/loop0 mount
|
||||||
- cp -r $(git ls-tree --name-only HEAD) mount/littlefs
|
|
||||||
- cd mount/littlefs
|
|
||||||
- ls
|
|
||||||
- make -B test_dirs test_files QUIET=1
|
|
||||||
|
|
||||||
before_install:
|
- ls mount
|
||||||
- fusermount -V
|
- mkdir mount/littlefs
|
||||||
- gcc --version
|
- cp -r $(git ls-tree --name-only HEAD) mount/littlefs
|
||||||
|
- cd mount/littlefs
|
||||||
|
- ls
|
||||||
|
- make -B test_dirs test_files QUIET=1
|
||||||
|
|
||||||
install:
|
# Automatically update releases
|
||||||
- sudo apt-get install libfuse-dev
|
- stage: deploy
|
||||||
- git clone --depth 1 https://github.com/geky/littlefs-fuse
|
env:
|
||||||
|
- STAGE=deploy
|
||||||
before_script:
|
- NAME=deploy
|
||||||
- rm -rf littlefs-fuse/littlefs/*
|
script:
|
||||||
- cp -r $(git ls-tree --name-only HEAD) littlefs-fuse/littlefs
|
# Update tag for version defined in lfs.h
|
||||||
|
- LFS_VERSION=$(grep -ox '#define LFS_VERSION .*' lfs.h | cut -d ' ' -f3)
|
||||||
- mkdir mount
|
- LFS_VERSION_MAJOR=$((0xffff & ($LFS_VERSION >> 16)))
|
||||||
- sudo chmod a+rw /dev/loop0
|
- LFS_VERSION_MINOR=$((0xffff & ($LFS_VERSION >> 0)))
|
||||||
- dd if=/dev/zero bs=512 count=2048 of=disk
|
- LFS_VERSION="v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR"
|
||||||
- losetup /dev/loop0 disk
|
- echo "littlefs version $LFS_VERSION"
|
||||||
|
- |
|
||||||
deploy:
|
curl -u $GEKY_BOT_RELEASES -X POST \
|
||||||
# Let before_deploy take over
|
https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs \
|
||||||
provider: script
|
|
||||||
script: 'true'
|
|
||||||
on:
|
|
||||||
branch: master
|
|
||||||
|
|
||||||
before_deploy:
|
|
||||||
- cd $TRAVIS_BUILD_DIR
|
|
||||||
# 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)))
|
|
||||||
- LFS_VERSION="v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR"
|
|
||||||
- echo "littlefs version $LFS_VERSION"
|
|
||||||
- |
|
|
||||||
curl -u $GEKY_BOT -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 -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
|
|
||||||
curl -u $GEKY_BOT -X POST \
|
|
||||||
https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases \
|
|
||||||
-d "{
|
-d "{
|
||||||
\"tag_name\": \"$LFS_VERSION\",
|
\"ref\": \"refs/tags/$LFS_VERSION\",
|
||||||
\"name\": \"$LFS_VERSION\"
|
\"sha\": \"$TRAVIS_COMMIT\"
|
||||||
}"
|
}"
|
||||||
RELEASE=$(
|
- |
|
||||||
curl -f https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases/tags/$LFS_VERSION
|
curl -f -u $GEKY_BOT_RELEASES -X PATCH \
|
||||||
)
|
https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs/tags/$LFS_VERSION \
|
||||||
CHANGES=$(
|
-d "{
|
||||||
git log --oneline $LFS_PREV_VERSION.. --grep='^Merge' --invert-grep
|
\"sha\": \"$TRAVIS_COMMIT\"
|
||||||
)
|
}"
|
||||||
curl -f -u $GEKY_BOT -X PATCH \
|
# Create release notes from commits
|
||||||
https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases/$(
|
- LFS_PREV_VERSION="v$LFS_VERSION_MAJOR.$(($LFS_VERSION_MINOR-1))"
|
||||||
jq -r '.id' <<< "$RELEASE"
|
- |
|
||||||
) \
|
if [ $(git tag -l "$LFS_PREV_VERSION") ]
|
||||||
-d "$(
|
then
|
||||||
jq -s '{
|
curl -u $GEKY_BOT_RELEASES -X POST \
|
||||||
"body": ((.[0] // "" | sub("(?<=\n)#+ Changes.*"; ""; "mi"))
|
https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases \
|
||||||
+ "### Changes\n\n" + .[1])
|
-d "{
|
||||||
}' <(jq '.body' <<< "$RELEASE") <(jq -sR '.' <<< "$CHANGES")
|
\"tag_name\": \"$LFS_VERSION\",
|
||||||
)"
|
\"name\": \"$LFS_VERSION\"
|
||||||
fi
|
}"
|
||||||
|
RELEASE=$(
|
||||||
|
curl -f 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
|
||||||
|
before_install:
|
||||||
|
- |
|
||||||
|
curl -u $GEKY_BOT_STATUSES -X POST \
|
||||||
|
https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
|
||||||
|
-d "{
|
||||||
|
\"context\": \"$STAGE/$NAME\",
|
||||||
|
\"state\": \"pending\",
|
||||||
|
\"description\": \"${STATUS:-In progress}\",
|
||||||
|
\"target_url\": \"https://travis-ci.org/$TRAVIS_REPO_SLUG/jobs/$TRAVIS_JOB_ID\"
|
||||||
|
}"
|
||||||
|
|
||||||
|
after_failure:
|
||||||
|
- |
|
||||||
|
curl -u $GEKY_BOT_STATUSES -X POST \
|
||||||
|
https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
|
||||||
|
-d "{
|
||||||
|
\"context\": \"$STAGE/$NAME\",
|
||||||
|
\"state\": \"failure\",
|
||||||
|
\"description\": \"${STATUS:-Failed}\",
|
||||||
|
\"target_url\": \"https://travis-ci.org/$TRAVIS_REPO_SLUG/jobs/$TRAVIS_JOB_ID\"
|
||||||
|
}"
|
||||||
|
|
||||||
|
after_success:
|
||||||
|
- |
|
||||||
|
curl -u $GEKY_BOT_STATUSES -X POST \
|
||||||
|
https://api.github.com/repos/$TRAVIS_REPO_SLUG/statuses/${TRAVIS_PULL_REQUEST_SHA:-$TRAVIS_COMMIT} \
|
||||||
|
-d "{
|
||||||
|
\"context\": \"$STAGE/$NAME\",
|
||||||
|
\"state\": \"success\",
|
||||||
|
\"description\": \"${STATUS:-Passed}\",
|
||||||
|
\"target_url\": \"https://travis-ci.org/$TRAVIS_REPO_SLUG/jobs/$TRAVIS_JOB_ID\"
|
||||||
|
}"
|
||||||
|
|
||||||
|
# Job control
|
||||||
|
stages:
|
||||||
|
- name: test
|
||||||
|
- name: deploy
|
||||||
|
if: branch = master AND type = push
|
||||||
|
|||||||
6
Makefile
6
Makefile
@@ -1,8 +1,8 @@
|
|||||||
TARGET = lfs
|
TARGET = lfs
|
||||||
|
|
||||||
CC = gcc
|
CC ?= gcc
|
||||||
AR = ar
|
AR ?= ar
|
||||||
SIZE = size
|
SIZE ?= size
|
||||||
|
|
||||||
SRC += $(wildcard *.c emubd/*.c)
|
SRC += $(wildcard *.c emubd/*.c)
|
||||||
OBJ := $(SRC:.c=.o)
|
OBJ := $(SRC:.c=.o)
|
||||||
|
|||||||
15
README.md
15
README.md
@@ -115,10 +115,17 @@ All littlefs have the potential to return a negative error code. The errors
|
|||||||
can be either one of those found in the `enum lfs_error` in [lfs.h](lfs.h),
|
can be either one of those found in the `enum lfs_error` in [lfs.h](lfs.h),
|
||||||
or an error returned by the user's block device operations.
|
or an error returned by the user's block device operations.
|
||||||
|
|
||||||
It should also be noted that the current implementation of littlefs doesn't
|
In the configuration struct, the `prog` and `erase` function provided by the
|
||||||
really do anything to ensure that the data written to disk is machine portable.
|
user may return a `LFS_ERR_CORRUPT` error if the implementation already can
|
||||||
This is fine as long as all of the involved machines share endianness
|
detect corrupt blocks. However, the wear leveling does not depend on the return
|
||||||
(little-endian) and don't have strange padding requirements.
|
code of these functions, instead all data is read back and checked for
|
||||||
|
integrity.
|
||||||
|
|
||||||
|
If your storage caches writes, make sure that the provided `sync` function
|
||||||
|
flushes all the data to memory and ensures that the next read fetches the data
|
||||||
|
from memory, otherwise data integrity can not be guaranteed. If the `write`
|
||||||
|
function does not perform caching, and therefore each `read` or `write` call
|
||||||
|
hits the memory, the `sync` function can simply return 0.
|
||||||
|
|
||||||
## Reference material
|
## Reference material
|
||||||
|
|
||||||
|
|||||||
128
lfs.h
128
lfs.h
@@ -27,14 +27,14 @@
|
|||||||
// Software library version
|
// Software library version
|
||||||
// Major (top-nibble), incremented on backwards incompatible changes
|
// Major (top-nibble), incremented on backwards incompatible changes
|
||||||
// Minor (bottom-nibble), incremented on feature additions
|
// Minor (bottom-nibble), incremented on feature additions
|
||||||
#define LFS_VERSION 0x00010002
|
#define LFS_VERSION 0x00010004
|
||||||
#define LFS_VERSION_MAJOR (0xffff & (LFS_VERSION >> 16))
|
#define LFS_VERSION_MAJOR (0xffff & (LFS_VERSION >> 16))
|
||||||
#define LFS_VERSION_MINOR (0xffff & (LFS_VERSION >> 0))
|
#define LFS_VERSION_MINOR (0xffff & (LFS_VERSION >> 0))
|
||||||
|
|
||||||
// Version of On-disk data structures
|
// Version of On-disk data structures
|
||||||
// Major (top-nibble), incremented on backwards incompatible changes
|
// Major (top-nibble), incremented on backwards incompatible changes
|
||||||
// Minor (bottom-nibble), incremented on feature additions
|
// Minor (bottom-nibble), incremented on feature additions
|
||||||
#define LFS_DISK_VERSION 0x00010001
|
#define LFS_DISK_VERSION 0x00010002
|
||||||
#define LFS_DISK_VERSION_MAJOR (0xffff & (LFS_DISK_VERSION >> 16))
|
#define LFS_DISK_VERSION_MAJOR (0xffff & (LFS_DISK_VERSION >> 16))
|
||||||
#define LFS_DISK_VERSION_MINOR (0xffff & (LFS_DISK_VERSION >> 0))
|
#define LFS_DISK_VERSION_MINOR (0xffff & (LFS_DISK_VERSION >> 0))
|
||||||
|
|
||||||
@@ -50,51 +50,78 @@ typedef int32_t lfs_soff_t;
|
|||||||
|
|
||||||
typedef uint32_t lfs_block_t;
|
typedef uint32_t lfs_block_t;
|
||||||
|
|
||||||
// Max name size in bytes
|
// Maximum inline file size in bytes. Large inline files require a larger
|
||||||
|
// read and prog cache, but if a file can be inline it does not need its own
|
||||||
|
// data block. LFS_ATTRS_MAX + LFS_INLINE_MAX must be <= 0xffff. Stored in
|
||||||
|
// superblock and must be respected by other littlefs drivers.
|
||||||
|
#ifndef LFS_INLINE_MAX
|
||||||
|
#define LFS_INLINE_MAX 0x3ff
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Maximum size of all attributes per file in bytes, may be redefined but a
|
||||||
|
// a smaller LFS_ATTRS_MAX has no benefit. LFS_ATTRS_MAX + LFS_INLINE_MAX
|
||||||
|
// must be <= 0xffff. Stored in superblock and must be respected by other
|
||||||
|
// littlefs drivers.
|
||||||
|
#ifndef LFS_ATTRS_MAX
|
||||||
|
#define LFS_ATTRS_MAX 0x3f
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Max name size in bytes, may be redefined to reduce the size of the
|
||||||
|
// info struct. Stored in superblock and must be respected by other
|
||||||
|
// littlefs drivers.
|
||||||
#ifndef LFS_NAME_MAX
|
#ifndef LFS_NAME_MAX
|
||||||
#define LFS_NAME_MAX 255
|
#define LFS_NAME_MAX 0xff
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Possible error codes, these are negative to allow
|
// Possible error codes, these are negative to allow
|
||||||
// valid positive return values
|
// valid positive return values
|
||||||
enum lfs_error {
|
enum lfs_error {
|
||||||
LFS_ERR_OK = 0, // No error
|
LFS_ERR_OK = 0, // No error
|
||||||
LFS_ERR_IO = -5, // Error during device operation
|
LFS_ERR_IO = -5, // Error during device operation
|
||||||
LFS_ERR_CORRUPT = -52, // Corrupted
|
LFS_ERR_CORRUPT = -52, // Corrupted
|
||||||
LFS_ERR_NOENT = -2, // No directory entry
|
LFS_ERR_NOENT = -2, // No directory entry
|
||||||
LFS_ERR_EXIST = -17, // Entry already exists
|
LFS_ERR_EXIST = -17, // Entry already exists
|
||||||
LFS_ERR_NOTDIR = -20, // Entry is not a dir
|
LFS_ERR_NOTDIR = -20, // Entry is not a dir
|
||||||
LFS_ERR_ISDIR = -21, // Entry is a dir
|
LFS_ERR_ISDIR = -21, // Entry is a dir
|
||||||
LFS_ERR_NOTEMPTY = -39, // Dir is not empty
|
LFS_ERR_NOTEMPTY = -39, // Dir is not empty
|
||||||
LFS_ERR_BADF = -9, // Bad file number
|
LFS_ERR_BADF = -9, // Bad file number
|
||||||
LFS_ERR_INVAL = -22, // Invalid parameter
|
LFS_ERR_INVAL = -22, // Invalid parameter
|
||||||
LFS_ERR_NOSPC = -28, // No space left on device
|
LFS_ERR_NOSPC = -28, // No space left on device
|
||||||
LFS_ERR_NOMEM = -12, // No more memory available
|
LFS_ERR_NOMEM = -12, // No more memory available
|
||||||
|
LFS_ERR_NAMETOOLONG = -36, // File name too long
|
||||||
};
|
};
|
||||||
|
|
||||||
// File types
|
// File types
|
||||||
enum lfs_type {
|
enum lfs_type {
|
||||||
LFS_TYPE_REG = 0x11,
|
// file type
|
||||||
LFS_TYPE_DIR = 0x22,
|
LFS_TYPE_REG = 0x01,
|
||||||
LFS_TYPE_SUPERBLOCK = 0x2e,
|
LFS_TYPE_DIR = 0x02,
|
||||||
|
LFS_TYPE_SUPERBLOCK = 0x0e,
|
||||||
|
|
||||||
|
// on disk structure
|
||||||
|
LFS_STRUCT_CTZ = 0x10,
|
||||||
|
LFS_STRUCT_DIR = 0x20,
|
||||||
|
LFS_STRUCT_INLINE = 0x30,
|
||||||
|
LFS_STRUCT_MOVED = 0x80,
|
||||||
};
|
};
|
||||||
|
|
||||||
// File open flags
|
// File open flags
|
||||||
enum lfs_open_flags {
|
enum lfs_open_flags {
|
||||||
// open flags
|
// open flags
|
||||||
LFS_O_RDONLY = 1, // Open a file as read only
|
LFS_O_RDONLY = 1, // Open a file as read only
|
||||||
LFS_O_WRONLY = 2, // Open a file as write only
|
LFS_O_WRONLY = 2, // Open a file as write only
|
||||||
LFS_O_RDWR = 3, // Open a file as read and write
|
LFS_O_RDWR = 3, // Open a file as read and write
|
||||||
LFS_O_CREAT = 0x0100, // Create a file if it does not exist
|
LFS_O_CREAT = 0x0100, // Create a file if it does not exist
|
||||||
LFS_O_EXCL = 0x0200, // Fail if a file already exists
|
LFS_O_EXCL = 0x0200, // Fail if a file already exists
|
||||||
LFS_O_TRUNC = 0x0400, // Truncate the existing file to zero size
|
LFS_O_TRUNC = 0x0400, // Truncate the existing file to zero size
|
||||||
LFS_O_APPEND = 0x0800, // Move to end of file on every write
|
LFS_O_APPEND = 0x0800, // Move to end of file on every write
|
||||||
|
|
||||||
// internally used flags
|
// internally used flags
|
||||||
LFS_F_DIRTY = 0x10000, // File does not match storage
|
LFS_F_DIRTY = 0x010000, // File does not match storage
|
||||||
LFS_F_WRITING = 0x20000, // File has been written since last flush
|
LFS_F_WRITING = 0x020000, // File has been written since last flush
|
||||||
LFS_F_READING = 0x40000, // File has been read since last flush
|
LFS_F_READING = 0x040000, // File has been read since last flush
|
||||||
LFS_F_ERRED = 0x80000, // An error occured during write
|
LFS_F_ERRED = 0x080000, // An error occured during write
|
||||||
|
LFS_F_INLINE = 0x100000, // Currently inlined in directory entry
|
||||||
};
|
};
|
||||||
|
|
||||||
// File seek flags
|
// File seek flags
|
||||||
@@ -171,6 +198,25 @@ struct lfs_config {
|
|||||||
// Optional, statically allocated buffer for files. Must be program sized.
|
// Optional, statically allocated buffer for files. Must be program sized.
|
||||||
// If enabled, only one file may be opened at a time.
|
// If enabled, only one file may be opened at a time.
|
||||||
void *file_buffer;
|
void *file_buffer;
|
||||||
|
|
||||||
|
// Optional upper limit on inlined files in bytes. Large inline files
|
||||||
|
// require a larger read and prog cache, but if a file can be inlined it
|
||||||
|
// does not need its own data block. Must be smaller than the read size
|
||||||
|
// and prog size. Defaults to min(LFS_INLINE_MAX, read_size) when zero.
|
||||||
|
// Stored in superblock and must be respected by other littlefs drivers.
|
||||||
|
lfs_size_t inline_size;
|
||||||
|
|
||||||
|
// Optional upper limit on attributes per file in bytes. No downside for
|
||||||
|
// larger attributes size but must be less than LFS_ATTRS_MAX. Defaults to
|
||||||
|
// LFS_ATTRS_MAX when zero.Stored in superblock and must be respected by
|
||||||
|
// other littlefs drivers.
|
||||||
|
lfs_size_t attrs_size;
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
lfs_size_t name_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -190,6 +236,7 @@ struct lfs_info {
|
|||||||
/// littlefs data structures ///
|
/// littlefs data structures ///
|
||||||
typedef struct lfs_entry {
|
typedef struct lfs_entry {
|
||||||
lfs_off_t off;
|
lfs_off_t off;
|
||||||
|
lfs_size_t size;
|
||||||
|
|
||||||
struct lfs_disk_entry {
|
struct lfs_disk_entry {
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
@@ -221,6 +268,7 @@ typedef struct lfs_file {
|
|||||||
lfs_size_t size;
|
lfs_size_t size;
|
||||||
|
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
|
lfs_size_t inline_size;
|
||||||
lfs_off_t pos;
|
lfs_off_t pos;
|
||||||
lfs_block_t block;
|
lfs_block_t block;
|
||||||
lfs_off_t off;
|
lfs_off_t off;
|
||||||
@@ -243,18 +291,16 @@ typedef struct lfs_dir {
|
|||||||
} lfs_dir_t;
|
} lfs_dir_t;
|
||||||
|
|
||||||
typedef struct lfs_superblock {
|
typedef struct lfs_superblock {
|
||||||
lfs_off_t off;
|
|
||||||
|
|
||||||
struct lfs_disk_superblock {
|
struct lfs_disk_superblock {
|
||||||
uint8_t type;
|
|
||||||
uint8_t elen;
|
|
||||||
uint8_t alen;
|
|
||||||
uint8_t nlen;
|
|
||||||
lfs_block_t root[2];
|
lfs_block_t root[2];
|
||||||
uint32_t block_size;
|
|
||||||
uint32_t block_count;
|
lfs_size_t block_size;
|
||||||
|
lfs_size_t block_count;
|
||||||
uint32_t version;
|
uint32_t version;
|
||||||
char magic[8];
|
|
||||||
|
lfs_size_t inline_size;
|
||||||
|
lfs_size_t attrs_size;
|
||||||
|
lfs_size_t name_size;
|
||||||
} d;
|
} d;
|
||||||
} lfs_superblock_t;
|
} lfs_superblock_t;
|
||||||
|
|
||||||
@@ -279,6 +325,10 @@ typedef struct lfs {
|
|||||||
|
|
||||||
lfs_free_t free;
|
lfs_free_t free;
|
||||||
bool deorphaned;
|
bool deorphaned;
|
||||||
|
|
||||||
|
lfs_size_t inline_size;
|
||||||
|
lfs_size_t attrs_size;
|
||||||
|
lfs_size_t name_size;
|
||||||
} lfs_t;
|
} lfs_t;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,11 @@
|
|||||||
*/
|
*/
|
||||||
#include "lfs_util.h"
|
#include "lfs_util.h"
|
||||||
|
|
||||||
|
// Only compile if user does not provide custom config
|
||||||
|
#ifndef LFS_CONFIG
|
||||||
|
|
||||||
|
|
||||||
|
// Software CRC implementation with small lookup table
|
||||||
void lfs_crc(uint32_t *restrict crc, const void *buffer, size_t size) {
|
void lfs_crc(uint32_t *restrict crc, const void *buffer, size_t size) {
|
||||||
static const uint32_t rtable[16] = {
|
static const uint32_t rtable[16] = {
|
||||||
0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
|
0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
|
||||||
@@ -34,3 +38,5 @@ void lfs_crc(uint32_t *restrict crc, const void *buffer, size_t size) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
148
lfs_util.h
148
lfs_util.h
@@ -18,13 +18,73 @@
|
|||||||
#ifndef LFS_UTIL_H
|
#ifndef LFS_UTIL_H
|
||||||
#define LFS_UTIL_H
|
#define LFS_UTIL_H
|
||||||
|
|
||||||
#include <stdlib.h>
|
// 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).
|
||||||
|
//
|
||||||
|
// If LFS_CONFIG is used, none of the default utils will be emitted and must be
|
||||||
|
// 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
|
||||||
|
|
||||||
|
// System includes
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifndef LFS_NO_MALLOC
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
#ifndef LFS_NO_ASSERT
|
||||||
|
#include <assert.h>
|
||||||
|
#endif
|
||||||
|
#if !defined(LFS_NO_DEBUG) || !defined(LFS_NO_WARN) || !defined(LFS_NO_ERROR)
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Builtin functions, these may be replaced by more
|
// Macros, may be replaced by system specific wrappers. Arguments to these
|
||||||
// efficient implementations in the system
|
// macros must not have side-effects as the macros can be removed for a smaller
|
||||||
|
// code footprint
|
||||||
|
|
||||||
|
// Logging functions
|
||||||
|
#ifndef LFS_NO_DEBUG
|
||||||
|
#define LFS_DEBUG(fmt, ...) \
|
||||||
|
printf("lfs debug:%d: " fmt "\n", __LINE__, __VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define LFS_DEBUG(fmt, ...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LFS_NO_WARN
|
||||||
|
#define LFS_WARN(fmt, ...) \
|
||||||
|
printf("lfs warn:%d: " fmt "\n", __LINE__, __VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define LFS_WARN(fmt, ...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LFS_NO_ERROR
|
||||||
|
#define LFS_ERROR(fmt, ...) \
|
||||||
|
printf("lfs error:%d: " fmt "\n", __LINE__, __VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define LFS_ERROR(fmt, ...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Runtime assertions
|
||||||
|
#ifndef LFS_NO_ASSERT
|
||||||
|
#define LFS_ASSERT(test) assert(test)
|
||||||
|
#else
|
||||||
|
#define LFS_ASSERT(test)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// Builtin functions, these may be replaced by more efficient
|
||||||
|
// toolchain-specific implementations. LFS_NO_INTRINSICS falls back to a more
|
||||||
|
// expensive basic C implementation for debugging purposes
|
||||||
|
|
||||||
|
// Min/max functions for unsigned 32-bit numbers
|
||||||
static inline uint32_t lfs_max(uint32_t a, uint32_t b) {
|
static inline uint32_t lfs_max(uint32_t a, uint32_t b) {
|
||||||
return (a > b) ? a : b;
|
return (a > b) ? a : b;
|
||||||
}
|
}
|
||||||
@@ -33,31 +93,93 @@ static inline uint32_t lfs_min(uint32_t a, uint32_t b) {
|
|||||||
return (a < b) ? a : b;
|
return (a < b) ? a : b;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32_t lfs_ctz(uint32_t a) {
|
// Find the next smallest power of 2 less than or equal to a
|
||||||
return __builtin_ctz(a);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline uint32_t lfs_npw2(uint32_t a) {
|
static inline uint32_t lfs_npw2(uint32_t a) {
|
||||||
|
#if !defined(LFS_NO_INTRINSICS) && (defined(__GNUC__) || defined(__CC_ARM))
|
||||||
return 32 - __builtin_clz(a-1);
|
return 32 - __builtin_clz(a-1);
|
||||||
|
#else
|
||||||
|
uint32_t r = 0;
|
||||||
|
uint32_t s;
|
||||||
|
a -= 1;
|
||||||
|
s = (a > 0xffff) << 4; a >>= s; r |= s;
|
||||||
|
s = (a > 0xff ) << 3; a >>= s; r |= s;
|
||||||
|
s = (a > 0xf ) << 2; a >>= s; r |= s;
|
||||||
|
s = (a > 0x3 ) << 1; a >>= s; r |= s;
|
||||||
|
return (r | (a >> 1)) + 1;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Count the number of trailing binary zeros in a
|
||||||
|
// lfs_ctz(0) may be undefined
|
||||||
|
static inline uint32_t lfs_ctz(uint32_t a) {
|
||||||
|
#if !defined(LFS_NO_INTRINSICS) && defined(__GNUC__)
|
||||||
|
return __builtin_ctz(a);
|
||||||
|
#else
|
||||||
|
return lfs_npw2((a & -a) + 1) - 1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count the number of binary ones in a
|
||||||
static inline uint32_t lfs_popc(uint32_t a) {
|
static inline uint32_t lfs_popc(uint32_t a) {
|
||||||
|
#if !defined(LFS_NO_INTRINSICS) && (defined(__GNUC__) || defined(__CC_ARM))
|
||||||
return __builtin_popcount(a);
|
return __builtin_popcount(a);
|
||||||
|
#else
|
||||||
|
a = a - ((a >> 1) & 0x55555555);
|
||||||
|
a = (a & 0x33333333) + ((a >> 2) & 0x33333333);
|
||||||
|
return (((a + (a >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find the sequence comparison of a and b, this is the distance
|
||||||
|
// between a and b ignoring overflow
|
||||||
static inline int lfs_scmp(uint32_t a, uint32_t b) {
|
static inline int lfs_scmp(uint32_t a, uint32_t b) {
|
||||||
return (int)(unsigned)(a - b);
|
return (int)(unsigned)(a - b);
|
||||||
}
|
}
|
||||||
|
|
||||||
// CRC-32 with polynomial = 0x04c11db7
|
// Convert from 32-bit little-endian to native order
|
||||||
|
static inline uint32_t lfs_fromle32(uint32_t a) {
|
||||||
|
#if !defined(LFS_NO_INTRINSICS) && ( \
|
||||||
|
(defined( BYTE_ORDER ) && BYTE_ORDER == ORDER_LITTLE_ENDIAN ) || \
|
||||||
|
(defined(__BYTE_ORDER ) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN ) || \
|
||||||
|
(defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
|
||||||
|
return a;
|
||||||
|
#elif !defined(LFS_NO_INTRINSICS) && ( \
|
||||||
|
(defined( BYTE_ORDER ) && BYTE_ORDER == ORDER_BIG_ENDIAN ) || \
|
||||||
|
(defined(__BYTE_ORDER ) && __BYTE_ORDER == __ORDER_BIG_ENDIAN ) || \
|
||||||
|
(defined(__BYTE_ORDER__) && __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);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert to 32-bit little-endian from native order
|
||||||
|
static inline uint32_t lfs_tole32(uint32_t a) {
|
||||||
|
return lfs_fromle32(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate CRC-32 with polynomial = 0x04c11db7
|
||||||
void lfs_crc(uint32_t *crc, const void *buffer, size_t size);
|
void lfs_crc(uint32_t *crc, const void *buffer, size_t size);
|
||||||
|
|
||||||
|
// Allocate memory, only used if buffers are not provided to littlefs
|
||||||
|
static inline void *lfs_malloc(size_t size) {
|
||||||
|
#ifndef LFS_NO_MALLOC
|
||||||
|
return malloc(size);
|
||||||
|
#else
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Logging functions, these may be replaced by system-specific
|
// Deallocate memory, only used if buffers are not provided to littlefs
|
||||||
// logging functions
|
static inline void lfs_free(void *p) {
|
||||||
#define LFS_DEBUG(fmt, ...) printf("lfs debug: " fmt "\n", __VA_ARGS__)
|
#ifndef LFS_NO_MALLOC
|
||||||
#define LFS_WARN(fmt, ...) printf("lfs warn: " fmt "\n", __VA_ARGS__)
|
free(p);
|
||||||
#define LFS_ERROR(fmt, ...) printf("lfs error: " fmt "\n", __VA_ARGS__)
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -33,10 +33,15 @@ def generate(test):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def compile():
|
def compile():
|
||||||
subprocess.check_call(['make', '--no-print-directory', '-s'])
|
subprocess.check_call([
|
||||||
|
os.environ.get('MAKE', 'make'),
|
||||||
|
'--no-print-directory', '-s'])
|
||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
subprocess.check_call(["./lfs"])
|
if 'EXEC' in os.environ:
|
||||||
|
subprocess.check_call([os.environ['EXEC'], "./lfs"])
|
||||||
|
else:
|
||||||
|
subprocess.check_call(["./lfs"])
|
||||||
|
|
||||||
def main(test=None):
|
def main(test=None):
|
||||||
if test and not test.startswith('-'):
|
if test and not test.startswith('-'):
|
||||||
|
|||||||
@@ -274,9 +274,12 @@ TEST
|
|||||||
tests/test.py << TEST
|
tests/test.py << TEST
|
||||||
lfs_mount(&lfs, &cfg) => 0;
|
lfs_mount(&lfs, &cfg) => 0;
|
||||||
|
|
||||||
// create one block whole for half a directory
|
// create one block hole for half a directory
|
||||||
lfs_file_open(&lfs, &file[0], "bump", LFS_O_WRONLY | LFS_O_CREAT) => 0;
|
lfs_file_open(&lfs, &file[0], "bump", LFS_O_WRONLY | LFS_O_CREAT) => 0;
|
||||||
lfs_file_write(&lfs, &file[0], (void*)"hi", 2) => 2;
|
for (lfs_size_t i = 0; i < cfg.block_size; i += 2) {
|
||||||
|
memcpy(&buffer[i], "hi", 2);
|
||||||
|
}
|
||||||
|
lfs_file_write(&lfs, &file[0], buffer, cfg.block_size) => cfg.block_size;
|
||||||
lfs_file_close(&lfs, &file[0]) => 0;
|
lfs_file_close(&lfs, &file[0]) => 0;
|
||||||
|
|
||||||
lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
|
lfs_file_open(&lfs, &file[0], "exhaustion", LFS_O_WRONLY | LFS_O_CREAT);
|
||||||
@@ -289,13 +292,16 @@ tests/test.py << TEST
|
|||||||
}
|
}
|
||||||
lfs_file_close(&lfs, &file[0]) => 0;
|
lfs_file_close(&lfs, &file[0]) => 0;
|
||||||
|
|
||||||
// open whole
|
// open hole
|
||||||
lfs_remove(&lfs, "bump") => 0;
|
lfs_remove(&lfs, "bump") => 0;
|
||||||
|
|
||||||
lfs_mkdir(&lfs, "splitdir") => 0;
|
lfs_mkdir(&lfs, "splitdir") => 0;
|
||||||
lfs_file_open(&lfs, &file[0], "splitdir/bump",
|
lfs_file_open(&lfs, &file[0], "splitdir/bump",
|
||||||
LFS_O_WRONLY | LFS_O_CREAT) => 0;
|
LFS_O_WRONLY | LFS_O_CREAT) => 0;
|
||||||
lfs_file_write(&lfs, &file[0], buffer, size) => LFS_ERR_NOSPC;
|
for (lfs_size_t i = 0; i < cfg.block_size; i += 2) {
|
||||||
|
memcpy(&buffer[i], "hi", 2);
|
||||||
|
}
|
||||||
|
lfs_file_write(&lfs, &file[0], buffer, cfg.block_size) => LFS_ERR_NOSPC;
|
||||||
lfs_file_close(&lfs, &file[0]) => 0;
|
lfs_file_close(&lfs, &file[0]) => 0;
|
||||||
|
|
||||||
lfs_unmount(&lfs) => 0;
|
lfs_unmount(&lfs) => 0;
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ lfs_mktree
|
|||||||
lfs_chktree
|
lfs_chktree
|
||||||
|
|
||||||
echo "--- Block corruption ---"
|
echo "--- Block corruption ---"
|
||||||
for i in {0..33}
|
for i in {2..33}
|
||||||
do
|
do
|
||||||
rm -rf blocks
|
rm -rf blocks
|
||||||
mkdir blocks
|
mkdir blocks
|
||||||
@@ -83,12 +83,12 @@ do
|
|||||||
done
|
done
|
||||||
|
|
||||||
echo "--- Block persistance ---"
|
echo "--- Block persistance ---"
|
||||||
for i in {0..33}
|
for i in {2..33}
|
||||||
do
|
do
|
||||||
rm -rf blocks
|
rm -rf blocks
|
||||||
mkdir blocks
|
mkdir blocks
|
||||||
lfs_mktree
|
lfs_mktree
|
||||||
chmod a-w blocks/$(printf '%x' $i)
|
chmod a-w blocks/$(printf '%x' $i) || true
|
||||||
lfs_mktree
|
lfs_mktree
|
||||||
lfs_chktree
|
lfs_chktree
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ tests/test.py << TEST
|
|||||||
sprintf((char*)buffer, "test%d", i);
|
sprintf((char*)buffer, "test%d", i);
|
||||||
lfs_dir_read(&lfs, &dir[0], &info) => 1;
|
lfs_dir_read(&lfs, &dir[0], &info) => 1;
|
||||||
strcmp(info.name, (char*)buffer) => 0;
|
strcmp(info.name, (char*)buffer) => 0;
|
||||||
|
info.type => LFS_TYPE_DIR;
|
||||||
}
|
}
|
||||||
lfs_dir_read(&lfs, &dir[0], &info) => 0;
|
lfs_dir_read(&lfs, &dir[0], &info) => 0;
|
||||||
lfs_unmount(&lfs) => 0;
|
lfs_unmount(&lfs) => 0;
|
||||||
@@ -355,5 +356,70 @@ tests/test.py << TEST
|
|||||||
lfs_unmount(&lfs) => 0;
|
lfs_unmount(&lfs) => 0;
|
||||||
TEST
|
TEST
|
||||||
|
|
||||||
|
echo "--- Multi-block directory with files ---"
|
||||||
|
tests/test.py << TEST
|
||||||
|
lfs_mount(&lfs, &cfg) => 0;
|
||||||
|
lfs_mkdir(&lfs, "prickly-pear") => 0;
|
||||||
|
for (int i = 0; i < $LARGESIZE; i++) {
|
||||||
|
sprintf((char*)buffer, "prickly-pear/test%d", i);
|
||||||
|
lfs_file_open(&lfs, &file[0], (char*)buffer,
|
||||||
|
LFS_O_WRONLY | LFS_O_CREAT) => 0;
|
||||||
|
size = 6;
|
||||||
|
memcpy(wbuffer, "Hello", size);
|
||||||
|
lfs_file_write(&lfs, &file[0], wbuffer, size) => size;
|
||||||
|
lfs_file_close(&lfs, &file[0]) => 0;
|
||||||
|
}
|
||||||
|
lfs_unmount(&lfs) => 0;
|
||||||
|
TEST
|
||||||
|
tests/test.py << TEST
|
||||||
|
lfs_mount(&lfs, &cfg) => 0;
|
||||||
|
lfs_dir_open(&lfs, &dir[0], "prickly-pear") => 0;
|
||||||
|
lfs_dir_read(&lfs, &dir[0], &info) => 1;
|
||||||
|
strcmp(info.name, ".") => 0;
|
||||||
|
info.type => LFS_TYPE_DIR;
|
||||||
|
lfs_dir_read(&lfs, &dir[0], &info) => 1;
|
||||||
|
strcmp(info.name, "..") => 0;
|
||||||
|
info.type => LFS_TYPE_DIR;
|
||||||
|
for (int i = 0; i < $LARGESIZE; i++) {
|
||||||
|
sprintf((char*)buffer, "test%d", i);
|
||||||
|
lfs_dir_read(&lfs, &dir[0], &info) => 1;
|
||||||
|
strcmp(info.name, (char*)buffer) => 0;
|
||||||
|
info.type => LFS_TYPE_REG;
|
||||||
|
info.size => 6;
|
||||||
|
}
|
||||||
|
lfs_dir_read(&lfs, &dir[0], &info) => 0;
|
||||||
|
lfs_unmount(&lfs) => 0;
|
||||||
|
TEST
|
||||||
|
|
||||||
|
echo "--- Multi-block remove with files ---"
|
||||||
|
tests/test.py << TEST
|
||||||
|
lfs_mount(&lfs, &cfg) => 0;
|
||||||
|
lfs_remove(&lfs, "prickly-pear") => LFS_ERR_NOTEMPTY;
|
||||||
|
|
||||||
|
for (int i = 0; i < $LARGESIZE; i++) {
|
||||||
|
sprintf((char*)buffer, "prickly-pear/test%d", i);
|
||||||
|
lfs_remove(&lfs, (char*)buffer) => 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
lfs_remove(&lfs, "prickly-pear") => 0;
|
||||||
|
lfs_unmount(&lfs) => 0;
|
||||||
|
TEST
|
||||||
|
tests/test.py << TEST
|
||||||
|
lfs_mount(&lfs, &cfg) => 0;
|
||||||
|
lfs_dir_open(&lfs, &dir[0], "/") => 0;
|
||||||
|
lfs_dir_read(&lfs, &dir[0], &info) => 1;
|
||||||
|
strcmp(info.name, ".") => 0;
|
||||||
|
info.type => LFS_TYPE_DIR;
|
||||||
|
lfs_dir_read(&lfs, &dir[0], &info) => 1;
|
||||||
|
strcmp(info.name, "..") => 0;
|
||||||
|
info.type => LFS_TYPE_DIR;
|
||||||
|
lfs_dir_read(&lfs, &dir[0], &info) => 1;
|
||||||
|
strcmp(info.name, "burito") => 0;
|
||||||
|
info.type => LFS_TYPE_REG;
|
||||||
|
lfs_dir_read(&lfs, &dir[0], &info) => 0;
|
||||||
|
lfs_dir_close(&lfs, &dir[0]) => 0;
|
||||||
|
lfs_unmount(&lfs) => 0;
|
||||||
|
TEST
|
||||||
|
|
||||||
echo "--- Results ---"
|
echo "--- Results ---"
|
||||||
tests/stats.py
|
tests/stats.py
|
||||||
|
|||||||
@@ -135,5 +135,24 @@ tests/test.py << TEST
|
|||||||
lfs_unmount(&lfs) => 0;
|
lfs_unmount(&lfs) => 0;
|
||||||
TEST
|
TEST
|
||||||
|
|
||||||
|
echo "--- Many file test ---"
|
||||||
|
tests/test.py << TEST
|
||||||
|
lfs_format(&lfs, &cfg) => 0;
|
||||||
|
TEST
|
||||||
|
tests/test.py << TEST
|
||||||
|
// Create 300 files of 6 bytes
|
||||||
|
lfs_mount(&lfs, &cfg) => 0;
|
||||||
|
lfs_mkdir(&lfs, "directory") => 0;
|
||||||
|
for (unsigned i = 0; i < 300; i++) {
|
||||||
|
snprintf((char*)buffer, sizeof(buffer), "file_%03d", i);
|
||||||
|
lfs_file_open(&lfs, &file[0], (char*)buffer, LFS_O_WRONLY | LFS_O_CREAT) => 0;
|
||||||
|
size = 6;
|
||||||
|
memcpy(wbuffer, "Hello", size);
|
||||||
|
lfs_file_write(&lfs, &file[0], wbuffer, size) => size;
|
||||||
|
lfs_file_close(&lfs, &file[0]) => 0;
|
||||||
|
}
|
||||||
|
lfs_unmount(&lfs) => 0;
|
||||||
|
TEST
|
||||||
|
|
||||||
echo "--- Results ---"
|
echo "--- Results ---"
|
||||||
tests/stats.py
|
tests/stats.py
|
||||||
|
|||||||
@@ -30,20 +30,10 @@ echo "--- Invalid mount ---"
|
|||||||
tests/test.py << TEST
|
tests/test.py << TEST
|
||||||
lfs_format(&lfs, &cfg) => 0;
|
lfs_format(&lfs, &cfg) => 0;
|
||||||
TEST
|
TEST
|
||||||
rm blocks/0 blocks/1
|
rm -f blocks/0 blocks/1
|
||||||
tests/test.py << TEST
|
tests/test.py << TEST
|
||||||
lfs_mount(&lfs, &cfg) => LFS_ERR_CORRUPT;
|
lfs_mount(&lfs, &cfg) => LFS_ERR_CORRUPT;
|
||||||
TEST
|
TEST
|
||||||
|
|
||||||
echo "--- Valid corrupt mount ---"
|
|
||||||
tests/test.py << TEST
|
|
||||||
lfs_format(&lfs, &cfg) => 0;
|
|
||||||
TEST
|
|
||||||
rm blocks/0
|
|
||||||
tests/test.py << TEST
|
|
||||||
lfs_mount(&lfs, &cfg) => 0;
|
|
||||||
lfs_unmount(&lfs) => 0;
|
|
||||||
TEST
|
|
||||||
|
|
||||||
echo "--- Results ---"
|
echo "--- Results ---"
|
||||||
tests/stats.py
|
tests/stats.py
|
||||||
|
|||||||
@@ -108,6 +108,10 @@ tests/test.py << TEST
|
|||||||
lfs_stat(&lfs, "/", &info) => 0;
|
lfs_stat(&lfs, "/", &info) => 0;
|
||||||
info.type => LFS_TYPE_DIR;
|
info.type => LFS_TYPE_DIR;
|
||||||
strcmp(info.name, "/") => 0;
|
strcmp(info.name, "/") => 0;
|
||||||
|
|
||||||
|
lfs_mkdir(&lfs, "/") => LFS_ERR_EXIST;
|
||||||
|
lfs_file_open(&lfs, &file[0], "/", LFS_O_WRONLY | LFS_O_CREAT)
|
||||||
|
=> LFS_ERR_ISDIR;
|
||||||
lfs_unmount(&lfs) => 0;
|
lfs_unmount(&lfs) => 0;
|
||||||
TEST
|
TEST
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user