Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/littlefs-project/littlefs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lfs.c
diff options
context:
space:
mode:
authorNoah Gorny <noah@gittabags.com>2020-06-17 15:42:46 +0300
committerNoah Gorny <noah@gittabags.com>2020-11-19 02:51:39 +0300
commit4bd653dd006ec4568ebae6d710f30ff5d853ed8e (patch)
treeffc022cec2f02fa1756e0d7dc1f5e8be382f058d /lfs.c
parent4c9146ea539f72749d6cc3ea076372a81b12cb11 (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.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/lfs.c b/lfs.c
index eb832fa..2b179a6 100644
--- a/lfs.c
+++ b/lfs.c
@@ -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) {