mirror of
https://github.com/eledio-devices/thirdparty-littlefs.git
synced 2025-11-01 08:48:31 +01:00
Compare commits
10 Commits
license-bs
...
v1.4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f94d233deb | ||
|
|
577d777c20 | ||
|
|
c72d25203c | ||
|
|
7e67f9324e | ||
|
|
5a17fa42e4 | ||
|
|
eed1eec5fd | ||
|
|
4a86370327 | ||
|
|
ba4f17173f | ||
|
|
51346b8bf4 | ||
|
|
93a2e0bbe5 |
@@ -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
|
||||||
|
|||||||
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)
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
|
||||||
// Block device emulated on existing filesystem
|
// Block device emulated on existing filesystem
|
||||||
@@ -85,7 +86,7 @@ int lfs_emubd_read(const struct lfs_config *cfg, lfs_block_t block,
|
|||||||
memset(data, 0, size);
|
memset(data, 0, size);
|
||||||
|
|
||||||
// Read data
|
// Read data
|
||||||
snprintf(emu->child, LFS_NAME_MAX, "%x", block);
|
snprintf(emu->child, LFS_NAME_MAX, "%" PRIx32, block);
|
||||||
|
|
||||||
FILE *f = fopen(emu->path, "rb");
|
FILE *f = fopen(emu->path, "rb");
|
||||||
if (!f && errno != ENOENT) {
|
if (!f && errno != ENOENT) {
|
||||||
@@ -124,7 +125,7 @@ int lfs_emubd_prog(const struct lfs_config *cfg, lfs_block_t block,
|
|||||||
assert(block < cfg->block_count);
|
assert(block < cfg->block_count);
|
||||||
|
|
||||||
// Program data
|
// Program data
|
||||||
snprintf(emu->child, LFS_NAME_MAX, "%x", block);
|
snprintf(emu->child, LFS_NAME_MAX, "%" PRIx32, block);
|
||||||
|
|
||||||
FILE *f = fopen(emu->path, "r+b");
|
FILE *f = fopen(emu->path, "r+b");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
@@ -171,7 +172,7 @@ int lfs_emubd_erase(const struct lfs_config *cfg, lfs_block_t block) {
|
|||||||
assert(block < cfg->block_count);
|
assert(block < cfg->block_count);
|
||||||
|
|
||||||
// Erase the block
|
// Erase the block
|
||||||
snprintf(emu->child, LFS_NAME_MAX, "%x", block);
|
snprintf(emu->child, LFS_NAME_MAX, "%" PRIx32, block);
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int err = stat(emu->path, &st);
|
int err = stat(emu->path, &st);
|
||||||
if (err && errno != ENOENT) {
|
if (err && errno != ENOENT) {
|
||||||
@@ -239,4 +240,3 @@ int lfs_emubd_sync(const struct lfs_config *cfg) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,11 @@
|
|||||||
#include "lfs.h"
|
#include "lfs.h"
|
||||||
#include "lfs_util.h"
|
#include "lfs_util.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Config options
|
// Config options
|
||||||
#ifndef LFS_EMUBD_READ_SIZE
|
#ifndef LFS_EMUBD_READ_SIZE
|
||||||
@@ -75,4 +80,8 @@ int lfs_emubd_erase(const struct lfs_config *cfg, lfs_block_t block);
|
|||||||
int lfs_emubd_sync(const struct lfs_config *cfg);
|
int lfs_emubd_sync(const struct lfs_config *cfg);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
76
lfs.c
76
lfs.c
@@ -7,6 +7,8 @@
|
|||||||
#include "lfs.h"
|
#include "lfs.h"
|
||||||
#include "lfs_util.h"
|
#include "lfs_util.h"
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
|
||||||
/// Caching block device operations ///
|
/// Caching block device operations ///
|
||||||
static int lfs_cache_read(lfs_t *lfs, lfs_cache_t *rcache,
|
static int lfs_cache_read(lfs_t *lfs, lfs_cache_t *rcache,
|
||||||
@@ -107,6 +109,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) {
|
||||||
@@ -128,7 +143,7 @@ static int lfs_cache_flush(lfs_t *lfs,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pcache->block = 0xffffffff;
|
lfs_cache_zero(lfs, pcache);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -233,7 +248,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) {
|
||||||
@@ -295,7 +310,8 @@ 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.ack == 0) {
|
if (lfs->free.ack == 0) {
|
||||||
LFS_WARN("No more free space %d", lfs->free.i + lfs->free.off);
|
LFS_WARN("No more free space %" PRIu32,
|
||||||
|
lfs->free.i + lfs->free.off);
|
||||||
return LFS_ERR_NOSPC;
|
return LFS_ERR_NOSPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -465,7 +481,8 @@ static int lfs_dir_fetch(lfs_t *lfs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
LFS_ERROR("Corrupted dir pair at %d %d", tpair[0], tpair[1]);
|
LFS_ERROR("Corrupted dir pair at %" PRIu32 " %" PRIu32 ,
|
||||||
|
tpair[0], tpair[1]);
|
||||||
return LFS_ERR_CORRUPT;
|
return LFS_ERR_CORRUPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -588,15 +605,16 @@ static int lfs_dir_commit(lfs_t *lfs, lfs_dir_t *dir,
|
|||||||
break;
|
break;
|
||||||
relocate:
|
relocate:
|
||||||
//commit was corrupted
|
//commit was corrupted
|
||||||
LFS_DEBUG("Bad block at %d", dir->pair[0]);
|
LFS_DEBUG("Bad block at %" PRIu32, dir->pair[0]);
|
||||||
|
|
||||||
// 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) {
|
||||||
LFS_WARN("Superblock %d has become unwritable", oldpair[0]);
|
LFS_WARN("Superblock %" PRIu32 " has become unwritable",
|
||||||
|
oldpair[0]);
|
||||||
return LFS_ERR_CORRUPT;
|
return LFS_ERR_CORRUPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -609,7 +627,7 @@ relocate:
|
|||||||
|
|
||||||
if (relocated) {
|
if (relocated) {
|
||||||
// update references if we relocated
|
// update references if we relocated
|
||||||
LFS_DEBUG("Relocating %d %d to %d %d",
|
LFS_DEBUG("Relocating %" PRIu32 " %" PRIu32 " to %" PRIu32 " %" PRIu32,
|
||||||
oldpair[0], oldpair[1], dir->pair[0], dir->pair[1]);
|
oldpair[0], oldpair[1], dir->pair[0], dir->pair[1]);
|
||||||
int err = lfs_relocate(lfs, oldpair, dir->pair);
|
int err = lfs_relocate(lfs, oldpair, dir->pair);
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -836,7 +854,7 @@ nextname:
|
|||||||
|
|
||||||
// find entry matching name
|
// 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;
|
||||||
}
|
}
|
||||||
@@ -1214,10 +1232,10 @@ static int lfs_ctz_extend(lfs_t *lfs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
relocate:
|
relocate:
|
||||||
LFS_DEBUG("Bad block at %d", nblock);
|
LFS_DEBUG("Bad block at %" PRIu32, 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1322,7 +1340,6 @@ 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) {
|
if (lfs->files) {
|
||||||
// already in use
|
// already in use
|
||||||
@@ -1341,6 +1358,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;
|
||||||
@@ -1369,7 +1389,7 @@ int lfs_file_close(lfs_t *lfs, lfs_file_t *file) {
|
|||||||
|
|
||||||
static int lfs_file_relocate(lfs_t *lfs, lfs_file_t *file) {
|
static int lfs_file_relocate(lfs_t *lfs, lfs_file_t *file) {
|
||||||
relocate:
|
relocate:
|
||||||
LFS_DEBUG("Bad block at %d", file->block);
|
LFS_DEBUG("Bad block at %" PRIu32, file->block);
|
||||||
|
|
||||||
// just relocate what exists into new block
|
// just relocate what exists into new block
|
||||||
lfs_block_t nblock;
|
lfs_block_t nblock;
|
||||||
@@ -1409,7 +1429,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;
|
||||||
@@ -1418,7 +1438,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1433,7 +1453,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
|
||||||
@@ -1451,8 +1471,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1630,7 +1650,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
|
||||||
@@ -1981,7 +2001,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 {
|
||||||
@@ -1992,7 +2011,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 {
|
||||||
@@ -2002,6 +2020,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);
|
||||||
@@ -2378,7 +2400,8 @@ static int lfs_relocate(lfs_t *lfs,
|
|||||||
|
|
||||||
// update internal root
|
// update internal root
|
||||||
if (lfs_paircmp(oldpair, lfs->root) == 0) {
|
if (lfs_paircmp(oldpair, lfs->root) == 0) {
|
||||||
LFS_DEBUG("Relocating root %d %d", newpair[0], newpair[1]);
|
LFS_DEBUG("Relocating root %" PRIu32 " %" PRIu32,
|
||||||
|
newpair[0], newpair[1]);
|
||||||
lfs->root[0] = newpair[0];
|
lfs->root[0] = newpair[0];
|
||||||
lfs->root[1] = newpair[1];
|
lfs->root[1] = newpair[1];
|
||||||
}
|
}
|
||||||
@@ -2434,7 +2457,7 @@ int lfs_deorphan(lfs_t *lfs) {
|
|||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
// we are an orphan
|
// we are an orphan
|
||||||
LFS_DEBUG("Found orphan %d %d",
|
LFS_DEBUG("Found orphan %" PRIu32 " %" PRIu32,
|
||||||
pdir.d.tail[0], pdir.d.tail[1]);
|
pdir.d.tail[0], pdir.d.tail[1]);
|
||||||
|
|
||||||
pdir.d.tail[0] = cwd.d.tail[0];
|
pdir.d.tail[0] = cwd.d.tail[0];
|
||||||
@@ -2450,7 +2473,7 @@ int lfs_deorphan(lfs_t *lfs) {
|
|||||||
|
|
||||||
if (!lfs_pairsync(entry.d.u.dir, pdir.d.tail)) {
|
if (!lfs_pairsync(entry.d.u.dir, pdir.d.tail)) {
|
||||||
// we have desynced
|
// we have desynced
|
||||||
LFS_DEBUG("Found desync %d %d",
|
LFS_DEBUG("Found desync %" PRIu32 " %" PRIu32,
|
||||||
entry.d.u.dir[0], entry.d.u.dir[1]);
|
entry.d.u.dir[0], entry.d.u.dir[1]);
|
||||||
|
|
||||||
pdir.d.tail[0] = entry.d.u.dir[0];
|
pdir.d.tail[0] = entry.d.u.dir[0];
|
||||||
@@ -2485,14 +2508,14 @@ int lfs_deorphan(lfs_t *lfs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (moved) {
|
if (moved) {
|
||||||
LFS_DEBUG("Found move %d %d",
|
LFS_DEBUG("Found move %" PRIu32 " %" PRIu32,
|
||||||
entry.d.u.dir[0], entry.d.u.dir[1]);
|
entry.d.u.dir[0], entry.d.u.dir[1]);
|
||||||
err = lfs_dir_remove(lfs, &cwd, &entry);
|
err = lfs_dir_remove(lfs, &cwd, &entry);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LFS_DEBUG("Found partial move %d %d",
|
LFS_DEBUG("Found partial move %" PRIu32 " %" PRIu32,
|
||||||
entry.d.u.dir[0], entry.d.u.dir[1]);
|
entry.d.u.dir[0], entry.d.u.dir[1]);
|
||||||
entry.d.type &= ~0x80;
|
entry.d.type &= ~0x80;
|
||||||
err = lfs_dir_update(lfs, &cwd, &entry, NULL);
|
err = lfs_dir_update(lfs, &cwd, &entry, NULL);
|
||||||
@@ -2508,4 +2531,3 @@ int lfs_deorphan(lfs_t *lfs) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
9
lfs.h
9
lfs.h
@@ -10,6 +10,11 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/// Version info ///
|
/// Version info ///
|
||||||
|
|
||||||
@@ -460,4 +465,8 @@ int lfs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data);
|
|||||||
int lfs_deorphan(lfs_t *lfs);
|
int lfs_deorphan(lfs_t *lfs);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
12
lfs_util.h
12
lfs_util.h
@@ -34,6 +34,11 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Macros, may be replaced by system specific wrappers. Arguments to these
|
// Macros, may be replaced by system specific wrappers. Arguments to these
|
||||||
// macros must not have side-effects as the macros can be removed for a smaller
|
// macros must not have side-effects as the macros can be removed for a smaller
|
||||||
@@ -158,6 +163,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
|
||||||
}
|
}
|
||||||
@@ -166,9 +172,15 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#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;
|
||||||
|
|||||||
@@ -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