aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
Diffstat (limited to 'toys')
-rw-r--r--toys/lsb/umount.c5
-rw-r--r--toys/posix/df.c33
2 files changed, 21 insertions, 17 deletions
diff --git a/toys/lsb/umount.c b/toys/lsb/umount.c
index cc40f144..d1a2c69d 100644
--- a/toys/lsb/umount.c
+++ b/toys/lsb/umount.c
@@ -119,7 +119,10 @@ void umount_main(void)
if (TT.t) arg_comma_collate(&typestr, TT.t);
// Loop through mounted filesystems
- for (mlsave = ml = xgetmountlist(0); ml; ml = ml->next) {
+ mlsave = xgetmountlist(0);
+ ml = ml->prev;
+
+ for (ml = dlist_terminate(mlsave); ml; ml = ml->prev) {
if (TT.t) {
char *type, *types = typestr;
int len, skip = strncmp(types, "no", 2);
diff --git a/toys/posix/df.c b/toys/posix/df.c
index 7fab4281..afb296b2 100644
--- a/toys/posix/df.c
+++ b/toys/posix/df.c
@@ -95,7 +95,7 @@ static void show_mt(struct mtab_list *mt)
void df_main(void)
{
- struct mtab_list *mt, *mt2, *mtlist;
+ struct mtab_list *mt, *mtstart, *mtend;
// Handle -P and -k
TT.units = 1024;
@@ -106,7 +106,8 @@ void df_main(void)
TT.units);
} else puts("Filesystem\t1K-blocks\tUsed Available Use% Mounted on");
- mtlist = xgetmountlist(0);
+ if (!(mtstart = xgetmountlist(0))) return;
+ mtend = dlist_terminate(mtstart);
// If we have a list of filesystems on the command line, loop through them.
if (*toys.optargs) {
@@ -123,36 +124,36 @@ void df_main(void)
// Find and display this filesystem. Use _last_ hit in case of
// overmounts (which is first hit in the reversed list).
- mt2 = NULL;
- for (mt = mtlist; mt; mt = mt->next) {
+ for (mt = mtend; mt; mt = mt->prev) {
if (st.st_dev == mt->stat.st_dev) {
- mt2 = mt;
+ show_mt(mt);
break;
}
}
- show_mt(mt2);
}
} else {
- // Get and loop through mount list.
-
- for (mt = mtlist; mt; mt = mt->next) {
+ // Loop through mount list to filter out overmounts.
+ for (mt = mtend; mt; mt = mt->prev) {
struct mtab_list *mt2, *mt3;
+ // 0:0 is LANANA null device
if (!mt->stat.st_dev) continue;
// Filter out overmounts.
mt3 = mt;
- for (mt2 = mt->next; mt2; mt2 = mt2->next) {
+ for (mt2 = mt->prev; mt2; mt2 = mt2->prev) {
if (mt->stat.st_dev == mt2->stat.st_dev) {
- // For --bind mounts, take last match
- if (!strcmp(mt->device, mt2->device)) mt3 = mt2;
- // Filter out overmounts
- mt2->stat.st_dev = 0;
+ // For --bind mounts, take show earliest mount
+ if (!strcmp(mt->device, mt2->device)) {
+ if (!toys.optflags & FLAG_a) mt3->stat.st_dev = 0;
+ mt3 = mt2;
+ } else mt2->stat.st_dev = 0;
}
}
- show_mt(mt3);
}
+ // Cosmetic: show filesystems in creation order
+ for (mt = mtstart; mt; mt = mt->next) if (mt->stat.st_dev) show_mt(mt);
}
- if (CFG_TOYBOX_FREE) llist_traverse(mtlist, free);
+ if (CFG_TOYBOX_FREE) llist_traverse(mtstart, free);
}