Mercurial > hg > toybox
annotate toys/pending/mount.c @ 1460:94f7ec50ef50 draft
Debugging pass on mount. Not quite done yet, but the basics seem to work now.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sun, 07 Sep 2014 14:42:51 -0500 |
parents | 3c0ed9acbaa3 |
children | 67c1402e9723 |
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)) |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
10 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
11 config MOUNT |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
12 bool "mount" |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
13 default n |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
14 help |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
15 usage: mount [-afFrsvw] [-t TYPE] [-o OPTIONS...] [[DEVICE] DIR] |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
16 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
17 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
|
18 mounts. |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
19 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
20 -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
|
21 -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
|
22 -f fake it (don't actually mount) |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
23 -r read only (same as -o ro) |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
24 -w read/write (default, same as -o rw) |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
25 -t specify filesystem type |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
26 -v verbose |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
27 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
28 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
|
29 as --longopts. |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
30 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 in /etc/fstab under /path, even if it's noauto. |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
35 */ |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
36 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
37 #define FOR_mount |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
38 #include "toys.h" |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
39 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
40 GLOBALS( |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
41 struct arg_list *optlist; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
42 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
|
43 char *bigO; |
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 unsigned long flags; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
46 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
|
47 int okuser; |
1323
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 |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
50 // 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
|
51 // 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
|
52 // 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
|
53 // 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
|
54 // 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
|
55 // 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
|
56 // 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
|
57 // 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
|
58 // 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
|
59 // 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
|
60 // TODO implement -v |
1453 | 61 // TODO "mount -a -o remount,ro" should detect overmounts |
62 // TODO work out how that differs from "mount -ar" | |
63 // TODO what if you --bind mount a block device somewhere (file, dir, dev) | |
64 // TODO "touch servername; mount -t cifs servername path" | |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
65 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
66 // 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
|
67 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
|
68 { |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
69 struct { |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
70 char *name; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
71 long flags; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
72 } opts[] = { |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
73 // 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
|
74 {"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
|
75 {"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
|
76 // {"noauto", 0}, {"swap", 0}, |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
77 {"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
|
78 {"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
|
79 {"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
|
80 {"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
|
81 {"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
|
82 {"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
|
83 {"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
|
84 {"loud", ~MS_SILENT}, |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
85 {"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
|
86 {"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
|
87 {"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
|
88 {"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
|
89 {"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
|
90 // 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
|
91 }; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
92 |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
93 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
|
94 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
|
95 int i; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
96 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
97 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
|
98 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
99 // 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
|
100 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
|
101 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
|
102 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
103 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
|
104 else flags |= ll; |
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 break; |
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 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
109 // 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
|
110 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
|
111 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
|
112 *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
|
113 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
|
114 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
|
115 } |
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 if (!comma) break; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
118 *comma = ','; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
119 new = comma + 1; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
120 } |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
121 |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
122 return flags; |
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
123 } |
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 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
|
126 unsigned long flags, char *opts) |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
127 { |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
128 FILE *fp = 0; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
129 int rc = EINVAL; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
130 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
131 if (toys.optflags & FLAG_f) return; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
132 |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
133 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
|
134 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
|
135 else { |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
136 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
|
137 return; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
138 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
139 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
140 |
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
|
141 // Autodetect bind mount or filesystem type |
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
|
142 if (!(flags & MS_MOVE) && (!type || !strcmp(type, "auto"))) { |
1334
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
143 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
|
144 |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
145 // 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
|
146 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
|
147 && ((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
|
148 || (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
|
149 { |
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 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
|
151 } 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
|
152 } 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
|
153 else if (!strcmp(type, "swap")) |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
154 toys.exitval |= xpclose(xpopen((char *[]){"swapon", "--", dev, 0}, 0), 0); |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
155 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
156 for (;;) { |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
157 char *buf = 0; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
158 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
159 // 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
|
160 if (fp) { |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
161 size_t i; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
162 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
163 if (getline(&buf, &i, fp)<0) break; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
164 type = buf; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
165 // skip nodev devices |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
166 if (!isspace(*type)) { |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
167 free(buf); |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
168 continue; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
169 } |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
170 // trim whitespace |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
171 while (isspace(*type)) type++; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
172 i = strlen(type); |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
173 if (i) type[i-1] = 0; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
174 } |
1334
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
175 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
|
176 printf("try '%s' type '%s' on '%s'\n", dev, type, dir); |
1453 | 177 for (;;) { |
178 rc = mount(dev, dir, type, flags, opts); | |
179 if ((rc != EACCES && rc != EROFS) || (flags & MS_RDONLY)) break; | |
180 fprintf(stderr, "'%s' is read-only", dev); | |
181 flags |= MS_RDONLY; | |
182 } | |
183 free(buf); | |
184 | |
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
|
185 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
|
186 |
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
|
187 // 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
|
188 // 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
|
189 // 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
|
190 // 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
|
191 // 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
|
192 // 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
|
193 // 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
|
194 // 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
|
195 // |
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
|
196 // 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
|
197 // 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
|
198 |
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 if (fp && errno == EINVAL) continue; |
1453 | 200 |
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
|
201 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
|
202 char *losetup[] = {"losetup", "-fs", dev, 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
|
203 int pipes[2], 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
|
204 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
|
205 |
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
|
206 if (flags & MS_RDONLY) losetup[1] = "-fsr"; |
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 pid = xpopen(losetup, pipes); |
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 len = readall(pipes[1], toybuf, sizeof(toybuf)-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
|
209 rc = xpclose(pid, pipes); |
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 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
|
211 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
|
212 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
|
213 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
|
214 |
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
|
215 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
|
216 } 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
|
217 } 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
|
218 |
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 break; |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
220 } |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
221 if (fp) fclose(fp); |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
222 } |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
223 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
224 void mount_main(void) |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
225 { |
1447
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
226 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
|
227 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
|
228 struct arg_list *o; |
1453 | 229 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
|
230 |
1453 | 231 // remount |
232 // - overmounts | |
233 // shared subtree | |
234 // -o parsed after fstab options | |
235 // test if mountpoint already exists (-o noremount?) | |
236 | |
237 // First pass; just accumulate string, don't parse flags yet. (This is so | |
238 // we can modify fstab entries with -a, or mtab with remount.) | |
239 for (o = TT.optlist; o; o = o->next) comma_collate(&opts, o->arg); | |
240 if (toys.optflags & FLAG_r) comma_collate(&opts, "ro"); | |
241 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
|
242 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
243 // 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
|
244 for (ss = toys.optargs; *ss; ss++) { |
1453 | 245 char *sss = *ss; |
246 | |
247 // If you realy, really want to mount a file named "--", we support it. | |
248 if (sss[0]=='-' && sss[1]=='-' && sss[2]) comma_collate(&opts, sss+2); | |
249 else if (!dev) dev = sss; | |
250 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
|
251 // 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
|
252 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
|
253 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
254 |
1453 | 255 if ((toys.optflags & FLAG_a) && dir) error_exit("-a with >1 arg"); |
256 | |
257 // For remount we need _last_ match (in case of overmounts), so traverse | |
258 // in reverse order. | |
259 if (comma_scan(opts, "remount", 1)) | |
260 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
|
261 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
262 // Do we need to do an /etc/fstab trawl? |
1453 | 263 // 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
|
264 if ((toys.optflags & FLAG_a) || (dev && (!dir || getuid() || remount))) { |
1453 | 265 if (!remount) 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
|
266 |
1453 | 267 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
|
268 { |
1453 | 269 int aflags, noauto, len; |
270 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
|
271 |
1453 | 272 // Check for noauto and get it out of the option list. (Unknown options |
273 // that make it to the kernel give filesystem drivers indigestion.) | |
274 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
|
275 if (toys.optflags & FLAG_a) { |
1453 | 276 // "mount -a /path" to mount all entries under /path |
277 if (dev) { | |
278 len = strlen(dev); | |
279 if (strncmp(dev, mm->dir, len) | |
280 || (mm->dir[len] && mm->dir[len] != '/')) continue; | |
281 } else if (noauto) continue; // never present in the remount case | |
282 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
|
283 continue; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
284 } else { |
1453 | 285 if (dir && strcmp(dir, mm->dir)) continue; |
286 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
|
287 continue; |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
288 } |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
289 |
487716951287
Work in progress snapshot of mount, with fallout to umount. (Not done yet.)
Rob Landley <rob@landley.net>
parents:
1385
diff
changeset
|
290 // user only counts from fstab, not opts. |
1453 | 291 TT.okuser = comma_scan(mm->opts, "user", 1); |
292 aflags = flag_opts(mm->opts, flags, &aopts); | |
293 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
|
294 |
1453 | 295 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
|
296 free(aopts); |
1334
9fd2bcedbeb5
mount: start on option parsing, implement loopback and bind mount autodetection.
Rob Landley <rob@landley.net>
parents:
1323
diff
changeset
|
297 |
1453 | 298 if (!(toys.optflags & FLAG_a)) break; |
299 } | |
300 if (CFG_TOYBOX_FREE) llist_traverse(mtl, free); | |
301 | |
302 // show mounts from /proc/mounts | |
303 } 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
|
304 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
|
305 char *s = 0; |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
306 |
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 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
|
308 if (*mm->device == '/') s = xabspath(mm->device, 0); |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
309 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
|
310 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
|
311 free(s); |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
312 } |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
313 |
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
314 // two arguments |
1453 | 315 } else { |
316 char *more = 0; | |
317 | |
318 mount_filesystem(dev, dir, TT.type, flag_opts(opts, flags, &more), more); | |
319 if (CFG_TOYBOX_FREE) free(more); | |
320 } | |
1323
c3061b237c4c
First stab at mount, very incomplete.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
321 } |