findmnt: skip shadowed entries when matching by --target#4451
Conversation
When a bind mount overlays the same mountpoint (e.g. mount -B /boot /boot), findmnt --target <path> produces duplicate results because both the original and bind entries match via mnt_fs_match_target(). Filter out over-mounted entries using mnt_table_over_fs() when the target match is active. This ensures --target returns only the visible (topmost) filesystem for the given path. [misc-utils/findmnt.c: match_func()] Fixes util-linux#4424
|
Thanks for looking into this. The fix addresses a real problem, but the approach in
The swap cases would cause false shadowed-entry filtering on what was originally a source spec. The good news is that this is already solved by existing infrastructure — we just need to enable it for The fix would be something like: case 'M':
findmnt.flags |= FL_STRICTTARGET;
FALLTHROUGH;
case 'T':
set_match(COL_TARGET, optarg);
force_target = 1;
break;where if (force_target) {
direction = MNT_ITER_BACKWARD;
findmnt.flags |= FL_NOSWAPMATCH | FL_FIRSTONLY;
}— assisted by Claude Code |
When a bind mount overlays the same mountpoint (e.g. mount -B /boot /boot), findmnt --target produces duplicate results because both the original and bind entries match via mnt_fs_match_target().
Filter out over-mounted entries using mnt_table_over_fs() when the target match is active. This ensures --target returns only the visible (topmost) filesystem for the given path.
[misc-utils/findmnt.c: match_func()]
Fixes #4424