Dropped LFS3_KVONLY and LFS3_2BONLY modes for now

I think these are good ideas to bring back when littlefs3 is more
mature, but at the moment the number of different builds is creating too
much friction.

LFS3_KVONLY and LFS3_2BONLY in particular _add_ significant chunks of
code (lfs3_file_readget_, lfs3_file_flushset_, and various extra logic
sprinkled throughout the codebase), and the current state of testing
means I have no idea if any of it still works.

These are also low-risk for introducing any disk related changes.

So, ripping out for now to keep the current experimental development
tractable. May reintroduce in the future (probably after littlefs3 is
stabilized) if there is sufficient user interest. But doing so will
probably also need to come with actual testing in CI.
This commit is contained in:
Christopher Haster 2025-10-23 23:20:22 -05:00
parent 207446223b
commit 5d905e6da4
4 changed files with 66 additions and 526 deletions

511
lfs3.c

File diff suppressed because it is too large Load Diff

56
lfs3.h
View File

@ -702,14 +702,10 @@ struct lfs3_file_cfg {
// these attributes will be kept up to date with the attributes on-disk.
// If writeable, these attributes will be written to disk atomically on
// every file sync or close.
#ifndef LFS3_KVONLY
struct lfs3_attr *attrs;
#endif
// Number of custom attributes in the list
#ifndef LFS3_KVONLY
lfs3_size_t attr_count;
#endif
};
@ -747,7 +743,7 @@ typedef struct lfs3_bptr {
// sign2(size)=0b10 => on-disk data
// sign2(size)=0b11 => block pointer
lfs3_data_t d;
#if !defined(LFS3_2BONLY) && !defined(LFS3_CKDATACKSUMS)
#ifndef LFS3_CKDATACKSUMS
// sign(cksize)=0 => block not erased
// sign(cksize)=1 => block erased
lfs3_size_t cksize;
@ -827,29 +823,23 @@ typedef struct lfs3_file {
const struct lfs3_file_cfg *cfg;
// current file position
#ifndef LFS3_KVONLY
lfs3_off_t pos;
#endif
// in-RAM cache
//
// note this lines up with lfs3_data_t's buffer representation
struct {
#ifndef LFS3_KVONLY
lfs3_off_t pos;
#endif
lfs3_off_t size;
uint8_t *buffer;
} cache;
// on-disk leaf bptr
#ifndef LFS3_KVONLY
struct {
lfs3_off_t pos;
lfs3_off_t weight;
lfs3_bptr_t bptr;
} leaf;
#endif
} lfs3_file_t;
// littlefs directory type
@ -947,9 +937,7 @@ typedef struct lfs3 {
lfs3_handle_t *handles;
lfs3_mdir_t mroot;
#ifndef LFS3_2BONLY
lfs3_btree_t mtree;
#endif
struct lfs3_rcache {
lfs3_block_t block;
@ -977,7 +965,7 @@ typedef struct lfs3 {
} ptail;
#endif
#if !defined(LFS3_RDONLY) && !defined(LFS3_2BONLY)
#ifndef LFS3_RDONLY
struct lfs3_lookahead {
lfs3_block_t window;
lfs3_block_t off;
@ -987,7 +975,7 @@ typedef struct lfs3 {
} lookahead;
#endif
#if !defined(LFS3_RDONLY) && !defined(LFS3_2BONLY)
#ifndef LFS3_RDONLY
const lfs3_data_t *graft;
lfs3_ssize_t graft_count;
#endif
@ -1007,7 +995,7 @@ typedef struct lfs3 {
// TODO can we actually get rid of grm_d when LFS3_RDONLY?
uint8_t grm_d[LFS3_GRM_DSIZE];
#if !defined(LFS3_2BONLY) && defined(LFS3_GBMAP)
#ifdef LFS3_GBMAP
lfs3_gbmap_t gbmap;
uint8_t gbmap_p[LFS3_GBMAP_DSIZE];
uint8_t gbmap_d[LFS3_GBMAP_DSIZE];
@ -1135,7 +1123,7 @@ int lfs3_removeattr(lfs3_t *lfs3, const char *path, uint8_t type);
// are values from the enum lfs3_open_flags that are bitwise-ored together.
//
// Returns a negative error code on failure.
#if !defined(LFS3_KVONLY) && !defined(LFS3_NO_MALLOC)
#ifndef LFS3_NO_MALLOC
int lfs3_file_open(lfs3_t *lfs3, lfs3_file_t *file,
const char *path, uint32_t flags);
#endif
@ -1150,11 +1138,9 @@ int lfs3_file_open(lfs3_t *lfs3, lfs3_file_t *file,
// the config struct must be zeroed for defaults and backwards compatibility.
//
// Returns a negative error code on failure.
#ifndef LFS3_KVONLY
int lfs3_file_opencfg(lfs3_t *lfs3, lfs3_file_t *file,
const char *path, uint32_t flags,
const struct lfs3_file_cfg *cfg);
#endif
// Close a file
//
@ -1167,9 +1153,7 @@ int lfs3_file_opencfg(lfs3_t *lfs3, lfs3_file_t *file,
// return 0.
//
// Returns a negative error code on failure.
#ifndef LFS3_KVONLY
int lfs3_file_close(lfs3_t *lfs3, lfs3_file_t *file);
#endif
// Synchronize a file on storage
//
@ -1179,9 +1163,7 @@ int lfs3_file_close(lfs3_t *lfs3, lfs3_file_t *file);
// now recieve file updates and syncs on close.
//
// Returns a negative error code on failure.
#ifndef LFS3_KVONLY
int lfs3_file_sync(lfs3_t *lfs3, lfs3_file_t *file);
#endif
// Flush any buffered data
//
@ -1190,9 +1172,7 @@ int lfs3_file_sync(lfs3_t *lfs3, lfs3_file_t *file);
// read operations.
//
// Returns a negative error code on failure.
#ifndef LFS3_KVONLY
int lfs3_file_flush(lfs3_t *lfs3, lfs3_file_t *file);
#endif
// Mark a file as desynchronized
//
@ -1207,9 +1187,7 @@ int lfs3_file_flush(lfs3_t *lfs3, lfs3_file_t *file);
// lfs3_file_resync reverses this, marking the file as synchronized again.
//
// Returns a negative error code on failure.
#ifndef LFS3_KVONLY
int lfs3_file_desync(lfs3_t *lfs3, lfs3_file_t *file);
#endif
// Discard unsynchronized changes and mark a file as synchronized
//
@ -1217,18 +1195,14 @@ int lfs3_file_desync(lfs3_t *lfs3, lfs3_file_t *file);
// may read from disk to figure out file state.
//
// Returns a negative error code on failure.
#ifndef LFS3_KVONLY
int lfs3_file_resync(lfs3_t *lfs3, lfs3_file_t *file);
#endif
// Read data from file
//
// Takes a buffer and size indicating where to store the read data.
// Returns the number of bytes read, or a negative error code on failure.
#ifndef LFS3_KVONLY
lfs3_ssize_t lfs3_file_read(lfs3_t *lfs3, lfs3_file_t *file,
void *buffer, lfs3_size_t size);
#endif
// Write data to file
//
@ -1236,7 +1210,7 @@ lfs3_ssize_t lfs3_file_read(lfs3_t *lfs3, lfs3_file_t *file,
// actually be updated on the storage until either sync or close is called.
//
// Returns the number of bytes written, or a negative error code on failure.
#if !defined(LFS3_RDONLY) && !defined(LFS3_KVONLY)
#ifndef LFS3_RDONLY
lfs3_ssize_t lfs3_file_write(lfs3_t *lfs3, lfs3_file_t *file,
const void *buffer, lfs3_size_t size);
#endif
@ -1245,10 +1219,8 @@ lfs3_ssize_t lfs3_file_write(lfs3_t *lfs3, lfs3_file_t *file,
//
// The change in position is determined by the offset and whence flag.
// Returns the new position of the file, or a negative error code on failure.
#ifndef LFS3_KVONLY
lfs3_soff_t lfs3_file_seek(lfs3_t *lfs3, lfs3_file_t *file,
lfs3_soff_t off, uint8_t whence);
#endif
// Truncate/grow the size of the file to the specified size
//
@ -1256,7 +1228,7 @@ lfs3_soff_t lfs3_file_seek(lfs3_t *lfs3, lfs3_file_t *file,
// as if the file was filled with zeros.
//
// Returns a negative error code on failure.
#if !defined(LFS3_RDONLY) && !defined(LFS3_KVONLY)
#ifndef LFS3_RDONLY
int lfs3_file_truncate(lfs3_t *lfs3, lfs3_file_t *file, lfs3_off_t size);
#endif
@ -1266,7 +1238,7 @@ int lfs3_file_truncate(lfs3_t *lfs3, lfs3_file_t *file, lfs3_off_t size);
// as if the file was filled with zeros.
//
// Returns a negative error code on failure.
#if !defined(LFS3_RDONLY) && !defined(LFS3_KVONLY)
#ifndef LFS3_RDONLY
int lfs3_file_fruncate(lfs3_t *lfs3, lfs3_file_t *file, lfs3_off_t size);
#endif
@ -1274,41 +1246,31 @@ int lfs3_file_fruncate(lfs3_t *lfs3, lfs3_file_t *file, lfs3_off_t size);
//
// Equivalent to lfs3_file_seek(lfs3, file, 0, LFS3_SEEK_CUR)
// Returns the position of the file, or a negative error code on failure.
#ifndef LFS3_KVONLY
lfs3_soff_t lfs3_file_tell(lfs3_t *lfs3, lfs3_file_t *file);
#endif
// Change the position of the file to the beginning of the file
//
// Equivalent to lfs3_file_seek(lfs3, file, 0, LFS3_SEEK_SET)
// Returns a negative error code on failure.
#ifndef LFS3_KVONLY
int lfs3_file_rewind(lfs3_t *lfs3, lfs3_file_t *file);
#endif
// Return the size of the file
//
// Similar to lfs3_file_seek(lfs3, file, 0, LFS3_SEEK_END)
// Returns the size of the file, or a negative error code on failure.
#ifndef LFS3_KVONLY
lfs3_soff_t lfs3_file_size(lfs3_t *lfs3, lfs3_file_t *file);
#endif
// Check a file for metadata errors
//
// Returns LFS3_ERR_CORRUPT if a checksum mismatch is found, or a negative
// error code on failure.
#ifndef LFS3_KVONLY
int lfs3_file_ckmeta(lfs3_t *lfs3, lfs3_file_t *file);
#endif
// Check a file for metadata + data errors
//
// Returns LFS3_ERR_CORRUPT if a checksum mismatch is found, or a negative
// error code on failure.
#ifndef LFS3_KVONLY
int lfs3_file_ckdata(lfs3_t *lfs3, lfs3_file_t *file);
#endif
/// Directory operations ///
@ -1480,7 +1442,7 @@ int lfs3_fs_unck(lfs3_t *lfs3, uint32_t flags);
// Note: This is irreversible.
//
// Returns a negative error code on failure.
#if !defined(LFS3_RDONLY) && !defined(LFS3_2BONLY)
#ifndef LFS3_RDONLY
int lfs3_fs_grow(lfs3_t *lfs3, lfs3_size_t block_count);
#endif

View File

@ -56,12 +56,6 @@
#ifdef LFS3_YES_RDONLY
#define LFS3_RDONLY
#endif
#ifdef LFS3_YES_KVONLY
#define LFS3_KVONLY
#endif
#ifdef LFS3_YES_2BONLY
#define LFS3_2BONLY
#endif
#ifdef LFS3_YES_REVDBG
#define LFS3_REVDBG
#endif
@ -209,18 +203,6 @@
#define LFS3_IFDEF_RDONLY(a, b) (b)
#endif
#ifdef LFS3_KVONLY
#define LFS3_IFDEF_KVONLY(a, b) (a)
#else
#define LFS3_IFDEF_KVONLY(a, b) (b)
#endif
#ifdef LFS3_2BONLY
#define LFS3_IFDEF_2BONLY(a, b) (a)
#else
#define LFS3_IFDEF_2BONLY(a, b) (b)
#endif
#ifdef LFS3_REVDBG
#define LFS3_IFDEF_REVDBG(a, b) (a)
#else

View File

@ -827,7 +827,6 @@ code = '''
# test kv files can be read as normal files
[cases.test_kv_interop_reads]
ifndef = 'LFS3_KVONLY'
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
@ -930,7 +929,6 @@ code = '''
# test normal files can be read a kv files
[cases.test_kv_interop_writes]
ifndef = 'LFS3_KVONLY'
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
@ -983,7 +981,6 @@ code = '''
# test kv files broadcast sync updates
[cases.test_kv_interop_sync]
defines.STICKYNOTES = [false, true]
ifndef = 'LFS3_KVONLY'
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
@ -1071,7 +1068,6 @@ code = '''
# test kv files don't interfere with desync files
[cases.test_kv_interop_desync]
defines.STICKYNOTES = [false, true]
ifndef = 'LFS3_KVONLY'
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
@ -1163,7 +1159,6 @@ code = '''
# test kv files work with resyncing files
[cases.test_kv_interop_resync]
defines.STICKYNOTES = [false, true]
ifndef = 'LFS3_KVONLY'
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
@ -1274,7 +1269,6 @@ defines.SIZE = 4
defines.OPS = ['4*N', '40*N']
defines.SEED = 'range(20)'
fuzz = 'SEED'
ifndef = 'LFS3_KVONLY'
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;
@ -1433,7 +1427,6 @@ defines.SIZE = 40000
defines.OPS = ['4*N', '40*N']
defines.SEED = 'range(20)'
fuzz = 'SEED'
ifndef = 'LFS3_KVONLY'
code = '''
lfs3_t lfs3;
lfs3_format(&lfs3, LFS3_F_RDWR, CFG) => 0;