Skip to content

Use dmpart for partition tables instead of a private parser - #61

Merged
JohnAmadis merged 2 commits into
mainfrom
claude/dmdevfs-use-dmpart
Sep 29, 2026
Merged

JohnAmadis merged 2 commits into
mainfrom
claude/dmdevfs-use-dmpart

Conversation

@JohnAmadis

@JohnAmadis JohnAmadis commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Part of choco-technologies/dmod-ecosystem#23 / #17.

Needs dmpart from the registry. That is now satisfied: dmblkid v0.1 is released and includes dmpart.

Summary

The MBR/GPT parser existed twice: src/partitions.c here, for partition nodes, and a copy in dmblkid, for telling a partitioned disk from a filesystem. It now lives in one place, dmpart, a small library module in the dmblkid repository (libs/dmpart, released with dmblkid):

int dmpart_scan(const dmpart_medium_t* medium, dmpart_found_t found,
                void* found_ctx, dmpart_info_t* info);
  • src/partitions.c/.h removed (−443 lines).
  • find_partitions() describes the medium as a dmpart_medium_t (driver read callback, block size, block count) and calls dmpart_scan(). The callbacks are unchanged static functions.
  • dmod_link_modules(... dmpart ...): dmdevfs.dmd now requires dmpart@>=0.1<1.0, so every package or image that contains dmdevfs must also contain dmpart.
  • Behaviour differences:
    • running out of memory while reading a table is now logged, where before it silently looked like "no table";
    • an exFAT boot sector is no longer taken for an MBR (FAT already wasn't).
  • README: the Partition Nodes section points to dmpart. dmblkid uses the same parser, so a medium that gets partition nodes here is always reported by dmblkid as a partition table, never as a filesystem to mount whole.

Tests: install dmdevfs's own dependencies (3ce65ac)

The test modules load dmdevfs by name (Dmod_LoadModuleByName("dmdevfs")) instead of depending on it. ctest therefore only installed the test module's own .dmd. Until now, dmdevfs's dependencies happened to be covered by the tests' own dependencies (libsystemd pulls in dmini), but dmpart is not.

With dmpart missing, dmod_loader correctly refused to load dmdevfs (Cannot load required module 'dmpart'). load_devfs() returned false, and the test steps, which do not check for that, then called the unset DIF pointers (g_fs.fopen is NULL). That NULL call caused the segfault in CI.

Correction: the message of 3ce65ac says dmdevfs was loaded without dmpart and dmpart_scan() jumped to 0. That is wrong. The loader never started dmdevfs; the NULL call is in the test code.

The fix installs dmdevfs.dmd before each test.

Test plan

  • In chocotechnologies/dmod:1.0.4, with dmpart 0.1 from the registry (no local packages):
    • ctest: 8/8;
    • test_partitions 12/12, running on dmpart;
    • test_dmdevfs and test_dmdevmon still pass.
  • Without 3ce65ac, reproduced the CI failure: Cannot load required module 'dmpart', then a segfault in the test.
  • Cortex-M7 build: no new warnings. The only warning (read_dir_name_from_path defined but not used) is already on main.
  • dmpart's own tests (test_dmpart, 15 steps, in dmblkid) cover the parser directly on an in-memory medium.

🤖 Generated with Claude Code

https://claude.ai/code/session_01TgkwHQKqf6c4DzypSKzZT7

The MBR/GPT parser (src/partitions.c) moved to dmpart, a small library
module released with dmblkid (choco-technologies/dmblkid, libs/dmpart).
dmblkid uses the same parser to tell a partitioned disk from a
filesystem, so a medium that gets partition nodes here is always
reported by dmblkid as a partition table - one implementation instead
of two copies that could drift apart.

find_partitions() now describes the medium as a dmpart_medium_t and
calls dmpart_scan(); running out of memory while reading the table is
logged instead of silently looking like "no table". dmpart also refuses
to take an exFAT boot sector for an MBR (FAT was already excluded).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TgkwHQKqf6c4DzypSKzZT7
The test modules mount dmdevfs by name instead of depending on it, so
ctest only installed the test module's dependencies (<name>.dmd).
dmdevfs's dependencies were covered by accident until it gained dmpart:
with dmpart missing, dmod_loader still loaded dmdevfs and the first
dmpart_scan() call jumped to address 0 - every test that mounts dmdevfs
crashed in CI once the real dmpart release was used.

Install dmdevfs.dmd first. With dmpart 0.1 from the registry: ctest 8/8,
test_partitions 12/12.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TgkwHQKqf6c4DzypSKzZT7
@JohnAmadis
JohnAmadis merged commit eede28e into main Sep 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants