mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-11-01 00:38:29 +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.
		
			
				
	
	
		
			31 lines
		
	
	
		
			805 B
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			805 B
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
| #!/usr/bin/env python
 | |
| 
 | |
| import struct
 | |
| import sys
 | |
| import time
 | |
| import os
 | |
| import re
 | |
| 
 | |
| def main():
 | |
|     with open('blocks/.config') as file:
 | |
|         s = struct.unpack('<LLLL', file.read())
 | |
|         print 'read_size: %d' % s[0]
 | |
|         print 'prog_size: %d' % s[1]
 | |
|         print 'block_size: %d' % s[2]
 | |
|         print 'block_size: %d' % s[3]
 | |
| 
 | |
|     print 'real_size: %d' % sum(
 | |
|         os.path.getsize(os.path.join('blocks', f))
 | |
|         for f in os.listdir('blocks') if re.match('\d+', f))
 | |
| 
 | |
|     with open('blocks/.stats') as file:
 | |
|         s = struct.unpack('<QQQ', file.read())
 | |
|         print 'read_count: %d' % s[0]
 | |
|         print 'prog_count: %d' % s[1]
 | |
|         print 'erase_count: %d' % s[2]
 | |
| 
 | |
|     print 'runtime: %.3f' % (time.time() - os.stat('blocks').st_ctime)
 | |
| 
 | |
| if __name__ == "__main__":
 | |
|     main(*sys.argv[1:])
 |