summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/utils_disk.c59
-rw-r--r--lib/utils_disk.h1
2 files changed, 38 insertions, 22 deletions
diff --git a/lib/utils_disk.c b/lib/utils_disk.c
index 74708c0..fd768b2 100644
--- a/lib/utils_disk.c
+++ b/lib/utils_disk.c
@@ -73,39 +73,54 @@ np_add_parameter(struct parameter_list **list, const char *name)
73 return new_path; 73 return new_path;
74} 74}
75 75
76/* returns a pointer to the struct found in the list */
77struct parameter_list *
78np_find_parameter(struct parameter_list *list, const char *name)
79{
80 struct parameter_list *temp_list;
81 for (temp_list = list; temp_list; temp_list = temp_list->name_next) {
82 if (! strcmp(temp_list->name, name))
83 return temp_list;
84 }
85
86 return NULL;
87}
88
76void 89void
77np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact) 90np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact)
78{ 91{
79 struct parameter_list *d; 92 struct parameter_list *d;
80 for (d = desired; d; d= d->name_next) { 93 for (d = desired; d; d= d->name_next) {
81 struct mount_entry *me; 94 if (! d->best_match) {
82 size_t name_len = strlen(d->name); 95 struct mount_entry *me;
83 size_t best_match_len = 0; 96 size_t name_len = strlen(d->name);
84 struct mount_entry *best_match = NULL; 97 size_t best_match_len = 0;
98 struct mount_entry *best_match = NULL;
85 99
86 for (me = mount_list; me; me = me->me_next) { 100 for (me = mount_list; me; me = me->me_next) {
87 size_t len = strlen (me->me_mountdir); 101 size_t len = strlen (me->me_mountdir);
88 if ((exact == FALSE && (best_match_len <= len && len <= name_len && 102 if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
89 (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0))) 103 (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0)))
90 || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0)) 104 || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0))
91 {
92 best_match = me;
93 best_match_len = len;
94 } else {
95 len = strlen (me->me_devname);
96 if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
97 (len == 1 || strncmp (me->me_devname, d->name, len) == 0)))
98 || (exact == TRUE && strcmp(me->me_devname, d->name)==0))
99 { 105 {
100 best_match = me; 106 best_match = me;
101 best_match_len = len; 107 best_match_len = len;
108 } else {
109 len = strlen (me->me_devname);
110 if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
111 (len == 1 || strncmp (me->me_devname, d->name, len) == 0)))
112 || (exact == TRUE && strcmp(me->me_devname, d->name)==0))
113 {
114 best_match = me;
115 best_match_len = len;
116 }
102 } 117 }
103 } 118 }
104 } 119 if (best_match) {
105 if (best_match) { 120 d->best_match = best_match;
106 d->best_match = best_match; 121 } else {
107 } else { 122 d->best_match = NULL; /* Not sure why this is needed as it should be null on initialisation */
108 d->best_match = NULL; /* Not sure why this is needed as it should be null on initialisation */ 123 }
109 } 124 }
110 } 125 }
111} 126}
diff --git a/lib/utils_disk.h b/lib/utils_disk.h
index 8bf4f11..55de938 100644
--- a/lib/utils_disk.h
+++ b/lib/utils_disk.h
@@ -28,5 +28,6 @@ void np_add_name (struct name_list **list, const char *name);
28int np_find_name (struct name_list *list, const char *name); 28int np_find_name (struct name_list *list, const char *name);
29int np_seen_name (struct name_list *list, const char *name); 29int np_seen_name (struct name_list *list, const char *name);
30struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name); 30struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name);
31struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name);
31int search_parameter_list (struct parameter_list *list, const char *name); 32int search_parameter_list (struct parameter_list *list, const char *name);
32void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact); 33void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact);