summaryrefslogtreecommitdiffstats
path: root/lib/utils_disk.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils_disk.c')
-rw-r--r--lib/utils_disk.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/utils_disk.c b/lib/utils_disk.c
index c7c9126e..468769b1 100644
--- a/lib/utils_disk.c
+++ b/lib/utils_disk.c
@@ -28,6 +28,7 @@
28 28
29#include "common.h" 29#include "common.h"
30#include "utils_disk.h" 30#include "utils_disk.h"
31#include "gl/fsusage.h"
31 32
32void 33void
33np_add_name (struct name_list **list, const char *name) 34np_add_name (struct name_list **list, const char *name)
@@ -46,9 +47,10 @@ np_add_parameter(struct parameter_list **list, const char *name)
46 struct parameter_list *current = *list; 47 struct parameter_list *current = *list;
47 struct parameter_list *new_path; 48 struct parameter_list *new_path;
48 new_path = (struct parameter_list *) malloc (sizeof *new_path); 49 new_path = (struct parameter_list *) malloc (sizeof *new_path);
49 new_path->name = (char *) name; 50 new_path->name = (char *) malloc(strlen(name) + 1);
50 new_path->best_match = NULL; 51 new_path->best_match = NULL;
51 new_path->name_next = NULL; 52 new_path->name_next = NULL;
53 new_path->name_prev = NULL;
52 new_path->freespace_bytes = NULL; 54 new_path->freespace_bytes = NULL;
53 new_path->freespace_units = NULL; 55 new_path->freespace_units = NULL;
54 new_path->freespace_percent = NULL; 56 new_path->freespace_percent = NULL;
@@ -74,13 +76,17 @@ np_add_parameter(struct parameter_list **list, const char *name)
74 new_path->dused_inodes_percent = 0; 76 new_path->dused_inodes_percent = 0;
75 new_path->dfree_inodes_percent = 0; 77 new_path->dfree_inodes_percent = 0;
76 78
79 strcpy(new_path->name, name);
80
77 if (current == NULL) { 81 if (current == NULL) {
78 *list = new_path; 82 *list = new_path;
83 new_path->name_prev = NULL;
79 } else { 84 } else {
80 while (current->name_next) { 85 while (current->name_next) {
81 current = current->name_next; 86 current = current->name_next;
82 } 87 }
83 current->name_next = new_path; 88 current->name_next = new_path;
89 new_path->name_prev = current;
84 } 90 }
85 return new_path; 91 return new_path;
86} 92}
@@ -89,6 +95,9 @@ np_add_parameter(struct parameter_list **list, const char *name)
89struct parameter_list * 95struct parameter_list *
90np_del_parameter(struct parameter_list *item, struct parameter_list *prev) 96np_del_parameter(struct parameter_list *item, struct parameter_list *prev)
91{ 97{
98 if (item == NULL) {
99 return NULL;
100 }
92 struct parameter_list *next; 101 struct parameter_list *next;
93 102
94 if (item->name_next) 103 if (item->name_next)
@@ -96,10 +105,17 @@ np_del_parameter(struct parameter_list *item, struct parameter_list *prev)
96 else 105 else
97 next = NULL; 106 next = NULL;
98 107
99 free(item); 108 if (next)
109 next->name_prev = prev;
110
100 if (prev) 111 if (prev)
101 prev->name_next = next; 112 prev->name_next = next;
102 113
114 if (item->name) {
115 free(item->name);
116 }
117 free(item);
118
103 return next; 119 return next;
104} 120}
105 121
@@ -127,9 +143,12 @@ np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list
127 size_t name_len = strlen(d->name); 143 size_t name_len = strlen(d->name);
128 size_t best_match_len = 0; 144 size_t best_match_len = 0;
129 struct mount_entry *best_match = NULL; 145 struct mount_entry *best_match = NULL;
146 struct fs_usage fsp;
130 147
131 /* set best match if path name exactly matches a mounted device name */ 148 /* set best match if path name exactly matches a mounted device name */
132 for (me = mount_list; me; me = me->me_next) { 149 for (me = mount_list; me; me = me->me_next) {
150 if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) < 0)
151 continue; /* skip if permissions do not suffice for accessing device */
133 if (strcmp(me->me_devname, d->name)==0) 152 if (strcmp(me->me_devname, d->name)==0)
134 best_match = me; 153 best_match = me;
135 } 154 }
@@ -137,6 +156,8 @@ np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list
137 /* set best match by directory name if no match was found by devname */ 156 /* set best match by directory name if no match was found by devname */
138 if (! best_match) { 157 if (! best_match) {
139 for (me = mount_list; me; me = me->me_next) { 158 for (me = mount_list; me; me = me->me_next) {
159 if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) < 0)
160 continue; /* skip if permissions do not suffice for accessing device */
140 size_t len = strlen (me->me_mountdir); 161 size_t len = strlen (me->me_mountdir);
141 if ((exact == FALSE && (best_match_len <= len && len <= name_len && 162 if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
142 (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0))) 163 (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0)))