Squished in-flight files/dirs into single list

This is an effort to try to consolidate the handling of in-flight files
and dirs opened by the user (and possibly opened internally). Both files
and dirs have metadata state that need to be kept in sync by the commit
logic.

This metadata state is mostly contained in the lfs_mdir_t type, which is
present in both the lfs_file_t and lfs_dir_t. Unfortunately both of
these structs have some relatively unrelated metadata that needs to be
kept in sync:
- Files store an id representing the open file
- Dirs store an id during iteration

While these take up the same space, they unfortunately need to be
managed differently by the commit logic.

The best solution I can come up with is to simple store a general
purpose list and tag both structures with LFS_TYPE_REG and LFS_TYPE_DIR
respectively. This is kinda funky, but wins out over duplicated the
commit logic.
This commit is contained in:
Christopher Haster
2018-08-01 10:24:59 -05:00
parent bd1e0c4059
commit 35f68d28cc
2 changed files with 472 additions and 456 deletions

45
lfs.h
View File

@@ -280,6 +280,12 @@ typedef struct lfs_mattr {
const struct lfs_mattr *next;
} lfs_mattr_t;
typedef struct lfs_cache {
lfs_block_t block;
lfs_off_t off;
uint8_t *buffer;
} lfs_cache_t;
typedef union lfs_global {
uint16_t u16[5];
} lfs_global_t;
@@ -288,24 +294,37 @@ typedef struct lfs_mdir {
lfs_block_t pair[2];
lfs_block_t tail[2];
uint32_t rev;
lfs_off_t off;
uint32_t etag;
lfs_off_t off;
uint16_t count;
bool erased;
bool split;
lfs_global_t locals;
} lfs_mdir_t;
typedef struct lfs_cache {
lfs_block_t block;
lfs_off_t off;
uint8_t *buffer;
} lfs_cache_t;
typedef struct lfs_mlist {
struct lfs_mlist *next;
uint16_t id;
uint8_t type;
lfs_mdir_t m;
} lfs_mlist_t;
typedef struct lfs_dir {
struct lfs_dir *next;
uint16_t id;
uint8_t type;
lfs_mdir_t m;
lfs_off_t pos;
lfs_block_t head[2];
} lfs_dir_t;
typedef struct lfs_file {
struct lfs_file *next;
uint16_t id;
lfs_block_t pair[2];
uint8_t type;
lfs_mdir_t m;
struct lfs_ctz {
lfs_block_t head;
lfs_size_t size;
@@ -320,15 +339,6 @@ typedef struct lfs_file {
const struct lfs_file_config *cfg;
} lfs_file_t;
typedef struct lfs_dir {
struct lfs_dir *next;
uint16_t id;
struct lfs_mdir m;
lfs_block_t head[2];
lfs_off_t pos;
} lfs_dir_t;
typedef struct lfs_superblock {
char magic[8];
uint32_t version;
@@ -355,8 +365,7 @@ typedef struct lfs {
lfs_cache_t pcache;
lfs_block_t root[2];
lfs_file_t *files;
lfs_dir_t *dirs;
lfs_mlist_t *mlist;
lfs_global_t globals;
lfs_global_t locals;