diff --git a/NEWS b/NEWS index 549f6d4c..5ce613c1 100644 --- a/NEWS +++ b/NEWS @@ -28,6 +28,9 @@ GNU findutils NEWS - User visible changes. -*- outline -*- (allout) are passed with a leading dash, e.g. '-!'. Future releases will not accept that any more. Accepting that was rather a bug "since the beginning". + The -mount option is now POSIX 2024 compliant. Find will ignore files on + different devices as opposed to being a mere alias for -xdev. [#54745] + ** Documentation Changes The forthcoming Issue 8 of the POSIX standard will standardise "find diff --git a/doc/find.texi b/doc/find.texi index 4852a5a1..192f7dea 100644 --- a/doc/find.texi +++ b/doc/find.texi @@ -1624,10 +1624,12 @@ them. There are two ways to avoid searching certain filesystems. One way is to tell @code{find} to only search one filesystem: +@deffn Option -mount +Ignore files on other devices. +@end deffn + @deffn Option -xdev -@deffnx Option -mount -Don't descend directories on other filesystems. These options are -synonyms. +Don't descend into directories on other devices. @end deffn The other way is to check the type of filesystem each file is on, and diff --git a/find/defs.h b/find/defs.h index ea3e5cab..f1c8d706 100644 --- a/find/defs.h +++ b/find/defs.h @@ -549,8 +549,11 @@ struct options are non-directories. */ bool no_leaf_check; + /* If true, skip files on other devices. */ + bool mount; + /* If true, don't cross filesystem boundaries. */ - bool stay_on_filesystem; + bool xdev; /* If true, we ignore the problem where we find that a directory entry * no longer exists by the time we get around to processing it. @@ -648,7 +651,7 @@ struct state int starting_path_length; /* If true, don't descend past current directory. - Can be set by -prune, -maxdepth, and -xdev/-mount. */ + Can be set by -prune, -maxdepth, -mount and -xdev. */ bool stop_at_current_level; /* Status value to return to system. */ diff --git a/find/find.1 b/find/find.1 index 88591d69..e5868272 100644 --- a/find/find.1 +++ b/find/find.1 @@ -630,10 +630,7 @@ non-negative integer). Using means process all files except the starting-points. .IP \-mount -Don't descend directories on other filesystems. An alternate name for -.BR \-xdev , -for compatibility with some other versions of -.BR find . +Ignore files on other devices. .IP \-noignore_readdir_race Turns off the effect of @@ -659,7 +656,7 @@ to stat them; this gives a significant increase in search speed. Print the \fBfind\fR version number and exit. .IP \-xdev -Don't descend directories on other filesystems. +Don't descend into directories on other devices. .SS TESTS Some tests, for example @@ -1989,7 +1986,7 @@ For closest compliance to the POSIX standard, you should set the .B POSIXLY_CORRECT environment variable. The following options are specified in the POSIX standard -(IEEE Std 1003.1-2008, 2016 Edition): +(IEEE Std 1003.1-2024 Edition): .IP \fB\-H\fR This option is supported. @@ -2053,6 +2050,7 @@ The primaries .BR \-exec , .BR \-group , .BR \-links , +.BR \-mount , .BR \-mtime , .BR \-nogroup , .BR \-nouser , diff --git a/find/ftsfind.c b/find/ftsfind.c index 5709b1db..17cfb1d1 100644 --- a/find/ftsfind.c +++ b/find/ftsfind.c @@ -480,7 +480,10 @@ find (char *arg) break; } - if (options.stay_on_filesystem) + if (options.mount) + ftsoptions |= FTS_MOUNT; + + if (options.xdev) ftsoptions |= FTS_XDEV; p = fts_open (arglist, ftsoptions, nullptr); diff --git a/find/parser.c b/find/parser.c index f740b06d..52df3577 100644 --- a/find/parser.c +++ b/find/parser.c @@ -122,6 +122,7 @@ static bool parse_ls (const struct parser_table*, char *argv[], int * static bool parse_maxdepth (const struct parser_table*, char *argv[], int *arg_ptr); static bool parse_mindepth (const struct parser_table*, char *argv[], int *arg_ptr); static bool parse_mmin (const struct parser_table*, char *argv[], int *arg_ptr); +static bool parse_mount (const struct parser_table*, char *argv[], int *arg_ptr); static bool parse_name (const struct parser_table*, char *argv[], int *arg_ptr); static bool parse_negate (const struct parser_table*, char *argv[], int *arg_ptr); static bool parse_newer (const struct parser_table*, char *argv[], int *arg_ptr); @@ -214,7 +215,7 @@ static struct parser_table const parse_table[] = { ARG_OPTION, "ignore_readdir_race", parse_ignore_race, nullptr }, /* GNU */ { ARG_OPTION, "maxdepth", parse_maxdepth, nullptr }, /* GNU */ { ARG_OPTION, "mindepth", parse_mindepth, nullptr }, /* GNU */ - { ARG_OPTION, "mount", parse_xdev, nullptr }, /* Unix */ + { ARG_OPTION, "mount", parse_mount, nullptr }, /* POSIX */ { ARG_OPTION, "noleaf", parse_noleaf, nullptr }, /* GNU */ { ARG_OPTION, "noignore_readdir_race", parse_noignore_race, nullptr }, /* GNU */ { ARG_OPTION, "xdev", parse_xdev, nullptr }, /* POSIX */ @@ -2476,10 +2477,17 @@ parse_context (const struct parser_table* entry, char **argv, int *arg_ptr) return true; } +static bool +parse_mount (const struct parser_table* entry, char **argv, int *arg_ptr) +{ + options.mount = true; + return parse_noop (entry, argv, arg_ptr); +} + static bool parse_xdev (const struct parser_table* entry, char **argv, int *arg_ptr) { - options.stay_on_filesystem = true; + options.xdev = true; return parse_noop (entry, argv, arg_ptr); } diff --git a/find/util.c b/find/util.c index 2e8fbc1e..509a6c2c 100644 --- a/find/util.c +++ b/find/util.c @@ -1010,7 +1010,7 @@ set_option_defaults (struct options *p) p->cur_day_start.tv_nsec = p->start_time.tv_nsec; p->full_days = false; - p->stay_on_filesystem = false; + p->mount = p->xdev = false; p->ignore_readdir_race = false; if (p->posixly_correct)