mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 16:14:16 +01:00 
			
		
		
		
	WIP Fixed ENOSPC issues with zero-granularity blocks
This commit is contained in:
		
							
								
								
									
										39
									
								
								tests/corrupt.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										39
									
								
								tests/corrupt.py
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,39 @@ | ||||
| #!/usr/bin/env python | ||||
|  | ||||
| import struct | ||||
| import sys | ||||
| import os | ||||
|  | ||||
| def main(*paths): | ||||
|     # find most recent block | ||||
|     file = None | ||||
|     rev = None | ||||
|     for path in paths: | ||||
|         try: | ||||
|             nfile = open(path, 'r+b') | ||||
|             nrev, = struct.unpack('<I', nfile.read(4)) | ||||
|  | ||||
|             assert rev != nrev | ||||
|             if not file or ((rev - nrev) & 0x80000000): | ||||
|                 file = nfile | ||||
|                 rev = nrev | ||||
|         except IOError: | ||||
|             pass | ||||
|  | ||||
|     # go to last commit | ||||
|     tag = 0 | ||||
|     while True: | ||||
|         try: | ||||
|             ntag, = struct.unpack('<I', file.read(4)) | ||||
|         except struct.error: | ||||
|             break | ||||
|  | ||||
|         tag ^= ntag | ||||
|         file.seek(tag & 0xfff, os.SEEK_CUR) | ||||
|  | ||||
|     # lob off last 3 bytes | ||||
|     file.seek(-((tag & 0xfff) + 3), os.SEEK_CUR) | ||||
|     file.truncate() | ||||
|  | ||||
| if __name__ == "__main__": | ||||
|     main(*sys.argv[1:]) | ||||
| @@ -59,7 +59,7 @@ tests/test.py << TEST | ||||
|     lfs_rename(&lfs, "b/hello", "c/hello") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| TEST | ||||
| truncate -s-7 blocks/6 | ||||
| tests/corrupt.py blocks/{6,7} | ||||
| tests/test.py << TEST | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir[0], "b") => 0; | ||||
| @@ -86,8 +86,8 @@ tests/test.py << TEST | ||||
|     lfs_rename(&lfs, "c/hello", "d/hello") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| TEST | ||||
| truncate -s-7 blocks/8 | ||||
| truncate -s-7 blocks/a | ||||
| tests/corrupt.py blocks/{8,9} | ||||
| tests/corrupt.py blocks/{a,b} | ||||
| tests/test.py << TEST | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir[0], "c") => 0; | ||||
| @@ -166,7 +166,7 @@ tests/test.py << TEST | ||||
|     lfs_rename(&lfs, "b/hi", "c/hi") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| TEST | ||||
| truncate -s-7 blocks/7 | ||||
| tests/corrupt.py blocks/{6,7} | ||||
| tests/test.py << TEST | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir[0], "b") => 0; | ||||
| @@ -193,8 +193,8 @@ tests/test.py << TEST | ||||
|     lfs_rename(&lfs, "c/hi", "d/hi") => 0; | ||||
|     lfs_unmount(&lfs) => 0; | ||||
| TEST | ||||
| truncate -s-7 blocks/9 | ||||
| truncate -s-7 blocks/b | ||||
| tests/corrupt.py blocks/{8,9} | ||||
| tests/corrupt.py blocks/{a,b} | ||||
| tests/test.py << TEST | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|     lfs_dir_open(&lfs, &dir[0], "c") => 0; | ||||
|   | ||||
| @@ -17,7 +17,7 @@ tests/test.py << TEST | ||||
| TEST | ||||
| # corrupt most recent commit, this should be the update to the previous | ||||
| # linked-list entry and should orphan the child | ||||
| truncate -s-14 blocks/8 | ||||
| tests/corrupt.py blocks/{8,9} | ||||
| tests/test.py  << TEST | ||||
|     lfs_mount(&lfs, &cfg) => 0; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user