Skip to content

Commit

Permalink
Fat32Content: enforce fat32
Browse files Browse the repository at this point in the history
mkfs.vfat can create fat 12, 16 and 32.
By default it uses whatever fits best.
Since the module is called Fat32, it should always create a fat32 filesystem
  • Loading branch information
MofX committed Nov 26, 2024
1 parent 04cac55 commit 39b7a6c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions embdgen-core/src/embdgen/plugins/content/Fat32Content.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def _prepare_result(self):

subprocess.run([
"mkfs.vfat",
"-F", "32",
self.result_file
],
check=True,
Expand Down
22 changes: 19 additions & 3 deletions embdgen-core/tests/content/test_Fat32Content.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
class MInfo(SimpleCommandParser):
ATTRIBUTE_MAP = {
"sector size": ("sector_size", lambda x: int(x.split()[0])),
"big size": ("sectors", lambda x: int(x.split()[0]))
"big size": ("sectors", lambda x: int(x.split()[0])),
"disk type": ("disk_type", lambda x: x[1:-1].strip())
}

sectors: int = -1
sector_size: int = -1
disk_type: str = ""

def __init__(self, image: Path) -> None:
super().__init__(["minfo", "-i", image])
Expand Down Expand Up @@ -50,12 +52,12 @@ def test_files(self, tmp_path: Path):
obj.prepare()
assert obj.size.is_undefined

obj.size = SizeType.parse("10MB")
obj.size = SizeType.parse("32MB")
obj.prepare()

with image.open("wb") as out_file:
obj.write(out_file)
assert image.stat().st_size == SizeType.parse("10MB").bytes
assert image.stat().st_size == SizeType.parse("32MB").bytes

res = subprocess.run([
"mdir",
Expand All @@ -79,3 +81,17 @@ def test_empty(self, tmp_path: Path) -> None:
minfo = MInfo(image)
assert minfo.ok, minfo.error

def test_type_small(self, tmp_path: Path) -> None:
BuildLocation().set_path(tmp_path)
image = tmp_path / "image"

obj = Fat32Content()
obj.size = SizeType.parse("10 MB")
obj.prepare()

with image.open("wb") as out_file:
obj.write(out_file)

minfo = MInfo(image)
assert minfo.ok, minfo.error
assert minfo.disk_type == "FAT32"
2 changes: 1 addition & 1 deletion embdgen-core/tests/test_utils/SimpleCommandParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, command: Iterable[str]) -> None:
self.ok = ret.returncode == 0

for line in ret.stdout.splitlines():
splits = re.split(r":\s+", line.strip(), 1)
splits = re.split(r"[:=]", line.strip(), 1)
if len(splits) != 2:
continue
key, value = splits
Expand Down

0 comments on commit 39b7a6c

Please sign in to comment.