mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 16:14:16 +01:00 
			
		
		
		
	WIP Refactor file/dir iteration for dir update checks
This commit is contained in:
		
							
								
								
									
										33
									
								
								lfs.c
									
									
									
									
									
								
							
							
						
						
									
										33
									
								
								lfs.c
									
									
									
									
									
								
							| @@ -863,8 +863,6 @@ static int lfs_dir_compact(lfs_t *lfs, | ||||
|         break; | ||||
|  | ||||
| split: | ||||
|         // TODO update dirs that get split here? | ||||
|  | ||||
|         // commit no longer fits, need to split dir, | ||||
|         // drop caches and create tail | ||||
|         lfs->pcache.block = 0xffffffff; | ||||
| @@ -923,6 +921,18 @@ relocate: | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // update any dirs/files that are affected | ||||
|     for (int i = 0; i < 2; i++) { | ||||
|         for (lfs_file_t *f = ((lfs_file_t**)&lfs->files)[i]; f; f = f->next) { | ||||
|             if (lfs_paircmp(f->pair, dir->pair) == 0 && | ||||
|                     f->id >= begin && f->id < end) { | ||||
|                 f->pair[0] = dir->pair[0]; | ||||
|                 f->pair[1] = dir->pair[1]; | ||||
|                 f->id -= begin; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     return 0; | ||||
| } | ||||
|  | ||||
| @@ -1052,19 +1062,17 @@ compact: | ||||
|     } | ||||
|  | ||||
|     // update any directories that are affected | ||||
|     // TODO what about pairs? what if we're splitting?? | ||||
|     for (lfs_dir_t *d = lfs->dirs; d; d = d->next) { | ||||
|         if (lfs_paircmp(d->m.pair, dir->pair) == 0) { | ||||
|             d->m = *dir; | ||||
|             if (d->id > lfs_tagid(deletetag)) { | ||||
|                 d->id -= 1; | ||||
|                 d->pos -= 1; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     for (lfs_file_t *f = lfs->files; f; f = f->next) { | ||||
|         if (lfs_paircmp(f->pair, dir->pair) == 0) { | ||||
|     for (int i = 0; i < 2; i++) { | ||||
|         for (lfs_file_t *f = ((lfs_file_t**)&lfs->files)[i]; f; f = f->next) { | ||||
|             if (f->id == lfs_tagid(deletetag)) { | ||||
|                 f->pair[0] = 0xffffffff; | ||||
|                 f->pair[1] = 0xffffffff; | ||||
| @@ -3186,8 +3194,6 @@ static int lfs_relocate(lfs_t *lfs, | ||||
|             lfs->root[1] = newpair[1]; | ||||
|         } | ||||
|  | ||||
|         // TODO update dir list!!? | ||||
|  | ||||
|         // clean up bad block, which should now be a desync | ||||
|         return lfs_deorphan(lfs); | ||||
|     } | ||||
| @@ -3212,17 +3218,6 @@ static int lfs_relocate(lfs_t *lfs, | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     // shift over any dirs/files that are affected | ||||
|     for (int i = 0; i < 2; i++) { | ||||
|         for (lfs_dir_t *d = ((void*[2]){lfs->dirs, lfs->files})[i]; | ||||
|                 d; d = d->next) { | ||||
|             if (lfs_paircmp(d->m.pair, oldpair) == 0) { | ||||
|                 d->m.pair[0] = newpair[0]; | ||||
|                 d->m.pair[1] = newpair[1]; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     return 0; | ||||
| } | ||||
|  | ||||
|   | ||||
							
								
								
									
										4
									
								
								lfs.h
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								lfs.h
									
									
									
									
									
								
							| @@ -295,8 +295,8 @@ typedef struct lfs_cache { | ||||
|  | ||||
| typedef struct lfs_file { | ||||
|     struct lfs_file *next; | ||||
|     lfs_block_t pair[2]; | ||||
|     uint16_t id; | ||||
|     lfs_block_t pair[2]; | ||||
|     struct lfs_ctz { | ||||
|         lfs_block_t head; | ||||
|         lfs_size_t size; | ||||
| @@ -313,10 +313,10 @@ typedef struct lfs_file { | ||||
|  | ||||
| typedef struct lfs_dir { | ||||
|     struct lfs_dir *next; | ||||
|     uint16_t id; | ||||
|     struct lfs_mdir m; | ||||
|  | ||||
|     lfs_block_t head[2]; | ||||
|     uint16_t id; | ||||
|     lfs_off_t pos; | ||||
| } lfs_dir_t; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user