autofs-5.0.3 - make is_mounted() use new ioctl interface, if available. From: Ian Kent 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. --- CHANGELOG | 1 + lib/mounts.c | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 083c5b6..8c4ace0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -51,6 +51,7 @@ - fix bad alloca usage. - add miscellaneous device node interface library. - use miscellaneous device node, if available, for active restart. +- make is_mounted() use new ioctl interface, if available. 14/01/2008 autofs-5.0.3 ----------------------- diff --git a/lib/mounts.c b/lib/mounts.c index 957448c..6d0a69c 100644 --- a/lib/mounts.c +++ b/lib/mounts.c @@ -405,7 +405,7 @@ int contained_in_local_fs(const char *path) 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; @@ -451,6 +451,35 @@ int is_mounted(const char *table, const char *path, unsigned int type) 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; @@ -917,10 +946,14 @@ int tree_find_mnt_ents(struct mnt_list *mnts, struct list_head *list, const char 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))