mirror of
https://github.com/eledio-devices/thirdparty-littlefs.git
synced 2025-11-02 08:48:29 +01:00
Compare commits
2 Commits
license-no
...
file-open-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6e3193051 | ||
|
|
97711d78c4 |
12
LICENSE.md
12
LICENSE.md
@@ -22,3 +22,15 @@ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
---
|
||||
|
||||
*Note*:
|
||||
Individual files contain the following tag instead of the full license text.
|
||||
|
||||
|
||||
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
This enables machine processing of license information based on the SPDX
|
||||
License Identifiers that are here available: http://spdx.org/licenses/
|
||||
|
||||
13
README.md
13
README.md
@@ -146,19 +146,6 @@ The tests assume a Linux environment and can be started with make:
|
||||
make test
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
The littlefs is provided under the [BSD-3-Clause](https://spdx.org/licenses/BSD-3-Clause.html)
|
||||
license. See [LICENSE.md](LICENSE.md) for more information. Contributions to
|
||||
this project are accepted under the same license.
|
||||
|
||||
Individual files contain the following tag instead of the full license text.
|
||||
|
||||
SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
This enables machine processing of license information based on the SPDX
|
||||
License Identifiers that are here available: http://spdx.org/licenses/
|
||||
|
||||
## Related projects
|
||||
|
||||
[Mbed OS](https://github.com/ARMmbed/mbed-os/tree/master/features/filesystem/littlefs) -
|
||||
|
||||
89
lfs.c
89
lfs.c
@@ -417,12 +417,9 @@ static int lfs_dir_alloc(lfs_t *lfs, lfs_dir_t *dir) {
|
||||
// rather than clobbering one of the blocks we just pretend
|
||||
// the revision may be valid
|
||||
int err = lfs_bd_read(lfs, dir->pair[0], 0, &dir->d.rev, 4);
|
||||
if (err && err != LFS_ERR_CORRUPT) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (err != LFS_ERR_CORRUPT) {
|
||||
dir->d.rev = lfs_fromle32(dir->d.rev);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// set defaults
|
||||
@@ -448,9 +445,6 @@ static int lfs_dir_fetch(lfs_t *lfs,
|
||||
int err = lfs_bd_read(lfs, tpair[i], 0, &test, sizeof(test));
|
||||
lfs_dir_fromle32(&test);
|
||||
if (err) {
|
||||
if (err == LFS_ERR_CORRUPT) {
|
||||
continue;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -470,9 +464,6 @@ static int lfs_dir_fetch(lfs_t *lfs,
|
||||
err = lfs_bd_crc(lfs, tpair[i], sizeof(test),
|
||||
(0x7fffffff & test.size) - sizeof(test), &crc);
|
||||
if (err) {
|
||||
if (err == LFS_ERR_CORRUPT) {
|
||||
continue;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -2016,21 +2007,6 @@ int lfs_rename(lfs_t *lfs, const char *oldpath, const char *newpath) {
|
||||
|
||||
|
||||
/// Filesystem operations ///
|
||||
static void lfs_deinit(lfs_t *lfs) {
|
||||
// free allocated memory
|
||||
if (!lfs->cfg->read_buffer) {
|
||||
lfs_free(lfs->rcache.buffer);
|
||||
}
|
||||
|
||||
if (!lfs->cfg->prog_buffer) {
|
||||
lfs_free(lfs->pcache.buffer);
|
||||
}
|
||||
|
||||
if (!lfs->cfg->lookahead_buffer) {
|
||||
lfs_free(lfs->free.buffer);
|
||||
}
|
||||
}
|
||||
|
||||
static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
lfs->cfg = cfg;
|
||||
|
||||
@@ -2040,7 +2016,7 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
} else {
|
||||
lfs->rcache.buffer = lfs_malloc(lfs->cfg->read_size);
|
||||
if (!lfs->rcache.buffer) {
|
||||
goto cleanup;
|
||||
return LFS_ERR_NOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2050,7 +2026,7 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
} else {
|
||||
lfs->pcache.buffer = lfs_malloc(lfs->cfg->prog_size);
|
||||
if (!lfs->pcache.buffer) {
|
||||
goto cleanup;
|
||||
return LFS_ERR_NOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2066,7 +2042,7 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
} else {
|
||||
lfs->free.buffer = lfs_malloc(lfs->cfg->lookahead/8);
|
||||
if (!lfs->free.buffer) {
|
||||
goto cleanup;
|
||||
return LFS_ERR_NOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2086,10 +2062,23 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
lfs->deorphaned = false;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
lfs_deinit(lfs);
|
||||
return LFS_ERR_NOMEM;
|
||||
static int lfs_deinit(lfs_t *lfs) {
|
||||
// free allocated memory
|
||||
if (!lfs->cfg->read_buffer) {
|
||||
lfs_free(lfs->rcache.buffer);
|
||||
}
|
||||
|
||||
if (!lfs->cfg->prog_buffer) {
|
||||
lfs_free(lfs->pcache.buffer);
|
||||
}
|
||||
|
||||
if (!lfs->cfg->lookahead_buffer) {
|
||||
lfs_free(lfs->free.buffer);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
@@ -2109,19 +2098,19 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
lfs_dir_t superdir;
|
||||
err = lfs_dir_alloc(lfs, &superdir);
|
||||
if (err) {
|
||||
goto cleanup;
|
||||
return err;
|
||||
}
|
||||
|
||||
// write root directory
|
||||
lfs_dir_t root;
|
||||
err = lfs_dir_alloc(lfs, &root);
|
||||
if (err) {
|
||||
goto cleanup;
|
||||
return err;
|
||||
}
|
||||
|
||||
err = lfs_dir_commit(lfs, &root, NULL, 0);
|
||||
if (err) {
|
||||
goto cleanup;
|
||||
return err;
|
||||
}
|
||||
|
||||
lfs->root[0] = root.pair[0];
|
||||
@@ -2152,28 +2141,24 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
&superblock.d, sizeof(superblock.d)}
|
||||
}, 1);
|
||||
if (err && err != LFS_ERR_CORRUPT) {
|
||||
goto cleanup;
|
||||
return err;
|
||||
}
|
||||
|
||||
valid = valid || !err;
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
err = LFS_ERR_CORRUPT;
|
||||
goto cleanup;
|
||||
return LFS_ERR_CORRUPT;
|
||||
}
|
||||
|
||||
// sanity check that fetch works
|
||||
err = lfs_dir_fetch(lfs, &superdir, (const lfs_block_t[2]){0, 1});
|
||||
if (err) {
|
||||
goto cleanup;
|
||||
return err;
|
||||
}
|
||||
|
||||
lfs_alloc_ack(lfs);
|
||||
|
||||
cleanup:
|
||||
lfs_deinit(lfs);
|
||||
return err;
|
||||
return lfs_deinit(lfs);
|
||||
}
|
||||
|
||||
int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
@@ -2193,7 +2178,7 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
lfs_superblock_t superblock;
|
||||
err = lfs_dir_fetch(lfs, &dir, (const lfs_block_t[2]){0, 1});
|
||||
if (err && err != LFS_ERR_CORRUPT) {
|
||||
goto cleanup;
|
||||
return err;
|
||||
}
|
||||
|
||||
if (!err) {
|
||||
@@ -2201,7 +2186,7 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
&superblock.d, sizeof(superblock.d));
|
||||
lfs_superblock_fromle32(&superblock.d);
|
||||
if (err) {
|
||||
goto cleanup;
|
||||
return err;
|
||||
}
|
||||
|
||||
lfs->root[0] = superblock.d.root[0];
|
||||
@@ -2210,8 +2195,7 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
|
||||
if (err || memcmp(superblock.d.magic, "littlefs", 8) != 0) {
|
||||
LFS_ERROR("Invalid superblock at %d %d", 0, 1);
|
||||
err = LFS_ERR_CORRUPT;
|
||||
goto cleanup;
|
||||
return LFS_ERR_CORRUPT;
|
||||
}
|
||||
|
||||
uint16_t major_version = (0xffff & (superblock.d.version >> 16));
|
||||
@@ -2219,21 +2203,14 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
|
||||
if ((major_version != LFS_DISK_VERSION_MAJOR ||
|
||||
minor_version > LFS_DISK_VERSION_MINOR)) {
|
||||
LFS_ERROR("Invalid version %d.%d", major_version, minor_version);
|
||||
err = LFS_ERR_INVAL;
|
||||
goto cleanup;
|
||||
return LFS_ERR_INVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
cleanup:
|
||||
|
||||
lfs_deinit(lfs);
|
||||
return err;
|
||||
}
|
||||
|
||||
int lfs_unmount(lfs_t *lfs) {
|
||||
lfs_deinit(lfs);
|
||||
return 0;
|
||||
return lfs_deinit(lfs);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user