- make it possible to recognize an autofs filesystem by find

- add a new find's option -xautofs to not descend directories on autofs
    filesystems
This commit is contained in:
Kamil Dudka 2009-10-20 12:51:28 +00:00
parent 11088d0573
commit 723ddb7a97
4 changed files with 200 additions and 13 deletions

View File

@ -10,15 +10,3 @@ diff -up findutils-4.4.2/Makefile.am_old findutils-4.4.2/Makefile.am
ACLOCAL_AMFLAGS = -I gnulib/m4 -I m4
diff -up findutils-4.4.2/Makefile.in_old findutils-4.4.2/Makefile.in
--- findutils-4.4.2/Makefile.in_old 2009-06-30 14:54:00.000000000 +0200
+++ findutils-4.4.2/Makefile.in 2009-06-30 14:54:35.000000000 +0200
@@ -607,7 +607,7 @@ EXTRA_DIST = COPYING ChangeLog TODO conf
DISTCLEANFILES = tool-versions.txt
# "tests" is the gnulib unit test dir.
-SUBDIRS = gnulib tests build-aux lib find xargs locate doc po m4
+SUBDIRS = gnulib tests build-aux lib find xargs doc po m4
ACLOCAL_AMFLAGS = -I gnulib/m4 -I m4
TESTFILE_SUFFIXES = .exp .xo .xe .xi
all: config.h

View File

@ -0,0 +1,87 @@
diff -rup findutils-4.4.2.orig/find/fstype.c findutils-4.4.2/find/fstype.c
--- findutils-4.4.2.orig/find/fstype.c 2009-05-16 17:17:01.000000000 +0200
+++ findutils-4.4.2/find/fstype.c 2009-10-20 12:47:10.589871024 +0200
@@ -205,7 +205,72 @@ must_read_fs_list(bool need_fs_type)
return entries;
}
+/* Return the device number from MOUNT_OPTIONS, if possible.
+ Otherwise return (dev_t) -1. Taken from 'mountlist' module
+ from gnulib. */
+static dev_t
+dev_from_mount_options (char const *mount_options)
+{
+ /* GNU/Linux allows file system implementations to define their own
+ meaning for "dev=" mount options, so don't trust the meaning
+ here. */
+# ifndef __linux__
+
+ static char const dev_pattern[] = ",dev=";
+ char const *devopt = strstr (mount_options, dev_pattern);
+
+ if (devopt)
+ {
+ char const *optval = devopt + sizeof dev_pattern - 1;
+ char *optvalend;
+ unsigned long int dev;
+ errno = 0;
+ dev = strtoul (optval, &optvalend, 16);
+ if (optval != optvalend
+ && (*optvalend == '\0' || *optvalend == ',')
+ && ! (dev == ULONG_MAX && errno == ERANGE)
+ && dev == (dev_t) dev)
+ return dev;
+ }
+
+# endif
+ (void) mount_options;
+ return -1;
+}
+
+/* Return true if the file described by STATP is on autofs file system
+ and call set_fstype_devno () if the autofs file system is matched. */
+static bool
+filesystem_check_autofs (const struct stat *statp)
+{
+ FILE *fp;
+ struct mntent *mnt;
+ struct mount_entry entry;
+ bool match = false;
+
+ /* open /proc/mounts because autofs is not listed in /etc/mtab */
+ fp = setmntent ("/proc/mounts", "r");
+ if (fp == NULL)
+ return false;
+ while ((mnt = getmntent (fp)))
+ {
+ if (0 != strcmp ("autofs", mnt->mnt_type))
+ continue;
+
+ entry.me_mountdir = mnt->mnt_dir;
+ entry.me_dev = dev_from_mount_options (mnt->mnt_opts);
+ set_fstype_devno (&entry);
+ if (entry.me_dev == statp->st_dev)
+ {
+ match = true;
+ break;
+ }
+ }
+
+ endmntent (fp);
+ return match;
+}
/* Return a newly allocated string naming the type of file system that the
file PATH, described by STATP, is on.
@@ -244,6 +309,10 @@ file_system_type_uncached (const struct
}
free_file_system_list(entries);
+ /* check for autofs */
+ if (type == NULL && filesystem_check_autofs (statp))
+ type = xstrdup ("autofs");
+
/* Don't cache unknown values. */
fstype_known = (type != NULL);

View File

