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.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/lib/utils_disk.c b/lib/utils_disk.c
index efe35fc5..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;
@@ -69,16 +71,22 @@ np_add_parameter(struct parameter_list **list, const char *name)
69 new_path->dtotal_units = 0; 71 new_path->dtotal_units = 0;
70 new_path->inodes_total = 0; 72 new_path->inodes_total = 0;
71 new_path->inodes_free = 0; 73 new_path->inodes_free = 0;
74 new_path->inodes_free_to_root = 0;
75 new_path->inodes_used = 0;
72 new_path->dused_inodes_percent = 0; 76 new_path->dused_inodes_percent = 0;
73 new_path->dfree_inodes_percent = 0; 77 new_path->dfree_inodes_percent = 0;
74 78
79 strcpy(new_path->name, name);
80
75 if (current == NULL) { 81 if (current == NULL) {
76 *list = new_path; 82 *list = new_path;
83 new_path->name_prev = NULL;
77 } else { 84 } else {
78 while (current->name_next) { 85 while (current->name_next) {
79 current = current->name_next; 86 current = current->name_next;
80 } 87 }
81 current->name_next = new_path; 88 current->name_next = new_path;
89 new_path->name_prev = current;
82 } 90 }
83 return new_path; 91 return new_path;
84} 92}
@@ -87,6 +95,9 @@ np_add_parameter(struct parameter_list **list, const char *name)
87struct parameter_list * 95struct parameter_list *
88np_del_parameter(struct parameter_list *item, struct parameter_list *prev) 96np_del_parameter(struct parameter_list *item, struct parameter_list *prev)
89{ 97{
98 if (item == NULL) {
99 return NULL;
100 }
90 struct parameter_list *next; 101 struct parameter_list *next;
91 102
92 if (item->name_next) 103 if (item->name_next)
@@ -94,10 +105,17 @@ np_del_parameter(struct parameter_list *item, struct parameter_list *prev)
94 else 105 else
95 next = NULL; 106 next = NULL;
96 107
97 free(item); 108 if (next)
109 next->name_prev = prev;
110
98 if (prev) 111 if (prev)
99 prev->name_next = next; 112 prev->name_next = next;
100 113
114 if (item->name) {
115 free(item->name);
116 }
117 free(item);
118
101 return next; 119 return next;
102} 120}
103 121
@@ -125,11 +143,15 @@ np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list
125 size_t name_len = strlen(d->name); 143 size_t name_len = strlen(d->name);
126 size_t best_match_len = 0; 144 size_t best_match_len = 0;
127 struct mount_entry *best_match = NULL; 145 struct mount_entry *best_match = NULL;
146 struct fs_usage fsp;
128 147
129 /* 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 */
130 for (me = mount_list; me; me = me->me_next) { 149 for (me = mount_list; me; me = me->me_next) {
131 if (strcmp(me->me_devname, d->name)==0) 150 if (strcmp(me->me_devname, d->name)==0) {
132 best_match = me; 151 if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) >= 0) {
152 best_match = me;
153 }
154 }
133 } 155 }
134 156
135 /* 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 */
@@ -140,8 +162,10 @@ np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list
140 (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0))) 162 (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0)))
141 || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0)) 163 || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0))
142 { 164 {
143 best_match = me; 165 if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) >= 0) {
144 best_match_len = len; 166 best_match = me;
167 best_match_len = len;
168 }
145 } 169 }
146 } 170 }
147 } 171 }