mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 16:14:16 +01:00 
			
		
		
		
	Fixed lookahead overflow and removed unbounded lookahead pointers
As pointed out by davidefer, the lookahead pointer modular arithmetic does not work around integer overflow when the pointer size is not a multiple of the block count. To avoid overflow problems, the easy solution is to stop trying to work around integer overflows and keep the lookahead offset inside the block device. To make this work, the ack was modified into a resetable counter that is decremented every block allocation. As a plus, quite a bit of the allocation logic ended up simplified.
This commit is contained in:
		| @@ -120,17 +120,16 @@ do | ||||
| tests/test.py << TEST | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|  | ||||
|     // setup lookahead to almost overflow | ||||
|     lfs.free.begin = ((lfs_size_t)-1) - $SIZE/(2*cfg.block_size); | ||||
|     lfs.free.size = 0; | ||||
|     lfs.free.off = 0; | ||||
| //    // setup lookahead to almost overflow | ||||
| //    lfs.free.begin = ((lfs_size_t)-1) - 2*$SIZE; | ||||
| //    lfs.free.size = 0; | ||||
| //    lfs.free.off = 0; | ||||
|  | ||||
|     lfs_file_open(&lfs, &file[0], "overflow/$name", | ||||
|             LFS_O_WRONLY | LFS_O_CREAT | LFS_O_APPEND) => 0; | ||||
|     size = strlen("$name"); | ||||
|     memcpy(buffer, "$name", size); | ||||
|     for (int i = 0; i < $SIZE; i++) { | ||||
|         printf("%d\n", lfs.free.begin); | ||||
|         lfs_file_write(&lfs, &file[0], buffer, size) => size; | ||||
|     } | ||||
|     lfs_file_close(&lfs, &file[0]) => 0; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user