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);