mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 01:40:14 +01:00
lib/littlefs: Update LittleFS to v2.11.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
This commit is contained in:
committed by
Damien George
parent
670b7c9350
commit
9dbae39348
@@ -3932,7 +3932,9 @@ static int lfs2_remove_(lfs2_t *lfs2, const char *path) {
|
||||
}
|
||||
|
||||
lfs2->mlist = dir.next;
|
||||
if (lfs2_tag_type3(tag) == LFS2_TYPE_DIR) {
|
||||
if (lfs2_gstate_hasorphans(&lfs2->gstate)) {
|
||||
LFS2_ASSERT(lfs2_tag_type3(tag) == LFS2_TYPE_DIR);
|
||||
|
||||
// fix orphan
|
||||
err = lfs2_fs_preporphans(lfs2, -1);
|
||||
if (err) {
|
||||
@@ -4076,8 +4078,10 @@ static int lfs2_rename_(lfs2_t *lfs2, const char *oldpath, const char *newpath)
|
||||
}
|
||||
|
||||
lfs2->mlist = prevdir.next;
|
||||
if (prevtag != LFS2_ERR_NOENT
|
||||
&& lfs2_tag_type3(prevtag) == LFS2_TYPE_DIR) {
|
||||
if (lfs2_gstate_hasorphans(&lfs2->gstate)) {
|
||||
LFS2_ASSERT(prevtag != LFS2_ERR_NOENT
|
||||
&& lfs2_tag_type3(prevtag) == LFS2_TYPE_DIR);
|
||||
|
||||
// fix orphan
|
||||
err = lfs2_fs_preporphans(lfs2, -1);
|
||||
if (err) {
|
||||
@@ -5233,40 +5237,64 @@ static int lfs2_fs_gc_(lfs2_t *lfs2) {
|
||||
#endif
|
||||
|
||||
#ifndef LFS2_READONLY
|
||||
#ifdef LFS2_SHRINKNONRELOCATING
|
||||
static int lfs2_shrink_checkblock(void *data, lfs2_block_t block) {
|
||||
lfs2_size_t threshold = *((lfs2_size_t*)data);
|
||||
if (block >= threshold) {
|
||||
return LFS2_ERR_NOTEMPTY;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int lfs2_fs_grow_(lfs2_t *lfs2, lfs2_size_t block_count) {
|
||||
int err;
|
||||
|
||||
if (block_count == lfs2->block_count) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifndef LFS2_SHRINKNONRELOCATING
|
||||
// shrinking is not supported
|
||||
LFS2_ASSERT(block_count >= lfs2->block_count);
|
||||
|
||||
if (block_count > lfs2->block_count) {
|
||||
lfs2->block_count = block_count;
|
||||
|
||||
// fetch the root
|
||||
lfs2_mdir_t root;
|
||||
int err = lfs2_dir_fetch(lfs2, &root, lfs2->root);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// update the superblock
|
||||
lfs2_superblock_t superblock;
|
||||
lfs2_stag_t tag = lfs2_dir_get(lfs2, &root, LFS2_MKTAG(0x7ff, 0x3ff, 0),
|
||||
LFS2_MKTAG(LFS2_TYPE_INLINESTRUCT, 0, sizeof(superblock)),
|
||||
&superblock);
|
||||
if (tag < 0) {
|
||||
return tag;
|
||||
}
|
||||
lfs2_superblock_fromle32(&superblock);
|
||||
|
||||
superblock.block_count = lfs2->block_count;
|
||||
|
||||
lfs2_superblock_tole32(&superblock);
|
||||
err = lfs2_dir_commit(lfs2, &root, LFS2_MKATTRS(
|
||||
{tag, &superblock}));
|
||||
#endif
|
||||
#ifdef LFS2_SHRINKNONRELOCATING
|
||||
if (block_count < lfs2->block_count) {
|
||||
err = lfs2_fs_traverse_(lfs2, lfs2_shrink_checkblock, &block_count, true);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
lfs2->block_count = block_count;
|
||||
|
||||
// fetch the root
|
||||
lfs2_mdir_t root;
|
||||
err = lfs2_dir_fetch(lfs2, &root, lfs2->root);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// update the superblock
|
||||
lfs2_superblock_t superblock;
|
||||
lfs2_stag_t tag = lfs2_dir_get(lfs2, &root, LFS2_MKTAG(0x7ff, 0x3ff, 0),
|
||||
LFS2_MKTAG(LFS2_TYPE_INLINESTRUCT, 0, sizeof(superblock)),
|
||||
&superblock);
|
||||
if (tag < 0) {
|
||||
return tag;
|
||||
}
|
||||
lfs2_superblock_fromle32(&superblock);
|
||||
|
||||
superblock.block_count = lfs2->block_count;
|
||||
|
||||
lfs2_superblock_tole32(&superblock);
|
||||
err = lfs2_dir_commit(lfs2, &root, LFS2_MKATTRS(
|
||||
{tag, &superblock}));
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -21,7 +21,7 @@ extern "C"
|
||||
// Software library version
|
||||
// Major (top-nibble), incremented on backwards incompatible changes
|
||||
// Minor (bottom-nibble), incremented on feature additions
|
||||
#define LFS2_VERSION 0x0002000a
|
||||
#define LFS2_VERSION 0x0002000b
|
||||
#define LFS2_VERSION_MAJOR (0xffff & (LFS2_VERSION >> 16))
|
||||
#define LFS2_VERSION_MINOR (0xffff & (LFS2_VERSION >> 0))
|
||||
|
||||
@@ -766,7 +766,11 @@ int lfs2_fs_gc(lfs2_t *lfs2);
|
||||
// Grows the filesystem to a new size, updating the superblock with the new
|
||||
// block count.
|
||||
//
|
||||
// Note: This is irreversible.
|
||||
// If LFS2_SHRINKNONRELOCATING is defined, this function will also accept
|
||||
// block_counts smaller than the current configuration, after checking
|
||||
// that none of the blocks that are being removed are in use.
|
||||
// Note that littlefs's pseudorandom block allocation means that
|
||||
// this is very unlikely to work in the general case.
|
||||
//
|
||||
// Returns a negative error code on failure.
|
||||
int lfs2_fs_grow(lfs2_t *lfs2, lfs2_size_t block_count);
|
||||
|
||||
@@ -195,10 +195,10 @@ static inline uint32_t lfs2_fromle32(uint32_t a) {
|
||||
(defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
|
||||
return __builtin_bswap32(a);
|
||||
#else
|
||||
return (((uint8_t*)&a)[0] << 0) |
|
||||
(((uint8_t*)&a)[1] << 8) |
|
||||
(((uint8_t*)&a)[2] << 16) |
|
||||
(((uint8_t*)&a)[3] << 24);
|
||||
return ((uint32_t)((uint8_t*)&a)[0] << 0) |
|
||||
((uint32_t)((uint8_t*)&a)[1] << 8) |
|
||||
((uint32_t)((uint8_t*)&a)[2] << 16) |
|
||||
((uint32_t)((uint8_t*)&a)[3] << 24);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -218,10 +218,10 @@ static inline uint32_t lfs2_frombe32(uint32_t a) {
|
||||
(defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
|
||||
return a;
|
||||
#else
|
||||
return (((uint8_t*)&a)[0] << 24) |
|
||||
(((uint8_t*)&a)[1] << 16) |
|
||||
(((uint8_t*)&a)[2] << 8) |
|
||||
(((uint8_t*)&a)[3] << 0);
|
||||
return ((uint32_t)((uint8_t*)&a)[0] << 24) |
|
||||
((uint32_t)((uint8_t*)&a)[1] << 16) |
|
||||
((uint32_t)((uint8_t*)&a)[2] << 8) |
|
||||
((uint32_t)((uint8_t*)&a)[3] << 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user