|
|
@@ -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 LFS_VERSION 0x00020008
|
|
|
+#define LFS_VERSION 0x00020009
|
|
|
#define LFS_VERSION_MAJOR (0xffff & (LFS_VERSION >> 16))
|
|
|
#define LFS_VERSION_MINOR (0xffff & (LFS_VERSION >> 0))
|
|
|
|
|
|
@@ -52,10 +52,8 @@ typedef uint32_t lfs_block_t;
|
|
|
#endif
|
|
|
|
|
|
// Maximum size of a file in bytes, may be redefined to limit to support other
|
|
|
-// drivers. Limited on disk to <= 4294967296. However, above 2147483647 the
|
|
|
-// functions lfs_file_seek, lfs_file_size, and lfs_file_tell will return
|
|
|
-// incorrect values due to using signed integers. Stored in superblock and
|
|
|
-// must be respected by other littlefs drivers.
|
|
|
+// drivers. Limited on disk to <= 2147483647. Stored in superblock and must be
|
|
|
+// respected by other littlefs drivers.
|
|
|
#ifndef LFS_FILE_MAX
|
|
|
#define LFS_FILE_MAX 2147483647
|
|
|
#endif
|
|
|
@@ -226,9 +224,20 @@ struct lfs_config {
|
|
|
// Size of the lookahead buffer in bytes. A larger lookahead buffer
|
|
|
// increases the number of blocks found during an allocation pass. The
|
|
|
// lookahead buffer is stored as a compact bitmap, so each byte of RAM
|
|
|
- // can track 8 blocks. Must be a multiple of 8.
|
|
|
+ // can track 8 blocks.
|
|
|
lfs_size_t lookahead_size;
|
|
|
|
|
|
+ // Threshold for metadata compaction during lfs_fs_gc in bytes. Metadata
|
|
|
+ // pairs that exceed this threshold will be compacted during lfs_fs_gc.
|
|
|
+ // Defaults to ~88% block_size when zero, though the default may change
|
|
|
+ // in the future.
|
|
|
+ //
|
|
|
+ // Note this only affects lfs_fs_gc. Normal compactions still only occur
|
|
|
+ // when full.
|
|
|
+ //
|
|
|
+ // Set to -1 to disable metadata compaction during lfs_fs_gc.
|
|
|
+ lfs_size_t compact_thresh;
|
|
|
+
|
|
|
// Optional statically allocated read buffer. Must be cache_size.
|
|
|
// By default lfs_malloc is used to allocate this buffer.
|
|
|
void *read_buffer;
|
|
|
@@ -237,9 +246,8 @@ struct lfs_config {
|
|
|
// By default lfs_malloc is used to allocate this buffer.
|
|
|
void *prog_buffer;
|
|
|
|
|
|
- // Optional statically allocated lookahead buffer. Must be lookahead_size
|
|
|
- // and aligned to a 32-bit boundary. By default lfs_malloc is used to
|
|
|
- // allocate this buffer.
|
|
|
+ // Optional statically allocated lookahead buffer. Must be lookahead_size.
|
|
|
+ // By default lfs_malloc is used to allocate this buffer.
|
|
|
void *lookahead_buffer;
|
|
|
|
|
|
// Optional upper limit on length of file names in bytes. No downside for
|
|
|
@@ -264,6 +272,15 @@ struct lfs_config {
|
|
|
// Defaults to block_size when zero.
|
|
|
lfs_size_t metadata_max;
|
|
|
|
|
|
+ // Optional upper limit on inlined files in bytes. Inlined files live in
|
|
|
+ // metadata and decrease storage requirements, but may be limited to
|
|
|
+ // improve metadata-related performance. Must be <= cache_size, <=
|
|
|
+ // attr_max, and <= block_size/8. Defaults to the largest possible
|
|
|
+ // inline_max when zero.
|
|
|
+ //
|
|
|
+ // Set to -1 to disable inlined files.
|
|
|
+ lfs_size_t inline_max;
|
|
|
+
|
|
|
#ifdef LFS_MULTIVERSION
|
|
|
// On-disk version to use when writing in the form of 16-bit major version
|
|
|
// + 16-bit minor version. This limiting metadata to what is supported by
|
|
|
@@ -430,19 +447,20 @@ typedef struct lfs {
|
|
|
lfs_gstate_t gdisk;
|
|
|
lfs_gstate_t gdelta;
|
|
|
|
|
|
- struct lfs_free {
|
|
|
- lfs_block_t off;
|
|
|
+ struct lfs_lookahead {
|
|
|
+ lfs_block_t start;
|
|
|
lfs_block_t size;
|
|
|
- lfs_block_t i;
|
|
|
- lfs_block_t ack;
|
|
|
- uint32_t *buffer;
|
|
|
- } free;
|
|
|
+ lfs_block_t next;
|
|
|
+ lfs_block_t ckpoint;
|
|
|
+ uint8_t *buffer;
|
|
|
+ } lookahead;
|
|
|
|
|
|
const struct lfs_config *cfg;
|
|
|
lfs_size_t block_count;
|
|
|
lfs_size_t name_max;
|
|
|
lfs_size_t file_max;
|
|
|
lfs_size_t attr_max;
|
|
|
+ lfs_size_t inline_max;
|
|
|
|
|
|
#ifdef LFS_MIGRATE
|
|
|
struct lfs1 *lfs1;
|
|
|
@@ -712,18 +730,6 @@ lfs_ssize_t lfs_fs_size(lfs_t *lfs);
|
|
|
// Returns a negative error code on failure.
|
|
|
int lfs_fs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data);
|
|
|
|
|
|
-// Attempt to proactively find free blocks
|
|
|
-//
|
|
|
-// Calling this function is not required, but may allowing the offloading of
|
|
|
-// the expensive block allocation scan to a less time-critical code path.
|
|
|
-//
|
|
|
-// Note: littlefs currently does not persist any found free blocks to disk.
|
|
|
-// This may change in the future.
|
|
|
-//
|
|
|
-// Returns a negative error code on failure. Finding no free blocks is
|
|
|
-// not an error.
|
|
|
-int lfs_fs_gc(lfs_t *lfs);
|
|
|
-
|
|
|
#ifndef LFS_READONLY
|
|
|
// Attempt to make the filesystem consistent and ready for writing
|
|
|
//
|
|
|
@@ -736,6 +742,24 @@ int lfs_fs_gc(lfs_t *lfs);
|
|
|
int lfs_fs_mkconsistent(lfs_t *lfs);
|
|
|
#endif
|
|
|
|
|
|
+#ifndef LFS_READONLY
|
|
|
+// Attempt any janitorial work
|
|
|
+//
|
|
|
+// This currently:
|
|
|
+// 1. Calls mkconsistent if not already consistent
|
|
|
+// 2. Compacts metadata > compact_thresh
|
|
|
+// 3. Populates the block allocator
|
|
|
+//
|
|
|
+// Though additional janitorial work may be added in the future.
|
|
|
+//
|
|
|
+// Calling this function is not required, but may allow the offloading of
|
|
|
+// expensive janitorial work to a less time-critical code path.
|
|
|
+//
|
|
|
+// Returns a negative error code on failure. Accomplishing nothing is not
|
|
|
+// an error.
|
|
|
+int lfs_fs_gc(lfs_t *lfs);
|
|
|
+#endif
|
|
|
+
|
|
|
#ifndef LFS_READONLY
|
|
|
// Grows the filesystem to a new size, updating the superblock with the new
|
|
|
// block count.
|