Mercurial > hg > toybox
annotate toys/posix/df.c @ 689:c29e69a0e85e
On 32 bit platforms %ld doesn't match uint64_t, so do long long and %lld (rather than deal with verbose PRIu64 nonsense).
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 10 Nov 2012 18:24:14 -0600 |
parents | 598263aee2b9 |
children | 786841fdb1e0 |
rev | line source |
---|---|
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
1 /* vi: set sw=4 ts=4: |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
2 * |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
1
diff
changeset
|
3 * df.c - report free disk space. |
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
1
diff
changeset
|
4 * |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
5 * 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
|
6 * |
656
6df4ccc0acbe
Regularize command headers, update links to standards documents.
Rob Landley <rob@landley.net>
parents:
653
diff
changeset
|
7 * 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
|
8 |
234
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
9 USE_DF(NEWTOY(df, "Pkt*a", TOYFLAG_USR|TOYFLAG_SBIN)) |
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
10 |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
11 config DF |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
12 bool "df (disk free)" |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
13 default y |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
14 help |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
15 usage: df [-t type] [FILESYSTEM ...] |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
16 |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
17 The "disk free" command, df shows total/used/available disk space for |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
18 each filesystem listed on the command line, or all currently mounted |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
19 filesystems. |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
20 |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
21 -t type |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
22 Display only filesystems of this type. |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
23 |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
24 config DF_PEDANTIC |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
25 bool "options -P and -k" |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
26 default y |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
27 depends on DF |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
28 help |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
29 usage: df [-Pk] |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
30 |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
31 -P The SUSv3 "Pedantic" option |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
32 |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
33 Provides a slightly less useful output format dictated by |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
34 the Single Unix Specification version 3, and sets the |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
35 units to 512 bytes instead of the default 1024 bytes. |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
36 |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
37 -k Sets units back to 1024 bytes (the default without -P) |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
186
diff
changeset
|
38 */ |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
1
diff
changeset
|
39 |
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
|
40 #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
|
41 #include "toys.h" |
59d58fab67c6
Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff
changeset
|
42 |
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
|
43 GLOBALS( |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
44 struct arg_list *fstype; |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
45 |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
46 long units; |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
47 ) |
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
48 |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
49 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
|
50 { |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
51 int len; |
689
c29e69a0e85e
On 32 bit platforms %ld doesn't match uint64_t, so do long long and %lld (rather than deal with verbose PRIu64 nonsense).
Rob Landley <rob@landley.net>
parents:
687
diff
changeset
|
52 long long size, used, avail, percent, block; |
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
|
53 char *device; |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
54 |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
55 // Return if it wasn't found (should never happen, but with /etc/mtab...) |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
56 if (!mt) return; |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
57 |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
58 // If we have -t, skip other filesystem types |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
59 if (TT.fstype) { |
32
993eab821bd5
More work on option parsing. "df -t tmpfs" actually seems to work now.
Rob Landley <rob@landley.net>
parents:
27
diff
changeset
|
60 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
|
61 |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
62 for (al = TT.fstype; al; al = al->next) { |
32
993eab821bd5
More work on option parsing. "df -t tmpfs" actually seems to work now.
Rob Landley <rob@landley.net>
parents:
27
diff
changeset
|
63 if (!strcmp(mt->type, al->arg)) break; |
993eab821bd5
More work on option parsing. "df -t tmpfs" actually seems to work now.
Rob Landley <rob@landley.net>
parents:
27
diff
changeset
|
64 } |
993eab821bd5
More work on option parsing. "df -t tmpfs" actually seems to work now.
Rob Landley <rob@landley.net>
parents:
27
diff
changeset
|
65 if (!al) return; |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
66 } |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
67 |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
68 // If we don't have -a, skip synthetic filesystems |
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
|
69 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
|
70 |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
71 // Figure out how much total/used/free space this filesystem has, |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
72 // forcing 64-bit math because filesystems are big now. |
560
979c5ab6f0c2
Replace ?: gcc extension with standard code
Kevin Chase <kevincha99@hotmail.com>
parents:
237
diff
changeset
|
73 block = mt->statvfs.f_bsize ? mt->statvfs.f_bsize : 1; |
687
598263aee2b9
Change df percentage calculation to match posix, spotted by Roy Tam.
Rob Landley <rob@landley.net>
parents:
681
diff
changeset
|
74 size = (block * mt->statvfs.f_blocks) / TT.units; |
598263aee2b9
Change df percentage calculation to match posix, spotted by Roy Tam.
Rob Landley <rob@landley.net>
parents:
681
diff
changeset
|
75 used = (block * (mt->statvfs.f_blocks-mt->statvfs.f_bfree)) / TT.units; |
598263aee2b9
Change df percentage calculation to match posix, spotted by Roy Tam.
Rob Landley <rob@landley.net>
parents:
681
diff
changeset
|
76 avail = (block * (getuid() ? mt->statvfs.f_bavail : mt->statvfs.f_bfree)) |
598263aee2b9
Change df percentage calculation to match posix, spotted by Roy Tam.
Rob Landley <rob@landley.net>
parents:
681
diff
changeset
|
77 / TT.units; |
598263aee2b9
Change df percentage calculation to match posix, spotted by Roy Tam.
Rob Landley <rob@landley.net>
parents:
681
diff
changeset
|
78 if (!(used+avail)) percent = 0; |
598263aee2b9
Change df percentage calculation to match posix, spotted by Roy Tam.
Rob Landley <rob@landley.net>
parents:
681
diff
changeset
|
79 else { |
598263aee2b9
Change df percentage calculation to match posix, spotted by Roy Tam.
Rob Landley <rob@landley.net>
parents:
681
diff
changeset
|
80 percent = (used*100)/(used+avail); |
598263aee2b9
Change df percentage calculation to match posix, spotted by Roy Tam.
Rob Landley <rob@landley.net>
parents:
681
diff
changeset
|
81 if (used*100 != percent*(used+avail)) percent++; |
598263aee2b9
Change df percentage calculation to match posix, spotted by Roy Tam.
Rob Landley <rob@landley.net>
parents:
681
diff
changeset
|
82 } |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
83 |
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
|
84 device = *mt->device == '/' ? realpath(mt->device, NULL) : NULL; |
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
|
85 if (!device) device = mt->device; |
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
|
86 |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
87 // Figure out appropriate spacing |
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
|
88 len = 25 - strlen(device); |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
89 if (len < 1) len = 1; |
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
|
90 if (CFG_DF_PEDANTIC && (toys.optflags & FLAG_P)) { |
689
c29e69a0e85e
On 32 bit platforms %ld doesn't match uint64_t, so do long long and %lld (rather than deal with verbose PRIu64 nonsense).
Rob Landley <rob@landley.net>
parents:
687
diff
changeset
|
91 xprintf("%s %lld %lld %lld %lld%% %s\n", device, size, used, avail, |
9
8f8a8ac59c14
Closer support for "pedantic" option for SUSv3. (Ok, it's %ld instead of the
landley@driftwood
parents:
7
diff
changeset
|
92 percent, mt->dir); |
8f8a8ac59c14
Closer support for "pedantic" option for SUSv3. (Ok, it's %ld instead of the
landley@driftwood
parents:
7
diff
changeset
|
93 } else { |
689
c29e69a0e85e
On 32 bit platforms %ld doesn't match uint64_t, so do long long and %lld (rather than deal with verbose PRIu64 nonsense).
Rob Landley <rob@landley.net>
parents:
687
diff
changeset
|
94 xprintf("%s% *lld % 10lld % 9lld % 3lld%% %s\n", device, len, |
9
8f8a8ac59c14
Closer support for "pedantic" option for SUSv3. (Ok, it's %ld instead of the
landley@driftwood
parents:
7
diff
changeset
|
95 size, used, avail, percent, mt->dir); |
8f8a8ac59c14
Closer support for "pedantic" option for SUSv3. (Ok, it's %ld instead of the
landley@driftwood
parents:
7
diff
changeset
|
96 } |
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
|
97 |
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
|
98 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
|
99 } |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
100 |
186
25447caf1b4b
Change command main() functions to return void, and exit(toys.exitval) from
Rob Landley <rob@landley.net>
parents:
164
diff
changeset
|
101 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
|
102 { |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
103 struct mtab_list *mt, *mt2, *mtlist; |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
1
diff
changeset
|
104 |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
105 // Handle -P and -k |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
106 TT.units = 1024; |
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
|
107 if (CFG_DF_PEDANTIC && (toys.optflags & FLAG_P)) { |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
108 // Units are 512 bytes if you select "pedantic" without "kilobytes". |
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
|
109 if ((toys.optflags&(FLAG_P|FLAG_k)) == FLAG_P) TT.units = 512; |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
110 printf("Filesystem %ld-blocks Used Available Capacity Mounted on\n", |
237
7cb15eae1664
Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
111 TT.units); |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
112 } else puts("Filesystem\t1K-blocks\tUsed Available Use% Mounted on"); |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
113 |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
1
diff
changeset
|
114 mtlist = getmountlist(1); |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
115 |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
116 // If we have a list of filesystems on the command line, loop through them. |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
9
diff
changeset
|
117 if (*toys.optargs) { |
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
9
diff
changeset
|
118 char **next; |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
119 |
25
eb46bb5626cb
New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents:
9
diff
changeset
|
120 for(next = toys.optargs; *next; next++) { |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
121 struct stat st; |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
122 |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
123 // Stat it (complain if we can't). |
27 | 124 if(stat(*next, &st)) { |
164
c79290b54bd3
Fix error message
Charlie Shepherd <masterdriverz@gentoo.org>
parents:
156
diff
changeset
|
125 perror_msg("`%s'", *next); |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
126 toys.exitval = 1; |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
127 continue; |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
128 } |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
129 |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
130 // Find and display this filesystem. Use _last_ hit in case of |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
131 // -- bind mounts. |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
132 mt2 = NULL; |
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
|
133 for (mt = mtlist; mt; mt = mt->next) { |
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
|
134 if (st.st_dev == mt->stat.st_dev) { |
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
|
135 mt2 = mt; |
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
|
136 break; |
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
|
137 } |
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
|
138 } |
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
139 show_mt(mt2); |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
140 } |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
141 } else { |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
142 // Get and loop through mount list. |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
143 |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
144 for (mt = mtlist; mt; mt = mt->next) { |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
145 struct mtab_list *mt2, *mt3; |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
146 |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
147 if (!mt->stat.st_dev) continue; |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
148 |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
149 // Filter out overmounts. |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
150 mt3 = mt; |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
151 for (mt2 = mt->next; mt2; mt2 = mt2->next) { |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
152 if (mt->stat.st_dev == mt2->stat.st_dev) { |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
153 // For --bind mounts, take last match |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
154 if (!strcmp(mt->device, mt2->device)) mt3 = mt2; |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
155 // Filter out overmounts |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
156 mt2->stat.st_dev = 0; |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
157 } |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
158 } |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
159 show_mt(mt3); |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
2
diff
changeset
|
160 } |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
1
diff
changeset
|
161 } |
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
1
diff
changeset
|
162 |
624
1e8b9acdafeb
Genericize llist code a bit: rename llist_free() to llist_traverse(), and no longer accept NULL as a synonym for free.
Rob Landley <rob@landley.net>
parents:
560
diff
changeset
|
163 if (CFG_TOYBOX_FREE) llist_traverse(mtlist, free); |
1
59d58fab67c6
Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff
changeset
|
164 } |