Renamed LFSR_TAG_ORPHAN -> LFSR_TAG_STICKYNOTE

I've been unhappy with LFSR_TAG_ORPHAN for a while now. While it's true
these represent orphaned files, they also represent zombied files. And
as long as a reference to the file exists in-RAM, I find it hard to say
these files are truely "orphaned".

We're also just using the term "orphan" for too many things.

Really this tag just represents an mid reservation. The term stickynote
works well enough for this, and fits in with the other internal tag,
LFSR_TAG_BOOKMARK.
This commit is contained in:
Christopher Haster
2024-12-27 01:38:27 -06:00
parent 11115dbe81
commit 66bf005bb8
8 changed files with 67 additions and 65 deletions
+48 -46
View File
@@ -1378,7 +1378,7 @@ enum lfsr_tag {
LFSR_TAG_REG = 0x0201,
LFSR_TAG_DIR = 0x0202,
LFSR_TAG_BOOKMARK = 0x0204,
LFSR_TAG_ORPHAN = 0x0205,
LFSR_TAG_STICKYNOTE = 0x0205,
// struct tags
LFSR_TAG_STRUCT = 0x0300,
@@ -1490,7 +1490,7 @@ static inline bool lfsr_tag_isunknown(lfsr_tag_t tag) {
return tag != LFSR_TAG_REG
&& tag != LFSR_TAG_DIR
&& tag != LFSR_TAG_BOOKMARK
&& tag != LFSR_TAG_ORPHAN;
&& tag != LFSR_TAG_STICKYNOTE;
}
static inline bool lfsr_tag_isinternal(lfsr_tag_t tag) {
@@ -7701,14 +7701,15 @@ static int lfsr_mdir_lookupnext(lfs_t *lfs, const lfsr_mdir_t *mdir,
return LFS_ERR_NOENT;
}
// intercept pending grms here and pretend they're orphaned files
// intercept pending grms here and pretend they're orphaned
// stickynotes
//
// fortunately pending grms/orphaned files have roughly the same
// semantics, and it's easier to manage the implied mid gap in
// fortunately pending grms/orphaned stickynotes have roughly the
// same semantics, and it's easier to manage the implied mid gap in
// higher-levels
if (lfsr_tag_suptype(tag__) == LFSR_TAG_NAME
&& lfsr_grm_ismidrm(lfs, mdir->mid)) {
tag__ = LFSR_TAG_ORPHAN;
tag__ = LFSR_TAG_STICKYNOTE;
}
if (tag_) {
@@ -9411,13 +9412,14 @@ static int lfsr_mdir_namelookup(lfs_t *lfs, const lfsr_mdir_t *mdir,
mdir->mid,
(cmp < LFS_CMP_EQ) ? rid+1 : rid);
// intercept pending grms here and pretend they're orphaned files
// intercept pending grms here and pretend they're orphaned
// stickynotes
//
// fortunately pending grms/orphaned files have roughly the same
// semantics, and it's easier to manage the implied mid gap in
// fortunately pending grms/orphaned stickynotes have roughly the
// same semantics, and it's easier to manage the implied mid gap in
// higher-levels
if (lfsr_grm_ismidrm(lfs, mid)) {
tag = LFSR_TAG_ORPHAN;
tag = LFSR_TAG_STICKYNOTE;
}
if (mid_) {
@@ -9600,7 +9602,7 @@ static int lfsr_mtree_pathlookup(lfs_t *lfs, const char **path,
// only continue if we hit a directory
if (tag != LFSR_TAG_DIR) {
return (tag == LFSR_TAG_ORPHAN)
return (tag == LFSR_TAG_STICKYNOTE)
? LFS_ERR_NOENT
: LFS_ERR_NOTDIR;
}
@@ -10376,9 +10378,9 @@ int lfsr_mkdir(lfs_t *lfs, const char *path) {
if (err && !(err == LFS_ERR_NOENT && lfsr_path_islast(path))) {
return err;
}
// already exists? orphans don't really exist
// already exists? stickynotes don't really exist
bool exists = (err != LFS_ERR_NOENT);
if (exists && tag != LFSR_TAG_ORPHAN) {
if (exists && tag != LFSR_TAG_STICKYNOTE) {
return LFS_ERR_EXIST;
}
@@ -10600,8 +10602,8 @@ int lfsr_remove(lfs_t *lfs, const char *path) {
if (err) {
return err;
}
// orphans don't really exist
if (tag == LFSR_TAG_ORPHAN) {
// stickynotes don't really exist
if (tag == LFSR_TAG_STICKYNOTE) {
return LFS_ERR_NOENT;
}
@@ -10640,13 +10642,13 @@ int lfsr_remove(lfs_t *lfs, const char *path) {
// remove the metadata entry
lfs_alloc_ckpoint(lfs);
err = lfsr_mdir_commit(lfs, &mdir, LFSR_RATS(
// create an orphan if zombied
// create a stickynote if zombied
//
// we use a create+delete here to also clear any rats
// and trim the entry size
(zombie)
? LFSR_RAT_NAME(
LFSR_TAG_SUP | LFSR_TAG_ORPHAN, 0,
LFSR_TAG_SUP | LFSR_TAG_STICKYNOTE, 0,
did, path, lfsr_path_namelen(path))
: LFSR_RAT(
LFSR_TAG_RM, -1, LFSR_DATA_NULL())));
@@ -10719,8 +10721,8 @@ int lfsr_rename(lfs_t *lfs, const char *old_path, const char *new_path) {
if (err) {
return err;
}
// orphans don't really exist
if (old_tag == LFSR_TAG_ORPHAN) {
// stickynotes don't really exist
if (old_tag == LFSR_TAG_STICKYNOTE) {
return LFS_ERR_NOENT;
}
@@ -10763,8 +10765,8 @@ int lfsr_rename(lfs_t *lfs, const char *old_path, const char *new_path) {
// renaming different types is an error
//
// unless we found a orphan, these don't really exist
if (old_tag != new_tag && new_tag != LFSR_TAG_ORPHAN) {
// unless we found a stickynote, these don't really exist
if (old_tag != new_tag && new_tag != LFSR_TAG_STICKYNOTE) {
return (new_tag == LFSR_TAG_DIR)
? LFS_ERR_ISDIR
: LFS_ERR_NOTDIR;
@@ -10931,8 +10933,8 @@ int lfsr_stat(lfs_t *lfs, const char *path, struct lfs_info *info) {
if (err) {
return err;
}
// orphans don't really exist
if (tag == LFSR_TAG_ORPHAN) {
// stickynotes don't really exist
if (tag == LFSR_TAG_STICKYNOTE) {
return LFS_ERR_NOENT;
}
@@ -10968,8 +10970,8 @@ int lfsr_dir_open(lfs_t *lfs, lfsr_dir_t *dir, const char *path) {
if (err) {
return err;
}
// orphans don't really exist
if (tag == LFSR_TAG_ORPHAN) {
// stickynotes don't really exist
if (tag == LFSR_TAG_STICKYNOTE) {
return LFS_ERR_NOENT;
}
@@ -11071,8 +11073,8 @@ int lfsr_dir_read(lfs_t *lfs, lfsr_dir_t *dir, struct lfs_info *info) {
return LFS_ERR_NOENT;
}
// skip orphans, we pretend these don't exist
if (tag == LFSR_TAG_ORPHAN) {
// skip stickynotes, we pretend these don't exist
if (tag == LFSR_TAG_STICKYNOTE) {
dir->o.mdir.mid += 1;
dir->pos += 1;
continue;
@@ -11184,8 +11186,8 @@ static int lfsr_lookupattr(lfs_t *lfs, const char *path, uint8_t type,
if (err) {
return err;
}
// orphans don't really exist
if (tag == LFSR_TAG_ORPHAN) {
// stickynotes don't really exist
if (tag == LFSR_TAG_STICKYNOTE) {
return LFS_ERR_NOENT;
}
@@ -11563,7 +11565,7 @@ int lfsr_file_opencfg(lfs_t *lfs, lfsr_file_t *file,
}
// creating a new entry?
if (err == LFS_ERR_NOENT || tag == LFSR_TAG_ORPHAN) {
if (err == LFS_ERR_NOENT || tag == LFSR_TAG_STICKYNOTE) {
if (!lfsr_o_iscreat(flags)) {
return LFS_ERR_NOENT;
}
@@ -11580,13 +11582,13 @@ int lfsr_file_opencfg(lfs_t *lfs, lfsr_file_t *file,
return LFS_ERR_NAMETOOLONG;
}
// create an orphan entry if we don't have one, this reserves the
// create a stickynote entry if we don't have one, this reserves the
// mid until first sync
if (err == LFS_ERR_NOENT) {
lfs_alloc_ckpoint(lfs);
err = lfsr_mdir_commit(lfs, &file->o.o.mdir, LFSR_RATS(
LFSR_RAT_NAME(
LFSR_TAG_ORPHAN, +1,
LFSR_TAG_STICKYNOTE, +1,
did, path, name_len)));
if (err) {
return err;
@@ -13029,10 +13031,10 @@ int lfsr_file_sync(lfs_t *lfs, lfsr_file_t *file) {
// not created yet? need to convert orphan to normal file
if (lfsr_o_isorphan(file->o.o.flags)) {
err = lfsr_mdir_lookup(lfs, &file->o.o.mdir, LFSR_TAG_ORPHAN,
err = lfsr_mdir_lookup(lfs, &file->o.o.mdir, LFSR_TAG_STICKYNOTE,
&name_data);
if (err) {
// orphan flag but no orphan tag?
// orphan flag but no stickynote tag?
LFS_ASSERT(err != LFS_ERR_NOENT);
goto failed;
}
@@ -14348,8 +14350,8 @@ static int lfsr_mountinited(lfs_t *lfs) {
return err;
}
// check for any orphaned files, note we only need this if
// filesystem will be writable
// check for any orphaned stickynotes, note we only need
// this if filesystem will be writable
if (!lfsr_m_isrdonly(lfs->flags)) {
for (lfs_size_t rid = 0;
rid < mdir->rbyd.weight;
@@ -14365,9 +14367,9 @@ static int lfsr_mountinited(lfs_t *lfs) {
// name 0 should be reserved
LFS_ASSERT(tag != (LFSR_TAG_NAME + 0));
// found an orphaned file?
if (tag == LFSR_TAG_ORPHAN) {
LFS_DEBUG("Found orphan "
// found an orphaned stickynote?
if (tag == LFSR_TAG_STICKYNOTE) {
LFS_DEBUG("Found orphaned stickynote "
"%"PRId32".%"PRId32,
lfsr_mid_bid(lfs, mdir->mid) >> lfs->mdir_bits,
rid);
@@ -14787,8 +14789,8 @@ static int lfsr_fs_fixorphans_(lfs_t *lfs, lfsr_mdir_t *mdir) {
continue;
}
// is this mid marked as an orphan?
err = lfsr_mdir_lookup(lfs, mdir, LFSR_TAG_ORPHAN,
// is this mid marked as a stickynote?
err = lfsr_mdir_lookup(lfs, mdir, LFSR_TAG_STICKYNOTE,
NULL);
if (err) {
if (err == LFS_ERR_NOENT) {
@@ -14798,8 +14800,8 @@ static int lfsr_fs_fixorphans_(lfs_t *lfs, lfsr_mdir_t *mdir) {
goto failed;
}
// we found an orphaned file, remove
LFS_DEBUG("Fixing orphan %"PRId32".%"PRId32,
// we found an orphaned stickynote, remove
LFS_DEBUG("Fixing orphaned stickynote %"PRId32".%"PRId32,
lfsr_mid_bid(lfs, mdir->mid) >> lfs->mdir_bits,
lfsr_mid_rid(lfs, mdir->mid));
@@ -14864,10 +14866,10 @@ int lfsr_fs_mkconsistent(lfs_t *lfs) {
}
}
// fix orphaned files
// fix orphaned stickynotes
//
// this must happen after fixgrm, since removing orphaned files risks
// outdating the grm
// this must happen after fixgrm, since removing orphaned
// stickynotes risks outdating the grm
//
if (lfsr_i_hasorphans(lfs->flags)) {
LFS_DEBUG("Fixing orphans...");
+1 -1
View File
@@ -121,7 +121,7 @@ enum lfs_type {
// internally used types, don't use these
LFS_TYPE_BOOKMARK = 4,
LFS_TYPE_ORPHAN = 5,
LFS_TYPE_STICKYNOTE = 5,
LFS_TYPE_TRAVERSAL = 9,
};
+1 -1
View File
@@ -30,7 +30,7 @@ TAG_NAME = 0x0200 ## 0x02tt v--- --1- -ttt tttt
TAG_REG = 0x0201 # 0x0201 v--- --1- ---- ---1
TAG_DIR = 0x0202 # 0x0202 v--- --1- ---- --1-
TAG_BOOKMARK = 0x0204 # 0x0204 v--- --1- ---- -1--
TAG_ORPHAN = 0x0205 # 0x0205 v--- --1- ---- -1-1
TAG_STICKYNOTE = 0x0205 # 0x0205 v--- --1- ---- -1-1
TAG_STRUCT = 0x0300 ## 0x03tt v--- --11 -ttt tttt
TAG_DATA = 0x0300 # 0x0300 v--- --11 ---- ----
TAG_BLOCK = 0x0304 # 0x0304 v--- --11 ---- -1rr
+2 -2
View File
@@ -28,7 +28,7 @@ TAG_NAME = 0x0200 ## 0x02tt v--- --1- -ttt tttt
TAG_REG = 0x0201 # 0x0201 v--- --1- ---- ---1
TAG_DIR = 0x0202 # 0x0202 v--- --1- ---- --1-
TAG_BOOKMARK = 0x0204 # 0x0204 v--- --1- ---- -1--
TAG_ORPHAN = 0x0205 # 0x0205 v--- --1- ---- -1-1
TAG_STICKYNOTE = 0x0205 # 0x0205 v--- --1- ---- -1-1
TAG_STRUCT = 0x0300 ## 0x03tt v--- --11 -ttt tttt
TAG_DATA = 0x0300 # 0x0300 v--- --11 ---- ----
TAG_BLOCK = 0x0304 # 0x0304 v--- --11 ---- -1rr
@@ -198,8 +198,8 @@ def tagrepr(tag, w=None, size=None, off=None):
'name' if (tag & 0xfff) == TAG_NAME
else 'reg' if (tag & 0xfff) == TAG_REG
else 'dir' if (tag & 0xfff) == TAG_DIR
else 'orphan' if (tag & 0xfff) == TAG_ORPHAN
else 'bookmark' if (tag & 0xfff) == TAG_BOOKMARK
else 'stickynote' if (tag & 0xfff) == TAG_STICKYNOTE
else 'name 0x%02x' % (tag & 0xff),
' w%d' % w if w else '',
' %s' % size if size is not None else '')
+9 -9
View File
@@ -29,7 +29,7 @@ TAG_NAME = 0x0200 ## 0x02tt v--- --1- -ttt tttt
TAG_REG = 0x0201 # 0x0201 v--- --1- ---- ---1
TAG_DIR = 0x0202 # 0x0202 v--- --1- ---- --1-
TAG_BOOKMARK = 0x0204 # 0x0204 v--- --1- ---- -1--
TAG_ORPHAN = 0x0205 # 0x0205 v--- --1- ---- -1-1
TAG_STICKYNOTE = 0x0205 # 0x0205 v--- --1- ---- -1-1
TAG_STRUCT = 0x0300 ## 0x03tt v--- --11 -ttt tttt
TAG_DATA = 0x0300 # 0x0300 v--- --11 ---- ----
TAG_BLOCK = 0x0304 # 0x0304 v--- --11 ---- -1rr
@@ -229,8 +229,8 @@ def tagrepr(tag, w=None, size=None, off=None):
'name' if (tag & 0xfff) == TAG_NAME
else 'reg' if (tag & 0xfff) == TAG_REG
else 'dir' if (tag & 0xfff) == TAG_DIR
else 'orphan' if (tag & 0xfff) == TAG_ORPHAN
else 'bookmark' if (tag & 0xfff) == TAG_BOOKMARK
else 'stickynote' if (tag & 0xfff) == TAG_STICKYNOTE
else 'name 0x%02x' % (tag & 0xff),
' w%d' % w if w else '',
' %s' % size if size is not None else '')
@@ -1251,7 +1251,7 @@ class GState:
yield grepr(tag, data), tag, data
def frepr(mdir, rid, tag):
if tag == TAG_REG or tag == TAG_ORPHAN:
if tag == TAG_REG or tag == TAG_STICKYNOTE:
size = 0
structs = []
# inlined data?
@@ -1278,7 +1278,7 @@ def frepr(mdir, rid, tag):
size = max(size, weight)
structs.append('btree 0x%x.%x' % (block, trunk))
return '%s %s' % (
'orphan' if tag == TAG_ORPHAN else 'reg',
'stickynote' if tag == TAG_STICKYNOTE else 'reg',
', '.join(it.chain(['%d' % size], structs)))
elif tag == TAG_DIR:
@@ -2046,8 +2046,8 @@ def main(disk, mroots=None, *,
# skip bookmarks
if tag == TAG_BOOKMARK:
continue
# skip orphans
if tag == TAG_ORPHAN:
# skip stickynotes
if tag == TAG_STICKYNOTE:
continue
# skip grmed entries
if (max(mbid-max(mw-1, 0), 0), rid) in gstate.grm:
@@ -2099,7 +2099,7 @@ def main(disk, mroots=None, *,
else '\x1b[90m'
if color and (grmed
or tag == TAG_BOOKMARK
or tag == TAG_ORPHAN)
or tag == TAG_STICKYNOTE)
else '',
'{%s}:' % ','.join('%04x' % block
for block in mdir.blocks)
@@ -2119,7 +2119,7 @@ def main(disk, mroots=None, *,
notes
or grmed
or tag == TAG_BOOKMARK
or tag == TAG_ORPHAN)
or tag == TAG_STICKYNOTE)
else ''))
pmbid = mbid
@@ -2156,7 +2156,7 @@ def main(disk, mroots=None, *,
line))
# print file contents?
if ((tag == TAG_REG or tag == TAG_ORPHAN)
if ((tag == TAG_REG or tag == TAG_STICKYNOTE)
and args.get('structs')):
# inlined sprout?
done, rid_, tag_, w_, j, d, data, _ = mdir.lookup(
+2 -2
View File
@@ -28,7 +28,7 @@ TAG_NAME = 0x0200 ## 0x02tt v--- --1- -ttt tttt
TAG_REG = 0x0201 # 0x0201 v--- --1- ---- ---1
TAG_DIR = 0x0202 # 0x0202 v--- --1- ---- --1-
TAG_BOOKMARK = 0x0204 # 0x0204 v--- --1- ---- -1--
TAG_ORPHAN = 0x0205 # 0x0205 v--- --1- ---- -1-1
TAG_STICKYNOTE = 0x0205 # 0x0205 v--- --1- ---- -1-1
TAG_STRUCT = 0x0300 ## 0x03tt v--- --11 -ttt tttt
TAG_DATA = 0x0300 # 0x0300 v--- --11 ---- ----
TAG_BLOCK = 0x0304 # 0x0304 v--- --11 ---- -1rr
@@ -213,8 +213,8 @@ def tagrepr(tag, w=None, size=None, off=None):
'name' if (tag & 0xfff) == TAG_NAME
else 'reg' if (tag & 0xfff) == TAG_REG
else 'dir' if (tag & 0xfff) == TAG_DIR
else 'orphan' if (tag & 0xfff) == TAG_ORPHAN
else 'bookmark' if (tag & 0xfff) == TAG_BOOKMARK
else 'stickynote' if (tag & 0xfff) == TAG_STICKYNOTE
else 'name 0x%02x' % (tag & 0xff),
' w%d' % w if w else '',
' %s' % size if size is not None else '')
+2 -2
View File
@@ -38,7 +38,7 @@ TAG_NAME = 0x0200 ## 0x02tt v--- --1- -ttt tttt
TAG_REG = 0x0201 # 0x0201 v--- --1- ---- ---1
TAG_DIR = 0x0202 # 0x0202 v--- --1- ---- --1-
TAG_BOOKMARK = 0x0204 # 0x0204 v--- --1- ---- -1--
TAG_ORPHAN = 0x0205 # 0x0205 v--- --1- ---- -1-1
TAG_STICKYNOTE = 0x0205 # 0x0205 v--- --1- ---- -1-1
TAG_STRUCT = 0x0300 ## 0x03tt v--- --11 -ttt tttt
TAG_DATA = 0x0300 # 0x0300 v--- --11 ---- ----
TAG_BLOCK = 0x0304 # 0x0304 v--- --11 ---- -1rr
@@ -201,8 +201,8 @@ def tagrepr(tag, w=None, size=None, off=None):
'name' if (tag & 0xfff) == TAG_NAME
else 'reg' if (tag & 0xfff) == TAG_REG
else 'dir' if (tag & 0xfff) == TAG_DIR
else 'orphan' if (tag & 0xfff) == TAG_ORPHAN
else 'bookmark' if (tag & 0xfff) == TAG_BOOKMARK
else 'stickynote' if (tag & 0xfff) == TAG_STICKYNOTE
else 'name 0x%02x' % (tag & 0xff),
' w%d' % w if w else '',
' %s' % size if size is not None else '')
+2 -2
View File
@@ -26,7 +26,7 @@ TAG_NAME = 0x0200 ## 0x02tt v--- --1- -ttt tttt
TAG_REG = 0x0201 # 0x0201 v--- --1- ---- ---1
TAG_DIR = 0x0202 # 0x0202 v--- --1- ---- --1-
TAG_BOOKMARK = 0x0204 # 0x0204 v--- --1- ---- -1--
TAG_ORPHAN = 0x0205 # 0x0205 v--- --1- ---- -1-1
TAG_STICKYNOTE = 0x0205 # 0x0205 v--- --1- ---- -1-1
TAG_STRUCT = 0x0300 ## 0x03tt v--- --11 -ttt tttt
TAG_DATA = 0x0300 # 0x0300 v--- --11 ---- ----
TAG_BLOCK = 0x0304 # 0x0304 v--- --11 ---- -1rr
@@ -155,8 +155,8 @@ def tagrepr(tag, w=None, size=None, off=None):
'name' if (tag & 0xfff) == TAG_NAME
else 'reg' if (tag & 0xfff) == TAG_REG
else 'dir' if (tag & 0xfff) == TAG_DIR
else 'orphan' if (tag & 0xfff) == TAG_ORPHAN
else 'bookmark' if (tag & 0xfff) == TAG_BOOKMARK
else 'stickynote' if (tag & 0xfff) == TAG_STICKYNOTE
else 'name 0x%02x' % (tag & 0xff),
' w%d' % w if w else '',
' %s' % size if size is not None else '')