Mercurial > hg > toybox
annotate toys/lsb/mount.c @ 1539:3e85af1f7e22 draft
First batch of sed tests.
Only good for TEST_HOST=1 at the moment because the test infrastructure itself
depends on sed, so if an unfinished sed is in the $PATH it goes boing. But
hey, corner cases!
I have... more.
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 29 Oct 2014 18:44:33 -0500 |
parents | 22691dfb17b9 |
children | 9b906eb047e8 |
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 |
1509
22691dfb17b9
Fix two mount bugs: 1) Don't skip a filesystem type when setting up loopback mount, 2) Don't stop checking filesystem types due to EBUSY, it may mean already mounted by another filesystem type you haven't tried yet.
Rob Landley <rob@landley.net>
parents:
1508
diff
changeset
|
75 // TODO mount image.img sub (auto-loopback) then umount image.img |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
76 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
77 // 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
|
78 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
|
79 { |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
80 struct { |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
81 char *name; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
82 long flags; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
83 } opts[] = { |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
84 // 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
|
85 {"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
|
86 {"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
|
87 {"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
|
88 {"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
|
89 {"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
|
90 {"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
|
91 {"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
|
92 {"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
|
93 {"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
|
94 {"loud", ~MS_SILENT}, |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
95 {"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
|
96 {"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
|
97 {"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
|
98 {"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
|
99 {"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
|
100 // 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
|
101 }; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
102 |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
103 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
|
104 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
|
105 int i; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
106 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
107 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
|
108 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
109 // 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
|
110 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
|
111 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
|
112 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
113 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
|
114 else flags |= ll; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
115 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
116 break; |
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 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
119 // 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
|
120 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
|
121 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
|
122 *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
|
123 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
|
124 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
|
125 } |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
126 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
127 if (!comma) break; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
128 *comma = ','; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
129 new = comma + 1; |
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 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
132 return flags; |
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 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
135 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
|
136 unsigned long flags, char *opts) |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
137 { |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
138 FILE *fp = 0; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
139 int rc = EINVAL; |
1509
22691dfb17b9
Fix two mount bugs: 1) Don't skip a filesystem type when setting up loopback mount, 2) Don't stop checking filesystem types due to EBUSY, it may mean already mounted by another filesystem type you haven't tried yet.
Rob Landley <rob@landley.net>
parents:
1508
diff
changeset
|
140 char *buf = 0; |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
141 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
142 if (toys.optflags & FLAG_f) return; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
143 |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
144 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
|
145 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
|
146 else { |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
147 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
|
148 return; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
149 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
150 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
151 |
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
|
152 // Autodetect bind mount or filesystem type |
1461 | 153 |
154 if (type && !strcmp(type, "auto")) type = 0; | |
155 if (flags & MS_MOVE) { | |
156 if (type) error_exit("--move with -t"); | |
157 } 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
|
158 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
|
159 |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
160 // 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
|
161 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
|
162 && ((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
|
163 || (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
|
164 { |
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
|
165 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
|
166 } 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
|
167 } 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
|
168 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
|
169 toys.exitval |= xrun((char *[]){"swapon", "--", dev, 0}); |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
170 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
171 for (;;) { |
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. |
1509
22691dfb17b9
Fix two mount bugs: 1) Don't skip a filesystem type when setting up loopback mount, 2) Don't stop checking filesystem types due to EBUSY, it may mean already mounted by another filesystem type you haven't tried yet.
Rob Landley <rob@landley.net>
parents:
1508
diff
changeset
|
173 if (fp && !buf) { |
1323
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); |
1509
22691dfb17b9
Fix two mount bugs: 1) Don't skip a filesystem type when setting up loopback mount, 2) Don't stop checking filesystem types due to EBUSY, it may mean already mounted by another filesystem type you haven't tried yet.
Rob Landley <rob@landley.net>
parents:
1508
diff
changeset
|
181 buf = 0; |
22691dfb17b9
Fix two mount bugs: 1) Don't skip a filesystem type when setting up loopback mount, 2) Don't stop checking filesystem types due to EBUSY, it may mean already mounted by another filesystem type you haven't tried yet.
Rob Landley <rob@landley.net>
parents:
1508
diff
changeset
|
182 |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
183 continue; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
184 } |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
185 // trim whitespace |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
186 while (isspace(*type)) type++; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
187 i = strlen(type); |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
188 if (i) type[i-1] = 0; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
189 } |
1334
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
190 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
|
191 printf("try '%s' type '%s' on '%s'\n", dev, type, dir); |
1453 | 192 for (;;) { |
193 rc = mount(dev, dir, type, flags, opts); | |
194 if ((rc != EACCES && rc != EROFS) || (flags & MS_RDONLY)) break; | |
195 fprintf(stderr, "'%s' is read-only", dev); | |
196 flags |= MS_RDONLY; | |
197 } | |
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
|
198 |
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
|
199 // 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
|
200 // 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
|
201 // 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
|
202 // 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
|
203 // 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
|
204 // 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
|
205 // 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
|
206 // 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
|
207 // |
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 // 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
|
209 // 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
|
210 |
1509
22691dfb17b9
Fix two mount bugs: 1) Don't skip a filesystem type when setting up loopback mount, 2) Don't stop checking filesystem types due to EBUSY, it may mean already mounted by another filesystem type you haven't tried yet.
Rob Landley <rob@landley.net>
parents:
1508
diff
changeset
|
211 if (rc && errno == ENOTBLK) { |
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
|
212 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
|
213 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
|
214 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
|
215 |
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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 |
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
|
225 continue; |
1509
22691dfb17b9
Fix two mount bugs: 1) Don't skip a filesystem type when setting up loopback mount, 2) Don't stop checking filesystem types due to EBUSY, it may mean already mounted by another filesystem type you haven't tried yet.
Rob Landley <rob@landley.net>
parents:
1508
diff
changeset
|
226 } |
22691dfb17b9
Fix two mount bugs: 1) Don't skip a filesystem type when setting up loopback mount, 2) Don't stop checking filesystem types due to EBUSY, it may mean already mounted by another filesystem type you haven't tried yet.
Rob Landley <rob@landley.net>
parents:
1508
diff
changeset
|
227 error_msg("losetup failed %d", rc); |
22691dfb17b9
Fix two mount bugs: 1) Don't skip a filesystem type when setting up loopback mount, 2) Don't stop checking filesystem types due to EBUSY, it may mean already mounted by another filesystem type you haven't tried yet.
Rob Landley <rob@landley.net>
parents:
1508
diff
changeset
|
228 |
22691dfb17b9
Fix two mount bugs: 1) Don't skip a filesystem type when setting up loopback mount, 2) Don't stop checking filesystem types due to EBUSY, it may mean already mounted by another filesystem type you haven't tried yet.
Rob Landley <rob@landley.net>
parents:
1508
diff
changeset
|
229 break; |
22691dfb17b9
Fix two mount bugs: 1) Don't skip a filesystem type when setting up loopback mount, 2) Don't stop checking filesystem types due to EBUSY, it may mean already mounted by another filesystem type you haven't tried yet.
Rob Landley <rob@landley.net>
parents:
1508
diff
changeset
|
230 } |
22691dfb17b9
Fix two mount bugs: 1) Don't skip a filesystem type when setting up loopback mount, 2) Don't stop checking filesystem types due to EBUSY, it may mean already mounted by another filesystem type you haven't tried yet.
Rob Landley <rob@landley.net>
parents:
1508
diff
changeset
|
231 |
22691dfb17b9
Fix two mount bugs: 1) Don't skip a filesystem type when setting up loopback mount, 2) Don't stop checking filesystem types due to EBUSY, it may mean already mounted by another filesystem type you haven't tried yet.
Rob Landley <rob@landley.net>
parents:
1508
diff
changeset
|
232 free(buf); |
22691dfb17b9
Fix two mount bugs: 1) Don't skip a filesystem type when setting up loopback mount, 2) Don't stop checking filesystem types due to EBUSY, it may mean already mounted by another filesystem type you haven't tried yet.
Rob Landley <rob@landley.net>
parents:
1508
diff
changeset
|
233 buf = 0; |
22691dfb17b9
Fix two mount bugs: 1) Don't skip a filesystem type when setting up loopback mount, 2) Don't stop checking filesystem types due to EBUSY, it may mean already mounted by another filesystem type you haven't tried yet.
Rob Landley <rob@landley.net>
parents:
1508
diff
changeset
|
234 if (!rc) break; |
22691dfb17b9
Fix two mount bugs: 1) Don't skip a filesystem type when setting up loopback mount, 2) Don't stop checking filesystem types due to EBUSY, it may mean already mounted by another filesystem type you haven't tried yet.
Rob Landley <rob@landley.net>
parents:
1508
diff
changeset
|
235 if (fp && (errno == EINVAL || errno == EBUSY)) continue; |
22691dfb17b9
Fix two mount bugs: 1) Don't skip a filesystem type when setting up loopback mount, 2) Don't stop checking filesystem types due to EBUSY, it may mean already mounted by another filesystem type you haven't tried yet.
Rob Landley <rob@landley.net>
parents:
1508
diff
changeset
|
236 |
22691dfb17b9
Fix two mount bugs: 1) Don't skip a filesystem type when setting up loopback mount, 2) Don't stop checking filesystem types due to EBUSY, it may mean already mounted by another filesystem type you haven't tried yet.
Rob Landley <rob@landley.net>
parents:
1508
diff
changeset
|
237 perror_msg("'%s'->'%s'", dev, dir); |
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
|
238 |
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
|
239 break; |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
240 } |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
241 if (fp) fclose(fp); |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
242 } |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
243 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
244 void mount_main(void) |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
245 { |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
246 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
|
247 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
|
248 struct arg_list *o; |
1453 | 249 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
|
250 |
1453 | 251 // remount |
252 // - overmounts | |
253 // shared subtree | |
254 // -o parsed after fstab options | |
255 // test if mountpoint already exists (-o noremount?) | |
256 | |
257 // First pass; just accumulate string, don't parse flags yet. (This is so | |
258 // we can modify fstab entries with -a, or mtab with remount.) | |
259 for (o = TT.optlist; o; o = o->next) comma_collate(&opts, o->arg); | |
260 if (toys.optflags & FLAG_r) comma_collate(&opts, "ro"); | |
261 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
|
262 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
263 // 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
|
264 for (ss = toys.optargs; *ss; ss++) { |
1453 | 265 char *sss = *ss; |
266 | |
267 // If you realy, really want to mount a file named "--", we support it. | |
268 if (sss[0]=='-' && sss[1]=='-' && sss[2]) comma_collate(&opts, sss+2); | |
269 else if (!dev) dev = sss; | |
270 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
|
271 // 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
|
272 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
|
273 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
274 |
1453 | 275 if ((toys.optflags & FLAG_a) && dir) error_exit("-a with >1 arg"); |
276 | |
277 // For remount we need _last_ match (in case of overmounts), so traverse | |
278 // in reverse order. | |
279 if (comma_scan(opts, "remount", 1)) | |
280 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
|
281 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
282 // Do we need to do an /etc/fstab trawl? |
1453 | 283 // 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
|
284 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
|
285 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
|
286 |
1453 | 287 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
|
288 { |
1453 | 289 int aflags, noauto, len; |
290 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
|
291 |
1453 | 292 // Check for noauto and get it out of the option list. (Unknown options |
293 // that make it to the kernel give filesystem drivers indigestion.) | |
294 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
|
295 if (toys.optflags & FLAG_a) { |
1453 | 296 // "mount -a /path" to mount all entries under /path |
297 if (dev) { | |
298 len = strlen(dev); | |
299 if (strncmp(dev, mm->dir, len) | |
300 || (mm->dir[len] && mm->dir[len] != '/')) continue; | |
301 } else if (noauto) continue; // never present in the remount case | |
302 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
|
303 continue; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
304 } else { |
1453 | 305 if (dir && strcmp(dir, mm->dir)) continue; |
306 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
|
307 continue; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
308 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
309 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
310 // user only counts from fstab, not opts. |
1453 | 311 TT.okuser = comma_scan(mm->opts, "user", 1); |
312 aflags = flag_opts(mm->opts, flags, &aopts); | |
313 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
|
314 |
1453 | 315 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
|
316 free(aopts); |
1334
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
317 |
1453 | 318 if (!(toys.optflags & FLAG_a)) break; |
319 } | |
320 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
|
321 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
|
322 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
|
323 remount ? "/proc/mounts" : "fstab"); |
1453 | 324 |
325 // show mounts from /proc/mounts | |
326 } 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
|
327 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
|
328 char *s = 0; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
329 |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
330 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
|
331 if (*mm->device == '/') s = xabspath(mm->device, 0); |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
332 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
|
333 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
|
334 free(s); |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
335 } |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
336 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
337 // two arguments |
1453 | 338 } else { |
339 char *more = 0; | |
340 | |
341 mount_filesystem(dev, dir, TT.type, flag_opts(opts, flags, &more), more); | |
342 if (CFG_TOYBOX_FREE) free(more); | |
343 } | |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
344 } |