Reverted most of dir offset changes, dirs to follow dstart when open
Unfortunately the previous attempt to fix the dir seek system didn't
really work. Using a packed mid/rid integer for the offset is tempting,
but since mid/rid can change with any metadata id change in the
filesystem, dir tell offsets would become invalidated if you modified
files in unrelated directories, which isn't great and likely to catch
users by surprise.
This solution builds on the previous dir offset design, which tracks the
dstart-relative position independently from the current mid/rid in our
directory. To update this correctly when there are unrelated changes to
the filesystem, we need to know if metadata id changes are in the range
between our directories dstart and current mid/rid. This in turn means
we need to track our dstart. So our opened directories need three
separate pointers we need to update on every mdir commit:
dir->pos
|
.-------+-------.
a b c d e f g h i j k l m n o p
^ ^
| |
dir->dstart dir->mdir
This has quite a few moving parts, which I was hoping to avoid.
Fortunately we don't need a second mdir, so the RAM cost is pretty
small.
We can also drop dir->did, since the dstart mid/rid render it redundant,
which is interesting.
This commit is contained in:
@@ -47,11 +47,6 @@ typedef uint32_t lfs_block_t;
|
||||
typedef uint16_t lfsr_tag_t;
|
||||
typedef int16_t lfsr_stag_t;
|
||||
|
||||
// mids are a tuple of bid (index in the mtree) and rid (index in the mdir)
|
||||
// shoved into an integer
|
||||
typedef lfs_size_t lfsr_mid_t;
|
||||
typedef lfs_ssize_t lfsr_smid_t;
|
||||
|
||||
// Maximum name size in bytes, may be redefined to reduce the size of the
|
||||
// info struct. Limited to <= 1022. Stored in superblock and must be
|
||||
// respected by other littlefs drivers.
|
||||
@@ -429,8 +424,9 @@ typedef struct lfs_dir {
|
||||
|
||||
typedef struct lfsr_dir {
|
||||
lfsr_openedmdir_t mdir;
|
||||
lfs_size_t did;
|
||||
uint8_t dots;
|
||||
lfs_ssize_t dstart_mid;
|
||||
lfs_ssize_t dstart_rid;
|
||||
lfs_off_t pos;
|
||||
} lfsr_dir_t;
|
||||
|
||||
// littlefs file type
|
||||
|
||||
Reference in New Issue
Block a user