f21840
From 113d6b31623db33fbea65e586f5bfaf1ea1c8d30 Mon Sep 17 00:00:00 2001
f21840
From: Kamil Dudka <kdudka@redhat.com>
f21840
Date: Wed, 11 May 2011 16:46:32 +0200
f21840
Subject: [PATCH 2/4] findutils-4.4.2-autofs.patch
f21840
f21840
---
f21840
 find/fstype.c |   69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
f21840
 1 files changed, 69 insertions(+), 0 deletions(-)
f21840
f21840
diff --git a/find/fstype.c b/find/fstype.c
f21840
index c6dbe8b..9cbf620 100644
f21840
--- a/find/fstype.c
f21840
+++ b/find/fstype.c
f21840
@@ -187,7 +187,72 @@ must_read_fs_list (bool need_fs_type)
f21840
   return entries;
f21840
 }
f21840
 
f21840
+/* Return the device number from MOUNT_OPTIONS, if possible.
f21840
+   Otherwise return (dev_t) -1. Taken from 'mountlist' module
f21840
+   from gnulib.  */
f21840
+static dev_t
f21840
+dev_from_mount_options (char const *mount_options)
f21840
+{
f21840
+  /* GNU/Linux allows file system implementations to define their own
f21840
+     meaning for "dev=" mount options, so don't trust the meaning
f21840
+     here.  */
f21840
+# ifndef __linux__
f21840
+
f21840
+  static char const dev_pattern[] = ",dev=";
f21840
+  char const *devopt = strstr (mount_options, dev_pattern);
f21840
+
f21840
+  if (devopt)
f21840
+    {
f21840
+      char const *optval = devopt + sizeof dev_pattern - 1;
f21840
+      char *optvalend;
f21840
+      unsigned long int dev;
f21840
+      errno = 0;
f21840
+      dev = strtoul (optval, &optvalend, 16);
f21840
+      if (optval != optvalend
f21840
+	  && (*optvalend == '\0' || *optvalend == ',')
f21840
+	  && ! (dev == ULONG_MAX && errno == ERANGE)
f21840
+	  && dev == (dev_t) dev)
f21840
+	return dev;
f21840
+    }
f21840
 
f21840
+# endif
f21840
+  (void) mount_options;
f21840
+  return -1;
f21840
+}
f21840
+
f21840
+/* Return true if the file described by STATP is on autofs file system
f21840
+   and call set_fstype_devno () if the autofs file system is matched.  */
f21840
+static bool
f21840
+filesystem_check_autofs (const struct stat *statp)
f21840
+{
f21840
+  FILE *fp;
f21840
+  struct mntent *mnt;
f21840
+  struct mount_entry entry;
f21840
+  bool match = false;
f21840
+
f21840
+  /* open /proc/mounts because autofs is not listed in /etc/mtab */
f21840
+  fp = setmntent ("/proc/mounts", "r");
f21840
+  if (fp == NULL)
f21840
+    return false;
f21840
+
f21840
+  while ((mnt = getmntent (fp)))
f21840
+    {
f21840
+      if (0 != strcmp ("autofs", mnt->mnt_type))
f21840
+	  continue;
f21840
+
f21840
+      entry.me_mountdir = mnt->mnt_dir;
f21840
+      entry.me_dev = dev_from_mount_options (mnt->mnt_opts);
f21840
+      set_fstype_devno (&entry);
f21840
+      if (entry.me_dev == statp->st_dev)
f21840
+	{
f21840
+	  match = true;
f21840
+	  break;
f21840
+	}
f21840
+    }
f21840
+
f21840
+  endmntent (fp);
f21840
+  return match;
f21840
+}
f21840
 
f21840
 /* Return a newly allocated string naming the type of file system that the
f21840
    file PATH, described by STATP, is on.
f21840
@@ -238,6 +303,10 @@ file_system_type_uncached (const struct stat *statp, const char *path)
f21840
     }
f21840
   free_file_system_list (entries);
f21840
 
f21840
+  /* check for autofs */
f21840
+  if (type == NULL && filesystem_check_autofs (statp))
f21840
+    type = xstrdup ("autofs");
f21840
+
f21840
   /* Don't cache unknown values. */
f21840
   fstype_known = (type != NULL);
f21840
 
f21840
-- 
f21840
1.7.4.4
f21840