Added lfsr_mid_isopened to dedup zombie/orphan checks
I think this also makes the logic easier to read. Less temporary
variables.
code stack
before: 33816 2944
after: 33812 (-0.0%) 2944 (+0.0%)
This commit is contained in:
@@ -5144,6 +5144,18 @@ static void lfsr_removeopened(lfs_t *lfs, lfsr_opened_t *opened) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool lfsr_mid_isopened(lfs_t *lfs, lfsr_smid_t mid) {
|
||||||
|
for (lfsr_opened_t *p = lfs->opened; p; p = p->next) {
|
||||||
|
// we really only care about regular open files here, all
|
||||||
|
// others are either transient (dirs) or fake (orphans)
|
||||||
|
if (p->type == LFS_TYPE_REG && p->mdir.mid == mid) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Metadata-tree things ///
|
/// Metadata-tree things ///
|
||||||
@@ -8236,18 +8248,7 @@ static int lfsr_fs_fixorphans(lfs_t *lfs) {
|
|||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// is this mid opened? skip
|
// is this mid opened? skip
|
||||||
bool notopened = true;
|
if (!lfsr_mid_isopened(lfs, mdir.mid)) {
|
||||||
for (lfsr_opened_t *opened = lfs->opened;
|
|
||||||
opened;
|
|
||||||
opened = opened->next) {
|
|
||||||
if (opened->type == LFS_TYPE_REG
|
|
||||||
&& opened->mdir.mid == mdir.mid) {
|
|
||||||
notopened = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (notopened) {
|
|
||||||
// are we an orphaned file?
|
// are we an orphaned file?
|
||||||
err = lfsr_mdir_lookup(lfs, &mdir, mdir.mid, LFSR_TAG_ORPHAN,
|
err = lfsr_mdir_lookup(lfs, &mdir, mdir.mid, LFSR_TAG_ORPHAN,
|
||||||
NULL);
|
NULL);
|
||||||
@@ -8577,16 +8578,7 @@ int lfsr_remove(lfs_t *lfs, const char *path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// are we removing an opened file?
|
// are we removing an opened file?
|
||||||
bool zombie = false;
|
bool zombie = lfsr_mid_isopened(lfs, mdir.mid);
|
||||||
for (lfsr_opened_t *opened = lfs->opened;
|
|
||||||
opened;
|
|
||||||
opened = opened->next) {
|
|
||||||
if (opened->type == LFS_TYPE_REG
|
|
||||||
&& opened->mdir.mid == mdir.mid) {
|
|
||||||
zombie = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove the metadata entry
|
// remove the metadata entry
|
||||||
err = lfsr_mdir_commit(lfs, &mdir, LFSR_ATTRS(
|
err = lfsr_mdir_commit(lfs, &mdir, LFSR_ATTRS(
|
||||||
@@ -9376,23 +9368,11 @@ int lfsr_file_close(lfs_t *lfs, lfsr_file_t *file) {
|
|||||||
lfs_free(file->buffer);
|
lfs_free(file->buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// never synced?
|
|
||||||
if (lfsr_f_isorphan(file->flags)) {
|
|
||||||
// are we orphaning a file?
|
// are we orphaning a file?
|
||||||
//
|
//
|
||||||
// make sure we check _after_ removing ourselves
|
// make sure we check _after_ removing ourselves
|
||||||
bool orphaned = true;
|
if (lfsr_f_isorphan(file->flags)
|
||||||
for (lfsr_opened_t *opened = lfs->opened;
|
&& !lfsr_mid_isopened(lfs, file->mdir.mid)) {
|
||||||
opened;
|
|
||||||
opened = opened->next) {
|
|
||||||
if (opened->type == LFS_TYPE_REG
|
|
||||||
&& opened->mdir.mid == file->mdir.mid) {
|
|
||||||
orphaned = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (orphaned) {
|
|
||||||
// this gets a bit tricky, since we're not able to write to the
|
// this gets a bit tricky, since we're not able to write to the
|
||||||
// filesystem if we're rdonly or desynced, fortunately we have
|
// filesystem if we're rdonly or desynced, fortunately we have
|
||||||
// a few tricks
|
// a few tricks
|
||||||
@@ -9406,7 +9386,6 @@ int lfsr_file_close(lfs_t *lfs, lfsr_file_t *file) {
|
|||||||
lfs->hasorphans = true;
|
lfs->hasorphans = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user