Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > 130701790bf2d95e902edf16031ff596 > files > 115

autofs-5.0.1-0.rc2.164.el5_8.src.rpm

autofs-5.0.3 - make is_mounted() use new ioctl interface, if available.

From: Ian Kent <raven@themaw.net>

This patch enables the function is_mounted() to use the updated ioctl
interface if it is available. This reduces the need to scan the file
or memory based mount table.
---

 lib/mounts.c |   35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)


--- autofs-5.0.1.orig/lib/mounts.c
+++ autofs-5.0.1/lib/mounts.c
@@ -397,7 +397,7 @@ int contained_in_local_fs(const char *pa
 	return ret;
 }
 
-int is_mounted(const char *table, const char *path, unsigned int type)
+static int table_is_mounted(const char *table, const char *path, unsigned int type)
 {
 	struct mntent *mnt;
 	struct mntent mnt_wrk;
@@ -443,6 +443,35 @@ int is_mounted(const char *table, const 
 	return ret;
 }
 
+static int ioctl_is_mounted(const char *path, unsigned int type)
+{
+	struct ioctl_ops *ops = get_ioctl_ops();
+	unsigned int mounted;
+
+	ops->ismountpoint(LOGOPT_NONE, -1, path, &mounted);
+	if (mounted) {
+		switch (type) {
+		case MNTS_ALL:
+			return 1;
+		case MNTS_AUTOFS:
+			return (mounted & DEV_IOCTL_IS_AUTOFS);
+		case MNTS_REAL:
+			return (mounted & DEV_IOCTL_IS_OTHER);
+		}
+	}
+	return 0;
+}
+
+int is_mounted(const char *table, const char *path, unsigned int type)
+{
+	struct ioctl_ops *ops = get_ioctl_ops();
+
+	if (ops->ismountpoint)
+		return ioctl_is_mounted(path, type);
+	else
+		return table_is_mounted(table, path, type);
+}
+
 int has_fstab_option(const char *opt)
 {
 	struct mntent *mnt;
@@ -909,10 +938,14 @@ int tree_find_mnt_ents(struct mnt_list *
 
 int tree_is_mounted(struct mnt_list *mnts, const char *path, unsigned int type)
 {
+	struct ioctl_ops *ops = get_ioctl_ops();
 	struct list_head *p;
 	struct list_head list;
 	int mounted = 0;
 
+	if (ops->ismountpoint)
+		return ioctl_is_mounted(path, type);
+
 	INIT_LIST_HEAD(&list);
 
 	if (!tree_find_mnt_ents(mnts, &list, path))