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