mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 16:14:16 +01:00 
			
		
		
		
	Add lfs_mlist_append/remove helper
This commit is contained in:
		
				
					committed by
					
						 Christopher Haster
						Christopher Haster
					
				
			
			
				
	
			
			
			
						parent
						
							6303558aee
						
					
				
				
					commit
					008ebc37df
				
			
							
								
								
									
										34
									
								
								lfs.c
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								lfs.c
									
									
									
									
									
								
							| @@ -422,6 +422,20 @@ static inline bool lfs_mlist_isopen(struct lfs_mlist *head, | |||||||
|     return false; |     return false; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | static inline void lfs_mlist_remove(lfs_t *lfs, struct lfs_mlist *mlist) { | ||||||
|  |     for (struct lfs_mlist **p = &lfs->mlist; *p; p = &(*p)->next) { | ||||||
|  |         if (*p == mlist) { | ||||||
|  |             *p = (*p)->next; | ||||||
|  |             break; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | static inline void lfs_mlist_append(lfs_t *lfs, struct lfs_mlist *mlist) { | ||||||
|  |     mlist->next = lfs->mlist; | ||||||
|  |     lfs->mlist = mlist; | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| /// 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, | ||||||
| @@ -2062,8 +2076,7 @@ int lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path) { | |||||||
|  |  | ||||||
|     // add to list of mdirs |     // add to list of mdirs | ||||||
|     dir->type = LFS_TYPE_DIR; |     dir->type = LFS_TYPE_DIR; | ||||||
|     dir->next = (lfs_dir_t*)lfs->mlist; |     lfs_mlist_append(lfs, (struct lfs_mlist *)dir); | ||||||
|     lfs->mlist = (struct lfs_mlist*)dir; |  | ||||||
|  |  | ||||||
|     LFS_TRACE("lfs_dir_open -> %d", 0); |     LFS_TRACE("lfs_dir_open -> %d", 0); | ||||||
|     return 0; |     return 0; | ||||||
| @@ -2072,12 +2085,7 @@ int lfs_dir_open(lfs_t *lfs, lfs_dir_t *dir, const char *path) { | |||||||
| int lfs_dir_close(lfs_t *lfs, lfs_dir_t *dir) { | int lfs_dir_close(lfs_t *lfs, lfs_dir_t *dir) { | ||||||
|     LFS_TRACE("lfs_dir_close(%p, %p)", (void*)lfs, (void*)dir); |     LFS_TRACE("lfs_dir_close(%p, %p)", (void*)lfs, (void*)dir); | ||||||
|     // remove from list of mdirs |     // remove from list of mdirs | ||||||
|     for (struct lfs_mlist **p = &lfs->mlist; *p; p = &(*p)->next) { |     lfs_mlist_remove(lfs, (struct lfs_mlist *)dir); | ||||||
|         if (*p == (struct lfs_mlist*)dir) { |  | ||||||
|             *p = (*p)->next; |  | ||||||
|             break; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     LFS_TRACE("lfs_dir_close -> %d", 0); |     LFS_TRACE("lfs_dir_close -> %d", 0); | ||||||
|     return 0; |     return 0; | ||||||
| @@ -2428,8 +2436,7 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file, | |||||||
|  |  | ||||||
|     // get id, add to list of mdirs to catch update changes |     // get id, add to list of mdirs to catch update changes | ||||||
|     file->type = LFS_TYPE_REG; |     file->type = LFS_TYPE_REG; | ||||||
|     file->next = (lfs_file_t*)lfs->mlist; |     lfs_mlist_append(lfs, (struct lfs_mlist *)file); | ||||||
|     lfs->mlist = (struct lfs_mlist*)file; |  | ||||||
|  |  | ||||||
|     if (tag == LFS_ERR_NOENT) { |     if (tag == LFS_ERR_NOENT) { | ||||||
|         if (!(flags & LFS_O_CREAT)) { |         if (!(flags & LFS_O_CREAT)) { | ||||||
| @@ -2565,12 +2572,7 @@ int lfs_file_close(lfs_t *lfs, lfs_file_t *file) { | |||||||
|     int err = lfs_file_sync(lfs, file); |     int err = lfs_file_sync(lfs, file); | ||||||
|  |  | ||||||
|     // remove from list of mdirs |     // remove from list of mdirs | ||||||
|     for (struct lfs_mlist **p = &lfs->mlist; *p; p = &(*p)->next) { |     lfs_mlist_remove(lfs, (struct lfs_mlist*)file); | ||||||
|         if (*p == (struct lfs_mlist*)file) { |  | ||||||
|             *p = (*p)->next; |  | ||||||
|             break; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     // clean up memory |     // clean up memory | ||||||
|     if (!file->cfg->buffer) { |     if (!file->cfg->buffer) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user