mirror of
https://github.com/eledio-devices/thirdparty-littlefs.git
synced 2025-11-01 16:14:13 +01:00
Compare commits
10 Commits
fix-lookah
...
sanity-tes
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1c15c1768 | ||
|
|
eed1eec5fd | ||
|
|
4a86370327 | ||
|
|
ba4f17173f | ||
|
|
51346b8bf4 | ||
|
|
93a2e0bbe5 | ||
|
|
6beff502e9 | ||
|
|
c5e2b335d6 | ||
|
|
015b86bc51 | ||
|
|
9637b96069 |
@@ -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,DEBUG,WARN,ERROR}"
|
CFLAGS+="-DLFS_NO_ASSERT -DLFS_NO_DEBUG -DLFS_NO_WARN -DLFS_NO_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
|
||||||
|
|||||||
183
LICENSE.md
183
LICENSE.md
@@ -1,165 +1,36 @@
|
|||||||
Apache License
|
Copyright (c) 2017, Arm Limited. All rights reserved.
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
1. Definitions.
|
- Redistributions of source code must retain the above copyright notice, this
|
||||||
|
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.
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction, and
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
distribution as defined by Sections 1 through 9 of this document.
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
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.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all other entities
|
*Note*:
|
||||||
that control, are controlled by, or are under common control with that entity.
|
Individual files contain the following tag instead of the full license text.
|
||||||
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.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical transformation or
|
SPDX-License-Identifier: BSD-3-Clause
|
||||||
translation of a Source form, including but not limited to compiled object code,
|
|
||||||
generated documentation, and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or Object form, made
|
This enables machine processing of license information based on the SPDX
|
||||||
available under the License, as indicated by a copyright notice that is included
|
License Identifiers that are here available: http://spdx.org/licenses/
|
||||||
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.
|
|
||||||
|
|||||||
11
Makefile
11
Makefile
@@ -1,4 +1,7 @@
|
|||||||
TARGET = lfs
|
TARGET = lfs.a
|
||||||
|
ifneq ($(wildcard test.c main.c),)
|
||||||
|
override TARGET = lfs
|
||||||
|
endif
|
||||||
|
|
||||||
CC ?= gcc
|
CC ?= gcc
|
||||||
AR ?= ar
|
AR ?= ar
|
||||||
@@ -22,7 +25,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
|
override CFLAGS += -std=c99 -Wall -pedantic -Wshadow -Wunused-parameter
|
||||||
|
|
||||||
|
|
||||||
all: $(TARGET)
|
all: $(TARGET)
|
||||||
@@ -35,7 +38,9 @@ size: $(OBJ)
|
|||||||
.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_interspersed test_alloc test_paths test_orphan test_move test_corrupt
|
test_interspersed 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
|
||||||
@@ -44,7 +49,7 @@ endif
|
|||||||
|
|
||||||
-include $(DEP)
|
-include $(DEP)
|
||||||
|
|
||||||
$(TARGET): $(OBJ)
|
lfs: $(OBJ)
|
||||||
$(CC) $(CFLAGS) $^ $(LFLAGS) -o $@
|
$(CC) $(CFLAGS) $^ $(LFLAGS) -o $@
|
||||||
|
|
||||||
%.a: $(OBJ)
|
%.a: $(OBJ)
|
||||||
|
|||||||
@@ -1,19 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Block device emulated on standard files
|
* Block device emulated on standard files
|
||||||
*
|
*
|
||||||
* Copyright (c) 2017 ARM Limited
|
* Copyright (c) 2017, Arm Limited. All rights reserved.
|
||||||
*
|
* 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,19 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* Block device emulated on standard files
|
* Block device emulated on standard files
|
||||||
*
|
*
|
||||||
* Copyright (c) 2017 ARM Limited
|
* Copyright (c) 2017, Arm Limited. All rights reserved.
|
||||||
*
|
* 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
|
||||||
|
|||||||
207
lfs.c
207
lfs.c
@@ -1,19 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* The little filesystem
|
* The little filesystem
|
||||||
*
|
*
|
||||||
* Copyright (c) 2017 ARM Limited
|
* Copyright (c) 2017, Arm Limited. All rights reserved.
|
||||||
*
|
* 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.h"
|
#include "lfs.h"
|
||||||
#include "lfs_util.h"
|
#include "lfs_util.h"
|
||||||
@@ -118,6 +107,19 @@ static int lfs_cache_crc(lfs_t *lfs, lfs_cache_t *rcache,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void lfs_cache_drop(lfs_t *lfs, lfs_cache_t *rcache) {
|
||||||
|
// do not zero, cheaper if cache is readonly or only going to be
|
||||||
|
// written with identical data (during relocates)
|
||||||
|
(void)lfs;
|
||||||
|
rcache->block = 0xffffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void lfs_cache_zero(lfs_t *lfs, lfs_cache_t *pcache) {
|
||||||
|
// zero to avoid information leak
|
||||||
|
memset(pcache->buffer, 0xff, lfs->cfg->prog_size);
|
||||||
|
pcache->block = 0xffffffff;
|
||||||
|
}
|
||||||
|
|
||||||
static int lfs_cache_flush(lfs_t *lfs,
|
static int lfs_cache_flush(lfs_t *lfs,
|
||||||
lfs_cache_t *pcache, lfs_cache_t *rcache) {
|
lfs_cache_t *pcache, lfs_cache_t *rcache) {
|
||||||
if (pcache->block != 0xffffffff) {
|
if (pcache->block != 0xffffffff) {
|
||||||
@@ -139,7 +141,7 @@ static int lfs_cache_flush(lfs_t *lfs,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pcache->block = 0xffffffff;
|
lfs_cache_zero(lfs, pcache);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -244,7 +246,7 @@ static int lfs_bd_erase(lfs_t *lfs, lfs_block_t block) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int lfs_bd_sync(lfs_t *lfs) {
|
static int lfs_bd_sync(lfs_t *lfs) {
|
||||||
lfs->rcache.block = 0xffffffff;
|
lfs_cache_drop(lfs, &lfs->rcache);
|
||||||
|
|
||||||
int err = lfs_cache_flush(lfs, &lfs->pcache, NULL);
|
int err = lfs_cache_flush(lfs, &lfs->pcache, NULL);
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -270,8 +272,7 @@ int lfs_deorphan(lfs_t *lfs);
|
|||||||
static int lfs_alloc_lookahead(void *p, lfs_block_t block) {
|
static int lfs_alloc_lookahead(void *p, lfs_block_t block) {
|
||||||
lfs_t *lfs = p;
|
lfs_t *lfs = p;
|
||||||
|
|
||||||
lfs_block_t off = (((lfs_soff_t)(block - lfs->free.begin)
|
lfs_block_t off = ((block - lfs->free.off)
|
||||||
% (lfs_soff_t)(lfs->cfg->block_count))
|
|
||||||
+ lfs->cfg->block_count) % lfs->cfg->block_count;
|
+ lfs->cfg->block_count) % lfs->cfg->block_count;
|
||||||
|
|
||||||
if (off < lfs->free.size) {
|
if (off < lfs->free.size) {
|
||||||
@@ -283,20 +284,22 @@ static int lfs_alloc_lookahead(void *p, lfs_block_t block) {
|
|||||||
|
|
||||||
static int lfs_alloc(lfs_t *lfs, lfs_block_t *block) {
|
static int lfs_alloc(lfs_t *lfs, lfs_block_t *block) {
|
||||||
while (true) {
|
while (true) {
|
||||||
while (lfs->free.off != lfs->free.size) {
|
while (lfs->free.i != lfs->free.size) {
|
||||||
lfs_block_t off = lfs->free.off;
|
lfs_block_t off = lfs->free.i;
|
||||||
lfs->free.off += 1;
|
lfs->free.i += 1;
|
||||||
|
lfs->free.ack -= 1;
|
||||||
|
|
||||||
if (!(lfs->free.buffer[off / 32] & (1U << (off % 32)))) {
|
if (!(lfs->free.buffer[off / 32] & (1U << (off % 32)))) {
|
||||||
// found a free block
|
// found a free block
|
||||||
*block = (lfs->free.begin + off) % lfs->cfg->block_count;
|
*block = (lfs->free.off + off) % lfs->cfg->block_count;
|
||||||
|
|
||||||
// eagerly find next off so an alloc ack can
|
// eagerly find next off so an alloc ack can
|
||||||
// discredit old lookahead blocks
|
// discredit old lookahead blocks
|
||||||
while (lfs->free.off != lfs->free.size &&
|
while (lfs->free.i != lfs->free.size &&
|
||||||
(lfs->free.buffer[lfs->free.off / 32] &
|
(lfs->free.buffer[lfs->free.i / 32]
|
||||||
(1U << (lfs->free.off % 32)))) {
|
& (1U << (lfs->free.i % 32)))) {
|
||||||
lfs->free.off += 1;
|
lfs->free.i += 1;
|
||||||
|
lfs->free.ack -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -304,15 +307,15 @@ static int lfs_alloc(lfs_t *lfs, lfs_block_t *block) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if we have looked at all blocks since last ack
|
// check if we have looked at all blocks since last ack
|
||||||
if (lfs->free.off == lfs->free.ack - lfs->free.begin) {
|
if (lfs->free.ack == 0) {
|
||||||
LFS_WARN("No more free space %d", lfs->free.off + lfs->free.begin);
|
LFS_WARN("No more free space %d", lfs->free.i + lfs->free.off);
|
||||||
return LFS_ERR_NOSPC;
|
return LFS_ERR_NOSPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
lfs->free.begin += lfs->free.size;
|
lfs->free.off = (lfs->free.off + lfs->free.size)
|
||||||
lfs->free.size = lfs_min(lfs->cfg->lookahead,
|
% lfs->cfg->block_count;
|
||||||
lfs->free.ack - lfs->free.begin);
|
lfs->free.size = lfs_min(lfs->cfg->lookahead, lfs->free.ack);
|
||||||
lfs->free.off = 0;
|
lfs->free.i = 0;
|
||||||
|
|
||||||
// find mask of free blocks from tree
|
// find mask of free blocks from tree
|
||||||
memset(lfs->free.buffer, 0, lfs->cfg->lookahead/8);
|
memset(lfs->free.buffer, 0, lfs->cfg->lookahead/8);
|
||||||
@@ -324,7 +327,7 @@ static int lfs_alloc(lfs_t *lfs, lfs_block_t *block) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void lfs_alloc_ack(lfs_t *lfs) {
|
static void lfs_alloc_ack(lfs_t *lfs) {
|
||||||
lfs->free.ack = lfs->free.begin+lfs->free.off + lfs->cfg->block_count;
|
lfs->free.ack = lfs->cfg->block_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -602,7 +605,7 @@ relocate:
|
|||||||
|
|
||||||
// drop caches and prepare to relocate block
|
// drop caches and prepare to relocate block
|
||||||
relocated = true;
|
relocated = true;
|
||||||
lfs->pcache.block = 0xffffffff;
|
lfs_cache_drop(lfs, &lfs->pcache);
|
||||||
|
|
||||||
// can't relocate superblock, filesystem is now frozen
|
// can't relocate superblock, filesystem is now frozen
|
||||||
if (lfs_paircmp(oldpair, (const lfs_block_t[2]){0, 1}) == 0) {
|
if (lfs_paircmp(oldpair, (const lfs_block_t[2]){0, 1}) == 0) {
|
||||||
@@ -782,26 +785,19 @@ static int lfs_dir_find(lfs_t *lfs, lfs_dir_t *dir,
|
|||||||
lfs_entry_t *entry, const char **path) {
|
lfs_entry_t *entry, const char **path) {
|
||||||
const char *pathname = *path;
|
const char *pathname = *path;
|
||||||
size_t pathlen;
|
size_t pathlen;
|
||||||
|
entry->d.type = LFS_TYPE_DIR;
|
||||||
|
entry->d.elen = sizeof(entry->d) - 4;
|
||||||
|
entry->d.alen = 0;
|
||||||
|
entry->d.nlen = 0;
|
||||||
|
entry->d.u.dir[0] = lfs->root[0];
|
||||||
|
entry->d.u.dir[1] = lfs->root[1];
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
nextname:
|
nextname:
|
||||||
// skip slashes
|
// skip slashes
|
||||||
pathname += strspn(pathname, "/");
|
pathname += strspn(pathname, "/");
|
||||||
pathlen = strcspn(pathname, "/");
|
pathlen = strcspn(pathname, "/");
|
||||||
|
|
||||||
// special case for root dir
|
|
||||||
if (pathname[0] == '\0') {
|
|
||||||
*entry = (lfs_entry_t){
|
|
||||||
.d.type = LFS_TYPE_DIR,
|
|
||||||
.d.elen = sizeof(entry->d) - 4,
|
|
||||||
.d.alen = 0,
|
|
||||||
.d.nlen = 0,
|
|
||||||
.d.u.dir[0] = lfs->root[0],
|
|
||||||
.d.u.dir[1] = lfs->root[1],
|
|
||||||
};
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// skip '.' and root '..'
|
// skip '.' and root '..'
|
||||||
if ((pathlen == 1 && memcmp(pathname, ".", 1) == 0) ||
|
if ((pathlen == 1 && memcmp(pathname, ".", 1) == 0) ||
|
||||||
(pathlen == 2 && memcmp(pathname, "..", 2) == 0)) {
|
(pathlen == 2 && memcmp(pathname, "..", 2) == 0)) {
|
||||||
@@ -833,12 +829,27 @@ static int lfs_dir_find(lfs_t *lfs, lfs_dir_t *dir,
|
|||||||
suffix += sufflen;
|
suffix += sufflen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// found path
|
||||||
|
if (pathname[0] == '\0') {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// update what we've found
|
// update what we've found
|
||||||
*path = pathname;
|
*path = pathname;
|
||||||
|
|
||||||
// find path
|
// continue on if we hit a directory
|
||||||
|
if (entry->d.type != LFS_TYPE_DIR) {
|
||||||
|
return LFS_ERR_NOTDIR;
|
||||||
|
}
|
||||||
|
|
||||||
|
int err = lfs_dir_fetch(lfs, dir, entry->d.u.dir);
|
||||||
|
if (err) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
// find entry matching name
|
||||||
while (true) {
|
while (true) {
|
||||||
int err = lfs_dir_next(lfs, dir, entry);
|
err = lfs_dir_next(lfs, dir, entry);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -872,21 +883,8 @@ static int lfs_dir_find(lfs_t *lfs, lfs_dir_t *dir,
|
|||||||
entry->d.type &= ~0x80;
|
entry->d.type &= ~0x80;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// to next name
|
||||||
pathname += pathlen;
|
pathname += pathlen;
|
||||||
pathname += strspn(pathname, "/");
|
|
||||||
if (pathname[0] == '\0') {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// continue on if we hit a directory
|
|
||||||
if (entry->d.type != LFS_TYPE_DIR) {
|
|
||||||
return LFS_ERR_NOTDIR;
|
|
||||||
}
|
|
||||||
|
|
||||||
int err = lfs_dir_fetch(lfs, dir, entry->d.u.dir);
|
|
||||||
if (err) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -903,13 +901,8 @@ int lfs_mkdir(lfs_t *lfs, const char *path) {
|
|||||||
|
|
||||||
// fetch parent directory
|
// fetch parent directory
|
||||||
lfs_dir_t cwd;
|
lfs_dir_t cwd;
|
||||||
int err = lfs_dir_fetch(lfs, &cwd, lfs->root);
|
|
||||||
if (err) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
lfs_entry_t entry;
|
lfs_entry_t entry;
|
||||||
err = lfs_dir_find(lfs, &cwd, &entry, &path);
|
int err = lfs_dir_find(lfs, &cwd, &entry, &path);
|
||||||
if (err != LFS_ERR_NOENT || strchr(path, '/') != NULL) {
|
if (err != LFS_ERR_NOENT || strchr(path, '/') != NULL) {
|
||||||
return err ? err : LFS_ERR_EXIST;
|
return err ? err : LFS_ERR_EXIST;
|
||||||
}
|
}
|
||||||
@@ -953,13 +946,8 @@ int lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path) {
|
|||||||
dir->pair[0] = lfs->root[0];
|
dir->pair[0] = lfs->root[0];
|
||||||
dir->pair[1] = lfs->root[1];
|
dir->pair[1] = lfs->root[1];
|
||||||
|
|
||||||
int err = lfs_dir_fetch(lfs, dir, dir->pair);
|
|
||||||
if (err) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
lfs_entry_t entry;
|
lfs_entry_t entry;
|
||||||
err = lfs_dir_find(lfs, dir, &entry, &path);
|
int err = lfs_dir_find(lfs, dir, &entry, &path);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
} else if (entry.d.type != LFS_TYPE_DIR) {
|
} else if (entry.d.type != LFS_TYPE_DIR) {
|
||||||
@@ -1242,7 +1230,7 @@ relocate:
|
|||||||
LFS_DEBUG("Bad block at %d", nblock);
|
LFS_DEBUG("Bad block at %d", nblock);
|
||||||
|
|
||||||
// just clear cache and try a new block
|
// just clear cache and try a new block
|
||||||
pcache->block = 0xffffffff;
|
lfs_cache_drop(lfs, &lfs->pcache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1301,13 +1289,8 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file,
|
|||||||
|
|
||||||
// allocate entry for file if it doesn't exist
|
// allocate entry for file if it doesn't exist
|
||||||
lfs_dir_t cwd;
|
lfs_dir_t cwd;
|
||||||
int err = lfs_dir_fetch(lfs, &cwd, lfs->root);
|
|
||||||
if (err) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
lfs_entry_t entry;
|
lfs_entry_t entry;
|
||||||
err = lfs_dir_find(lfs, &cwd, &entry, &path);
|
int err = lfs_dir_find(lfs, &cwd, &entry, &path);
|
||||||
if (err && (err != LFS_ERR_NOENT || strchr(path, '/') != NULL)) {
|
if (err && (err != LFS_ERR_NOENT || strchr(path, '/') != NULL)) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -1352,8 +1335,11 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// allocate buffer if needed
|
// allocate buffer if needed
|
||||||
file->cache.block = 0xffffffff;
|
|
||||||
if (lfs->cfg->file_buffer) {
|
if (lfs->cfg->file_buffer) {
|
||||||
|
if (lfs->files) {
|
||||||
|
// already in use
|
||||||
|
return LFS_ERR_NOMEM;
|
||||||
|
}
|
||||||
file->cache.buffer = lfs->cfg->file_buffer;
|
file->cache.buffer = lfs->cfg->file_buffer;
|
||||||
} else if ((file->flags & 3) == LFS_O_RDONLY) {
|
} else if ((file->flags & 3) == LFS_O_RDONLY) {
|
||||||
file->cache.buffer = lfs_malloc(lfs->cfg->read_size);
|
file->cache.buffer = lfs_malloc(lfs->cfg->read_size);
|
||||||
@@ -1367,6 +1353,9 @@ int lfs_file_open(lfs_t *lfs, lfs_file_t *file,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// zero to avoid information leak
|
||||||
|
lfs_cache_zero(lfs, &file->cache);
|
||||||
|
|
||||||
// add to list of files
|
// add to list of files
|
||||||
file->next = lfs->files;
|
file->next = lfs->files;
|
||||||
lfs->files = file;
|
lfs->files = file;
|
||||||
@@ -1435,7 +1424,7 @@ relocate:
|
|||||||
memcpy(file->cache.buffer, lfs->pcache.buffer, lfs->cfg->prog_size);
|
memcpy(file->cache.buffer, lfs->pcache.buffer, lfs->cfg->prog_size);
|
||||||
file->cache.block = lfs->pcache.block;
|
file->cache.block = lfs->pcache.block;
|
||||||
file->cache.off = lfs->pcache.off;
|
file->cache.off = lfs->pcache.off;
|
||||||
lfs->pcache.block = 0xffffffff;
|
lfs_cache_zero(lfs, &lfs->pcache);
|
||||||
|
|
||||||
file->block = nblock;
|
file->block = nblock;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1444,7 +1433,7 @@ relocate:
|
|||||||
static int lfs_file_flush(lfs_t *lfs, lfs_file_t *file) {
|
static int lfs_file_flush(lfs_t *lfs, lfs_file_t *file) {
|
||||||
if (file->flags & LFS_F_READING) {
|
if (file->flags & LFS_F_READING) {
|
||||||
// just drop read cache
|
// just drop read cache
|
||||||
file->cache.block = 0xffffffff;
|
lfs_cache_drop(lfs, &file->cache);
|
||||||
file->flags &= ~LFS_F_READING;
|
file->flags &= ~LFS_F_READING;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1459,7 +1448,7 @@ static int lfs_file_flush(lfs_t *lfs, lfs_file_t *file) {
|
|||||||
.pos = file->pos,
|
.pos = file->pos,
|
||||||
.cache = lfs->rcache,
|
.cache = lfs->rcache,
|
||||||
};
|
};
|
||||||
lfs->rcache.block = 0xffffffff;
|
lfs_cache_drop(lfs, &lfs->rcache);
|
||||||
|
|
||||||
while (file->pos < file->size) {
|
while (file->pos < file->size) {
|
||||||
// copy over a byte at a time, leave it up to caching
|
// copy over a byte at a time, leave it up to caching
|
||||||
@@ -1477,8 +1466,8 @@ static int lfs_file_flush(lfs_t *lfs, lfs_file_t *file) {
|
|||||||
|
|
||||||
// keep our reference to the rcache in sync
|
// keep our reference to the rcache in sync
|
||||||
if (lfs->rcache.block != 0xffffffff) {
|
if (lfs->rcache.block != 0xffffffff) {
|
||||||
orig.cache.block = 0xffffffff;
|
lfs_cache_drop(lfs, &orig.cache);
|
||||||
lfs->rcache.block = 0xffffffff;
|
lfs_cache_drop(lfs, &lfs->rcache);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1656,7 +1645,7 @@ lfs_ssize_t lfs_file_write(lfs_t *lfs, lfs_file_t *file,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// mark cache as dirty since we may have read data into it
|
// mark cache as dirty since we may have read data into it
|
||||||
file->cache.block = 0xffffffff;
|
lfs_cache_zero(lfs, &file->cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
// extend file with new blocks
|
// extend file with new blocks
|
||||||
@@ -1813,13 +1802,8 @@ lfs_soff_t lfs_file_size(lfs_t *lfs, lfs_file_t *file) {
|
|||||||
/// General fs operations ///
|
/// General fs operations ///
|
||||||
int lfs_stat(lfs_t *lfs, const char *path, struct lfs_info *info) {
|
int lfs_stat(lfs_t *lfs, const char *path, struct lfs_info *info) {
|
||||||
lfs_dir_t cwd;
|
lfs_dir_t cwd;
|
||||||
int err = lfs_dir_fetch(lfs, &cwd, lfs->root);
|
|
||||||
if (err) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
lfs_entry_t entry;
|
lfs_entry_t entry;
|
||||||
err = lfs_dir_find(lfs, &cwd, &entry, &path);
|
int err = lfs_dir_find(lfs, &cwd, &entry, &path);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -1854,13 +1838,8 @@ int lfs_remove(lfs_t *lfs, const char *path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
lfs_dir_t cwd;
|
lfs_dir_t cwd;
|
||||||
int err = lfs_dir_fetch(lfs, &cwd, lfs->root);
|
|
||||||
if (err) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
lfs_entry_t entry;
|
lfs_entry_t entry;
|
||||||
err = lfs_dir_find(lfs, &cwd, &entry, &path);
|
int err = lfs_dir_find(lfs, &cwd, &entry, &path);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -1915,24 +1894,14 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) {
|
|||||||
|
|
||||||
// find old entry
|
// find old entry
|
||||||
lfs_dir_t oldcwd;
|
lfs_dir_t oldcwd;
|
||||||
int err = lfs_dir_fetch(lfs, &oldcwd, lfs->root);
|
|
||||||
if (err) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
lfs_entry_t oldentry;
|
lfs_entry_t oldentry;
|
||||||
err = lfs_dir_find(lfs, &oldcwd, &oldentry, &oldpath);
|
int err = lfs_dir_find(lfs, &oldcwd, &oldentry, &oldpath);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
// allocate new entry
|
// allocate new entry
|
||||||
lfs_dir_t newcwd;
|
lfs_dir_t newcwd;
|
||||||
err = lfs_dir_fetch(lfs, &newcwd, lfs->root);
|
|
||||||
if (err) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
lfs_entry_t preventry;
|
lfs_entry_t preventry;
|
||||||
err = lfs_dir_find(lfs, &newcwd, &preventry, &newpath);
|
err = lfs_dir_find(lfs, &newcwd, &preventry, &newpath);
|
||||||
if (err && (err != LFS_ERR_NOENT || strchr(newpath, '/') != NULL)) {
|
if (err && (err != LFS_ERR_NOENT || strchr(newpath, '/') != NULL)) {
|
||||||
@@ -2027,7 +1996,6 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
|
|||||||
lfs->cfg = cfg;
|
lfs->cfg = cfg;
|
||||||
|
|
||||||
// setup read cache
|
// setup read cache
|
||||||
lfs->rcache.block = 0xffffffff;
|
|
||||||
if (lfs->cfg->read_buffer) {
|
if (lfs->cfg->read_buffer) {
|
||||||
lfs->rcache.buffer = lfs->cfg->read_buffer;
|
lfs->rcache.buffer = lfs->cfg->read_buffer;
|
||||||
} else {
|
} else {
|
||||||
@@ -2038,7 +2006,6 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setup program cache
|
// setup program cache
|
||||||
lfs->pcache.block = 0xffffffff;
|
|
||||||
if (lfs->cfg->prog_buffer) {
|
if (lfs->cfg->prog_buffer) {
|
||||||
lfs->pcache.buffer = lfs->cfg->prog_buffer;
|
lfs->pcache.buffer = lfs->cfg->prog_buffer;
|
||||||
} else {
|
} else {
|
||||||
@@ -2048,6 +2015,10 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// zero to avoid information leaks
|
||||||
|
lfs_cache_zero(lfs, &lfs->rcache);
|
||||||
|
lfs_cache_zero(lfs, &lfs->pcache);
|
||||||
|
|
||||||
// setup lookahead, round down to nearest 32-bits
|
// setup lookahead, round down to nearest 32-bits
|
||||||
LFS_ASSERT(lfs->cfg->lookahead % 32 == 0);
|
LFS_ASSERT(lfs->cfg->lookahead % 32 == 0);
|
||||||
LFS_ASSERT(lfs->cfg->lookahead > 0);
|
LFS_ASSERT(lfs->cfg->lookahead > 0);
|
||||||
@@ -2103,9 +2074,9 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) {
|
|||||||
|
|
||||||
// create free lookahead
|
// create free lookahead
|
||||||
memset(lfs->free.buffer, 0, lfs->cfg->lookahead/8);
|
memset(lfs->free.buffer, 0, lfs->cfg->lookahead/8);
|
||||||
lfs->free.begin = 0;
|
|
||||||
lfs->free.size = lfs_min(lfs->cfg->lookahead, lfs->cfg->block_count);
|
|
||||||
lfs->free.off = 0;
|
lfs->free.off = 0;
|
||||||
|
lfs->free.size = lfs_min(lfs->cfg->lookahead, lfs->cfg->block_count);
|
||||||
|
lfs->free.i = 0;
|
||||||
lfs_alloc_ack(lfs);
|
lfs_alloc_ack(lfs);
|
||||||
|
|
||||||
// create superblock dir
|
// create superblock dir
|
||||||
@@ -2182,9 +2153,9 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// setup free lookahead
|
// setup free lookahead
|
||||||
lfs->free.begin = 0;
|
|
||||||
lfs->free.size = 0;
|
|
||||||
lfs->free.off = 0;
|
lfs->free.off = 0;
|
||||||
|
lfs->free.size = 0;
|
||||||
|
lfs->free.i = 0;
|
||||||
lfs_alloc_ack(lfs);
|
lfs_alloc_ack(lfs);
|
||||||
|
|
||||||
// load superblock
|
// load superblock
|
||||||
|
|||||||
21
lfs.h
21
lfs.h
@@ -1,19 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* The little filesystem
|
* The little filesystem
|
||||||
*
|
*
|
||||||
* Copyright (c) 2017 ARM Limited
|
* Copyright (c) 2017, Arm Limited. All rights reserved.
|
||||||
*
|
* 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
|
||||||
@@ -27,7 +16,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 0x00010003
|
#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))
|
||||||
|
|
||||||
@@ -259,9 +248,9 @@ typedef struct lfs_superblock {
|
|||||||
} lfs_superblock_t;
|
} lfs_superblock_t;
|
||||||
|
|
||||||
typedef struct lfs_free {
|
typedef struct lfs_free {
|
||||||
lfs_block_t begin;
|
|
||||||
lfs_block_t size;
|
|
||||||
lfs_block_t off;
|
lfs_block_t off;
|
||||||
|
lfs_block_t size;
|
||||||
|
lfs_block_t i;
|
||||||
lfs_block_t ack;
|
lfs_block_t ack;
|
||||||
uint32_t *buffer;
|
uint32_t *buffer;
|
||||||
} lfs_free_t;
|
} lfs_free_t;
|
||||||
|
|||||||
15
lfs_util.c
15
lfs_util.c
@@ -1,19 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* lfs util functions
|
* lfs util functions
|
||||||
*
|
*
|
||||||
* Copyright (c) 2017 ARM Limited
|
* Copyright (c) 2017, Arm Limited. All rights reserved.
|
||||||
*
|
* 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,19 +1,8 @@
|
|||||||
/*
|
/*
|
||||||
* lfs utility functions
|
* lfs utility functions
|
||||||
*
|
*
|
||||||
* Copyright (c) 2017 ARM Limited
|
* Copyright (c) 2017, Arm Limited. All rights reserved.
|
||||||
*
|
* 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
|
||||||
@@ -169,6 +158,7 @@ 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
|
||||||
}
|
}
|
||||||
@@ -177,6 +167,8 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ TEST
|
|||||||
|
|
||||||
w_test() {
|
w_test() {
|
||||||
tests/test.py << TEST
|
tests/test.py << TEST
|
||||||
lfs_size_t size = $1;
|
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
|
||||||
lfs_size_t size = $1;
|
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;
|
||||||
|
|||||||
@@ -90,6 +90,22 @@ 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;
|
||||||
|
|
||||||
lfs_size_t size = lfs_file_size(&lfs, &file[0]);
|
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;
|
||||||
|
|
||||||
lfs_size_t size = lfs_file_size(&lfs, &file[0]);
|
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;
|
||||||
|
|
||||||
lfs_size_t size = lfs_file_size(&lfs, &file[0]);
|
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;
|
||||||
|
|
||||||
lfs_size_t size = lfs_file_size(&lfs, &file[0]);
|
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