Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/littlefs-project/littlefs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lfs.h
diff options
context:
space:
mode:
authorChristopher Haster <chaster@utexas.edu>2017-04-30 19:19:37 +0300
committerChristopher Haster <chaster@utexas.edu>2017-05-08 08:44:54 +0300
commit4808e9ae26ad7dad71c729173d3cf0f5cdf9a008 (patch)
tree046fb3494de3efa8edb36847a75e0faef33b4f08 /lfs.h
parent6869b14694aaef4b46ba957385bd3773ae3ffc7c (diff)
Added caching with managed caches at the file level
This adds a fully independent layer between the rest of the filesystem and the block device. This requires some additionally logic around cache invalidation and flushing, but removes the need for any higher layer to consider read/write sizes less than what is supported by the hardware. Additionally, these caches can be used for possible speed improvements. This is left up to the user to optimize for their use cases. For very limited embedded systems with byte-level read/writes, the caches could be omitted completely, or they could even be the size of a full block for minimizing storage access. (A full block may not be the best for speed, consider if only a small portion of the read block is used, but I'll leave that evaluation as an exercise for any consumers of this library)
Diffstat (limited to 'lfs.h')
-rw-r--r--lfs.h65
1 files changed, 38 insertions, 27 deletions
diff --git a/lfs.h b/lfs.h
index a1017f5..c7a9759 100644
--- a/lfs.h
+++ b/lfs.h
@@ -47,15 +47,19 @@ enum lfs_type {
};
enum lfs_open_flags {
- LFS_O_RDONLY = 0,
- LFS_O_WRONLY = 1,
- LFS_O_RDWR = 2,
- LFS_O_CREAT = 0x020,
- LFS_O_EXCL = 0x040,
- LFS_O_TRUNC = 0x080,
- LFS_O_APPEND = 0x100,
- LFS_O_SYNC = 0x200,
- LFS_O_DIRTY = 0x10000,
+ // open flags
+ LFS_O_RDONLY = 1,
+ LFS_O_WRONLY = 2,
+ LFS_O_RDWR = 3,
+ LFS_O_CREAT = 0x0100,
+ LFS_O_EXCL = 0x0200,
+ LFS_O_TRUNC = 0x0400,
+ LFS_O_APPEND = 0x0800,
+
+ // internally used flags
+ LFS_F_DIRTY = 0x10000,
+ LFS_F_WRITING = 0x20000,
+ LFS_F_READING = 0x40000,
};
enum lfs_whence_flags {
@@ -112,6 +116,10 @@ struct lfs_config {
// Optional, statically allocated lookahead buffer.
// Must be 1 bit per lookahead block.
void *lookahead_buffer;
+
+ // Optional, statically allocated buffer for files. Must be program sized.
+ // If enabled, only one file may be opened at a time
+ void *file_buffer;
};
// File info structure
@@ -144,21 +152,25 @@ typedef struct lfs_entry {
} d;
} lfs_entry_t;
+typedef struct lfs_cache {
+ lfs_block_t block;
+ lfs_off_t off;
+ uint8_t *buffer;
+} lfs_cache_t;
+
typedef struct lfs_file {
struct lfs_file *next;
lfs_block_t pair[2];
- lfs_off_t off;
+ lfs_off_t poff;
+
lfs_block_t head;
lfs_size_t size;
uint32_t flags;
lfs_off_t pos;
-
- lfs_block_t wblock;
- lfs_off_t woff;
-
- lfs_block_t rblock;
- lfs_off_t roff;
+ lfs_block_t block;
+ lfs_off_t off;
+ lfs_cache_t cache;
} lfs_file_t;
typedef struct lfs_dir {
@@ -189,6 +201,12 @@ typedef struct lfs_superblock {
} d;
} lfs_superblock_t;
+typedef struct lfs_free {
+ lfs_block_t start;
+ lfs_block_t off;
+ uint32_t *lookahead;
+} lfs_free_t;
+
// littlefs type
typedef struct lfs {
const struct lfs_config *cfg;
@@ -198,17 +216,10 @@ typedef struct lfs {
lfs_dir_t *scratch;
lfs_file_t *files;
- struct {
- lfs_block_t block;
- lfs_off_t off;
- uint8_t *buffer;
- } rcache, pcache;
-
- struct {
- lfs_block_t start;
- lfs_block_t off;
- uint32_t *lookahead;
- } free;
+ lfs_cache_t rcache;
+ lfs_cache_t pcache;
+
+ lfs_free_t free;
} lfs_t;