aboutsummaryrefslogtreecommitdiff
path: root/lib/getmountlist.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-05-29 05:22:02 -0500
committerRob Landley <rob@landley.net>2014-05-29 05:22:02 -0500
commitdc640259adff6007d195fd4cc78dcf9829e5e6ee (patch)
tree97ab6eb6abb286a3d612b8aa86646cf655b1a1cf /lib/getmountlist.c
parent55e9f35223e40f455b80671f25b412072d9af678 (diff)
downloadtoybox-dc640259adff6007d195fd4cc78dcf9829e5e6ee.tar.gz
Switch mtab_list to doubly linked so we can traverse in either order. Convert umount and df. Add dlist_terminate() to break lists for traversal in either direction.
Diffstat (limited to 'lib/getmountlist.c')
-rw-r--r--lib/getmountlist.c21
1 files changed, 12 insertions, 9 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;