Mercurial > hg > toybox
annotate toys/lsb/mount.c @ 1508:b0ade326c855 draft
mount: terminate list so unknown user mount attempts don't endlessly loop, add better error reporting.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sun, 28 Sep 2014 13:15:41 -0500 |
parents | 2f9bc9495144 |
children | 22691dfb17b9 |
rev | line source |
---|---|
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1 /* mount.c - mount filesystems |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 * |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3 * Copyright 2014 Rob Landley <rob@landley.net> |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
4 * |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
5 * See http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/mount.html |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
6 * Note: -hV is bad spec, haven't implemented -FsLU yet |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
7 * no mtab (/proc/mounts does it) so -n is NOP. |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
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:
1385
diff
changeset
|
9 USE_MOUNT(NEWTOY(mount, "?O:afnrvwt:o*[-rw]", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_STAYROOT)) |
1472
2f9bc9495144
Split xpopen() into xpopen_both(), xpopen(), and xrun() depending on whether we want to redirect both, one, or neither of stdin/stdout.
Rob Landley <rob@landley.net>
parents:
1462
diff
changeset
|
10 USE_NFSMOUNT(NEWTOY(nfsmount, "?<2>2", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_STAYROOT)) |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
11 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
12 config MOUNT |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
13 bool "mount" |
1462
83cbfc4b0de7
Promote mount. It's not perfect, but it basically works now.
Rob Landley <rob@landley.net>
parents:
1461
diff
changeset
|
14 default y |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
15 help |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
16 usage: mount [-afFrsvw] [-t TYPE] [-o OPTIONS...] [[DEVICE] DIR] |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
17 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
18 Mount new filesystem(s) on directories. With no arguments, display existing |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
19 mounts. |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
20 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
21 -a mount all entries in /etc/fstab (with -t, only entries of that TYPE) |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
22 -O only mount -a entries that have this option |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
23 -f fake it (don't actually mount) |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
24 -r read only (same as -o ro) |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
25 -w read/write (default, same as -o rw) |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
26 -t specify filesystem type |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
27 -v verbose |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
28 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
29 OPTIONS is a comma separated list of options, which can also be supplied |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
30 as --longopts. |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
31 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
32 This mount autodetects loopback mounts (a file on a directory) and |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
33 bind mounts (file on file, directory on directory), so you don't need |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
34 to say --bind or --loop. You can also "mount -a /path" to mount everything |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
35 in /etc/fstab under /path, even if it's noauto. |
1472
2f9bc9495144
Split xpopen() into xpopen_both(), xpopen(), and xrun() depending on whether we want to redirect both, one, or neither of stdin/stdout.
Rob Landley <rob@landley.net>
parents:
1462
diff
changeset
|
36 |
2f9bc9495144
Split xpopen() into xpopen_both(), xpopen(), and xrun() depending on whether we want to redirect both, one, or neither of stdin/stdout.
Rob Landley <rob@landley.net>
parents:
1462
diff
changeset
|
37 config NFSMOUNT |
2f9bc9495144
Split xpopen() into xpopen_both(), xpopen(), and xrun() depending on whether we want to redirect both, one, or neither of stdin/stdout.
Rob Landley <rob@landley.net>
parents:
1462
diff
changeset
|
38 bool "nfsmount" |
2f9bc9495144
Split xpopen() into xpopen_both(), xpopen(), and xrun() depending on whether we want to redirect both, one, or neither of stdin/stdout.
Rob Landley <rob@landley.net>
parents:
1462
diff
changeset
|
39 default n |
2f9bc9495144
Split xpopen() into xpopen_both(), xpopen(), and xrun() depending on whether we want to redirect both, one, or neither of stdin/stdout.
Rob Landley <rob@landley.net>
parents:
1462
diff
changeset
|
40 help |
2f9bc9495144
Split xpopen() into xpopen_both(), xpopen(), and xrun() depending on whether we want to redirect both, one, or neither of stdin/stdout.
Rob Landley <rob@landley.net>
parents:
1462
diff
changeset
|
41 usage: nfsmount SHARE DIR |
2f9bc9495144
Split xpopen() into xpopen_both(), xpopen(), and xrun() depending on whether we want to redirect both, one, or neither of stdin/stdout.
Rob Landley <rob@landley.net>
parents:
1462
diff
changeset
|
42 |
2f9bc9495144
Split xpopen() into xpopen_both(), xpopen(), and xrun() depending on whether we want to redirect both, one, or neither of stdin/stdout.
Rob Landley <rob@landley.net>
parents:
1462
diff
changeset
|
43 Invoke an eldrich horror from the dawn of time. |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
44 */ |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
45 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
46 #define FOR_mount |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
47 #include "toys.h" |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
48 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
49 GLOBALS( |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
50 struct arg_list *optlist; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
51 char *type; |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
52 char *bigO; |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
53 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
54 unsigned long flags; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
55 char *opts; |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
56 int okuser; |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
57 ) |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
58 |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
59 // TODO detect existing identical mount (procfs with different dev name?) |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
60 // TODO user, users, owner, group, nofail |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
61 // TODO -p (passfd) |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
62 // TODO -a -t notype,type2 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
63 // TODO --subtree |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
64 // TODO --rbind, -R |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
65 // TODO make "mount --bind,ro old new" work (implicit -o remount) |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
66 // TODO mount -a |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
67 // TODO mount -o remount |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
68 // TODO fstab: lookup default options for mount |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
69 // TODO implement -v |
1453 | 70 // TODO "mount -a -o remount,ro" should detect overmounts |
71 // TODO work out how that differs from "mount -ar" | |
72 // TODO what if you --bind mount a block device somewhere (file, dir, dev) | |
73 // TODO "touch servername; mount -t cifs servername path" | |
1508
b0ade326c855
mount: terminate list so unknown user mount attempts don't endlessly loop, add better error reporting.
Rob Landley <rob@landley.net>
parents:
1472
diff
changeset
|
74 // TODO mount -o remount a user mount |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
75 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
76 // Strip flags out of comma separated list of options, return flags,. |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
77 static long flag_opts(char *new, long flags, char **more) |
1334
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
78 { |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
79 struct { |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
80 char *name; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
81 long flags; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
82 } opts[] = { |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
83 // NOPs (we autodetect --loop and --bind) |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
84 {"loop", 0}, {"bind", 0}, {"defaults", 0}, {"quiet", 0}, |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
85 {"user", 0}, {"nouser", 0}, // checked in fstab, ignored in -o |
1334
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
86 {"ro", MS_RDONLY}, {"rw", ~MS_RDONLY}, |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
87 {"nosuid", MS_NOSUID}, {"suid", ~MS_NOSUID}, |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
88 {"nodev", MS_NODEV}, {"dev", ~MS_NODEV}, |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
89 {"noexec", MS_NOEXEC}, {"exec", ~MS_NOEXEC}, |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
90 {"sync", MS_SYNCHRONOUS}, {"async", ~MS_SYNCHRONOUS}, |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
91 {"noatime", MS_NOATIME}, {"atime", ~MS_NOATIME}, |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
92 {"nodiratime", MS_NODIRATIME}, {"diratime", ~MS_NODIRATIME}, |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
93 {"loud", ~MS_SILENT}, |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
94 {"shared", MS_SHARED}, {"rshared", MS_SHARED|MS_REC}, |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
95 {"slave", MS_SLAVE}, {"rslave", MS_SLAVE|MS_REC}, |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
96 {"private", MS_PRIVATE}, {"rprivate", MS_SLAVE|MS_REC}, |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
97 {"unbindable", MS_UNBINDABLE}, {"runbindable", MS_UNBINDABLE|MS_REC}, |
1385
ffc015bddb26
Autodetect --bind and --loop mounts in a way that doesn't interfere with network filesystems or -t newtype mounts that trigger a module load.
Rob Landley <rob@landley.net>
parents:
1334
diff
changeset
|
98 {"remount", MS_REMOUNT}, {"move", MS_MOVE}, |
1334
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
99 // mand dirsync rec iversion strictatime |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
100 }; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
101 |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
102 if (new) for (;;) { |
1334
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
103 char *comma = strchr(new, ','); |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
104 int i; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
105 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
106 if (comma) *comma = 0; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
107 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
108 // If we recognize an option, apply flags |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
109 for (i = 0; i < ARRAY_LEN(opts); i++) if (!strcasecmp(opts[i].name, new)) { |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
110 long ll = opts[i].flags; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
111 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
112 if (ll < 0) flags &= ll; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
113 else flags |= ll; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
114 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
115 break; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
116 } |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
117 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
118 // If we didn't recognize it, keep string version |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
119 if (more && i == ARRAY_LEN(opts)) { |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
120 i = *more ? strlen(*more) : 0; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
121 *more = xrealloc(*more, i + strlen(new) + 2); |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
122 if (i) (*more)[i++] = ','; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
123 strcpy(i+*more, new); |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
124 } |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
125 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
126 if (!comma) break; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
127 *comma = ','; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
128 new = comma + 1; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
129 } |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
130 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
131 return flags; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
132 } |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
133 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
134 static void mount_filesystem(char *dev, char *dir, char *type, |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
135 unsigned long flags, char *opts) |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
136 { |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
137 FILE *fp = 0; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
138 int rc = EINVAL; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
139 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
140 if (toys.optflags & FLAG_f) return; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
141 |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
142 if (getuid()) { |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
143 if (TT.okuser) TT.okuser = 0; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
144 else { |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
145 error_msg("'%s' not user mountable in fstab"); |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
146 return; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
147 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
148 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
149 |
1385
ffc015bddb26
Autodetect --bind and --loop mounts in a way that doesn't interfere with network filesystems or -t newtype mounts that trigger a module load.
Rob Landley <rob@landley.net>
parents:
1334
diff
changeset
|
150 // Autodetect bind mount or filesystem type |
1461 | 151 |
152 if (type && !strcmp(type, "auto")) type = 0; | |
153 if (flags & MS_MOVE) { | |
154 if (type) error_exit("--move with -t"); | |
155 } else if (!type) { | |
1334
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
156 struct stat stdev, stdir; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
157 |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
158 // file on file or dir on dir is a --bind mount. |
1385
ffc015bddb26
Autodetect --bind and --loop mounts in a way that doesn't interfere with network filesystems or -t newtype mounts that trigger a module load.
Rob Landley <rob@landley.net>
parents:
1334
diff
changeset
|
159 if (!stat(dev, &stdev) && !stat(dir, &stdir) |
ffc015bddb26
Autodetect --bind and --loop mounts in a way that doesn't interfere with network filesystems or -t newtype mounts that trigger a module load.
Rob Landley <rob@landley.net>
parents:
1334
diff
changeset
|
160 && ((S_ISREG(stdev.st_mode) && S_ISREG(stdir.st_mode)) |
ffc015bddb26
Autodetect --bind and --loop mounts in a way that doesn't interfere with network filesystems or -t newtype mounts that trigger a module load.
Rob Landley <rob@landley.net>
parents:
1334
diff
changeset
|
161 || (S_ISDIR(stdev.st_mode) && S_ISDIR(stdir.st_mode)))) |
ffc015bddb26
Autodetect --bind and --loop mounts in a way that doesn't interfere with network filesystems or -t newtype mounts that trigger a module load.
Rob Landley <rob@landley.net>
parents:
1334
diff
changeset
|
162 { |
ffc015bddb26
Autodetect --bind and --loop mounts in a way that doesn't interfere with network filesystems or -t newtype mounts that trigger a module load.
Rob Landley <rob@landley.net>
parents:
1334
diff
changeset
|
163 flags |= MS_BIND; |
ffc015bddb26
Autodetect --bind and --loop mounts in a way that doesn't interfere with network filesystems or -t newtype mounts that trigger a module load.
Rob Landley <rob@landley.net>
parents:
1334
diff
changeset
|
164 } else fp = xfopen("/proc/filesystems", "r"); |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
165 } else if (!strcmp(type, "ignore")) return; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
166 else if (!strcmp(type, "swap")) |
1472
2f9bc9495144
Split xpopen() into xpopen_both(), xpopen(), and xrun() depending on whether we want to redirect both, one, or neither of stdin/stdout.
Rob Landley <rob@landley.net>
parents:
1462
diff
changeset
|
167 toys.exitval |= xrun((char *[]){"swapon", "--", dev, 0}); |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
168 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
169 for (;;) { |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
170 char *buf = 0; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
171 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
172 // If type wasn't specified, try all of them in order. |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
173 if (fp) { |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
174 size_t i; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
175 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
176 if (getline(&buf, &i, fp)<0) break; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
177 type = buf; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
178 // skip nodev devices |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
179 if (!isspace(*type)) { |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
180 free(buf); |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
181 continue; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
182 } |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
183 // trim whitespace |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
184 while (isspace(*type)) type++; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
185 i = strlen(type); |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
186 if (i) type[i-1] = 0; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
187 } |
1334
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
188 if (toys.optflags & FLAG_v) |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
189 printf("try '%s' type '%s' on '%s'\n", dev, type, dir); |
1453 | 190 for (;;) { |
191 rc = mount(dev, dir, type, flags, opts); | |
192 if ((rc != EACCES && rc != EROFS) || (flags & MS_RDONLY)) break; | |
193 fprintf(stderr, "'%s' is read-only", dev); | |
194 flags |= MS_RDONLY; | |
195 } | |
196 free(buf); | |
197 | |
1460
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
198 if (!rc) break; |
1385
ffc015bddb26
Autodetect --bind and --loop mounts in a way that doesn't interfere with network filesystems or -t newtype mounts that trigger a module load.
Rob Landley <rob@landley.net>
parents:
1334
diff
changeset
|
199 |
1460
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
200 // Trying to autodetect loop mounts like bind mounts above (file on dir) |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
201 // isn't good enough because "mount -t ext2 fs.img dir" is valid, but if |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
202 // you _do_ accept loop mounts with -t how do you tell "-t cifs" isn't |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
203 // looking for a block device if it's not in /proc/filesystems yet |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
204 // because the module that won't be loaded until you try the mount, and |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
205 // if you can't then DEVICE existing as a file would cause a false |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
206 // positive loopback mount (so "touch servername" becomes a potential |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
207 // denial of service attack...) |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
208 // |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
209 // Solution: try the mount, let the kernel tell us it wanted a block |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
210 // device, then do the loopback setup and retry the mount. |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
211 |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
212 if (fp && errno == EINVAL) continue; |
1453 | 213 |
1460
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
214 if (errno == ENOTBLK) { |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
215 char *losetup[] = {"losetup", "-fs", dev, 0}; |
1472
2f9bc9495144
Split xpopen() into xpopen_both(), xpopen(), and xrun() depending on whether we want to redirect both, one, or neither of stdin/stdout.
Rob Landley <rob@landley.net>
parents:
1462
diff
changeset
|
216 int pipe, len; |
1460
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
217 pid_t pid; |
1385
ffc015bddb26
Autodetect --bind and --loop mounts in a way that doesn't interfere with network filesystems or -t newtype mounts that trigger a module load.
Rob Landley <rob@landley.net>
parents:
1334
diff
changeset
|
218 |
1460
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
219 if (flags & MS_RDONLY) losetup[1] = "-fsr"; |
1472
2f9bc9495144
Split xpopen() into xpopen_both(), xpopen(), and xrun() depending on whether we want to redirect both, one, or neither of stdin/stdout.
Rob Landley <rob@landley.net>
parents:
1462
diff
changeset
|
220 pid = xpopen(losetup, &pipe, 1); |
2f9bc9495144
Split xpopen() into xpopen_both(), xpopen(), and xrun() depending on whether we want to redirect both, one, or neither of stdin/stdout.
Rob Landley <rob@landley.net>
parents:
1462
diff
changeset
|
221 len = readall(pipe, toybuf, sizeof(toybuf)-1); |
2f9bc9495144
Split xpopen() into xpopen_both(), xpopen(), and xrun() depending on whether we want to redirect both, one, or neither of stdin/stdout.
Rob Landley <rob@landley.net>
parents:
1462
diff
changeset
|
222 rc = xpclose(pid, pipe); |
1460
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
223 if (!rc && len > 1) { |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
224 if (toybuf[len-1] == '\n') --len; |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
225 toybuf[len] = 0; |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
226 dev = toybuf; |
1385
ffc015bddb26
Autodetect --bind and --loop mounts in a way that doesn't interfere with network filesystems or -t newtype mounts that trigger a module load.
Rob Landley <rob@landley.net>
parents:
1334
diff
changeset
|
227 |
1460
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
228 continue; |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
229 } else error_msg("losetup failed %d", rc); |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
230 } else perror_msg("'%s'->'%s'", dev, dir); |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
231 |
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
232 break; |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
233 } |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
234 if (fp) fclose(fp); |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
235 } |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
236 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
237 void mount_main(void) |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
238 { |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
239 char *opts = 0, *dev = 0, *dir = 0, **ss; |
1334
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
240 long flags = MS_SILENT; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
241 struct arg_list *o; |
1453 | 242 struct mtab_list *mtl, *mm, *remount = 0; |
1334
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
243 |
1453 | 244 // remount |
245 // - overmounts | |
246 // shared subtree | |
247 // -o parsed after fstab options | |
248 // test if mountpoint already exists (-o noremount?) | |
249 | |
250 // First pass; just accumulate string, don't parse flags yet. (This is so | |
251 // we can modify fstab entries with -a, or mtab with remount.) | |
252 for (o = TT.optlist; o; o = o->next) comma_collate(&opts, o->arg); | |
253 if (toys.optflags & FLAG_r) comma_collate(&opts, "ro"); | |
254 if (toys.optflags & FLAG_w) comma_collate(&opts, "rw"); | |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
255 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
256 // Treat each --option as -o option |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
257 for (ss = toys.optargs; *ss; ss++) { |
1453 | 258 char *sss = *ss; |
259 | |
260 // If you realy, really want to mount a file named "--", we support it. | |
261 if (sss[0]=='-' && sss[1]=='-' && sss[2]) comma_collate(&opts, sss+2); | |
262 else if (!dev) dev = sss; | |
263 else if (!dir) dir = sss; | |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
264 // same message as lib/args.c ">2" which we can't use because --opts count |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
265 else error_exit("Max 2 arguments\n"); |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
266 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
267 |
1453 | 268 if ((toys.optflags & FLAG_a) && dir) error_exit("-a with >1 arg"); |
269 | |
270 // For remount we need _last_ match (in case of overmounts), so traverse | |
271 // in reverse order. | |
272 if (comma_scan(opts, "remount", 1)) | |
273 remount = dlist_terminate(mtl = xgetmountlist("/proc/mounts")); | |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
274 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
275 // Do we need to do an /etc/fstab trawl? |
1453 | 276 // This covers -a, -o remount, one argument, all user mounts |
1460
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
277 if ((toys.optflags & FLAG_a) || (dev && (!dir || getuid() || remount))) { |
1508
b0ade326c855
mount: terminate list so unknown user mount attempts don't endlessly loop, add better error reporting.
Rob Landley <rob@landley.net>
parents:
1472
diff
changeset
|
278 if (!remount) dlist_terminate(mtl = xgetmountlist("/etc/fstab")); |
1460
94f7ec50ef50
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
Rob Landley <rob@landley.net>
parents:
1453
diff
changeset
|
279 |
1453 | 280 for (mm = remount ? remount : mtl; mm; mm = (remount ? mm->prev : mm->next)) |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
281 { |
1453 | 282 int aflags, noauto, len; |
283 char *aopts = 0; | |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
284 |
1453 | 285 // Check for noauto and get it out of the option list. (Unknown options |
286 // that make it to the kernel give filesystem drivers indigestion.) | |
287 noauto = comma_scan(mm->opts, "noauto", 1); | |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
288 if (toys.optflags & FLAG_a) { |
1453 | 289 // "mount -a /path" to mount all entries under /path |
290 if (dev) { | |
291 len = strlen(dev); | |
292 if (strncmp(dev, mm->dir, len) | |
293 || (mm->dir[len] && mm->dir[len] != '/')) continue; | |
294 } else if (noauto) continue; // never present in the remount case | |
295 if (!mountlist_istype(mm,TT.type) || !comma_scanall(mm->opts,TT.bigO)) | |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
296 continue; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
297 } else { |
1453 | 298 if (dir && strcmp(dir, mm->dir)) continue; |
299 if (dev && strcmp(dev, mm->device) && (dir || strcmp(dev, mm->dir))) | |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
300 continue; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
301 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
302 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
303 // user only counts from fstab, not opts. |
1453 | 304 TT.okuser = comma_scan(mm->opts, "user", 1); |
305 aflags = flag_opts(mm->opts, flags, &aopts); | |
306 aflags = flag_opts(opts, aflags, &aopts); | |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
307 |
1453 | 308 mount_filesystem(mm->device, mm->dir, mm->type, aflags, aopts); |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
309 free(aopts); |
1334
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
310 |
1453 | 311 if (!(toys.optflags & FLAG_a)) break; |
312 } | |
313 if (CFG_TOYBOX_FREE) llist_traverse(mtl, free); | |
1508
b0ade326c855
mount: terminate list so unknown user mount attempts don't endlessly loop, add better error reporting.
Rob Landley <rob@landley.net>
parents:
1472
diff
changeset
|
314 if (!mm && !(toys.optflags & FLAG_a)) |
b0ade326c855
mount: terminate list so unknown user mount attempts don't endlessly loop, add better error reporting.
Rob Landley <rob@landley.net>
parents:
1472
diff
changeset
|
315 error_exit("'%s' not in %s", dir ? dir : dev, |
b0ade326c855
mount: terminate list so unknown user mount attempts don't endlessly loop, add better error reporting.
Rob Landley <rob@landley.net>
parents:
1472
diff
changeset
|
316 remount ? "/proc/mounts" : "fstab"); |
1453 | 317 |
318 // show mounts from /proc/mounts | |
319 } else if (!dev) { | |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
320 for (mtl = xgetmountlist(0); mtl && (mm = dlist_pop(&mtl)); free(mm)) { |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
321 char *s = 0; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
322 |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
323 if (TT.type && strcmp(TT.type, mm->type)) continue; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
324 if (*mm->device == '/') s = xabspath(mm->device, 0); |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
325 xprintf("%s on %s type %s (%s)\n", |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
326 s ? s : mm->device, mm->dir, mm->type, mm->opts); |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
327 free(s); |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
328 } |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
329 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
330 // two arguments |
1453 | 331 } else { |
332 char *more = 0; | |
333 | |
334 mount_filesystem(dev, dir, TT.type, flag_opts(opts, flags, &more), more); | |
335 if (CFG_TOYBOX_FREE) free(more); | |
336 } | |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
337 } |