mirror of
https://github.com/eledio-devices/thirdparty-littlefs.git
synced 2025-11-01 08:48:31 +01:00
Generated v2 prefixes
This commit is contained in:
18
lfs2.c
18
lfs2.c
@@ -84,9 +84,12 @@ static int lfs2_bd_read(lfs2_t *lfs2,
|
|||||||
LFS2_ASSERT(block < lfs2->cfg->block_count);
|
LFS2_ASSERT(block < lfs2->cfg->block_count);
|
||||||
rcache->block = block;
|
rcache->block = block;
|
||||||
rcache->off = lfs2_aligndown(off, lfs2->cfg->read_size);
|
rcache->off = lfs2_aligndown(off, lfs2->cfg->read_size);
|
||||||
rcache->size = lfs2_min(lfs2_alignup(off+hint, lfs2->cfg->read_size),
|
rcache->size = lfs2_min(
|
||||||
lfs2_min(lfs2->cfg->block_size - rcache->off,
|
lfs2_min(
|
||||||
lfs2->cfg->cache_size));
|
lfs2_alignup(off+hint, lfs2->cfg->read_size),
|
||||||
|
lfs2->cfg->block_size)
|
||||||
|
- rcache->off,
|
||||||
|
lfs2->cfg->cache_size);
|
||||||
int err = lfs2->cfg->read(lfs2->cfg, rcache->block,
|
int err = lfs2->cfg->read(lfs2->cfg, rcache->block,
|
||||||
rcache->off, rcache->buffer, rcache->size);
|
rcache->off, rcache->buffer, rcache->size);
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -2734,7 +2737,7 @@ lfs2_ssize_t lfs2_file_write(lfs2_t *lfs2, lfs2_file_t *file,
|
|||||||
|
|
||||||
if ((file->flags & LFS2_F_INLINE) &&
|
if ((file->flags & LFS2_F_INLINE) &&
|
||||||
lfs2_max(file->pos+nsize, file->ctz.size) >
|
lfs2_max(file->pos+nsize, file->ctz.size) >
|
||||||
lfs2_min(LFS2_ATTR_MAX, lfs2_min(
|
lfs2_min(0x3fe, lfs2_min(
|
||||||
lfs2->cfg->cache_size, lfs2->cfg->block_size/8))) {
|
lfs2->cfg->cache_size, lfs2->cfg->block_size/8))) {
|
||||||
// inline file doesn't fit anymore
|
// inline file doesn't fit anymore
|
||||||
file->off = file->pos;
|
file->off = file->pos;
|
||||||
@@ -2864,13 +2867,14 @@ int lfs2_file_truncate(lfs2_t *lfs2, lfs2_file_t *file, lfs2_off_t size) {
|
|||||||
// lookup new head in ctz skip list
|
// lookup new head in ctz skip list
|
||||||
err = lfs2_ctz_find(lfs2, NULL, &file->cache,
|
err = lfs2_ctz_find(lfs2, NULL, &file->cache,
|
||||||
file->ctz.head, file->ctz.size,
|
file->ctz.head, file->ctz.size,
|
||||||
size, &file->ctz.head, &(lfs2_off_t){0});
|
size, &file->block, &file->off);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file->ctz.head = file->block;
|
||||||
file->ctz.size = size;
|
file->ctz.size = size;
|
||||||
file->flags |= LFS2_F_DIRTY;
|
file->flags |= LFS2_F_DIRTY | LFS2_F_READING;
|
||||||
} else if (size > oldsize) {
|
} else if (size > oldsize) {
|
||||||
lfs2_off_t pos = file->pos;
|
lfs2_off_t pos = file->pos;
|
||||||
|
|
||||||
@@ -3900,7 +3904,7 @@ typedef struct lfs21_superblock {
|
|||||||
|
|
||||||
|
|
||||||
/// Low-level wrappers v1->v2 ///
|
/// Low-level wrappers v1->v2 ///
|
||||||
void lfs21_crc(uint32_t *crc, const void *buffer, size_t size) {
|
static void lfs21_crc(uint32_t *crc, const void *buffer, size_t size) {
|
||||||
*crc = lfs2_crc(*crc, buffer, size);
|
*crc = lfs2_crc(*crc, buffer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
24
lfs2_util.h
24
lfs2_util.h
@@ -143,14 +143,14 @@ static inline int lfs2_scmp(uint32_t a, uint32_t b) {
|
|||||||
// Convert between 32-bit little-endian and native order
|
// Convert between 32-bit little-endian and native order
|
||||||
static inline uint32_t lfs2_fromle32(uint32_t a) {
|
static inline uint32_t lfs2_fromle32(uint32_t a) {
|
||||||
#if !defined(LFS2_NO_INTRINSICS) && ( \
|
#if !defined(LFS2_NO_INTRINSICS) && ( \
|
||||||
(defined( BYTE_ORDER ) && BYTE_ORDER == ORDER_LITTLE_ENDIAN ) || \
|
(defined( BYTE_ORDER ) && defined( ORDER_LITTLE_ENDIAN ) && BYTE_ORDER == ORDER_LITTLE_ENDIAN ) || \
|
||||||
(defined(__BYTE_ORDER ) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN ) || \
|
(defined(__BYTE_ORDER ) && defined(__ORDER_LITTLE_ENDIAN ) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN ) || \
|
||||||
(defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
|
(defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
|
||||||
return a;
|
return a;
|
||||||
#elif !defined(LFS2_NO_INTRINSICS) && ( \
|
#elif !defined(LFS2_NO_INTRINSICS) && ( \
|
||||||
(defined( BYTE_ORDER ) && BYTE_ORDER == ORDER_BIG_ENDIAN ) || \
|
(defined( BYTE_ORDER ) && defined( ORDER_BIG_ENDIAN ) && BYTE_ORDER == ORDER_BIG_ENDIAN ) || \
|
||||||
(defined(__BYTE_ORDER ) && __BYTE_ORDER == __ORDER_BIG_ENDIAN ) || \
|
(defined(__BYTE_ORDER ) && defined(__ORDER_BIG_ENDIAN ) && __BYTE_ORDER == __ORDER_BIG_ENDIAN ) || \
|
||||||
(defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
|
(defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
|
||||||
return __builtin_bswap32(a);
|
return __builtin_bswap32(a);
|
||||||
#else
|
#else
|
||||||
return (((uint8_t*)&a)[0] << 0) |
|
return (((uint8_t*)&a)[0] << 0) |
|
||||||
@@ -167,14 +167,14 @@ static inline uint32_t lfs2_tole32(uint32_t a) {
|
|||||||
// Convert between 32-bit big-endian and native order
|
// Convert between 32-bit big-endian and native order
|
||||||
static inline uint32_t lfs2_frombe32(uint32_t a) {
|
static inline uint32_t lfs2_frombe32(uint32_t a) {
|
||||||
#if !defined(LFS2_NO_INTRINSICS) && ( \
|
#if !defined(LFS2_NO_INTRINSICS) && ( \
|
||||||
(defined( BYTE_ORDER ) && BYTE_ORDER == ORDER_LITTLE_ENDIAN ) || \
|
(defined( BYTE_ORDER ) && defined( ORDER_LITTLE_ENDIAN ) && BYTE_ORDER == ORDER_LITTLE_ENDIAN ) || \
|
||||||
(defined(__BYTE_ORDER ) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN ) || \
|
(defined(__BYTE_ORDER ) && defined(__ORDER_LITTLE_ENDIAN ) && __BYTE_ORDER == __ORDER_LITTLE_ENDIAN ) || \
|
||||||
(defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
|
(defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
|
||||||
return __builtin_bswap32(a);
|
return __builtin_bswap32(a);
|
||||||
#elif !defined(LFS2_NO_INTRINSICS) && ( \
|
#elif !defined(LFS2_NO_INTRINSICS) && ( \
|
||||||
(defined( BYTE_ORDER ) && BYTE_ORDER == ORDER_BIG_ENDIAN ) || \
|
(defined( BYTE_ORDER ) && defined( ORDER_BIG_ENDIAN ) && BYTE_ORDER == ORDER_BIG_ENDIAN ) || \
|
||||||
(defined(__BYTE_ORDER ) && __BYTE_ORDER == __ORDER_BIG_ENDIAN ) || \
|
(defined(__BYTE_ORDER ) && defined(__ORDER_BIG_ENDIAN ) && __BYTE_ORDER == __ORDER_BIG_ENDIAN ) || \
|
||||||
(defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
|
(defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
|
||||||
return a;
|
return a;
|
||||||
#else
|
#else
|
||||||
return (((uint8_t*)&a)[0] << 24) |
|
return (((uint8_t*)&a)[0] << 24) |
|
||||||
|
|||||||
@@ -11,6 +11,150 @@ tests/test.py << TEST
|
|||||||
lfs2_format(&lfs2, &cfg) => 0;
|
lfs2_format(&lfs2, &cfg) => 0;
|
||||||
TEST
|
TEST
|
||||||
|
|
||||||
|
echo "--- Simple truncate ---"
|
||||||
|
tests/test.py << TEST
|
||||||
|
lfs2_mount(&lfs2, &cfg) => 0;
|
||||||
|
lfs2_file_open(&lfs2, &file[0], "baldynoop",
|
||||||
|
LFS2_O_WRONLY | LFS2_O_CREAT) => 0;
|
||||||
|
|
||||||
|
strcpy((char*)buffer, "hair");
|
||||||
|
size = strlen((char*)buffer);
|
||||||
|
for (lfs2_off_t j = 0; j < $LARGESIZE; j += size) {
|
||||||
|
lfs2_file_write(&lfs2, &file[0], buffer, size) => size;
|
||||||
|
}
|
||||||
|
lfs2_file_size(&lfs2, &file[0]) => $LARGESIZE;
|
||||||
|
|
||||||
|
lfs2_file_close(&lfs2, &file[0]) => 0;
|
||||||
|
lfs2_unmount(&lfs2) => 0;
|
||||||
|
TEST
|
||||||
|
tests/test.py << TEST
|
||||||
|
lfs2_mount(&lfs2, &cfg) => 0;
|
||||||
|
lfs2_file_open(&lfs2, &file[0], "baldynoop", LFS2_O_RDWR) => 0;
|
||||||
|
lfs2_file_size(&lfs2, &file[0]) => $LARGESIZE;
|
||||||
|
|
||||||
|
lfs2_file_truncate(&lfs2, &file[0], $MEDIUMSIZE) => 0;
|
||||||
|
lfs2_file_size(&lfs2, &file[0]) => $MEDIUMSIZE;
|
||||||
|
|
||||||
|
lfs2_file_close(&lfs2, &file[0]) => 0;
|
||||||
|
lfs2_unmount(&lfs2) => 0;
|
||||||
|
TEST
|
||||||
|
tests/test.py << TEST
|
||||||
|
lfs2_mount(&lfs2, &cfg) => 0;
|
||||||
|
lfs2_file_open(&lfs2, &file[0], "baldynoop", LFS2_O_RDONLY) => 0;
|
||||||
|
lfs2_file_size(&lfs2, &file[0]) => $MEDIUMSIZE;
|
||||||
|
|
||||||
|
size = strlen("hair");
|
||||||
|
for (lfs2_off_t j = 0; j < $MEDIUMSIZE; j += size) {
|
||||||
|
lfs2_file_read(&lfs2, &file[0], buffer, size) => size;
|
||||||
|
memcmp(buffer, "hair", size) => 0;
|
||||||
|
}
|
||||||
|
lfs2_file_read(&lfs2, &file[0], buffer, size) => 0;
|
||||||
|
|
||||||
|
lfs2_file_close(&lfs2, &file[0]) => 0;
|
||||||
|
lfs2_unmount(&lfs2) => 0;
|
||||||
|
TEST
|
||||||
|
|
||||||
|
echo "--- Truncate and read ---"
|
||||||
|
tests/test.py << TEST
|
||||||
|
lfs2_mount(&lfs2, &cfg) => 0;
|
||||||
|
lfs2_file_open(&lfs2, &file[0], "baldyread",
|
||||||
|
LFS2_O_WRONLY | LFS2_O_CREAT) => 0;
|
||||||
|
|
||||||
|
strcpy((char*)buffer, "hair");
|
||||||
|
size = strlen((char*)buffer);
|
||||||
|
for (lfs2_off_t j = 0; j < $LARGESIZE; j += size) {
|
||||||
|
lfs2_file_write(&lfs2, &file[0], buffer, size) => size;
|
||||||
|
}
|
||||||
|
lfs2_file_size(&lfs2, &file[0]) => $LARGESIZE;
|
||||||
|
|
||||||
|
lfs2_file_close(&lfs2, &file[0]) => 0;
|
||||||
|
lfs2_unmount(&lfs2) => 0;
|
||||||
|
TEST
|
||||||
|
tests/test.py << TEST
|
||||||
|
lfs2_mount(&lfs2, &cfg) => 0;
|
||||||
|
lfs2_file_open(&lfs2, &file[0], "baldyread", LFS2_O_RDWR) => 0;
|
||||||
|
lfs2_file_size(&lfs2, &file[0]) => $LARGESIZE;
|
||||||
|
|
||||||
|
lfs2_file_truncate(&lfs2, &file[0], $MEDIUMSIZE) => 0;
|
||||||
|
lfs2_file_size(&lfs2, &file[0]) => $MEDIUMSIZE;
|
||||||
|
|
||||||
|
size = strlen("hair");
|
||||||
|
for (lfs2_off_t j = 0; j < $MEDIUMSIZE; j += size) {
|
||||||
|
lfs2_file_read(&lfs2, &file[0], buffer, size) => size;
|
||||||
|
memcmp(buffer, "hair", size) => 0;
|
||||||
|
}
|
||||||
|
lfs2_file_read(&lfs2, &file[0], buffer, size) => 0;
|
||||||
|
|
||||||
|
lfs2_file_close(&lfs2, &file[0]) => 0;
|
||||||
|
lfs2_unmount(&lfs2) => 0;
|
||||||
|
TEST
|
||||||
|
tests/test.py << TEST
|
||||||
|
lfs2_mount(&lfs2, &cfg) => 0;
|
||||||
|
lfs2_file_open(&lfs2, &file[0], "baldyread", LFS2_O_RDONLY) => 0;
|
||||||
|
lfs2_file_size(&lfs2, &file[0]) => $MEDIUMSIZE;
|
||||||
|
|
||||||
|
size = strlen("hair");
|
||||||
|
for (lfs2_off_t j = 0; j < $MEDIUMSIZE; j += size) {
|
||||||
|
lfs2_file_read(&lfs2, &file[0], buffer, size) => size;
|
||||||
|
memcmp(buffer, "hair", size) => 0;
|
||||||
|
}
|
||||||
|
lfs2_file_read(&lfs2, &file[0], buffer, size) => 0;
|
||||||
|
|
||||||
|
lfs2_file_close(&lfs2, &file[0]) => 0;
|
||||||
|
lfs2_unmount(&lfs2) => 0;
|
||||||
|
TEST
|
||||||
|
|
||||||
|
echo "--- Truncate and write ---"
|
||||||
|
tests/test.py << TEST
|
||||||
|
lfs2_mount(&lfs2, &cfg) => 0;
|
||||||
|
lfs2_file_open(&lfs2, &file[0], "baldywrite",
|
||||||
|
LFS2_O_WRONLY | LFS2_O_CREAT) => 0;
|
||||||
|
|
||||||
|
strcpy((char*)buffer, "hair");
|
||||||
|
size = strlen((char*)buffer);
|
||||||
|
for (lfs2_off_t j = 0; j < $LARGESIZE; j += size) {
|
||||||
|
lfs2_file_write(&lfs2, &file[0], buffer, size) => size;
|
||||||
|
}
|
||||||
|
lfs2_file_size(&lfs2, &file[0]) => $LARGESIZE;
|
||||||
|
|
||||||
|
lfs2_file_close(&lfs2, &file[0]) => 0;
|
||||||
|
lfs2_unmount(&lfs2) => 0;
|
||||||
|
TEST
|
||||||
|
tests/test.py << TEST
|
||||||
|
lfs2_mount(&lfs2, &cfg) => 0;
|
||||||
|
lfs2_file_open(&lfs2, &file[0], "baldywrite", LFS2_O_RDWR) => 0;
|
||||||
|
lfs2_file_size(&lfs2, &file[0]) => $LARGESIZE;
|
||||||
|
|
||||||
|
lfs2_file_truncate(&lfs2, &file[0], $MEDIUMSIZE) => 0;
|
||||||
|
lfs2_file_size(&lfs2, &file[0]) => $MEDIUMSIZE;
|
||||||
|
|
||||||
|
strcpy((char*)buffer, "bald");
|
||||||
|
size = strlen((char*)buffer);
|
||||||
|
for (lfs2_off_t j = 0; j < $MEDIUMSIZE; j += size) {
|
||||||
|
lfs2_file_write(&lfs2, &file[0], buffer, size) => size;
|
||||||
|
}
|
||||||
|
lfs2_file_size(&lfs2, &file[0]) => $MEDIUMSIZE;
|
||||||
|
|
||||||
|
lfs2_file_close(&lfs2, &file[0]) => 0;
|
||||||
|
lfs2_unmount(&lfs2) => 0;
|
||||||
|
TEST
|
||||||
|
tests/test.py << TEST
|
||||||
|
lfs2_mount(&lfs2, &cfg) => 0;
|
||||||
|
lfs2_file_open(&lfs2, &file[0], "baldywrite", LFS2_O_RDONLY) => 0;
|
||||||
|
lfs2_file_size(&lfs2, &file[0]) => $MEDIUMSIZE;
|
||||||
|
|
||||||
|
size = strlen("bald");
|
||||||
|
for (lfs2_off_t j = 0; j < $MEDIUMSIZE; j += size) {
|
||||||
|
lfs2_file_read(&lfs2, &file[0], buffer, size) => size;
|
||||||
|
memcmp(buffer, "bald", size) => 0;
|
||||||
|
}
|
||||||
|
lfs2_file_read(&lfs2, &file[0], buffer, size) => 0;
|
||||||
|
|
||||||
|
lfs2_file_close(&lfs2, &file[0]) => 0;
|
||||||
|
lfs2_unmount(&lfs2) => 0;
|
||||||
|
TEST
|
||||||
|
|
||||||
|
# More aggressive general truncation tests
|
||||||
truncate_test() {
|
truncate_test() {
|
||||||
STARTSIZES="$1"
|
STARTSIZES="$1"
|
||||||
STARTSEEKS="$2"
|
STARTSEEKS="$2"
|
||||||
|
|||||||
Reference in New Issue
Block a user