diff options
author | Noah Gorny <noah@gittabags.com> | 2020-06-17 15:42:46 +0300 |
---|---|---|
committer | Noah Gorny <noah@gittabags.com> | 2020-11-19 02:51:39 +0300 |
commit | 4bd653dd006ec4568ebae6d710f30ff5d853ed8e (patch) | |
tree | ffc022cec2f02fa1756e0d7dc1f5e8be382f058d /lfs.c | |
parent | 4c9146ea539f72749d6cc3ea076372a81b12cb11 (diff) |
Assert that file/dir struct is not reused in lfs_file_opencfg/lfs_dir_open
Diffstat (limited to 'lfs.c')
-rw-r--r-- | lfs.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -411,6 +411,17 @@ static inline void lfs_superblock_tole32(lfs_superblock_t *superblock) { superblock->attr_max = lfs_tole32(superblock->attr_max); } +static inline bool lfs_mlist_isopen(struct lfs_mlist *head, + struct lfs_mlist *node) { + for (struct lfs_mlist **p = &head; *p; p = &(*p)->next) { + if (*p == (struct lfs_mlist*)node) { + return true; + } + } + + return false; +} + /// Internal operations predeclared here /// static int lfs_dir_commit(lfs_t *lfs, lfs_mdir_t *dir, @@ -2007,6 +2018,8 @@ int lfs_mkdir(lfs_t *lfs, const char *path) { int lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path) { LFS_TRACE("lfs_dir_open(%p, %p, \"%s\")", (void*)lfs, (void*)dir, path); + LFS_ASSERT(!lfs_mlist_isopen(lfs->mlist, (struct lfs_mlist*)dir)); + lfs_stag_t tag = lfs_dir_find(lfs, &dir->m, &path, NULL); if (tag < 0) { LFS_TRACE("lfs_dir_open -> %"PRId32, tag); @@ -2387,6 +2400,7 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file, ".buffer=%p, .attrs=%p, .attr_count=%"PRIu32"})", (void*)lfs, (void*)file, path, flags, (void*)cfg, cfg->buffer, (void*)cfg->attrs, cfg->attr_count); + LFS_ASSERT(!lfs_mlist_isopen(lfs->mlist, (struct lfs_mlist*)file)); // deorphan if we haven't yet, needed at most once after poweron if ((flags & 3) != LFS_O_RDONLY) { |