mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 00:32:38 +01:00 
			
		
		
		
	Fixed the orphan test to handle logging metadata-pairs
The main issue here was that the old orphan test relied on deleting the block that contained the most recent update. In the new design this doesn't really work since updates get appended to metadata-pairs incrementally. This is fixed by instead using the truncate command on the appropriate block. We're now passing orphan tests.
This commit is contained in:
		
							
								
								
									
										42
									
								
								lfs.c
									
									
									
									
									
								
							
							
						
						
									
										42
									
								
								lfs.c
									
									
									
									
									
								
							| @@ -3255,6 +3255,12 @@ int lfs_fs_traverse(lfs_t *lfs, int (*cb)(void*, lfs_block_t), void *data) { | ||||
| } | ||||
| */ | ||||
| static int lfs_pred(lfs_t *lfs, const lfs_block_t pair[2], lfs_mdir_t *pdir) { | ||||
|     if (lfs_pairisnull(lfs->root)) { | ||||
|         // TODO best place for this? | ||||
|         // TODO needed for relocate | ||||
|         return LFS_ERR_NOENT; | ||||
|     } | ||||
|  | ||||
|     // iterate over all directory directory entries | ||||
|     pdir->tail[0] = 0; | ||||
|     pdir->tail[1] = 1; | ||||
| @@ -3275,6 +3281,11 @@ static int lfs_pred(lfs_t *lfs, const lfs_block_t pair[2], lfs_mdir_t *pdir) { | ||||
|  | ||||
| static int32_t lfs_parent(lfs_t *lfs, const lfs_block_t pair[2], | ||||
|         lfs_mdir_t *parent) { | ||||
|     if (lfs_pairisnull(lfs->root)) { | ||||
|         // TODO best place for this? | ||||
|         return LFS_ERR_NOENT; | ||||
|     } | ||||
|  | ||||
|     // search for both orderings so we can reuse the find function | ||||
|     lfs_block_t child[2] = {pair[0], pair[1]}; | ||||
|  | ||||
| @@ -3531,18 +3542,19 @@ int lfs_deorphan(lfs_t *lfs) { | ||||
| //    return lfs_dir_setattrs(lfs, &dir, &entry, attrs, count); | ||||
| //} | ||||
|  | ||||
| //static int lfs_fs_size_count(void *p, lfs_block_t block) { | ||||
| //    lfs_size_t *size = p; | ||||
| //    *size += 1; | ||||
| //    return 0; | ||||
| //} | ||||
| // | ||||
| //lfs_ssize_t lfs_fs_size(lfs_t *lfs) { | ||||
| //    lfs_size_t size = 0; | ||||
| //    int err = lfs_fs_traverse(lfs, lfs_fs_size_count, &size); | ||||
| //    if (err) { | ||||
| //        return err; | ||||
| //    } | ||||
| // | ||||
| //    return size; | ||||
| //} | ||||
| // TODO need lfs? | ||||
| static int lfs_fs_size_count(lfs_t *lfs, void *p, lfs_block_t block) { | ||||
|     lfs_size_t *size = p; | ||||
|     *size += 1; | ||||
|     return 0; | ||||
| } | ||||
|  | ||||
| lfs_ssize_t lfs_fs_size(lfs_t *lfs) { | ||||
|     lfs_size_t size = 0; | ||||
|     int err = lfs_fs_traverse(lfs, lfs_fs_size_count, &size); | ||||
|     if (err) { | ||||
|         return err; | ||||
|     } | ||||
|  | ||||
|     return size; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user