The previous approach filtered shadowed entries in match_func() using
mnt_table_over_fs() with is_defined_match(COL_TARGET) as the trigger.
This was fragile because COL_TARGET matching is also enabled by other
code paths (source/target swap fallback in get_next_fs(), poll_match()
swap logic, and positional arguments).
Replace with the standard mountinfo iteration pattern: read
/proc/self/mountinfo backward (MNT_ITER_BACKWARD), stop at the first
match (FL_FIRSTONLY), and disable source/target swapping
(FL_NOSWAPMATCH). Since later mounts appear later in mountinfo,
backward iteration naturally finds the visible (topmost) filesystem
for the given target path.
Fixes https://github.com/util-linux/util-linux/issues/4424
char *outarg = NULL;
size_t i;
int force_tree = 0, istree = 0;
+ int force_target = 0;
struct libscols_table *table = NULL;
FALLTHROUGH;
case 'T':
set_match(COL_TARGET, optarg);
- findmnt.flags |= FL_NOSWAPMATCH;
+ force_target = 1;
break;
case 'U':
findmnt.flags |= FL_UNIQ;
findmnt.flags |= FL_NOSWAPMATCH;
}
+ if (force_target) {
+ direction = MNT_ITER_BACKWARD;
+ findmnt.flags |= FL_NOSWAPMATCH | FL_FIRSTONLY;
+ }
+
/*
* initialize libmount
*/