mirror of
https://github.com/eledio-devices/thirdparty-littlefs.git
synced 2025-11-01 08:48:31 +01:00
In writing the initial allocator, I ran into the rather difficult problem of trying to iterate through the entire filesystem cheaply and with only constant memory consumption (which prohibits recursive functions). The solution was to simply thread all directory blocks onto a massive linked-list that spans the entire filesystem. With the linked-list it was easy to create a traverse function for all blocks in use on the filesystem (which has potential for other utility), and add the rudimentary block allocator using a bit-vector. While the linked-list may add complexity (especially where needing to maintain atomic operations), the linked-list helps simplify what is currently the most expensive operation in the filesystem, with no cost to space (the linked-list can reuse the pointers used for chained directory blocks).
50 lines
1.3 KiB
Python
Executable File
50 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
import re
|
|
import sys
|
|
import subprocess
|
|
import os
|
|
|
|
def generate(test):
|
|
with open("tests/template.fmt") as file:
|
|
template = file.read()
|
|
|
|
lines = []
|
|
for line in re.split('(?<=[;{}])\n', test.read()):
|
|
match = re.match('(?: *\n)*( *)(.*)=>(.*);', line, re.DOTALL | re.MULTILINE)
|
|
if match:
|
|
tab, test, expect = match.groups()
|
|
lines.append(tab+'res = {test};'.format(test=test.strip()))
|
|
lines.append(tab+'test_assert("{name}", res, {expect});'.format(
|
|
name = re.match('\w*', test.strip()).group(),
|
|
expect = expect.strip()))
|
|
else:
|
|
lines.append(line)
|
|
|
|
with open('test.c', 'w') as file:
|
|
file.write(template.format(tests='\n'.join(lines)))
|
|
|
|
def compile():
|
|
os.environ['CFLAGS'] = os.environ.get('CFLAGS', '') + ' -Werror'
|
|
subprocess.check_call(['make', '--no-print-directory', '-s'], env=os.environ)
|
|
|
|
def execute():
|
|
subprocess.check_call(["./lfs"])
|
|
|
|
def main(test=None):
|
|
if test and not test.startswith('-'):
|
|
with open(test) as file:
|
|
generate(file)
|
|
else:
|
|
generate(sys.stdin)
|
|
|
|
compile()
|
|
|
|
if test == '-s':
|
|
sys.exit(1)
|
|
|
|
execute()
|
|
|
|
if __name__ == "__main__":
|
|
main(*sys.argv[1:])
|