Blame SOURCES/autofs-5.1.2-add-function-conf_amd_get_mount_paths.patch

304803
autofs-5.1.2 - add function conf_amd_get_mount_paths()
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
Add configuration function to get an array of amd mount section
304803
paths.
304803
304803
Signed-off-by: Ian Kent <raven@themaw.net>
304803
---
304803
 CHANGELOG          |    1 
304803
 include/defaults.h |    1 
304803
 lib/defaults.c     |   80 +++++++++++++++++++++++++++++++++++++++++++++++++++++
304803
 3 files changed, 82 insertions(+)
304803
304803
--- autofs-5.0.7.orig/CHANGELOG
304803
+++ autofs-5.0.7/CHANGELOG
304803
@@ -226,6 +226,7 @@
304803
 - add ref counting to struct map_source.
304803
 - add support for amd browsable option.
304803
 - add function conf_amd_get_map_name().
304803
+- add function conf_amd_get_mount_paths().
304803
 
304803
 25/07/2012 autofs-5.0.7
304803
 =======================
304803
--- autofs-5.0.7.orig/include/defaults.h
304803
+++ autofs-5.0.7/include/defaults.h
304803
@@ -171,6 +171,7 @@ unsigned int defaults_use_hostname_for_m
304803
 unsigned int defaults_disable_not_found_message(void);
304803
 
304803
 unsigned int conf_amd_mount_section_exists(const char *);
304803
+char **conf_amd_get_mount_paths(void);
304803
 char *conf_amd_get_arch(void);
304803
 char *conf_amd_get_karch(void);
304803
 char *conf_amd_get_os(void);
304803
--- autofs-5.0.7.orig/lib/defaults.c
304803
+++ autofs-5.0.7/lib/defaults.c
304803
@@ -763,6 +763,81 @@ static struct conf_option *conf_lookup(c
304803
 	return co;
304803
 }
304803
 
304803
+static char **conf_enumerate_amd_mount_sections(void)
304803
+{
304803
+	struct conf_option *this;
304803
+	unsigned int count;
304803
+	char **paths;
304803
+	char *last;
304803
+	int i, j;
304803
+
304803
+	last = NULL;
304803
+	count = 0;
304803
+	for (i = 0; i < CFG_TABLE_SIZE; i++) {
304803
+		if (!config->hash[i])
304803
+			continue;
304803
+
304803
+		this = config->hash[i];
304803
+		while (this) {
304803
+			/* Only amd mount section names begin with '/' */
304803
+			if (*this->section != '/') {
304803
+				this = this->next;
304803
+				continue;
304803
+			}
304803
+
304803
+			if (!last ||
304803
+			   strcmp(this->section, last))
304803
+				count ++;
304803
+			last = this->section;
304803
+			this = this->next;
304803
+		}
304803
+	}
304803
+
304803
+	if (!count)
304803
+		return NULL;
304803
+
304803
+	paths = (char **) malloc(((count + 1) * sizeof(char *)));
304803
+	if (!paths)
304803
+		return NULL;
304803
+	memset(paths, 0, ((count + 1) * sizeof(char *)));
304803
+
304803
+	last = NULL;
304803
+	j = 0;
304803
+
304803
+	for (i = 0; i < CFG_TABLE_SIZE; i++) {
304803
+		if (!config->hash[i])
304803
+			continue;
304803
+
304803
+		this = config->hash[i];
304803
+		while (this) {
304803
+			/* Only amd mount section names begin with '/' */
304803
+			if (*this->section != '/') {
304803
+				this = this->next;
304803
+				continue;
304803
+			}
304803
+
304803
+			if (!last ||
304803
+			    strcmp(this->section, last)) {
304803
+				char *path = strdup(this->section);
304803
+				if (!path)
304803
+					goto fail;
304803
+				paths[j++] = path;
304803
+			}
304803
+			last = this->section;
304803
+			this = this->next;
304803
+		}
304803
+	}
304803
+
304803
+	return paths;
304803
+
304803
+fail:
304803
+	i = 0;
304803
+	while (paths[i])
304803
+		free(paths[i++]);
304803
+	free(paths);
304803
+	return NULL;
304803
+}
304803
+
304803
 static unsigned int conf_section_exists(const char *section)
304803
 {
304803
 	struct conf_option *co;
304803
@@ -1758,6 +1833,11 @@ unsigned int conf_amd_mount_section_exis
304803
 	return conf_section_exists(section);
304803
 }
304803
 
304803
+char **conf_amd_get_mount_paths(void)
304803
+{
304803
+	return conf_enumerate_amd_mount_sections();
304803
+}
304803
+
304803
 char *conf_amd_get_arch(void)
304803
 {
304803
 	return conf_get_string(amd_gbl_sec, NAME_AMD_ARCH);