@ -0,0 +1,103 @@
diff -rup findutils-4.4.2.orig/doc/find.texi findutils-4.4.2/doc/find.texi
--- findutils-4.4.2.orig/doc/find.texi 2009-10-20 14:31:43.902741386 +0200
+++ findutils-4.4.2/doc/find.texi 2009-10-20 14:30:55.680178944 +0200
@@ -1420,6 +1420,10 @@ them.
There are two ways to avoid searching certain filesystems. One way is
to tell @code{find} to only search one filesystem:
+@deffn Option -xautofs
+Don't descend directories on autofs filesystems.
+@end deffn
+
@deffn Option -xdev
@deffnx Option -mount
Don't descend directories on other filesystems. These options are
diff -rup findutils-4.4.2.orig/find/defs.h findutils-4.4.2/find/defs.h
--- findutils-4.4.2.orig/find/defs.h 2009-10-20 14:31:43.902741386 +0200
+++ findutils-4.4.2/find/defs.h 2009-10-20 14:30:55.680906690 +0200
@@ -559,6 +559,9 @@ struct options
/* If true, don't cross filesystem boundaries. */
boolean stay_on_filesystem;
+ /* If true, don't descend directories on autofs filesystems. */
+ boolean bypass_autofs;
+
/* 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.
*/
diff -rup findutils-4.4.2.orig/find/find.1 findutils-4.4.2/find/find.1
--- findutils-4.4.2.orig/find/find.1 2009-10-20 14:31:43.903741308 +0200
+++ findutils-4.4.2/find/find.1 2009-10-20 14:30:55.680906690 +0200
@@ -451,6 +451,9 @@ if standard input is a tty, and to
.B \-nowarn
otherwise.
+.IP \-xautofs
+Don't descend directories on autofs filesystems.
+
.IP \-xdev
Don't descend directories on other filesystems.
diff -rup findutils-4.4.2.orig/find/ftsfind.c findutils-4.4.2/find/ftsfind.c
--- findutils-4.4.2.orig/find/ftsfind.c 2009-05-16 17:17:01.000000000 +0200
+++ findutils-4.4.2/find/ftsfind.c 2009-10-20 14:31:04.745866565 +0200
@@ -525,6 +525,12 @@ consider_visiting(FTS *p, FTSENT *ent)
}
}
+ if (options.bypass_autofs &&
+ 0 == strcmp ("autofs", filesystem_type (&statbuf, ent->fts_name)))
+ {
+ fts_set(p, ent, FTS_SKIP); /* descend no further */
+ }
+
if ( (ent->fts_info == FTS_D) && !options.do_dir_first )
{
/* this is the preorder visit, but user said -depth */
diff -rup findutils-4.4.2.orig/find/parser.c findutils-4.4.2/find/parser.c
--- findutils-4.4.2.orig/find/parser.c 2009-10-20 14:31:43.906741469 +0200
+++ findutils-4.4.2/find/parser.c 2009-10-20 14:30:55.683024396 +0200
@@ -154,6 +154,7 @@ static boolean parse_user PARAM
static boolean parse_version PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
static boolean parse_wholename PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
static boolean parse_xdev PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_xautofs PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
static boolean parse_ignore_race PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
static boolean parse_noignore_race PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
static boolean parse_warn PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
@@ -330,6 +331,7 @@ static struct parser_table const parse_t
PARSE_TEST_NP ("wholename", wholename), /* GNU, replaced -path, but anyway -path will soon be in POSIX */
{ARG_TEST, "writable", parse_accesscheck, pred_writable}, /* GNU, 4.3.0+ */
PARSE_OPTION ("xdev", xdev), /* POSIX */
+ PARSE_OPTION ("xautofs", xautofs),
PARSE_TEST ("xtype", xtype), /* GNU */
#ifdef UNIMPLEMENTED_UNIX
/* It's pretty ugly for find to know about archive formats.
@@ -2696,6 +2698,16 @@ parse_xdev (const struct parser_table* e
}
static boolean
+parse_xautofs (const struct parser_table* entry, char **argv, int *arg_ptr)
+{
+ (void) argv;
+ (void) arg_ptr;
+ (void) entry;
+ options.bypass_autofs = true;
+ return true;
+}
+
+static boolean
parse_ignore_race (const struct parser_table* entry, char **argv, int *arg_ptr)
{
options.ignore_readdir_race = true;
diff -rup findutils-4.4.2.orig/find/util.c findutils-4.4.2/find/util.c
--- findutils-4.4.2.orig/find/util.c 2009-05-16 17:17:01.000000000 +0200
+++ findutils-4.4.2/find/util.c 2009-10-20 14:30:55.684180119 +0200
@@ -933,6 +933,7 @@ set_option_defaults(struct options *p)
p->full_days = false;
p->stay_on_filesystem = false;
+ p->bypass_autofs = false;
p->ignore_readdir_race = false;
if (p->posixly_correct)

View File

@ -1,7 +1,7 @@
Summary: The GNU versions of find utilities (find and xargs)
Name: findutils
Version: 4.4.2
Release: 3%{?dist}
Release: 4%{?dist}
Epoch: 1
License: GPLv3+
Group: Applications/File
@ -10,6 +10,8 @@ Source0: ftp://ftp.gnu.org/gnu/findutils/%{name}-%{version}.tar.gz
Source1: ftp://ftp.gnu.org/gnu/findutils/%{name}-%{version}.tar.gz.sig
Patch1: findutils-4.4.0-no-locate.patch
Patch2: findutils-4.4.0-selinux.patch
Patch3: findutils-4.4.2-autofs.patch
Patch4: findutils-4.4.2-xautofs.patch
Requires(post): /sbin/install-info
Requires(preun): /sbin/install-info
Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
@ -32,6 +34,8 @@ useful for finding things on your system.
%setup -q
%patch1 -p1 -b .no-locate
%patch2 -p1 -b .selinux
%patch3 -p1 -b .autofs
%patch4 -p1 -b .xautofs
autoreconf
@ -89,6 +93,11 @@ rm -rf $RPM_BUILD_ROOT
%{_infodir}/find-maint.info.gz
%changelog
* Tue Oct 20 2009 Kamil Dudka <kdudka@redhat.com> - 1:4.4.2-4
- make it possible to recognize an autofs filesystem by find
- add a new find's option -xautofs to not descend directories on autofs
filesystems
* Mon Sep 14 2009 Kamil Dudka <kdudka@redhat.com> - 1:4.4.2-3
- do process install-info only without --excludedocs(#515914)