aboutsummaryrefslogtreecommitdiff
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 74708c0e..fd768b20 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)
return new_path;
}
+/* returns a pointer to the struct found in the list */
+struct parameter_list *
+np_find_parameter(struct parameter_list *list, const char *name)
+{
+ struct parameter_list *temp_list;
+ for (temp_list = list; temp_list; temp_list = temp_list->name_next) {
+ if (! strcmp(temp_list->name, name))
+ return temp_list;
+ }
+
+ return NULL;
+}
+
void
np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact)
{
struct parameter_list *d;
for (d = desired; d; d= d->name_next) {
- struct mount_entry *me;
- size_t name_len = strlen(d->name);
- size_t best_match_len = 0;
- struct mount_entry *best_match = NULL;
+ if (! d->best_match) {
+ struct mount_entry *me;
+ size_t name_len = strlen(d->name);
+ size_t best_match_len = 0;
+ struct mount_entry *best_match = NULL;
- for (me = mount_list; me; me = me->me_next) {
- size_t len = strlen (me->me_mountdir);
- if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
- (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0)))
- || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0))
- {
- best_match = me;
- best_match_len = len;
- } else {
- len = strlen (me->me_devname);
- if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
- (len == 1 || strncmp (me->me_devname, d->name, len) == 0)))
- || (exact == TRUE && strcmp(me->me_devname, d->name)==0))
+ for (me = mount_list; me; me = me->me_next) {
+ size_t len = strlen (me->me_mountdir);
+ if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
+ (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0)))
+ || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0))
{
best_match = me;
best_match_len = len;
+ } else {
+ len = strlen (me->me_devname);
+ if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
+ (len == 1 || strncmp (me->me_devname, d->name, len) == 0)))
+ || (exact == TRUE && strcmp(me->me_devname, d->name)==0))
+ {
+ best_match = me;
+ best_match_len = len;
+ }
}
}
- }
- if (best_match) {
- d->best_match = best_match;
- } else {
- d->best_match = NULL; /* Not sure why this is needed as it should be null on initialisation */
+ if (best_match) {
+ d->best_match = best_match;
+ } else {
+ d->best_match = NULL; /* Not sure why this is needed as it should be null on initialisation */
+ }
}
}
}
diff --git a/lib/utils_disk.h b/lib/utils_disk.h
index 8bf4f113..55de9385 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);
int np_find_name (struct name_list *list, const char *name);
int np_seen_name (struct name_list *list, const char *name);
struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name);
+struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name);
int search_parameter_list (struct parameter_list *list, const char *name);
void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact);