mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 08:42:40 +01:00 
			
		
		
		
	This implements the second step of full dynamic wear-leveling, block allocation randomization. This is the key part the uniformly distributes wear across the filesystem, even through reboots. The entropy actually comes from the filesystem itself, by xoring together all of the CRCs in the metadata-pairs on the filesystem. While this sounds like a ridiculous operation, it's easy to do when we already scan the metadata-pairs at mount time. This gives us a random number we can use for block allocation. Unfortunately it's not a great general purpose random generator as the output only changes every filesystem write. Fortunately that's exactly when we need our allocator. --- Additionally, the randomization created a mess for the testing framework. Fortunately, this method of randomization is deterministic. A very useful property for reproducing bugs.
		
			
				
	
	
		
			46 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/bin/bash
 | |
| set -eu
 | |
| 
 | |
| echo "=== Orphan tests ==="
 | |
| rm -rf blocks
 | |
| tests/test.py << TEST
 | |
|     lfs_format(&lfs, &cfg) => 0;
 | |
| TEST
 | |
| 
 | |
| echo "--- Orphan test ---"
 | |
| tests/test.py << TEST
 | |
|     lfs_mount(&lfs, &cfg) => 0;
 | |
|     lfs_mkdir(&lfs, "parent") => 0;
 | |
|     lfs_mkdir(&lfs, "parent/orphan") => 0;
 | |
|     lfs_mkdir(&lfs, "parent/child") => 0;
 | |
|     lfs_remove(&lfs, "parent/orphan") => 0;
 | |
| TEST
 | |
| # corrupt most recent commit, this should be the update to the previous
 | |
| # linked-list entry and should orphan the child
 | |
| tests/corrupt.py
 | |
| tests/test.py << TEST
 | |
|     lfs_mount(&lfs, &cfg) => 0;
 | |
| 
 | |
|     lfs_stat(&lfs, "parent/orphan", &info) => LFS_ERR_NOENT;
 | |
|     lfs_ssize_t before = lfs_fs_size(&lfs);
 | |
|     before => 8;
 | |
| 
 | |
|     lfs_unmount(&lfs) => 0;
 | |
|     lfs_mount(&lfs, &cfg) => 0;
 | |
| 
 | |
|     lfs_stat(&lfs, "parent/orphan", &info) => LFS_ERR_NOENT;
 | |
|     lfs_ssize_t orphaned = lfs_fs_size(&lfs);
 | |
|     orphaned => 8;
 | |
| 
 | |
|     lfs_mkdir(&lfs, "parent/otherchild") => 0;
 | |
| 
 | |
|     lfs_stat(&lfs, "parent/orphan", &info) => LFS_ERR_NOENT;
 | |
|     lfs_ssize_t deorphaned = lfs_fs_size(&lfs);
 | |
|     deorphaned => 8;
 | |
| 
 | |
|     lfs_unmount(&lfs) => 0;
 | |
| TEST
 | |
| 
 | |
| echo "--- Results ---"
 | |
| tests/stats.py
 |