mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 08:42:40 +01:00 
			
		
		
		
	Fixed issue with negative modulo with unaligned lookaheads
When the lookahead buffer wraps around in an unaligned filesystem, it's possible for blocks at the beginning of the disk to have a negative distance from the lookahead, but still reside in the lookahead buffer. Switching to signed modulo doesn't quite work due to how negative modulo is implemented in C, so the simple solution is to shift the region to be positive.
This commit is contained in:
		| @@ -9,6 +9,9 @@ script: | ||||
|         -include stdio.h -Werror' make all size | ||||
|  | ||||
|     # run tests | ||||
|     - CFLAGS="-DLFS_READ_SIZE=16  -DLFS_PROG_SIZE=16"  make test | ||||
|     - make test | ||||
|  | ||||
|     # run tests with a few different configurations | ||||
|     - CFLAGS="-DLFS_READ_SIZE=1   -DLFS_PROG_SIZE=1"   make test | ||||
|     - CFLAGS="-DLFS_READ_SIZE=512 -DLFS_PROG_SIZE=512" make test | ||||
|     - CFLAGS="-DLFS_BLOCK_COUNT=1023" make test | ||||
|   | ||||
							
								
								
									
										6
									
								
								lfs.c
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								lfs.c
									
									
									
									
									
								
							| @@ -262,7 +262,10 @@ int lfs_deorphan(lfs_t *lfs); | ||||
| static int lfs_alloc_lookahead(void *p, lfs_block_t block) { | ||||
|     lfs_t *lfs = p; | ||||
|  | ||||
|     lfs_block_t off = (block - lfs->free.start) % lfs->cfg->block_count; | ||||
|     lfs_block_t off = (((lfs_soff_t)(block - lfs->free.start) | ||||
|                 % (lfs_soff_t)(lfs->cfg->block_count)) | ||||
|             + lfs->cfg->block_count) % lfs->cfg->block_count; | ||||
|  | ||||
|     if (off < lfs->cfg->lookahead) { | ||||
|         lfs->free.lookahead[off / 32] |= 1U << (off % 32); | ||||
|     } | ||||
| @@ -994,6 +997,7 @@ static int lfs_index_extend(lfs_t *lfs, | ||||
|         if (err) { | ||||
|             return err; | ||||
|         } | ||||
|         assert(*block >= 2 && *block <= lfs->cfg->block_count); | ||||
|  | ||||
|         err = lfs_bd_erase(lfs, *block); | ||||
|         if (err) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user