mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 16:14:16 +01:00 
			
		
		
		
	Assert that file/dir struct is not reused in lfs_file_opencfg/lfs_dir_open
This commit is contained in:
		
							
								
								
									
										14
									
								
								lfs.c
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								lfs.c
									
									
									
									
									
								
							| @@ -411,6 +411,17 @@ static inline void lfs_superblock_tole32(lfs_superblock_t *superblock) { | |||||||
|     superblock->attr_max    = lfs_tole32(superblock->attr_max); |     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 /// | /// Internal operations predeclared here /// | ||||||
| static int lfs_dir_commit(lfs_t *lfs, lfs_mdir_t *dir, | 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) { | 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_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); |     lfs_stag_t tag = lfs_dir_find(lfs, &dir->m, &path, NULL); | ||||||
|     if (tag < 0) { |     if (tag < 0) { | ||||||
|         LFS_TRACE("lfs_dir_open -> %"PRId32, tag); |         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"})", |                  ".buffer=%p, .attrs=%p, .attr_count=%"PRIu32"})", | ||||||
|             (void*)lfs, (void*)file, path, flags, |             (void*)lfs, (void*)file, path, flags, | ||||||
|             (void*)cfg, cfg->buffer, (void*)cfg->attrs, cfg->attr_count); |             (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 |     // deorphan if we haven't yet, needed at most once after poweron | ||||||
|     if ((flags & 3) != LFS_O_RDONLY) { |     if ((flags & 3) != LFS_O_RDONLY) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user