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.c34
1 files changed, 28 insertions, 6 deletions
diff --git a/lib/utils_disk.c b/lib/utils_disk.c
index c7c9126e..582d3ea1 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,11 +143,15 @@ 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) {
133 if (strcmp(me->me_devname, d->name)==0) 150 if (strcmp(me->me_devname, d->name)==0) {
134 best_match = me; 151 if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) >= 0) {
152 best_match = me;
153 }
154 }
135 } 155 }
136 156
137 /* set best match by directory name if no match was found by devname */ 157 /* set best match by directory name if no match was found by devname */
@@ -142,8 +162,10 @@ np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list
142 (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0))) 162 (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0)))
143 || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0)) 163 || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0))
144 { 164 {
145 best_match = me; 165 if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) >= 0) {
146 best_match_len = len; 166 best_match = me;
167 best_match_len = len;
168 }
147 } 169 }
148 } 170 }
149 } 171 }