Mercurial > hg > toybox
annotate lib/getmountlist.c @ 1775:57f2a26fa92c draft toast
To ensure that toybox can be installed alongside busybox without
confusing update-alternatives, the paths of the links installed by toybox should
match those installed by busybox. This is accomplished by changing the flags
of a few tools within toybox.
author | Paul Barker <paul@paulbarker.me.uk> |
---|---|
date | Sat, 04 Apr 2015 11:58:06 -0500 |
parents | ba22c0d4273f |
children |
rev | line source |
---|---|
7
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
6
diff
changeset
|
1 /* getmountlist.c - Get a linked list of mount points, with stat information. |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
6
diff
changeset
|
2 * |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
6
diff
changeset
|
3 * Copyright 2006 Rob Landley <rob@landley.net> |
fc9c0503d5e2
Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents:
6
diff
changeset
|
4 */ |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
5 |
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
6 #include "toys.h" |
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
7 #include <mntent.h> |
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
8 |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
9 // Realloc *old with oldstring,newstring |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
10 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
11 void comma_collate(char **old, char *new) |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
12 { |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
13 char *temp, *atold = *old; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
14 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
15 // Only add a comma if old string didn't end with one |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
16 if (atold && *atold) { |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
17 char *comma = ","; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
18 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
19 if (atold[strlen(atold)-1] == ',') comma = ""; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
20 temp = xmprintf("%s%s%s", atold, comma, new); |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
21 } else temp = xstrdup(new); |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
22 free (atold); |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
23 *old = temp; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
24 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
25 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
26 // iterate through strings in a comma separated list. |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
27 // returns start of next entry or NULL if none |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
28 // sets *len to length of entry (not including comma) |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
29 // advances *list to start of next entry |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
30 char *comma_iterate(char **list, int *len) |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
31 { |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
32 char *start = *list, *end; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
33 |
1460
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1447
diff
changeset
|
34 if (!*list || !**list) return 0; |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
35 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
36 if (!(end = strchr(*list, ','))) { |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
37 *len = strlen(*list); |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
38 *list = 0; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
39 } else *list += (*len = end-start)+1; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
40 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
41 return start; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
42 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
43 |
1741
fece3d1f2924
Rename a function to better describe what it does.
Rob Landley <rob@landley.net>
parents:
1507
diff
changeset
|
44 static void octal_deslash(char *s) |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
45 { |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
46 char *o = s; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
47 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
48 while (*s) { |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
49 if (*s == '\\') { |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
50 int i, oct = 0; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
51 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
52 for (i = 1; i < 4; i++) { |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
53 if (!isdigit(s[i])) break; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
54 oct = (oct<<3)+s[i]-'0'; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
55 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
56 if (i == 4) { |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
57 *o++ = oct; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
58 s += i; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
59 continue; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
60 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
61 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
62 *o++ = *s++; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
63 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
64 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
65 *o = 0; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
66 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
67 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
68 // check all instances of opt and "no"opt in optlist, return true if opt |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
69 // found and last instance wasn't no. If clean, remove each instance from list. |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
70 int comma_scan(char *optlist, char *opt, int clean) |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
71 { |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
72 int optlen = strlen(opt), len, no, got = 0; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
73 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
74 if (optlist) for (;;) { |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
75 char *s = comma_iterate(&optlist, &len); |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
76 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
77 if (!s) break; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
78 no = 2*(*s == 'n' && s[1] == 'o'); |
1507
321e9d5032c1
Brown paper bag time: comma_scan() didn't work for anything but the last entry.
Rob Landley <rob@landley.net>
parents:
1460
diff
changeset
|
79 if (optlen == len-no && !strncmp(opt, s+no, optlen)) { |
1460
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1447
diff
changeset
|
80 got = !no; |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1447
diff
changeset
|
81 if (clean) memmove(s, optlist, strlen(optlist)+1); |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1447
diff
changeset
|
82 } |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
83 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
84 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
85 return got; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
86 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
87 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
88 // return true if all scanlist options enabled in optlist |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
89 int comma_scanall(char *optlist, char *scanlist) |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
90 { |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
91 int i = 1; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
92 |
1742
ba22c0d4273f
Fix mount -a segfault without -O, reported by Janus Troelsen.
Rob Landley <rob@landley.net>
parents:
1741
diff
changeset
|
93 while (scanlist && *scanlist) { |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
94 char *opt = comma_iterate(&scanlist, &i), *s = xstrndup(opt, i); |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
95 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
96 i = comma_scan(optlist, s, 0); |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
97 free(s); |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
98 if (!i) break; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
99 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
100 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
101 return i; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
102 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
103 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
104 // Check if this type matches list. |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
105 // Odd syntax: typelist all yes = if any, typelist all no = if none. |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
106 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
107 int mountlist_istype(struct mtab_list *ml, char *typelist) |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
108 { |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
109 int len, skip; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
110 char *t; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
111 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
112 if (!typelist) return 1; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
113 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
114 skip = strncmp(typelist, "no", 2); |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
115 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
116 for (;;) { |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
117 if (!(t = comma_iterate(&typelist, &len))) break; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
118 if (!skip) { |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
119 // If one -t starts with "no", the rest must too |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
120 if (strncmp(t, "no", 2)) error_exit("bad typelist"); |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
121 if (!strncmp(t+2, ml->type, len-2)) { |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
122 skip = 1; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
123 break; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
124 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
125 } else if (!strncmp(t, ml->type, len) && !ml->type[len]) { |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
126 skip = 0; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
127 break; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
128 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
129 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
130 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
131 return !skip; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
132 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
133 |
897
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
134 // Get list of mounted filesystems, including stat and statvfs info. |
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
135 // Returns a reversed list, which is good for finding overmounts and such. |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
136 |
1033
11cf9b97fae7
Allow getmountlist to read fstab too.
Rob Landley <rob@landley.net>
parents:
901
diff
changeset
|
137 struct mtab_list *xgetmountlist(char *path) |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
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:
1320
diff
changeset
|
139 struct mtab_list *mtlist = 0, *mt; |
897
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
140 struct mntent *me; |
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:
442
diff
changeset
|
141 FILE *fp; |
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:
1320
diff
changeset
|
142 char *p = path ? path : "/proc/mounts"; |
897
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
143 |
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:
1320
diff
changeset
|
144 if (!(fp = setmntent(p, "r"))) perror_exit("bad %s", p); |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
145 |
901
c44dff160d65
Silence warning and comment a subtle bit.
Rob Landley <rob@landley.net>
parents:
897
diff
changeset
|
146 // The "test" part of the loop is done before the first time through and |
c44dff160d65
Silence warning and comment a subtle bit.
Rob Landley <rob@landley.net>
parents:
897
diff
changeset
|
147 // again after each "increment", so putting the actual load there avoids |
c44dff160d65
Silence warning and comment a subtle bit.
Rob Landley <rob@landley.net>
parents:
897
diff
changeset
|
148 // duplicating it. If the load was NULL, the loop stops. |
c44dff160d65
Silence warning and comment a subtle bit.
Rob Landley <rob@landley.net>
parents:
897
diff
changeset
|
149 |
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:
1320
diff
changeset
|
150 while ((me = getmntent(fp))) { |
897
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
151 mt = xzalloc(sizeof(struct mtab_list) + strlen(me->mnt_fsname) + |
1320
b2cc738d3cfc
Add mount options to data getmountlist collects.
Rob Landley <rob@landley.net>
parents:
1033
diff
changeset
|
152 strlen(me->mnt_dir) + strlen(me->mnt_type) + strlen(me->mnt_opts) + 4); |
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:
1320
diff
changeset
|
153 dlist_add_nomalloc((void *)&mtlist, (void *)mt); |
897
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
154 |
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:
1320
diff
changeset
|
155 // Collect details about mounted filesystem |
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:
1320
diff
changeset
|
156 // Don't report errors, just leave data zeroed |
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:
1320
diff
changeset
|
157 if (!path) { |
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:
1320
diff
changeset
|
158 stat(me->mnt_dir, &(mt->stat)); |
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:
1320
diff
changeset
|
159 statvfs(me->mnt_dir, &(mt->statvfs)); |
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:
1320
diff
changeset
|
160 } |
897
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
161 |
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
162 // Remember information from /proc/mounts |
1320
b2cc738d3cfc
Add mount options to data getmountlist collects.
Rob Landley <rob@landley.net>
parents:
1033
diff
changeset
|
163 mt->dir = stpcpy(mt->type, me->mnt_type)+1; |
b2cc738d3cfc
Add mount options to data getmountlist collects.
Rob Landley <rob@landley.net>
parents:
1033
diff
changeset
|
164 mt->device = stpcpy(mt->dir, me->mnt_dir)+1; |
b2cc738d3cfc
Add mount options to data getmountlist collects.
Rob Landley <rob@landley.net>
parents:
1033
diff
changeset
|
165 mt->opts = stpcpy(mt->device, me->mnt_fsname)+1; |
b2cc738d3cfc
Add mount options to data getmountlist collects.
Rob Landley <rob@landley.net>
parents:
1033
diff
changeset
|
166 strcpy(mt->opts, me->mnt_opts); |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1321
diff
changeset
|
167 |
1741
fece3d1f2924
Rename a function to better describe what it does.
Rob Landley <rob@landley.net>
parents:
1507
diff
changeset
|
168 octal_deslash(mt->dir); |
fece3d1f2924
Rename a function to better describe what it does.
Rob Landley <rob@landley.net>
parents:
1507
diff
changeset
|
169 octal_deslash(mt->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:
442
diff
changeset
|
170 } |
703 | 171 endmntent(fp); |
897
849e14fecf2b
Convert getmountlist() to xgetmountlist().
Rob Landley <rob@landley.net>
parents:
882
diff
changeset
|
172 |
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:
442
diff
changeset
|
173 return mtlist; |
2
67b517913e56
Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents:
diff
changeset
|
174 } |