aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/getmountlist.c21
-rw-r--r--lib/lib.h3
-rw-r--r--lib/llist.c14
3 files changed, 28 insertions, 10 deletions
diff --git a/lib/getmountlist.c b/lib/getmountlist.c
index d5a392d6..0b7ff06b 100644
--- a/lib/getmountlist.c
+++ b/lib/getmountlist.c
@@ -11,25 +11,28 @@
struct mtab_list *xgetmountlist(char *path)
{
- struct mtab_list *mtlist, *mt;
+ struct mtab_list *mtlist = 0, *mt;
struct mntent *me;
FILE *fp;
+ char *p = path ? path : "/proc/mounts";
- if (!path) path = "/proc/mounts";
- if (!(fp = setmntent(path, "r"))) perror_exit("bad %s", path);
+ if (!(fp = setmntent(p, "r"))) perror_exit("bad %s", p);
// The "test" part of the loop is done before the first time through and
// again after each "increment", so putting the actual load there avoids
// duplicating it. If the load was NULL, the loop stops.
- for (mtlist = 0; (me = getmntent(fp)); mtlist = mt) {
+ while ((me = getmntent(fp))) {
mt = xzalloc(sizeof(struct mtab_list) + strlen(me->mnt_fsname) +
strlen(me->mnt_dir) + strlen(me->mnt_type) + strlen(me->mnt_opts) + 4);
- mt->next = mtlist;
-
- // Collect details about mounted filesystem (don't bother for /etc/fstab).
- if (stat(me->mnt_dir, &(mt->stat)) || statvfs(me->mnt_dir, &(mt->statvfs)))
- perror_msg("stat '%s'");
+ dlist_add_nomalloc((void *)&mtlist, (void *)mt);
+
+ // Collect details about mounted filesystem
+ // Don't report errors, just leave data zeroed
+ if (!path) {
+ stat(me->mnt_dir, &(mt->stat));
+ statvfs(me->mnt_dir, &(mt->statvfs));
+ }
// Remember information from /proc/mounts
mt->dir = stpcpy(mt->type, me->mnt_type)+1;
diff --git a/lib/lib.h b/lib/lib.h
index bbb1488d..09af2837 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -31,6 +31,7 @@ void *llist_pop(void *list); // actually void **list
void *dlist_pop(void *list); // actually struct double_list **list
void dlist_add_nomalloc(struct double_list **list, struct double_list *new);
struct double_list *dlist_add(struct double_list **list, char *data);
+void *dlist_terminate(void *list);
// args.c
void get_optflags(void);
@@ -162,7 +163,7 @@ int xsocket(int domain, int type, int protocol);
// getmountlist.c
struct mtab_list {
- struct mtab_list *next;
+ struct mtab_list *next, *prev;
struct stat stat;
struct statvfs statvfs;
char *dir;
diff --git a/lib/llist.c b/lib/llist.c
index 2d5bc97a..6b4b8f2c 100644
--- a/lib/llist.c
+++ b/lib/llist.c
@@ -85,3 +85,17 @@ struct double_list *dlist_add(struct double_list **list, char *data)
return new;
}
+
+// Terminate circular list for traversal in either direction. Returns end *.
+void *dlist_terminate(void *list)
+{
+ struct double_list *end = list;
+
+ if (!list) return 0;
+
+ end = end->prev;
+ end->next->prev = 0;
+ end->next = 0;
+
+ return end;
+}