mirror of
https://github.com/eledio-devices/thirdparty-littlefs.git
synced 2025-11-01 16:14:13 +01:00
Compare commits
12 Commits
sanity-tes
...
resizable-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
04b1103de1 | ||
|
|
87df75d009 | ||
|
|
1ea3d04d9c | ||
|
|
126f6d334e | ||
|
|
385b74944d | ||
|
|
3a10f5c29b | ||
|
|
96cca2f5b6 | ||
|
|
32f43462ea | ||
|
|
efc634f3ed | ||
|
|
2f7adc3461 | ||
|
|
e934a22c3a | ||
|
|
5937fd79dd |
@@ -27,7 +27,7 @@ script:
|
|||||||
# compile and find the code size with the smallest configuration
|
# compile and find the code size with the smallest configuration
|
||||||
- make clean size
|
- make clean size
|
||||||
OBJ="$(ls lfs*.o | tr '\n' ' ')"
|
OBJ="$(ls lfs*.o | tr '\n' ' ')"
|
||||||
CFLAGS+="-DLFS_NO_ASSERT -DLFS_NO_DEBUG -DLFS_NO_WARN -DLFS_NO_ERROR"
|
CFLAGS+="-DLFS_NO{ASSERT,DEBUG,WARN,ERROR}"
|
||||||
| tee sizes
|
| tee sizes
|
||||||
|
|
||||||
# update status if we succeeded, compare with master if possible
|
# update status if we succeeded, compare with master if possible
|
||||||
@@ -35,7 +35,7 @@ script:
|
|||||||
if [ "$TRAVIS_TEST_RESULT" -eq 0 ]
|
if [ "$TRAVIS_TEST_RESULT" -eq 0 ]
|
||||||
then
|
then
|
||||||
CURR=$(tail -n1 sizes | awk '{print $1}')
|
CURR=$(tail -n1 sizes | awk '{print $1}')
|
||||||
PREV=$(curl -u $GEKY_BOT_STATUSES https://api.github.com/repos/$TRAVIS_REPO_SLUG/status/master \
|
PREV=$(curl https://api.github.com/repos/$TRAVIS_REPO_SLUG/status/master \
|
||||||
| jq -re "select(.sha != \"$TRAVIS_COMMIT\")
|
| jq -re "select(.sha != \"$TRAVIS_COMMIT\")
|
||||||
| .statuses[] | select(.context == \"$STAGE/$NAME\").description
|
| .statuses[] | select(.context == \"$STAGE/$NAME\").description
|
||||||
| capture(\"code size is (?<size>[0-9]+)\").size" \
|
| capture(\"code size is (?<size>[0-9]+)\").size" \
|
||||||
@@ -165,8 +165,7 @@ jobs:
|
|||||||
\"name\": \"$LFS_VERSION\"
|
\"name\": \"$LFS_VERSION\"
|
||||||
}"
|
}"
|
||||||
RELEASE=$(
|
RELEASE=$(
|
||||||
curl -f -u $GEKY_BOT_RELEASES \
|
curl -f https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases/tags/$LFS_VERSION
|
||||||
https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases/tags/$LFS_VERSION
|
|
||||||
)
|
)
|
||||||
CHANGES=$(
|
CHANGES=$(
|
||||||
git log --oneline $LFS_PREV_VERSION.. --grep='^Merge' --invert-grep
|
git log --oneline $LFS_PREV_VERSION.. --grep='^Merge' --invert-grep
|
||||||
|
|||||||
183
LICENSE.md
183
LICENSE.md
@@ -1,36 +1,165 @@
|
|||||||
Copyright (c) 2017, Arm Limited. All rights reserved.
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification,
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
- Redistributions of source code must retain the above copyright notice, this
|
1. Definitions.
|
||||||
list of conditions and the following disclaimer.
|
|
||||||
- Redistributions in binary form must reproduce the above copyright notice, this
|
|
||||||
list of conditions and the following disclaimer in the documentation and/or
|
|
||||||
other materials provided with the distribution.
|
|
||||||
- Neither the name of ARM nor the names of its contributors may be used to
|
|
||||||
endorse or promote products derived from this software without specific prior
|
|
||||||
written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
"License" shall mean the terms and conditions for use, reproduction, and
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
distribution as defined by Sections 1 through 9 of this document.
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
||||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
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.
|
|
||||||
|
|
||||||
---
|
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
||||||
|
owner that is granting the License.
|
||||||
|
|
||||||
*Note*:
|
"Legal Entity" shall mean the union of the acting entity and all other entities
|
||||||
Individual files contain the following tag instead of the full license text.
|
that control, are controlled by, or are under common control with that entity.
|
||||||
|
For the purposes of this definition, "control" means (i) the power, direct or
|
||||||
|
indirect, to cause the direction or management of such entity, whether by
|
||||||
|
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
||||||
|
permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications, including
|
||||||
|
but not limited to software source code, documentation source, and configuration
|
||||||
|
files.
|
||||||
|
|
||||||
SPDX-License-Identifier: BSD-3-Clause
|
"Object" form shall mean any form resulting from mechanical transformation or
|
||||||
|
translation of a Source form, including but not limited to compiled object code,
|
||||||
|
generated documentation, and conversions to other media types.
|
||||||
|
|
||||||
This enables machine processing of license information based on the SPDX
|
"Work" shall mean the work of authorship, whether in Source or Object form, made
|
||||||
License Identifiers that are here available: http://spdx.org/licenses/
|
available under the License, as indicated by a copyright notice that is included
|
||||||
|
in or attached to the work (an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
||||||
|
is based on (or derived from) the Work and for which the editorial revisions,
|
||||||
|
annotations, elaborations, or other modifications represent, as a whole, an
|
||||||
|
original work of authorship. For the purposes of this License, Derivative Works
|
||||||
|
shall not include works that remain separable from, or merely link (or bind by
|
||||||
|
name) to the interfaces of, the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including the original version
|
||||||
|
of the Work and any modifications or additions to that Work or Derivative Works
|
||||||
|
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
||||||
|
by the copyright owner or by an individual or Legal Entity authorized to submit
|
||||||
|
on behalf of the copyright owner. For the purposes of this definition,
|
||||||
|
"submitted" means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems, and
|
||||||
|
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
||||||
|
the purpose of discussing and improving the Work, but excluding communication
|
||||||
|
that is conspicuously marked or otherwise designated in writing by the copyright
|
||||||
|
owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
||||||
|
of whom a Contribution has been received by Licensor and subsequently
|
||||||
|
incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License.
|
||||||
|
|
||||||
|
Subject to the terms and conditions of this License, each Contributor hereby
|
||||||
|
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
||||||
|
irrevocable copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the Work and such
|
||||||
|
Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License.
|
||||||
|
|
||||||
|
Subject to the terms and conditions of this License, each Contributor hereby
|
||||||
|
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
||||||
|
irrevocable (except as stated in this section) patent license to make, have
|
||||||
|
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
|
||||||
|
such license applies only to those patent claims licensable by such Contributor
|
||||||
|
that are necessarily infringed by their Contribution(s) alone or by combination
|
||||||
|
of their Contribution(s) with the Work to which such Contribution(s) was
|
||||||
|
submitted. If You institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
||||||
|
Contribution incorporated within the Work constitutes direct or contributory
|
||||||
|
patent infringement, then any patent licenses granted to You under this License
|
||||||
|
for that Work shall terminate as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution.
|
||||||
|
|
||||||
|
You may reproduce and distribute copies of the Work or Derivative Works thereof
|
||||||
|
in any medium, with or without modifications, and in Source or Object form,
|
||||||
|
provided that You meet the following conditions:
|
||||||
|
|
||||||
|
You must give any other recipients of the Work or Derivative Works a copy of
|
||||||
|
this License; and
|
||||||
|
You must cause any modified files to carry prominent notices stating that You
|
||||||
|
changed the files; and
|
||||||
|
You must retain, in the Source form of any Derivative Works that You distribute,
|
||||||
|
all copyright, patent, trademark, and attribution notices from the Source form
|
||||||
|
of the Work, excluding those notices that do not pertain to any part of the
|
||||||
|
Derivative Works; and
|
||||||
|
If the Work includes a "NOTICE" text file as part of its distribution, then any
|
||||||
|
Derivative Works that You distribute must include a readable copy of the
|
||||||
|
attribution notices contained within such NOTICE file, excluding those notices
|
||||||
|
that do not pertain to any part of the Derivative Works, in at least one of the
|
||||||
|
following places: within a NOTICE text file distributed as part of the
|
||||||
|
Derivative Works; within the Source form or documentation, if provided along
|
||||||
|
with the Derivative Works; or, within a display generated by the Derivative
|
||||||
|
Works, if and wherever such third-party notices normally appear. The contents of
|
||||||
|
the NOTICE file are for informational purposes only and do not modify the
|
||||||
|
License. You may add Your own attribution notices within Derivative Works that
|
||||||
|
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
||||||
|
provided that such additional attribution notices cannot be construed as
|
||||||
|
modifying the License.
|
||||||
|
You may add Your own copyright statement to Your modifications and may provide
|
||||||
|
additional or different license terms and conditions for use, reproduction, or
|
||||||
|
distribution of Your modifications, or for any such Derivative Works as a whole,
|
||||||
|
provided Your use, reproduction, and distribution of the Work otherwise complies
|
||||||
|
with the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions.
|
||||||
|
|
||||||
|
Unless You explicitly state otherwise, any Contribution intentionally submitted
|
||||||
|
for inclusion in the Work by You to the Licensor shall be under the terms and
|
||||||
|
conditions of this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify the terms of
|
||||||
|
any separate license agreement you may have executed with Licensor regarding
|
||||||
|
such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks.
|
||||||
|
|
||||||
|
This License does not grant permission to use the trade names, trademarks,
|
||||||
|
service marks, or product names of the Licensor, except as required for
|
||||||
|
reasonable and customary use in describing the origin of the Work and
|
||||||
|
reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, Licensor provides the
|
||||||
|
Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
|
||||||
|
including, without limitation, any warranties or conditions of TITLE,
|
||||||
|
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
|
||||||
|
solely responsible for determining the appropriateness of using or
|
||||||
|
redistributing the Work and assume any risks associated with Your exercise of
|
||||||
|
permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability.
|
||||||
|
|
||||||
|
In no event and under no legal theory, whether in tort (including negligence),
|
||||||
|
contract, or otherwise, unless required by applicable law (such as deliberate
|
||||||
|
and grossly negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special, incidental,
|
||||||
|
or consequential damages of any character arising as a result of this License or
|
||||||
|
out of the use or inability to use the Work (including but not limited to
|
||||||
|
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
||||||
|
any and all other commercial damages or losses), even if such Contributor has
|
||||||
|
been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability.
|
||||||
|
|
||||||
|
While redistributing the Work or Derivative Works thereof, You may choose to
|
||||||
|
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
|
||||||
|
other liability obligations and/or rights consistent with this License. However,
|
||||||
|
in accepting such obligations, You may act only on Your own behalf and on Your
|
||||||
|
sole responsibility, not on behalf of any other Contributor, and only if You
|
||||||
|
agree to indemnify, defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason of your
|
||||||
|
accepting any such warranty or additional liability.
|
||||||
|
|||||||
15
Makefile
15
Makefile
@@ -1,7 +1,4 @@
|
|||||||
TARGET = lfs.a
|
TARGET = lfs
|
||||||
ifneq ($(wildcard test.c main.c),)
|
|
||||||
override TARGET = lfs
|
|
||||||
endif
|
|
||||||
|
|
||||||
CC ?= gcc
|
CC ?= gcc
|
||||||
AR ?= ar
|
AR ?= ar
|
||||||
@@ -25,7 +22,7 @@ ifdef WORD
|
|||||||
override CFLAGS += -m$(WORD)
|
override CFLAGS += -m$(WORD)
|
||||||
endif
|
endif
|
||||||
override CFLAGS += -I.
|
override CFLAGS += -I.
|
||||||
override CFLAGS += -std=c99 -Wall -pedantic -Wshadow -Wunused-parameter
|
override CFLAGS += -std=c99 -Wall -pedantic
|
||||||
|
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
@@ -36,11 +33,9 @@ size: $(OBJ)
|
|||||||
$(SIZE) -t $^
|
$(SIZE) -t $^
|
||||||
|
|
||||||
.SUFFIXES:
|
.SUFFIXES:
|
||||||
test: test_format test_dirs test_files test_seek test_truncate \
|
test: test_format test_dirs test_files test_seek test_truncate test_parallel \
|
||||||
test_interspersed test_alloc test_paths test_orphan test_move test_corrupt
|
test_alloc test_paths test_orphan test_move test_corrupt
|
||||||
@rm test.c
|
|
||||||
test_%: tests/test_%.sh
|
test_%: tests/test_%.sh
|
||||||
|
|
||||||
ifdef QUIET
|
ifdef QUIET
|
||||||
@./$< | sed -n '/^[-=]/p'
|
@./$< | sed -n '/^[-=]/p'
|
||||||
else
|
else
|
||||||
@@ -49,7 +44,7 @@ endif
|
|||||||
|
|
||||||
-include $(DEP)
|
-include $(DEP)
|
||||||
|
|
||||||
lfs: $(OBJ)
|
$(TARGET): $(OBJ)
|
||||||
$(CC) $(CFLAGS) $^ $(LFLAGS) -o $@
|
$(CC) $(CFLAGS) $^ $(LFLAGS) -o $@
|
||||||
|
|
||||||
%.a: $(OBJ)
|
%.a: $(OBJ)
|
||||||
|
|||||||
@@ -1,8 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
* Block device emulated on standard files
|
* Block device emulated on standard files
|
||||||
*
|
*
|
||||||
* Copyright (c) 2017, Arm Limited. All rights reserved.
|
* Copyright (c) 2017 ARM Limited
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
#include "emubd/lfs_emubd.h"
|
#include "emubd/lfs_emubd.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
* Block device emulated on standard files
|
* Block device emulated on standard files
|
||||||
*
|
*
|
||||||
* Copyright (c) 2017, Arm Limited. All rights reserved.
|
* Copyright (c) 2017 ARM Limited
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
#ifndef LFS_EMUBD_H
|
#ifndef LFS_EMUBD_H
|
||||||
#define LFS_EMUBD_H
|
#define LFS_EMUBD_H
|
||||||
|
|||||||
40
lfs.h
40
lfs.h
@@ -1,8 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
* The little filesystem
|
* The little filesystem
|
||||||
*
|
*
|
||||||
* Copyright (c) 2017, Arm Limited. All rights reserved.
|
* Copyright (c) 2017 ARM Limited
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
#ifndef LFS_H
|
#ifndef LFS_H
|
||||||
#define LFS_H
|
#define LFS_H
|
||||||
@@ -16,7 +27,7 @@
|
|||||||
// 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 0x00010004
|
#define LFS_VERSION 0x00010003
|
||||||
#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))
|
||||||
|
|
||||||
@@ -63,9 +74,15 @@ enum lfs_error {
|
|||||||
|
|
||||||
// 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_MOVED = 0x80,
|
||||||
};
|
};
|
||||||
|
|
||||||
// File open flags
|
// File open flags
|
||||||
@@ -179,6 +196,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;
|
||||||
@@ -232,8 +250,6 @@ 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 type;
|
||||||
uint8_t elen;
|
uint8_t elen;
|
||||||
@@ -248,9 +264,9 @@ typedef struct lfs_superblock {
|
|||||||
} lfs_superblock_t;
|
} lfs_superblock_t;
|
||||||
|
|
||||||
typedef struct lfs_free {
|
typedef struct lfs_free {
|
||||||
lfs_block_t off;
|
lfs_block_t begin;
|
||||||
lfs_block_t size;
|
lfs_block_t size;
|
||||||
lfs_block_t i;
|
lfs_block_t off;
|
||||||
lfs_block_t ack;
|
lfs_block_t ack;
|
||||||
uint32_t *buffer;
|
uint32_t *buffer;
|
||||||
} lfs_free_t;
|
} lfs_free_t;
|
||||||
@@ -309,6 +325,10 @@ int lfs_remove(lfs_t *lfs, const char *path);
|
|||||||
// If the destination exists, it must match the source in type.
|
// If the destination exists, it must match the source in type.
|
||||||
// If the destination is a directory, the directory must be empty.
|
// If the destination is a directory, the directory must be empty.
|
||||||
//
|
//
|
||||||
|
// Note: If power loss occurs, it is possible that the file or directory
|
||||||
|
// will exist in both the oldpath and newpath simultaneously after the
|
||||||
|
// next mount.
|
||||||
|
//
|
||||||
// Returns a negative error code on failure.
|
// Returns a negative error code on failure.
|
||||||
int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath);
|
int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath);
|
||||||
|
|
||||||
|
|||||||
15
lfs_util.c
15
lfs_util.c
@@ -1,8 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
* lfs util functions
|
* lfs util functions
|
||||||
*
|
*
|
||||||
* Copyright (c) 2017, Arm Limited. All rights reserved.
|
* Copyright (c) 2017 ARM Limited
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
#include "lfs_util.h"
|
#include "lfs_util.h"
|
||||||
|
|
||||||
|
|||||||
18
lfs_util.h
18
lfs_util.h
@@ -1,8 +1,19 @@
|
|||||||
/*
|
/*
|
||||||
* lfs utility functions
|
* lfs utility functions
|
||||||
*
|
*
|
||||||
* Copyright (c) 2017, Arm Limited. All rights reserved.
|
* Copyright (c) 2017 ARM Limited
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
#ifndef LFS_UTIL_H
|
#ifndef LFS_UTIL_H
|
||||||
#define LFS_UTIL_H
|
#define LFS_UTIL_H
|
||||||
@@ -158,7 +169,6 @@ static inline void *lfs_malloc(size_t size) {
|
|||||||
#ifndef LFS_NO_MALLOC
|
#ifndef LFS_NO_MALLOC
|
||||||
return malloc(size);
|
return malloc(size);
|
||||||
#else
|
#else
|
||||||
(void)size;
|
|
||||||
return NULL;
|
return NULL;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -167,8 +177,6 @@ static inline void *lfs_malloc(size_t size) {
|
|||||||
static inline void lfs_free(void *p) {
|
static inline void lfs_free(void *p) {
|
||||||
#ifndef LFS_NO_MALLOC
|
#ifndef LFS_NO_MALLOC
|
||||||
free(p);
|
free(p);
|
||||||
#else
|
|
||||||
(void)p;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ tests/test.py << TEST
|
|||||||
}
|
}
|
||||||
lfs_file_close(&lfs, &file[0]) => 0;
|
lfs_file_close(&lfs, &file[0]) => 0;
|
||||||
|
|
||||||
// open hole
|
// open whole
|
||||||
lfs_remove(&lfs, "bump") => 0;
|
lfs_remove(&lfs, "bump") => 0;
|
||||||
|
|
||||||
lfs_mkdir(&lfs, "splitdir") => 0;
|
lfs_mkdir(&lfs, "splitdir") => 0;
|
||||||
@@ -301,128 +301,5 @@ tests/test.py << TEST
|
|||||||
lfs_unmount(&lfs) => 0;
|
lfs_unmount(&lfs) => 0;
|
||||||
TEST
|
TEST
|
||||||
|
|
||||||
echo "--- Outdated lookahead test ---"
|
|
||||||
rm -rf blocks
|
|
||||||
tests/test.py << TEST
|
|
||||||
lfs_format(&lfs, &cfg) => 0;
|
|
||||||
|
|
||||||
lfs_mount(&lfs, &cfg) => 0;
|
|
||||||
|
|
||||||
// fill completely with two files
|
|
||||||
lfs_file_open(&lfs, &file[0], "exhaustion1",
|
|
||||||
LFS_O_WRONLY | LFS_O_CREAT) => 0;
|
|
||||||
size = strlen("blahblahblahblah");
|
|
||||||
memcpy(buffer, "blahblahblahblah", size);
|
|
||||||
for (lfs_size_t i = 0;
|
|
||||||
i < ((cfg.block_count-4)/2)*(cfg.block_size-8);
|
|
||||||
i += size) {
|
|
||||||
lfs_file_write(&lfs, &file[0], buffer, size) => size;
|
|
||||||
}
|
|
||||||
lfs_file_close(&lfs, &file[0]) => 0;
|
|
||||||
|
|
||||||
lfs_file_open(&lfs, &file[0], "exhaustion2",
|
|
||||||
LFS_O_WRONLY | LFS_O_CREAT) => 0;
|
|
||||||
size = strlen("blahblahblahblah");
|
|
||||||
memcpy(buffer, "blahblahblahblah", size);
|
|
||||||
for (lfs_size_t i = 0;
|
|
||||||
i < ((cfg.block_count-4+1)/2)*(cfg.block_size-8);
|
|
||||||
i += size) {
|
|
||||||
lfs_file_write(&lfs, &file[0], buffer, size) => size;
|
|
||||||
}
|
|
||||||
lfs_file_close(&lfs, &file[0]) => 0;
|
|
||||||
|
|
||||||
// remount to force reset of lookahead
|
|
||||||
lfs_unmount(&lfs) => 0;
|
|
||||||
|
|
||||||
lfs_mount(&lfs, &cfg) => 0;
|
|
||||||
|
|
||||||
// rewrite one file
|
|
||||||
lfs_file_open(&lfs, &file[0], "exhaustion1",
|
|
||||||
LFS_O_WRONLY | LFS_O_TRUNC) => 0;
|
|
||||||
lfs_file_sync(&lfs, &file[0]) => 0;
|
|
||||||
size = strlen("blahblahblahblah");
|
|
||||||
memcpy(buffer, "blahblahblahblah", size);
|
|
||||||
for (lfs_size_t i = 0;
|
|
||||||
i < ((cfg.block_count-4)/2)*(cfg.block_size-8);
|
|
||||||
i += size) {
|
|
||||||
lfs_file_write(&lfs, &file[0], buffer, size) => size;
|
|
||||||
}
|
|
||||||
lfs_file_close(&lfs, &file[0]) => 0;
|
|
||||||
|
|
||||||
// rewrite second file, this requires lookahead does not
|
|
||||||
// use old population
|
|
||||||
lfs_file_open(&lfs, &file[0], "exhaustion2",
|
|
||||||
LFS_O_WRONLY | LFS_O_TRUNC) => 0;
|
|
||||||
lfs_file_sync(&lfs, &file[0]) => 0;
|
|
||||||
size = strlen("blahblahblahblah");
|
|
||||||
memcpy(buffer, "blahblahblahblah", size);
|
|
||||||
for (lfs_size_t i = 0;
|
|
||||||
i < ((cfg.block_count-4+1)/2)*(cfg.block_size-8);
|
|
||||||
i += size) {
|
|
||||||
lfs_file_write(&lfs, &file[0], buffer, size) => size;
|
|
||||||
}
|
|
||||||
lfs_file_close(&lfs, &file[0]) => 0;
|
|
||||||
TEST
|
|
||||||
|
|
||||||
echo "--- Outdated lookahead and split dir test ---"
|
|
||||||
rm -rf blocks
|
|
||||||
tests/test.py << TEST
|
|
||||||
lfs_format(&lfs, &cfg) => 0;
|
|
||||||
|
|
||||||
lfs_mount(&lfs, &cfg) => 0;
|
|
||||||
|
|
||||||
// fill completely with two files
|
|
||||||
lfs_file_open(&lfs, &file[0], "exhaustion1",
|
|
||||||
LFS_O_WRONLY | LFS_O_CREAT) => 0;
|
|
||||||
size = strlen("blahblahblahblah");
|
|
||||||
memcpy(buffer, "blahblahblahblah", size);
|
|
||||||
for (lfs_size_t i = 0;
|
|
||||||
i < ((cfg.block_count-4)/2)*(cfg.block_size-8);
|
|
||||||
i += size) {
|
|
||||||
lfs_file_write(&lfs, &file[0], buffer, size) => size;
|
|
||||||
}
|
|
||||||
lfs_file_close(&lfs, &file[0]) => 0;
|
|
||||||
|
|
||||||
lfs_file_open(&lfs, &file[0], "exhaustion2",
|
|
||||||
LFS_O_WRONLY | LFS_O_CREAT) => 0;
|
|
||||||
size = strlen("blahblahblahblah");
|
|
||||||
memcpy(buffer, "blahblahblahblah", size);
|
|
||||||
for (lfs_size_t i = 0;
|
|
||||||
i < ((cfg.block_count-4+1)/2)*(cfg.block_size-8);
|
|
||||||
i += size) {
|
|
||||||
lfs_file_write(&lfs, &file[0], buffer, size) => size;
|
|
||||||
}
|
|
||||||
lfs_file_close(&lfs, &file[0]) => 0;
|
|
||||||
|
|
||||||
// remount to force reset of lookahead
|
|
||||||
lfs_unmount(&lfs) => 0;
|
|
||||||
|
|
||||||
lfs_mount(&lfs, &cfg) => 0;
|
|
||||||
|
|
||||||
// rewrite one file with a hole of one block
|
|
||||||
lfs_file_open(&lfs, &file[0], "exhaustion1",
|
|
||||||
LFS_O_WRONLY | LFS_O_TRUNC) => 0;
|
|
||||||
lfs_file_sync(&lfs, &file[0]) => 0;
|
|
||||||
size = strlen("blahblahblahblah");
|
|
||||||
memcpy(buffer, "blahblahblahblah", size);
|
|
||||||
for (lfs_size_t i = 0;
|
|
||||||
i < ((cfg.block_count-4)/2 - 1)*(cfg.block_size-8);
|
|
||||||
i += size) {
|
|
||||||
lfs_file_write(&lfs, &file[0], buffer, size) => size;
|
|
||||||
}
|
|
||||||
lfs_file_close(&lfs, &file[0]) => 0;
|
|
||||||
|
|
||||||
// try to allocate a directory, should fail!
|
|
||||||
lfs_mkdir(&lfs, "split") => LFS_ERR_NOSPC;
|
|
||||||
|
|
||||||
// file should not fail
|
|
||||||
lfs_file_open(&lfs, &file[0], "notasplit",
|
|
||||||
LFS_O_WRONLY | LFS_O_CREAT) => 0;
|
|
||||||
lfs_file_write(&lfs, &file[0], "hi", 2) => 2;
|
|
||||||
lfs_file_close(&lfs, &file[0]) => 0;
|
|
||||||
|
|
||||||
lfs_unmount(&lfs) => 0;
|
|
||||||
TEST
|
|
||||||
|
|
||||||
echo "--- Results ---"
|
echo "--- Results ---"
|
||||||
tests/stats.py
|
tests/stats.py
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ TEST
|
|||||||
|
|
||||||
w_test() {
|
w_test() {
|
||||||
tests/test.py << TEST
|
tests/test.py << TEST
|
||||||
size = $1;
|
lfs_size_t size = $1;
|
||||||
lfs_size_t chunk = 31;
|
lfs_size_t chunk = 31;
|
||||||
srand(0);
|
srand(0);
|
||||||
lfs_mount(&lfs, &cfg) => 0;
|
lfs_mount(&lfs, &cfg) => 0;
|
||||||
@@ -50,7 +50,7 @@ TEST
|
|||||||
|
|
||||||
r_test() {
|
r_test() {
|
||||||
tests/test.py << TEST
|
tests/test.py << TEST
|
||||||
size = $1;
|
lfs_size_t size = $1;
|
||||||
lfs_size_t chunk = 29;
|
lfs_size_t chunk = 29;
|
||||||
srand(0);
|
srand(0);
|
||||||
lfs_mount(&lfs, &cfg) => 0;
|
lfs_mount(&lfs, &cfg) => 0;
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
echo "=== Interspersed tests ==="
|
echo "=== Parallel tests ==="
|
||||||
rm -rf blocks
|
rm -rf blocks
|
||||||
tests/test.py << TEST
|
tests/test.py << TEST
|
||||||
lfs_format(&lfs, &cfg) => 0;
|
lfs_format(&lfs, &cfg) => 0;
|
||||||
TEST
|
TEST
|
||||||
|
|
||||||
echo "--- Interspersed file test ---"
|
echo "--- Parallel file test ---"
|
||||||
tests/test.py << TEST
|
tests/test.py << TEST
|
||||||
lfs_mount(&lfs, &cfg) => 0;
|
lfs_mount(&lfs, &cfg) => 0;
|
||||||
lfs_file_open(&lfs, &file[0], "a", LFS_O_WRONLY | LFS_O_CREAT) => 0;
|
lfs_file_open(&lfs, &file[0], "a", LFS_O_WRONLY | LFS_O_CREAT) => 0;
|
||||||
@@ -77,7 +77,7 @@ tests/test.py << TEST
|
|||||||
lfs_unmount(&lfs) => 0;
|
lfs_unmount(&lfs) => 0;
|
||||||
TEST
|
TEST
|
||||||
|
|
||||||
echo "--- Interspersed remove file test ---"
|
echo "--- Parallel remove file test ---"
|
||||||
tests/test.py << TEST
|
tests/test.py << TEST
|
||||||
lfs_mount(&lfs, &cfg) => 0;
|
lfs_mount(&lfs, &cfg) => 0;
|
||||||
lfs_file_open(&lfs, &file[0], "e", LFS_O_WRONLY | LFS_O_CREAT) => 0;
|
lfs_file_open(&lfs, &file[0], "e", LFS_O_WRONLY | LFS_O_CREAT) => 0;
|
||||||
@@ -90,22 +90,6 @@ tests/test.py << TEST
|
|||||||
lfs_unmount(&lfs) => 0;
|
lfs_unmount(&lfs) => 0;
|
||||||
TEST
|
TEST
|
||||||
|
|
||||||
echo "--- Trailing dot path tests ---"
|
|
||||||
tests/test.py << TEST
|
|
||||||
lfs_mount(&lfs, &cfg) => 0;
|
|
||||||
lfs_stat(&lfs, "tea/hottea/", &info) => 0;
|
|
||||||
strcmp(info.name, "hottea") => 0;
|
|
||||||
lfs_stat(&lfs, "tea/hottea/.", &info) => 0;
|
|
||||||
strcmp(info.name, "hottea") => 0;
|
|
||||||
lfs_stat(&lfs, "tea/hottea/./.", &info) => 0;
|
|
||||||
strcmp(info.name, "hottea") => 0;
|
|
||||||
lfs_stat(&lfs, "tea/hottea/..", &info) => 0;
|
|
||||||
strcmp(info.name, "tea") => 0;
|
|
||||||
lfs_stat(&lfs, "tea/hottea/../.", &info) => 0;
|
|
||||||
strcmp(info.name, "tea") => 0;
|
|
||||||
lfs_unmount(&lfs) => 0;
|
|
||||||
TEST
|
|
||||||
|
|
||||||
echo "--- Root dot dot path tests ---"
|
echo "--- Root dot dot path tests ---"
|
||||||
tests/test.py << TEST
|
tests/test.py << TEST
|
||||||
lfs_mount(&lfs, &cfg) => 0;
|
lfs_mount(&lfs, &cfg) => 0;
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ tests/test.py << TEST
|
|||||||
lfs_file_read(&lfs, &file[0], buffer, size) => size;
|
lfs_file_read(&lfs, &file[0], buffer, size) => size;
|
||||||
memcmp(buffer, "kittycatcat", size) => 0;
|
memcmp(buffer, "kittycatcat", size) => 0;
|
||||||
|
|
||||||
size = lfs_file_size(&lfs, &file[0]);
|
lfs_size_t size = lfs_file_size(&lfs, &file[0]);
|
||||||
lfs_file_seek(&lfs, &file[0], 0, LFS_SEEK_CUR) => size;
|
lfs_file_seek(&lfs, &file[0], 0, LFS_SEEK_CUR) => size;
|
||||||
|
|
||||||
lfs_file_close(&lfs, &file[0]) => 0;
|
lfs_file_close(&lfs, &file[0]) => 0;
|
||||||
@@ -202,7 +202,7 @@ tests/test.py << TEST
|
|||||||
lfs_file_read(&lfs, &file[0], buffer, size) => size;
|
lfs_file_read(&lfs, &file[0], buffer, size) => size;
|
||||||
memcmp(buffer, "kittycatcat", size) => 0;
|
memcmp(buffer, "kittycatcat", size) => 0;
|
||||||
|
|
||||||
size = lfs_file_size(&lfs, &file[0]);
|
lfs_size_t size = lfs_file_size(&lfs, &file[0]);
|
||||||
lfs_file_seek(&lfs, &file[0], 0, LFS_SEEK_CUR) => size;
|
lfs_file_seek(&lfs, &file[0], 0, LFS_SEEK_CUR) => size;
|
||||||
|
|
||||||
lfs_file_close(&lfs, &file[0]) => 0;
|
lfs_file_close(&lfs, &file[0]) => 0;
|
||||||
@@ -243,7 +243,7 @@ tests/test.py << TEST
|
|||||||
lfs_file_read(&lfs, &file[0], buffer, size) => size;
|
lfs_file_read(&lfs, &file[0], buffer, size) => size;
|
||||||
memcmp(buffer, "kittycatcat", size) => 0;
|
memcmp(buffer, "kittycatcat", size) => 0;
|
||||||
|
|
||||||
size = lfs_file_size(&lfs, &file[0]);
|
lfs_size_t size = lfs_file_size(&lfs, &file[0]);
|
||||||
lfs_file_seek(&lfs, &file[0], 0, LFS_SEEK_CUR) => size;
|
lfs_file_seek(&lfs, &file[0], 0, LFS_SEEK_CUR) => size;
|
||||||
|
|
||||||
lfs_file_close(&lfs, &file[0]) => 0;
|
lfs_file_close(&lfs, &file[0]) => 0;
|
||||||
@@ -286,7 +286,7 @@ tests/test.py << TEST
|
|||||||
lfs_file_read(&lfs, &file[0], buffer, size) => size;
|
lfs_file_read(&lfs, &file[0], buffer, size) => size;
|
||||||
memcmp(buffer, "kittycatcat", size) => 0;
|
memcmp(buffer, "kittycatcat", size) => 0;
|
||||||
|
|
||||||
size = lfs_file_size(&lfs, &file[0]);
|
lfs_size_t size = lfs_file_size(&lfs, &file[0]);
|
||||||
lfs_file_seek(&lfs, &file[0], 0, LFS_SEEK_CUR) => size;
|
lfs_file_seek(&lfs, &file[0], 0, LFS_SEEK_CUR) => size;
|
||||||
|
|
||||||
lfs_file_close(&lfs, &file[0]) => 0;
|
lfs_file_close(&lfs, &file[0]) => 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user