Merge branch 'bugfix/fatfsgen-add-name-termination' into 'master'

fatfsgen.py: fixed missing NULL terminator

Closes IDF-5964

See merge request espressif/esp-idf!20130
This commit is contained in:
Martin Vychodil
2022-09-15 19:58:27 +08:00
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_count: int = get_required_lfn_entries_count(lfn_full_name)
# entries in long file name entries chain starts with the last entry # 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: for i, name_split_to_entry in split_names_reversed:
order: int = i + 1 order: int = i + 1
blocks_: List[bytes] = split_name_to_lfn_entry_blocks(name_split_to_entry) 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, The extension is optional, and the long filename entry explicitly specifies it,
on the opposite as for short file names. 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, def convert_to_utf16_and_pad(content: str,
expected_size: int, expected_size: int,
pad: bytes = FULL_BYTE, pad: bytes = FULL_BYTE) -> bytes:
terminator: bytes = b'\x00\x00') -> bytes:
# we need to get rid of the Byte order mark 0xfeff or 0xfffe, fatfs does not use it # we need to get rid of the Byte order mark 0xfeff or 0xfffe, fatfs does not use it
bom_utf16: bytes = b'\xfe\xff' bom_utf16: bytes = b'\xfe\xff'
encoded_content_utf16: bytes = content.encode(LONG_NAMES_ENCODING)[len(bom_utf16):] 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( return encoded_content_utf16.ljust(2 * expected_size, pad)
encoded_content_utf16) > 0) else encoded_content_utf16
return terminated_encoded_content_utf16.ljust(2 * expected_size, pad)
def split_to_name_and_extension(full_name: str) -> Tuple[str, str]: def split_to_name_and_extension(full_name: str) -> Tuple[str, str]: