mirror of
https://github.com/eledio-devices/thirdparty-littlefs.git
synced 2025-11-01 16:14:13 +01:00
Before, the tag format's type field was limited to 9-bits. This sounds
like a lot, but this field needed to encode up to 256 user-specified
types. This limited the flexibility of the encoded types. As time went
on, more bits in the type field were repurposed for various things,
leaving a rather fragile type field.
Here we make the jump to full 11-bit type fields. This comes at the cost
of a smaller length field, however the use of the length field was
always going to come with a RAM limitation. Rather than putting pressure
on RAM for inline files, the new type field lets us encode a chunk
number, splitting up inline files into multiple updatable units. This
actually pushes the theoretical inline max from 8KiB to 256KiB! (Note
that we only allow a single 1KiB chunk for now, chunky inline files
is just a theoretical future improvement).
Here is the new 32-bit tag format, note that there are multiple levels
of types which break down into more info:
[---- 32 ----]
[1|-- 11 --|-- 10 --|-- 10 --]
^. ^ . ^ ^- entry length
|. | . \------------ file id chunk info
|. \-----.------------------ type info (type3)
\.-----------.------------------ valid bit
[-3-|-- 8 --]
^ ^- chunk info
\------- type info (type1)
Additionally, I've split the CREATE tag into separate SPLICE and NAME
tags. This simplified the new compact logic a bit. For now, littlefs
still follows the rule that a NAME tag precedes any other tags related
to a file, but this can change in the future.
45 lines
1.1 KiB
Python
Executable File
45 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
import struct
|
|
import sys
|
|
import os
|
|
import argparse
|
|
|
|
def corrupt(block):
|
|
with open(block, 'r+b') as file:
|
|
# skip rev
|
|
file.read(4)
|
|
|
|
# go to last commit
|
|
tag = 0xffffffff
|
|
while True:
|
|
try:
|
|
ntag, = struct.unpack('>I', file.read(4))
|
|
except struct.error:
|
|
break
|
|
|
|
tag ^= ntag
|
|
size = (tag & 0x3ff) if (tag & 0x3ff) != 0x3ff else 0
|
|
file.seek(size, os.SEEK_CUR)
|
|
|
|
# lob off last 3 bytes
|
|
file.seek(-(size + 3), os.SEEK_CUR)
|
|
file.truncate()
|
|
|
|
def main(args):
|
|
if args.n or not args.blocks:
|
|
with open('blocks/.history', 'rb') as file:
|
|
for i in range(int(args.n or 1)):
|
|
last, = struct.unpack('<I', file.read(4))
|
|
args.blocks.append('blocks/%x' % last)
|
|
|
|
for block in args.blocks:
|
|
print 'corrupting %s' % block
|
|
corrupt(block)
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('-n')
|
|
parser.add_argument('blocks', nargs='*')
|
|
main(parser.parse_args())
|