Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 1 | /* |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 2 | * Mini mount implementation for busybox |
| 3 | * |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 4 | * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>. |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | * |
| 20 | * 3/21/1999 Charles P. Wright <cpwright@cpwright.com> |
| 21 | * searches through fstab when -a is passed |
| 22 | * will try mounting stuff with all fses when passed -t auto |
| 23 | * |
| 24 | * 1999-04-17 Dave Cinege...Rewrote -t auto. Fixed ro mtab. |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 25 | * |
| 26 | * 1999-10-07 Erik Andersen <andersen@lineo.com>, <andersee@debian.org>. |
| 27 | * Rewrote of a lot of code. Removed mtab usage (I plan on |
| 28 | * putting it back as a compile-time option some time), |
| 29 | * major adjustments to option parsing, and some serious |
| 30 | * dieting all around. |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 31 | */ |
| 32 | |
| 33 | #include "internal.h" |
| 34 | #include <stdlib.h> |
| 35 | #include <unistd.h> |
| 36 | #include <errno.h> |
| 37 | #include <string.h> |
| 38 | #include <stdio.h> |
| 39 | #include <mntent.h> |
| 40 | #include <sys/mount.h> |
| 41 | #include <ctype.h> |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 42 | #include <fstab.h> |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 43 | |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 44 | extern const char mtab_file[]; /* Defined in utility.c */ |
| 45 | |
Eric Andersen | d73dc5b | 1999-11-10 23:13:02 +0000 | [diff] [blame] | 46 | static const char mount_usage[] = "\tmount [flags]\n" |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 47 | "\tmount [flags] device directory [-o options,more-options]\n" |
| 48 | "\n" |
| 49 | "Flags:\n" |
| 50 | "\t-a:\tMount all file systems in fstab.\n" |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 51 | #ifdef BB_MTAB |
| 52 | "\t-f:\t\"Fake\" mount. Add entry to mount table but don't mount it.\n" |
| 53 | "\t-n:\tDon't write a mount table entry.\n" |
| 54 | #endif |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 55 | "\t-o option:\tOne of many filesystem options, listed below.\n" |
| 56 | "\t-r:\tMount the filesystem read-only.\n" |
| 57 | "\t-t filesystem-type:\tSpecify the filesystem type.\n" |
| 58 | "\t-w:\tMount for reading and writing (default).\n" |
| 59 | "\n" |
| 60 | "Options for use with the \"-o\" flag:\n" |
| 61 | "\tasync / sync:\tWrites are asynchronous / synchronous.\n" |
| 62 | "\tdev / nodev:\tAllow use of special device files / disallow them.\n" |
| 63 | "\texec / noexec:\tAllow use of executable files / disallow them.\n" |
| 64 | "\tsuid / nosuid:\tAllow set-user-id-root programs / disallow them.\n" |
| 65 | "\tremount: Re-mount a currently-mounted filesystem, changing its flags.\n" |
| 66 | "\tro / rw: Mount for read-only / read-write.\n" |
| 67 | "\t" |
| 68 | "There are EVEN MORE flags that are specific to each filesystem.\n" |
| 69 | "You'll have to see the written documentation for those.\n"; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 70 | |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 71 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 72 | struct mount_options { |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 73 | const char *name; |
| 74 | unsigned long and; |
| 75 | unsigned long or; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 78 | static const struct mount_options mount_options[] = { |
| 79 | {"async", ~MS_SYNCHRONOUS, 0}, |
| 80 | {"defaults", ~0, 0}, |
| 81 | {"dev", ~MS_NODEV, 0}, |
| 82 | {"exec", ~MS_NOEXEC, 0}, |
| 83 | {"nodev", ~0, MS_NODEV}, |
| 84 | {"noexec", ~0, MS_NOEXEC}, |
| 85 | {"nosuid", ~0, MS_NOSUID}, |
| 86 | {"remount", ~0, MS_REMOUNT}, |
| 87 | {"ro", ~0, MS_RDONLY}, |
| 88 | {"rw", ~MS_RDONLY, 0}, |
| 89 | {"suid", ~MS_NOSUID, 0}, |
| 90 | {"sync", ~0, MS_SYNCHRONOUS}, |
| 91 | {0, 0, 0} |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 94 | #if ! defined BB_MTAB |
Eric Andersen | a9c95ea | 1999-11-15 17:33:30 +0000 | [diff] [blame] | 95 | #define do_mount(specialfile, dir, filesystemtype, flags, string_flags, useMtab, fakeIt, mtab_opts) \ |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 96 | mount(specialfile, dir, filesystemtype, flags, string_flags) |
| 97 | #else |
| 98 | static int |
| 99 | do_mount(char* specialfile, char* dir, char* filesystemtype, |
Eric Andersen | a9c95ea | 1999-11-15 17:33:30 +0000 | [diff] [blame] | 100 | long flags, void* string_flags, int useMtab, int fakeIt, char* mtab_opts) |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 101 | { |
| 102 | int status=0; |
| 103 | |
| 104 | if (fakeIt==FALSE) |
| 105 | status=mount(specialfile, dir, filesystemtype, flags, string_flags); |
| 106 | |
| 107 | if ( status == 0 ) { |
| 108 | if ( useMtab==TRUE ) |
Eric Andersen | a9c95ea | 1999-11-15 17:33:30 +0000 | [diff] [blame] | 109 | write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts); |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 110 | return 0; |
| 111 | } |
| 112 | else |
| 113 | return( status); |
| 114 | } |
| 115 | #endif |
| 116 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 117 | |
Erik Andersen | 0881de7 | 2000-01-05 09:34:26 +0000 | [diff] [blame^] | 118 | #if defined BB_MTAB |
| 119 | #define whine_if_fstab_is_missing() {} |
| 120 | #else |
| 121 | extern void whine_if_fstab_is_missing() |
| 122 | { |
| 123 | struct stat statBuf; |
| 124 | if (stat("/etc/fstab", &statBuf) < 0) |
| 125 | fprintf(stderr, "/etc/fstab file missing -- install one to name /dev/root.\n\n"); |
| 126 | } |
| 127 | #endif |
| 128 | |
| 129 | |
Eric Andersen | 8341a15 | 1999-10-08 17:14:14 +0000 | [diff] [blame] | 130 | /* Seperate standard mount options from the nonstandard string options */ |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 131 | static void |
Eric Andersen | 8341a15 | 1999-10-08 17:14:14 +0000 | [diff] [blame] | 132 | parse_mount_options ( char *options, unsigned long *flags, char *strflags) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 133 | { |
Eric Andersen | 8341a15 | 1999-10-08 17:14:14 +0000 | [diff] [blame] | 134 | while (options) { |
| 135 | int gotone=FALSE; |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 136 | char *comma = strchr (options, ','); |
| 137 | const struct mount_options* f = mount_options; |
| 138 | if (comma) |
| 139 | *comma = '\0'; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 140 | |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 141 | while (f->name != 0) { |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 142 | if (strcasecmp (f->name, options) == 0) { |
Eric Andersen | 3ae0c78 | 1999-11-04 01:13:21 +0000 | [diff] [blame] | 143 | |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 144 | *flags &= f->and; |
| 145 | *flags |= f->or; |
Eric Andersen | 8341a15 | 1999-10-08 17:14:14 +0000 | [diff] [blame] | 146 | gotone=TRUE; |
| 147 | break; |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 148 | } |
| 149 | f++; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 150 | } |
Eric Andersen | 8341a15 | 1999-10-08 17:14:14 +0000 | [diff] [blame] | 151 | if (*strflags && strflags!= '\0' && gotone==FALSE) { |
| 152 | char *temp=strflags; |
| 153 | temp += strlen (strflags); |
| 154 | *temp++ = ','; |
| 155 | *temp++ = '\0'; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 156 | } |
Eric Andersen | 8341a15 | 1999-10-08 17:14:14 +0000 | [diff] [blame] | 157 | if (gotone==FALSE) { |
| 158 | strcat (strflags, options); |
| 159 | gotone=FALSE; |
| 160 | } |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 161 | if (comma) { |
| 162 | *comma = ','; |
| 163 | options = ++comma; |
Eric Andersen | 8341a15 | 1999-10-08 17:14:14 +0000 | [diff] [blame] | 164 | } else { |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 165 | break; |
Eric Andersen | 8341a15 | 1999-10-08 17:14:14 +0000 | [diff] [blame] | 166 | } |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 167 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | int |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 171 | mount_one(char *blockDevice, char *directory, char *filesystemType, |
Eric Andersen | a9c95ea | 1999-11-15 17:33:30 +0000 | [diff] [blame] | 172 | unsigned long flags, char *string_flags, int useMtab, int fakeIt, char *mtab_opts) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 173 | { |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 174 | int status = 0; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 175 | |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 176 | char buf[255]; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 177 | |
Eric Andersen | 0ecb54a | 1999-12-05 23:24:55 +0000 | [diff] [blame] | 178 | #if defined BB_FEATURE_USE_PROCFS |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 179 | if (strcmp(filesystemType, "auto") == 0) { |
| 180 | FILE *f = fopen ("/proc/filesystems", "r"); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 181 | |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 182 | if (f == NULL) |
| 183 | return( FALSE); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 184 | |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 185 | while (fgets (buf, sizeof (buf), f) != NULL) { |
| 186 | filesystemType = buf; |
| 187 | if (*filesystemType == '\t') { // Not a nodev filesystem |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 188 | |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 189 | // Add NULL termination to each line |
| 190 | while (*filesystemType && *filesystemType != '\n') |
| 191 | filesystemType++; |
| 192 | *filesystemType = '\0'; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 193 | |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 194 | filesystemType = buf; |
| 195 | filesystemType++; // hop past tab |
| 196 | |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 197 | status = do_mount (blockDevice, directory, filesystemType, |
Eric Andersen | a9c95ea | 1999-11-15 17:33:30 +0000 | [diff] [blame] | 198 | flags | MS_MGC_VAL, string_flags, useMtab, |
| 199 | fakeIt, mtab_opts); |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 200 | if (status == 0) |
| 201 | break; |
| 202 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 203 | } |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 204 | fclose (f); |
Eric Andersen | 0ecb54a | 1999-12-05 23:24:55 +0000 | [diff] [blame] | 205 | } else |
| 206 | #endif |
| 207 | { |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 208 | status = do_mount (blockDevice, directory, filesystemType, |
Eric Andersen | a9c95ea | 1999-11-15 17:33:30 +0000 | [diff] [blame] | 209 | flags | MS_MGC_VAL, string_flags, useMtab, |
| 210 | fakeIt, mtab_opts); |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 211 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 212 | |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 213 | if (status) { |
| 214 | fprintf (stderr, "Mounting %s on %s failed: %s\n", |
| 215 | blockDevice, directory, strerror(errno)); |
| 216 | return (FALSE); |
| 217 | } |
| 218 | return (TRUE); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 221 | extern int mount_main (int argc, char **argv) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 222 | { |
Eric Andersen | a9c95ea | 1999-11-15 17:33:30 +0000 | [diff] [blame] | 223 | char string_flags_buf[1024]=""; |
| 224 | char *string_flags = string_flags_buf; |
| 225 | char *extra_opts = string_flags_buf; |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 226 | unsigned long flags = 0; |
| 227 | char *filesystemType = "auto"; |
Eric Andersen | 8341a15 | 1999-10-08 17:14:14 +0000 | [diff] [blame] | 228 | char *device = NULL; |
| 229 | char *directory = NULL; |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 230 | int all = FALSE; |
| 231 | int fakeIt = FALSE; |
| 232 | int useMtab = TRUE; |
Eric Andersen | 8341a15 | 1999-10-08 17:14:14 +0000 | [diff] [blame] | 233 | int i; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 234 | |
Eric Andersen | 29d2e36 | 1999-11-06 06:07:27 +0000 | [diff] [blame] | 235 | /* Only compiled in if BB_MTAB is not defined */ |
| 236 | whine_if_fstab_is_missing(); |
Eric Andersen | cb6e256 | 1999-10-16 15:48:40 +0000 | [diff] [blame] | 237 | |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 238 | if (argc == 1) { |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 239 | FILE *mountTable = setmntent (mtab_file, "r"); |
| 240 | if (mountTable) { |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 241 | struct mntent *m; |
| 242 | while ((m = getmntent (mountTable)) != 0) { |
Eric Andersen | cb6e256 | 1999-10-16 15:48:40 +0000 | [diff] [blame] | 243 | struct fstab* fstabItem; |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 244 | char *blockDevice = m->mnt_fsname; |
Eric Andersen | cb6e256 | 1999-10-16 15:48:40 +0000 | [diff] [blame] | 245 | /* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */ |
| 246 | if (strcmp (blockDevice, "/dev/root") == 0) { |
| 247 | fstabItem = getfsfile ("/"); |
| 248 | if (fstabItem != NULL) |
| 249 | blockDevice = fstabItem->fs_spec; |
| 250 | } |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 251 | printf ("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir, |
| 252 | m->mnt_type, m->mnt_opts); |
| 253 | } |
| 254 | endmntent (mountTable); |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 255 | } else { |
| 256 | perror(mtab_file); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 257 | } |
Eric Andersen | 3c16382 | 1999-10-14 22:16:57 +0000 | [diff] [blame] | 258 | exit( TRUE); |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 259 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 260 | |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 261 | |
| 262 | /* Parse options */ |
Eric Andersen | 8341a15 | 1999-10-08 17:14:14 +0000 | [diff] [blame] | 263 | i = --argc; |
| 264 | argv++; |
| 265 | while (i > 0 && **argv) { |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 266 | if (**argv == '-') { |
Eric Andersen | a9c95ea | 1999-11-15 17:33:30 +0000 | [diff] [blame] | 267 | char *opt = *argv; |
| 268 | while (i>0 && *++opt) switch (*opt) { |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 269 | case 'o': |
Eric Andersen | 8341a15 | 1999-10-08 17:14:14 +0000 | [diff] [blame] | 270 | if (--i == 0) { |
Eric Andersen | d73dc5b | 1999-11-10 23:13:02 +0000 | [diff] [blame] | 271 | goto goodbye; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 272 | } |
Eric Andersen | 8341a15 | 1999-10-08 17:14:14 +0000 | [diff] [blame] | 273 | parse_mount_options (*(++argv), &flags, string_flags); |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 274 | break; |
| 275 | case 'r': |
| 276 | flags |= MS_RDONLY; |
| 277 | break; |
| 278 | case 't': |
Eric Andersen | 8341a15 | 1999-10-08 17:14:14 +0000 | [diff] [blame] | 279 | if (--i == 0) { |
Eric Andersen | d73dc5b | 1999-11-10 23:13:02 +0000 | [diff] [blame] | 280 | goto goodbye; |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 281 | } |
Eric Andersen | 8341a15 | 1999-10-08 17:14:14 +0000 | [diff] [blame] | 282 | filesystemType = *(++argv); |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 283 | break; |
| 284 | case 'w': |
| 285 | flags &= ~MS_RDONLY; |
| 286 | break; |
| 287 | case 'a': |
Eric Andersen | 3ae0c78 | 1999-11-04 01:13:21 +0000 | [diff] [blame] | 288 | all = TRUE; |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 289 | break; |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 290 | #ifdef BB_MTAB |
| 291 | case 'f': |
| 292 | fakeIt = TRUE; |
| 293 | break; |
| 294 | case 'n': |
| 295 | useMtab = FALSE; |
| 296 | break; |
| 297 | #endif |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 298 | case 'v': |
| 299 | case 'h': |
| 300 | case '-': |
Eric Andersen | d73dc5b | 1999-11-10 23:13:02 +0000 | [diff] [blame] | 301 | goto goodbye; |
Eric Andersen | 8341a15 | 1999-10-08 17:14:14 +0000 | [diff] [blame] | 302 | } |
| 303 | } else { |
| 304 | if (device == NULL) |
| 305 | device=*argv; |
| 306 | else if (directory == NULL) |
| 307 | directory=*argv; |
| 308 | else { |
Eric Andersen | d73dc5b | 1999-11-10 23:13:02 +0000 | [diff] [blame] | 309 | goto goodbye; |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | i--; |
| 313 | argv++; |
| 314 | } |
| 315 | |
Eric Andersen | 3ae0c78 | 1999-11-04 01:13:21 +0000 | [diff] [blame] | 316 | if (all == TRUE) { |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 317 | struct mntent *m; |
| 318 | FILE *f = setmntent ("/etc/fstab", "r"); |
| 319 | |
| 320 | if (f == NULL) { |
| 321 | perror("/etc/fstab"); |
Eric Andersen | 3c16382 | 1999-10-14 22:16:57 +0000 | [diff] [blame] | 322 | exit( FALSE); |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 323 | } |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 324 | while ((m = getmntent (f)) != NULL) { |
Eric Andersen | 3ae0c78 | 1999-11-04 01:13:21 +0000 | [diff] [blame] | 325 | // If the file system isn't noauto, and isn't mounted on /, |
| 326 | // and isn't swap or nfs, then mount it |
| 327 | if ((!strstr (m->mnt_opts, "noauto")) && |
| 328 | (m->mnt_dir[1] != '\0') && |
| 329 | (!strstr (m->mnt_type, "swap")) && |
| 330 | (!strstr (m->mnt_type, "nfs"))) |
| 331 | { |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 332 | flags = 0; |
Eric Andersen | 3ae0c78 | 1999-11-04 01:13:21 +0000 | [diff] [blame] | 333 | *string_flags = '\0'; |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 334 | parse_mount_options(m->mnt_opts, &flags, string_flags); |
| 335 | mount_one (m->mnt_fsname, m->mnt_dir, m->mnt_type, |
Eric Andersen | a9c95ea | 1999-11-15 17:33:30 +0000 | [diff] [blame] | 336 | flags, string_flags, useMtab, fakeIt, extra_opts); |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 337 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 338 | } |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 339 | endmntent (f); |
| 340 | } else { |
Eric Andersen | 8341a15 | 1999-10-08 17:14:14 +0000 | [diff] [blame] | 341 | if (device && directory) { |
Eric Andersen | a9c95ea | 1999-11-15 17:33:30 +0000 | [diff] [blame] | 342 | #ifdef BB_NFSMOUNT |
| 343 | if (strcmp(filesystemType, "nfs") == 0) { |
| 344 | if (nfsmount(device, directory, &flags, &extra_opts, &string_flags, 1) != 0) |
| 345 | exit(FALSE); |
| 346 | } |
| 347 | #endif |
Eric Andersen | 3c16382 | 1999-10-14 22:16:57 +0000 | [diff] [blame] | 348 | exit (mount_one (device, directory, filesystemType, |
Eric Andersen | a9c95ea | 1999-11-15 17:33:30 +0000 | [diff] [blame] | 349 | flags, string_flags, useMtab, fakeIt, extra_opts)); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 350 | } else { |
Eric Andersen | d73dc5b | 1999-11-10 23:13:02 +0000 | [diff] [blame] | 351 | goto goodbye; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 352 | } |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 353 | } |
Eric Andersen | 3c16382 | 1999-10-14 22:16:57 +0000 | [diff] [blame] | 354 | exit( TRUE); |
Eric Andersen | d73dc5b | 1999-11-10 23:13:02 +0000 | [diff] [blame] | 355 | |
| 356 | goodbye: |
| 357 | usage( mount_usage); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 358 | } |