annotate toys/posix/df.c @ 1753:0f940c4f9658 draft

Promote runcon to android (and add an android menu).
author Rob Landley <rob@landley.net>
date Mon, 23 Mar 2015 13:45:47 -0500
parents 0c8ef714cf03
children 57f2a26fa92c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
1 /* df.c - report free disk space.
2
67b517913e56 Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents: 1
diff changeset
2 *
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 186
diff changeset
3 * Copyright 2006 Rob Landley <rob@landley.net>
156
1e8f4b05cb65 Remove trailing whitespace (thanks to Charlie Shepherd), and a couple comment
Rob Landley <rob@landley.net>
parents: 90
diff changeset
4 *
656
6df4ccc0acbe Regularize command headers, update links to standards documents.
Rob Landley <rob@landley.net>
parents: 653
diff changeset
5 * See http://opengroup.org/onlinepubs/9699919799/utilities/df.html
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 186
diff changeset
6
1574
991f4d613388 Variant of a patch from Ashwini Sharma, making df /dev/node work and tweaking the spacing.
Rob Landley <rob@landley.net>
parents: 1321
diff changeset
7 USE_DF(NEWTOY(df, "Pkt*a[-Pk]", TOYFLAG_USR|TOYFLAG_SBIN))
234
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
8
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 186
diff changeset
9 config DF
1007
c05343c592fa Normalize df menu entry and tweak help text.
Rob Landley <rob@landley.net>
parents: 897
diff changeset
10 bool "df"
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
11 default y
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
12 help
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
13 usage: df [-t type] [FILESYSTEM ...]
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 186
diff changeset
14
1007
c05343c592fa Normalize df menu entry and tweak help text.
Rob Landley <rob@landley.net>
parents: 897
diff changeset
15 The "disk free" command shows total/used/available disk space for
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
16 each filesystem listed on the command line, or all currently mounted
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
17 filesystems.
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 186
diff changeset
18
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
19 -P The SUSv3 "Pedantic" option
1196
37ea9dff9c27 Tweak help text.
Rob Landley <rob@landley.net>
parents: 1033
diff changeset
20 -k Sets units back to 1024 bytes (the default without -P)
1574
991f4d613388 Variant of a patch from Ashwini Sharma, making df /dev/node work and tweaking the spacing.
Rob Landley <rob@landley.net>
parents: 1321
diff changeset
21 -t type Display only filesystems of this type.
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 186
diff changeset
22
1196
37ea9dff9c27 Tweak help text.
Rob Landley <rob@landley.net>
parents: 1033
diff changeset
23 Pedantic provides a slightly less useful output format dictated by Posix,
37ea9dff9c27 Tweak help text.
Rob Landley <rob@landley.net>
parents: 1033
diff changeset
24 and sets the units to 512 bytes instead of the default 1024 bytes.
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 186
diff changeset
25 */
2
67b517913e56 Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents: 1
diff changeset
26
674
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
27 #define FOR_df
1
59d58fab67c6 Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff changeset
28 #include "toys.h"
59d58fab67c6 Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff changeset
29
674
7e846e281e38 New build infrastructure to generate FLAG_ macros and TT alias, #define FOR_commandname before #including toys.h to trigger it. Rename DEFINE_GLOBALS() to just GLOBALS() (because I could never remember if it was DECLARE_GLOBALS). Convert existing commands to use new infrastructure, and replace optflag constants with FLAG_ macros where appropriate.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
30 GLOBALS(
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
31 struct arg_list *fstype;
237
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
32
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
33 long units;
237
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
34 )
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
35
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 2
diff changeset
36 static void show_mt(struct mtab_list *mt)
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 2
diff changeset
37 {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
38 int len;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
39 long long size, used, avail, percent, block;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
40 char *device;
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 2
diff changeset
41
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
42 // Return if it wasn't found (should never happen, but with /etc/mtab...)
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
43 if (!mt) return;
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 2
diff changeset
44
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
45 // If we have -t, skip other filesystem types
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
46 if (TT.fstype) {
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
47 struct arg_list *al;
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 2
diff changeset
48
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
49 for (al = TT.fstype; al; al = al->next)
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
50 if (!strcmp(mt->type, al->arg)) break;
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 2
diff changeset
51
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
52 if (!al) return;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
53 }
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
54
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
55 // If we don't have -a, skip synthetic filesystems
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
56 if (!(toys.optflags & FLAG_a) && !mt->statvfs.f_blocks) return;
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 2
diff changeset
57
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
58 // Figure out how much total/used/free space this filesystem has,
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
59 // forcing 64-bit math because filesystems are big now.
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
60 block = mt->statvfs.f_bsize ? mt->statvfs.f_bsize : 1;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
61 size = (block * mt->statvfs.f_blocks) / TT.units;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
62 used = (block * (mt->statvfs.f_blocks-mt->statvfs.f_bfree)) / TT.units;
1574
991f4d613388 Variant of a patch from Ashwini Sharma, making df /dev/node work and tweaking the spacing.
Rob Landley <rob@landley.net>
parents: 1321
diff changeset
63 avail = (block*(getuid()?mt->statvfs.f_bavail:mt->statvfs.f_bfree))/TT.units;
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
64 if (!(used+avail)) percent = 0;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
65 else {
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
66 percent = (used*100)/(used+avail);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
67 if (used*100 != percent*(used+avail)) percent++;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
68 }
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 2
diff changeset
69
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
70 device = *mt->device == '/' ? realpath(mt->device, NULL) : NULL;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
71 if (!device) device = mt->device;
681
44904c7212e7 Follow symlinks to get actual device name, getmountlist() reverses order for us now, detect stdout to full device.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
72
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
73 // Figure out appropriate spacing
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
74 len = 25 - strlen(device);
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
75 if (len < 1) len = 1;
1574
991f4d613388 Variant of a patch from Ashwini Sharma, making df /dev/node work and tweaking the spacing.
Rob Landley <rob@landley.net>
parents: 1321
diff changeset
76 xprintf("%s% *lld % 10lld % 10lld % *lld%% %s\n", device, len,
991f4d613388 Variant of a patch from Ashwini Sharma, making df /dev/node work and tweaking the spacing.
Rob Landley <rob@landley.net>
parents: 1321
diff changeset
77 size, used, avail, (toys.optflags & FLAG_P) ? 7 : 3, percent, mt->dir);
681
44904c7212e7 Follow symlinks to get actual device name, getmountlist() reverses order for us now, detect stdout to full device.
Rob Landley <rob@landley.net>
parents: 674
diff changeset
78
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
79 if (device != mt->device) free(device);
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 2
diff changeset
80 }
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 2
diff changeset
81
186
25447caf1b4b Change command main() functions to return void, and exit(toys.exitval) from
Rob Landley <rob@landley.net>
parents: 164
diff changeset
82 void df_main(void)
1
59d58fab67c6 Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff changeset
83 {
1321
4d898affda0c 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.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
84 struct mtab_list *mt, *mtstart, *mtend;
1574
991f4d613388 Variant of a patch from Ashwini Sharma, making df /dev/node work and tweaking the spacing.
Rob Landley <rob@landley.net>
parents: 1321
diff changeset
85 int p = toys.optflags & FLAG_P;
2
67b517913e56 Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents: 1
diff changeset
86
1574
991f4d613388 Variant of a patch from Ashwini Sharma, making df /dev/node work and tweaking the spacing.
Rob Landley <rob@landley.net>
parents: 1321
diff changeset
87 // Units are 512 bytes if you select "pedantic" without "kilobytes".
991f4d613388 Variant of a patch from Ashwini Sharma, making df /dev/node work and tweaking the spacing.
Rob Landley <rob@landley.net>
parents: 1321
diff changeset
88 TT.units = p ? 512 : 1024;
1714
0c8ef714cf03 Patches from Elliott Hughes to fix various printf() format strings.
Rob Landley <rob@landley.net>
parents: 1574
diff changeset
89 xprintf("Filesystem%8s-blocks\tUsed Available %s Mounted on\n",
1574
991f4d613388 Variant of a patch from Ashwini Sharma, making df /dev/node work and tweaking the spacing.
Rob Landley <rob@landley.net>
parents: 1321
diff changeset
90 p ? "512" : "1K", p ? "Capacity" : "Use%");
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 2
diff changeset
91
1321
4d898affda0c 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.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
92 if (!(mtstart = xgetmountlist(0))) return;
4d898affda0c 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.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
93 mtend = dlist_terminate(mtstart);
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 2
diff changeset
94
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
95 // If we have a list of filesystems on the command line, loop through them.
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
96 if (*toys.optargs) {
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
97 char **next;
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 2
diff changeset
98
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
99 for(next = toys.optargs; *next; next++) {
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
100 struct stat st;
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 2
diff changeset
101
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
102 // Stat it (complain if we can't).
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
103 if(stat(*next, &st)) {
1574
991f4d613388 Variant of a patch from Ashwini Sharma, making df /dev/node work and tweaking the spacing.
Rob Landley <rob@landley.net>
parents: 1321
diff changeset
104 perror_msg("'%s'", *next);
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
105 continue;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
106 }
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 2
diff changeset
107
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
108 // Find and display this filesystem. Use _last_ hit in case of
1224
3aba6950b886 Clarify an unclear comment pointed out by Steve Long.
Rob Landley <rob@landley.net>
parents: 1196
diff changeset
109 // overmounts (which is first hit in the reversed list).
1321
4d898affda0c 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.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
110 for (mt = mtend; mt; mt = mt->prev) {
1574
991f4d613388 Variant of a patch from Ashwini Sharma, making df /dev/node work and tweaking the spacing.
Rob Landley <rob@landley.net>
parents: 1321
diff changeset
111 if (st.st_dev == mt->stat.st_dev
991f4d613388 Variant of a patch from Ashwini Sharma, making df /dev/node work and tweaking the spacing.
Rob Landley <rob@landley.net>
parents: 1321
diff changeset
112 || (st.st_rdev && (st.st_rdev == mt->stat.st_dev)))
991f4d613388 Variant of a patch from Ashwini Sharma, making df /dev/node work and tweaking the spacing.
Rob Landley <rob@landley.net>
parents: 1321
diff changeset
113 {
1321
4d898affda0c 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.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
114 show_mt(mt);
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
115 break;
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
116 }
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
117 }
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
118 }
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
119 } else {
1321
4d898affda0c 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.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
120 // Loop through mount list to filter out overmounts.
4d898affda0c 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.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
121 for (mt = mtend; mt; mt = mt->prev) {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
122 struct mtab_list *mt2, *mt3;
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 2
diff changeset
123
1321
4d898affda0c 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.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
124 // 0:0 is LANANA null device
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
125 if (!mt->stat.st_dev) continue;
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 2
diff changeset
126
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
127 // Filter out overmounts.
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
128 mt3 = mt;
1321
4d898affda0c 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.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
129 for (mt2 = mt->prev; mt2; mt2 = mt2->prev) {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
130 if (mt->stat.st_dev == mt2->stat.st_dev) {
1574
991f4d613388 Variant of a patch from Ashwini Sharma, making df /dev/node work and tweaking the spacing.
Rob Landley <rob@landley.net>
parents: 1321
diff changeset
131 // For --bind mounts, show earliest mount
1321
4d898affda0c 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.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
132 if (!strcmp(mt->device, mt2->device)) {
4d898affda0c 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.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
133 if (!toys.optflags & FLAG_a) mt3->stat.st_dev = 0;
4d898affda0c 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.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
134 mt3 = mt2;
4d898affda0c 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.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
135 } else mt2->stat.st_dev = 0;
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
136 }
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
137 }
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
138 }
1321
4d898affda0c 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.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
139 // Cosmetic: show filesystems in creation order
4d898affda0c 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.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
140 for (mt = mtstart; mt; mt = mt->next) if (mt->stat.st_dev) show_mt(mt);
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 689
diff changeset
141 }
2
67b517913e56 Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents: 1
diff changeset
142
1321
4d898affda0c 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.
Rob Landley <rob@landley.net>
parents: 1224
diff changeset
143 if (CFG_TOYBOX_FREE) llist_traverse(mtstart, free);
1
59d58fab67c6 Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff changeset
144 }