Blame SOURCES/findutils-4.4.2-autofs.patch

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