* find/defs.h (struct options): Add mount member and rename stay_on_filesystem
to xdev.
* find/ftsfind.c (find): Set FTS_MOUNT flag when -mount is enabled.
* find/parser.c (parse_table): Use a separate parser for -mount.
(parse_mount): Declare and define function.
(parse_xdev): Use xdev option flag.
* find/util.c (set_option_defaults): Initialize new struct members.
* doc/find.texi (node Filesystems): Add new section describing the new behaviour
of -mount and specify the current behaviour of -xdev.
* find/find.1: Document the new -mount behaviour and specify current behaviour
of -xdev.
* NEWS (Changes in find): Mention the -mount behaviour change.
---
 NEWS           |  3 +++
 doc/find.texi  |  8 +++++---
 find/defs.h    |  7 +++++--
 find/find.1    | 10 ++++------
 find/ftsfind.c |  5 ++++-
 find/parser.c  | 12 ++++++++++--
 find/util.c    |  2 +-
 7 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/NEWS b/NEWS
index 06fe48e7..b2f02418 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 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 af93f9ed..f68b9486 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 80a22a5f..3337c4f9 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 70c0de64..00e747a4 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 4614369a..d1923b48 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 03000645..6fce0806 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 eb628aa7..cd7dd05c 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)
-- 
2.52.0


Reply via email to