fatfsgen.py: fixed missing NULL terminator

This commit is contained in:
Martin Gaňo 2022-09-13 20:09:40 +02:00
parent 719ff3392e
commit 131b28314e
3 changed files with 9 additions and 7 deletions

View File

@ -210,7 +210,7 @@ class Directory:
entries_count: int = get_required_lfn_entries_count(lfn_full_name)
# entries in long file name entries chain starts with the last entry
split_names_reversed = reversed(list(enumerate(split_name_to_lfn_entries(lfn_full_name, entries_count))))
split_names_reversed = list(reversed(list(enumerate(split_name_to_lfn_entries(lfn_full_name, entries_count)))))
for i, name_split_to_entry in split_names_reversed:
order: int = i + 1
blocks_: List[bytes] = split_name_to_lfn_entry_blocks(name_split_to_entry)

View File

@ -85,4 +85,9 @@ def build_lfn_full_name(name: str, extension: str) -> str:
The extension is optional, and the long filename entry explicitly specifies it,
on the opposite as for short file names.
"""
return f'{name}.{extension}' if len(extension) > 0 else name
lfn_record: str = f'{name}.{extension}' if len(extension) > 0 else name
# the name must be terminated with NULL terminator
# if it doesn't fit into the set of long name directory entries
if len(lfn_record) % Entry.CHARS_PER_ENTRY != 0:
return lfn_record + chr(0)
return lfn_record

View File

@ -119,14 +119,11 @@ def lfn_checksum(short_entry_name: str) -> int:
def convert_to_utf16_and_pad(content: str,
expected_size: int,
pad: bytes = FULL_BYTE,
terminator: bytes = b'\x00\x00') -> bytes:
pad: bytes = FULL_BYTE) -> bytes:
# we need to get rid of the Byte order mark 0xfeff or 0xfffe, fatfs does not use it
bom_utf16: bytes = b'\xfe\xff'
encoded_content_utf16: bytes = content.encode(LONG_NAMES_ENCODING)[len(bom_utf16):]
terminated_encoded_content_utf16: bytes = (encoded_content_utf16 + terminator) if (2 * expected_size > len(
encoded_content_utf16) > 0) else encoded_content_utf16
return terminated_encoded_content_utf16.ljust(2 * expected_size, pad)
return encoded_content_utf16.ljust(2 * expected_size, pad)
def split_to_name_and_extension(full_name: str) -> Tuple[str, str]: