Skip to content

Commit

Permalink
reduce LFS_NAME_MAX to 1022, the maximum valid value LittleFS support…
Browse files Browse the repository at this point in the history
…s. (#62)
  • Loading branch information
BrianPugh authored Dec 1, 2023
1 parent 77fe07f commit 54e3831
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
("LFS_NO_WARN", "1"),
("LFS_NO_ERROR", "1"),
("LFS_MULTIVERSION", "1"),
("LFS_NAME_MAX", "32767"),
("LFS_NAME_MAX", "1022"), # LittleFS limitation: must be <= 1022
# ('LFS_YES_TRACE', '1')
],
extra_compile_args=["-std=c99", "-UNDEBUG"],
Expand All @@ -39,9 +39,7 @@
package_data={"*": ["py.typed", "*.pyi"]},
package_dir={"": "src"},
zip_safe=False,
ext_modules=cythonize(
EXTENSIONS, language_level=3, annotate=False, compiler_directives={"embedsignature": True}
),
ext_modules=cythonize(EXTENSIONS, language_level=3, annotate=False, compiler_directives={"embedsignature": True}),
entry_points={
"console_scripts": [
"littlefs-python = littlefs.__main__:main",
Expand Down
3 changes: 3 additions & 0 deletions src/littlefs/lfs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ cdef class LFSConfig:
if block_size < 128:
raise ValueError('Minimal block size is 128')

if name_max > 1022: # LittleFS maximum name length limitation
raise ValueError(f"name_max must be <=1022.")

self._impl.read_size = read_size if read_size else block_size
self._impl.prog_size = prog_size if prog_size else block_size
self._impl.block_size = block_size
Expand Down
30 changes: 30 additions & 0 deletions test/test_name_max.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pytest
from littlefs import lfs, LittleFS


def test_name_max_gt_1022():
"""Don't allow a `name_max > 1022`.
From the LittleFS documentation:
// Maximum name size in bytes, may be redefined to reduce the size of the
// info struct. Limited to <= 1022. Stored in superblock and must be
// respected by other littlefs drivers.
Originally reported:
https://github.com/jrast/littlefs-python/issues/61
"""

with pytest.raises(ValueError):
LittleFS(name_max=1023)


def test_name_max_0():
"""Ensures that defaulting to ``LFS_NAME_MAX`` is valid.
Originally reported:
https://github.com/jrast/littlefs-python/issues/61
"""
fs = LittleFS(name_max=0)
stat = fs.fs_stat()
assert stat.name_max == 1022

0 comments on commit 54e3831

Please sign in to comment.