Blame SOURCES/findutils-4.4.2-autofs.patch

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