diff options
author | Christopher Haster <chaster@utexas.edu> | 2018-07-28 17:47:57 +0300 |
---|---|---|
committer | Christopher Haster <chaster@utexas.edu> | 2018-10-16 14:00:18 +0300 |
commit | 392b2ac79f428affebf19a05234b01e461292fef (patch) | |
tree | 3f45531f93c32ad8f7366a07a03d89f2e41e0aa8 | |
parent | d9a24d0a2b7814ad8d7dabe9382301cd5c2c9ac8 (diff) |
Refactored the updates of in-flight files/dirs
Updated to account for changes as a result of commits/compacts. And
changed instances of iteration over both files and dirs to use a single
nested loop.
This does rely implicitly on the structure layout of dirs/files and
their location in lfs_t, which isn't great. But it gets the job done
with less code duplication.
-rw-r--r-- | lfs.c | 33 | ||||
-rw-r--r-- | lfs.h | 4 |
2 files changed, 16 insertions, 21 deletions
@@ -863,8 +863,6 @@ static int lfs_dir_compact(lfs_t *lfs, break; split: - // TODO update dirs that get split here? - // commit no longer fits, need to split dir, // drop caches and create tail lfs->pcache.block = 0xffffffff; @@ -923,6 +921,18 @@ relocate: } } + // update any dirs/files that are affected + for (int i = 0; i < 2; i++) { + for (lfs_file_t *f = ((lfs_file_t**)&lfs->files)[i]; f; f = f->next) { + if (lfs_paircmp(f->pair, dir->pair) == 0 && + f->id >= begin && f->id < end) { + f->pair[0] = dir->pair[0]; + f->pair[1] = dir->pair[1]; + f->id -= begin; + } + } + } + return 0; } @@ -1052,19 +1062,17 @@ compact: } // update any directories that are affected - // TODO what about pairs? what if we're splitting?? for (lfs_dir_t *d = lfs->dirs; d; d = d->next) { if (lfs_paircmp(d->m.pair, dir->pair) == 0) { d->m = *dir; if (d->id > lfs_tagid(deletetag)) { - d->id -= 1; d->pos -= 1; } } } - for (lfs_file_t *f = lfs->files; f; f = f->next) { - if (lfs_paircmp(f->pair, dir->pair) == 0) { + for (int i = 0; i < 2; i++) { + for (lfs_file_t *f = ((lfs_file_t**)&lfs->files)[i]; f; f = f->next) { if (f->id == lfs_tagid(deletetag)) { f->pair[0] = 0xffffffff; f->pair[1] = 0xffffffff; @@ -3186,8 +3194,6 @@ static int lfs_relocate(lfs_t *lfs, lfs->root[1] = newpair[1]; } - // TODO update dir list!!? - // clean up bad block, which should now be a desync return lfs_deorphan(lfs); } @@ -3212,17 +3218,6 @@ static int lfs_relocate(lfs_t *lfs, } } - // shift over any dirs/files that are affected - for (int i = 0; i < 2; i++) { - for (lfs_dir_t *d = ((void*[2]){lfs->dirs, lfs->files})[i]; - d; d = d->next) { - if (lfs_paircmp(d->m.pair, oldpair) == 0) { - d->m.pair[0] = newpair[0]; - d->m.pair[1] = newpair[1]; - } - } - } - return 0; } @@ -295,8 +295,8 @@ typedef struct lfs_cache { typedef struct lfs_file { struct lfs_file *next; - lfs_block_t pair[2]; uint16_t id; + lfs_block_t pair[2]; struct lfs_ctz { lfs_block_t head; lfs_size_t size; @@ -313,10 +313,10 @@ typedef struct lfs_file { typedef struct lfs_dir { struct lfs_dir *next; + uint16_t id; struct lfs_mdir m; lfs_block_t head[2]; - uint16_t id; lfs_off_t pos; } lfs_dir_t; |