Skip to content

Resolve symlinks in device path for removable check#52

Merged
twoerner merged 1 commit into
yoctoproject:mainfrom
airtower-luna:fix-removable-dev-symlink
Jun 5, 2026
Merged

Resolve symlinks in device path for removable check#52
twoerner merged 1 commit into
yoctoproject:mainfrom
airtower-luna:fix-removable-dev-symlink

Conversation

@airtower-luna

Copy link
Copy Markdown

When running with --removable-device, the basename of dest is used to construct the path of the "removable" sysfs file for the device. However, if dest is a symlink the basename may be very different from the actual device name, and theoretically might even match a different device. Make the path absolute and resolve any symlinks before taking the basename to avoid that problem.

This is of practical importance because it allows using /dev/disk/... symlinks created by udev, which is much less error-prone than using e.g. /dev/sdX.

@airtower-luna airtower-luna force-pushed the fix-removable-dev-symlink branch from 7ae5ae3 to f2fc471 Compare April 25, 2025 08:27
@airtower-luna

Copy link
Copy Markdown
Author

Reformatted as suggested by black.

When running with --removable-device, the basename of dest is used to
construct the path of the "removable" sysfs file for the
device. However, if dest is a symlink the basename may be very
different from the actual device name, and theoretically might even
match a different device. Make the path absolute and resolve any
symlinks before taking the basename to avoid that problem.

This is of practical importance because it allows using
/dev/disk/... symlinks created by udev, which is much less error-prone
than using e.g. /dev/sdX.

Signed-off-by: Fiona Klute <fiona.klute@gmx.de>
@twoerner twoerner force-pushed the fix-removable-dev-symlink branch from f2fc471 to 2586500 Compare June 5, 2026 14:28

@twoerner twoerner left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: APPROVE

This PR is a one-line change in src/bmaptool/CLI.py that wraps args.dest in os.path.realpath() before taking the basename, so the --removable-device precondition resolves /dev/disk/by-id/...-style symlinks to their underlying block device before looking up /sys/block/<name>/removable.

Must-fix before merge

Nothing must change before merge.

Suggestions

  • Consider mentioning /dev/disk/by-id/... (or by-uuid, by-label, etc.) in bmaptool --help's description of the --removable-device flag, since the new behavior makes those forms first-class arguments. Optional - not blocking.

Test follow-up

Regression test recommended as follow-up: a unit test that monkeypatches os.path.realpath and the sysfs open(...) to pin the sysfs path the precondition cascade computes for a symlinked destination, so a future regression that drops the realpath call surfaces as an assertion failure rather than silently re-introducing the bug. Not added on this PR to keep the scope honest; will be landed as its own maintainer PR.

CI status

All eight required contexts green on the rebased head (lint, test (3.9) through test (3.14), test (native)). The three advisory CodeQL / Analyze checks are also green.

Reviewed against

Head SHA 258650043ece7072aa0bc337d790c96e50108637, rebased clean onto main at 0c3f66af538f. smoke-full green end-to-end on the rebased tree.

@twoerner twoerner merged commit fe7ab42 into yoctoproject:main Jun 5, 2026
8 checks 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