From: dengbo Date: Thu, 25 Jun 2026 13:52:16 +0000 (+0800) Subject: findmnt: skip shadowed entries when matching by --target X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6df11b009a950b317218df175575a2d8e1462bd1;p=thirdparty%2Futil-linux.git findmnt: skip shadowed entries when matching by --target 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 --- diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c index c892bf299..eca6dc74b 100644 --- a/misc-utils/findmnt.c +++ b/misc-utils/findmnt.c @@ -1763,6 +1763,7 @@ int main(int argc, char *argv[]) char *outarg = NULL; size_t i; int force_tree = 0, istree = 0; + int force_target = 0; struct libscols_table *table = NULL; @@ -2001,7 +2002,7 @@ int main(int argc, char *argv[]) FALLTHROUGH; case 'T': set_match(COL_TARGET, optarg); - findmnt.flags |= FL_NOSWAPMATCH; + force_target = 1; break; case 'U': findmnt.flags |= FL_UNIQ; @@ -2143,6 +2144,11 @@ int main(int argc, char *argv[]) findmnt.flags |= FL_NOSWAPMATCH; } + if (force_target) { + direction = MNT_ITER_BACKWARD; + findmnt.flags |= FL_NOSWAPMATCH | FL_FIRSTONLY; + } + /* * initialize libmount */