Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 2 | /* |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 3 | * Mini mount implementation for busybox |
| 4 | * |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 5 | * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>. |
Eric Andersen | 1d1d2f9 | 2002-04-13 08:31:59 +0000 | [diff] [blame] | 6 | * Copyright (C) 1999-2002 by Erik Andersen <andersee@debian.org> |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | * |
| 22 | * 3/21/1999 Charles P. Wright <cpwright@cpwright.com> |
| 23 | * searches through fstab when -a is passed |
| 24 | * will try mounting stuff with all fses when passed -t auto |
| 25 | * |
| 26 | * 1999-04-17 Dave Cinege...Rewrote -t auto. Fixed ro mtab. |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 27 | * |
Eric Andersen | 3ece93b | 2002-06-22 17:23:45 +0000 | [diff] [blame] | 28 | * 1999-10-07 Erik Andersen <andersee@debian.org>. |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 29 | * Rewrite of a lot of code. Removed mtab usage (I plan on |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 30 | * putting it back as a compile-time option some time), |
| 31 | * major adjustments to option parsing, and some serious |
| 32 | * dieting all around. |
Erik Andersen | b7cc49d | 2000-01-13 06:38:14 +0000 | [diff] [blame] | 33 | * |
Erik Andersen | 3163821 | 2000-01-15 22:28:50 +0000 | [diff] [blame] | 34 | * 1999-11-06 mtab suppport is back - andersee |
| 35 | * |
Erik Andersen | b7cc49d | 2000-01-13 06:38:14 +0000 | [diff] [blame] | 36 | * 2000-01-12 Ben Collins <bcollins@debian.org>, Borrowed utils-linux's |
| 37 | * mount to add loop support. |
Eric Andersen | fdd5103 | 2000-08-02 18:48:26 +0000 | [diff] [blame] | 38 | * |
| 39 | * 2000-04-30 Dave Cinege <dcinege@psychosis.com> |
| 40 | * Rewrote fstab while loop and lower mount section. Can now do |
| 41 | * single mounts from fstab. Can override fstab options for single |
| 42 | * mount. Common mount_one call for single mounts and 'all'. Fixed |
| 43 | * mtab updating and stale entries. Removed 'remount' default. |
| 44 | * |
Erik Andersen | b7cc49d | 2000-01-13 06:38:14 +0000 | [diff] [blame] | 45 | */ |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 46 | |
Matt Kraai | 3425111 | 2001-05-02 21:17:38 +0000 | [diff] [blame] | 47 | #include <limits.h> |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 48 | #include <stdlib.h> |
| 49 | #include <unistd.h> |
| 50 | #include <errno.h> |
| 51 | #include <string.h> |
| 52 | #include <stdio.h> |
| 53 | #include <mntent.h> |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 54 | #include <ctype.h> |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 55 | #include "busybox.h" |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 56 | |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 57 | enum { |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 58 | MS_MGC_VAL = 0xc0ed0000, /* Magic number indicatng "new" flags */ |
| 59 | MS_RDONLY = 1, /* Mount read-only */ |
| 60 | MS_NOSUID = 2, /* Ignore suid and sgid bits */ |
| 61 | MS_NODEV = 4, /* Disallow access to device special files */ |
| 62 | MS_NOEXEC = 8, /* Disallow program execution */ |
| 63 | MS_SYNCHRONOUS = 16, /* Writes are synced at once */ |
| 64 | MS_REMOUNT = 32, /* Alter flags of a mounted FS */ |
| 65 | MS_MANDLOCK = 64, /* Allow mandatory locks on an FS */ |
| 66 | S_QUOTA = 128, /* Quota initialized for file/directory/symlink */ |
| 67 | S_APPEND = 256, /* Append-only file */ |
| 68 | S_IMMUTABLE = 512, /* Immutable file */ |
| 69 | MS_NOATIME = 1024, /* Do not update access times. */ |
| 70 | MS_NODIRATIME = 2048, /* Do not update directory access times */ |
| 71 | MS_BIND = 4096, /* Use the new linux 2.4.x "mount --bind" feature */ |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 72 | }; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 73 | |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 74 | |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 75 | #if defined CONFIG_FEATURE_MOUNT_LOOP |
Erik Andersen | b7cc49d | 2000-01-13 06:38:14 +0000 | [diff] [blame] | 76 | #include <fcntl.h> |
| 77 | #include <sys/ioctl.h> |
Erik Andersen | e132f4b | 2000-02-09 04:16:43 +0000 | [diff] [blame] | 78 | static int use_loop = FALSE; |
Erik Andersen | b7cc49d | 2000-01-13 06:38:14 +0000 | [diff] [blame] | 79 | #endif |
| 80 | |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 81 | extern int mount(__const char *__special_file, __const char *__dir, |
| 82 | __const char *__fstype, unsigned long int __rwflag, |
| 83 | __const void *__data); |
| 84 | extern int umount(__const char *__special_file); |
| 85 | extern int umount2(__const char *__special_file, int __flags); |
Eric Andersen | de44067 | 2001-03-01 07:55:49 +0000 | [diff] [blame] | 86 | |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 87 | extern int sysfs(int option, unsigned int fs_index, char *buf); |
Eric Andersen | a57ba4d | 2000-07-08 19:20:49 +0000 | [diff] [blame] | 88 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 89 | struct mount_options { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 90 | const char *name; |
| 91 | unsigned long and; |
| 92 | unsigned long or; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 95 | static const struct mount_options mount_options[] = { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 96 | {"async", ~MS_SYNCHRONOUS, 0}, |
Erik Andersen | 6c5f2c6 | 2000-05-05 19:49:33 +0000 | [diff] [blame] | 97 | {"atime", ~0, ~MS_NOATIME}, |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 98 | {"defaults", ~0, 0}, |
Robert Griebl | aa385d4 | 2002-05-14 22:56:29 +0000 | [diff] [blame] | 99 | {"noauto", ~0, 0}, |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 100 | {"dev", ~MS_NODEV, 0}, |
Erik Andersen | 6c5f2c6 | 2000-05-05 19:49:33 +0000 | [diff] [blame] | 101 | {"diratime", ~0, ~MS_NODIRATIME}, |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 102 | {"exec", ~MS_NOEXEC, 0}, |
Erik Andersen | 6c5f2c6 | 2000-05-05 19:49:33 +0000 | [diff] [blame] | 103 | {"noatime", ~0, MS_NOATIME}, |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 104 | {"nodev", ~0, MS_NODEV}, |
Erik Andersen | 6c5f2c6 | 2000-05-05 19:49:33 +0000 | [diff] [blame] | 105 | {"nodiratime", ~0, MS_NODIRATIME}, |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 106 | {"noexec", ~0, MS_NOEXEC}, |
| 107 | {"nosuid", ~0, MS_NOSUID}, |
| 108 | {"remount", ~0, MS_REMOUNT}, |
| 109 | {"ro", ~0, MS_RDONLY}, |
| 110 | {"rw", ~MS_RDONLY, 0}, |
| 111 | {"suid", ~MS_NOSUID, 0}, |
| 112 | {"sync", ~0, MS_SYNCHRONOUS}, |
Eric Andersen | 2f6e1f8 | 2001-05-21 15:59:34 +0000 | [diff] [blame] | 113 | {"bind", ~0, MS_BIND}, |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 114 | {0, 0, 0} |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 115 | }; |
| 116 | |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 117 | static int |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 118 | do_mount(char *specialfile, char *dir, char *filesystemtype, long flags, |
| 119 | void *string_flags, int useMtab, int fakeIt, char *mtab_opts, |
| 120 | int mount_all) |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 121 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 122 | int status = 0; |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 123 | |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 124 | #if defined CONFIG_FEATURE_MOUNT_LOOP |
Erik Andersen | e132f4b | 2000-02-09 04:16:43 +0000 | [diff] [blame] | 125 | char *lofile = NULL; |
Eric Andersen | 8847b9a | 2000-09-21 01:33:05 +0000 | [diff] [blame] | 126 | #endif |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 127 | |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 128 | if (!fakeIt) { |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 129 | #if defined CONFIG_FEATURE_MOUNT_LOOP |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 130 | if (use_loop == TRUE) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 131 | int loro = flags & MS_RDONLY; |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 132 | |
Mark Whitley | e677dfe | 2001-02-26 17:45:58 +0000 | [diff] [blame] | 133 | lofile = specialfile; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 134 | |
| 135 | specialfile = find_unused_loop_device(); |
| 136 | if (specialfile == NULL) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 137 | bb_error_msg_and_die("Could not find a spare loop device"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 138 | } |
| 139 | if (set_loop(specialfile, lofile, 0, &loro)) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 140 | bb_error_msg_and_die("Could not setup loop device"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 141 | } |
| 142 | if (!(flags & MS_RDONLY) && loro) { /* loop is ro, but wanted rw */ |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 143 | bb_error_msg("WARNING: loop device is read-only"); |
Matt Kraai | 94f3a57 | 2001-07-05 14:46:07 +0000 | [diff] [blame] | 144 | flags |= MS_RDONLY; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 145 | } |
| 146 | } |
Erik Andersen | b7cc49d | 2000-01-13 06:38:14 +0000 | [diff] [blame] | 147 | #endif |
Eric Andersen | a42982e | 2000-06-07 17:28:53 +0000 | [diff] [blame] | 148 | status = mount(specialfile, dir, filesystemtype, flags, string_flags); |
Matt Kraai | 9344f75 | 2001-06-03 02:21:38 +0000 | [diff] [blame] | 149 | if (status < 0 && errno == EROFS) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 150 | bb_error_msg("%s is write-protected, mounting read-only", |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 151 | specialfile); |
| 152 | status = mount(specialfile, dir, filesystemtype, flags |= |
| 153 | MS_RDONLY, string_flags); |
Eric Andersen | 0cccdfa | 2000-09-20 06:23:36 +0000 | [diff] [blame] | 154 | } |
Matt Kraai | 9344f75 | 2001-06-03 02:21:38 +0000 | [diff] [blame] | 155 | /* Don't whine about already mounted filesystems when mounting all. */ |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 156 | if (status < 0 && errno == EBUSY && mount_all) { |
Matt Kraai | 9344f75 | 2001-06-03 02:21:38 +0000 | [diff] [blame] | 157 | return TRUE; |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 158 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 159 | } |
Erik Andersen | 5cbdd71 | 2000-01-26 20:06:48 +0000 | [diff] [blame] | 160 | |
| 161 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 162 | /* If the mount was sucessful, do anything needed, then return TRUE */ |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 163 | if (status == 0 || fakeIt == TRUE) { |
Erik Andersen | 5cbdd71 | 2000-01-26 20:06:48 +0000 | [diff] [blame] | 164 | |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 165 | #if defined CONFIG_FEATURE_MTAB_SUPPORT |
Matt Kraai | 1f0c436 | 2001-12-20 23:13:26 +0000 | [diff] [blame] | 166 | if (useMtab) { |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 167 | erase_mtab(specialfile); /* Clean any stale entries */ |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 168 | write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts); |
| 169 | } |
| 170 | #endif |
| 171 | return (TRUE); |
| 172 | } |
| 173 | |
| 174 | /* Bummer. mount failed. Clean up */ |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 175 | #if defined CONFIG_FEATURE_MOUNT_LOOP |
Erik Andersen | e132f4b | 2000-02-09 04:16:43 +0000 | [diff] [blame] | 176 | if (lofile != NULL) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 177 | del_loop(specialfile); |
Erik Andersen | 5cbdd71 | 2000-01-26 20:06:48 +0000 | [diff] [blame] | 178 | } |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 179 | #endif |
Eric Andersen | a42982e | 2000-06-07 17:28:53 +0000 | [diff] [blame] | 180 | |
| 181 | if (errno == EPERM) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 182 | bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); |
Eric Andersen | a42982e | 2000-06-07 17:28:53 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 185 | return (FALSE); |
Erik Andersen | b7cc49d | 2000-01-13 06:38:14 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Eric Andersen | d0246fb | 1999-11-04 21:18:07 +0000 | [diff] [blame] | 188 | |
Eric Andersen | 8b1aa4d | 2002-06-22 17:20:50 +0000 | [diff] [blame] | 189 | static void paste_str(char **s1, const char *s2) |
| 190 | { |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 191 | *s1 = xrealloc(*s1, strlen(*s1) + strlen(s2) + 1); |
Eric Andersen | 8b1aa4d | 2002-06-22 17:20:50 +0000 | [diff] [blame] | 192 | strcat(*s1, s2); |
| 193 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 194 | |
Eric Andersen | 8341a15 | 1999-10-08 17:14:14 +0000 | [diff] [blame] | 195 | /* Seperate standard mount options from the nonstandard string options */ |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 196 | static void parse_mount_options(char *options, int *flags, char **strflags) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 197 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 198 | while (options) { |
| 199 | int gotone = FALSE; |
| 200 | char *comma = strchr(options, ','); |
| 201 | const struct mount_options *f = mount_options; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 202 | |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 203 | if (comma) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 204 | *comma = '\0'; |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 205 | } |
Eric Andersen | 3ae0c78 | 1999-11-04 01:13:21 +0000 | [diff] [blame] | 206 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 207 | while (f->name != 0) { |
| 208 | if (strcasecmp(f->name, options) == 0) { |
| 209 | |
| 210 | *flags &= f->and; |
| 211 | *flags |= f->or; |
| 212 | gotone = TRUE; |
| 213 | break; |
| 214 | } |
| 215 | f++; |
| 216 | } |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 217 | #if defined CONFIG_FEATURE_MOUNT_LOOP |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 218 | if (!strcasecmp("loop", options)) { /* loop device support */ |
Erik Andersen | e132f4b | 2000-02-09 04:16:43 +0000 | [diff] [blame] | 219 | use_loop = TRUE; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 220 | gotone = TRUE; |
| 221 | } |
Erik Andersen | b7cc49d | 2000-01-13 06:38:14 +0000 | [diff] [blame] | 222 | #endif |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 223 | if (!gotone) { |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 224 | if (**strflags) { |
| 225 | /* have previous parsed options */ |
Eric Andersen | 8b1aa4d | 2002-06-22 17:20:50 +0000 | [diff] [blame] | 226 | paste_str(strflags, ","); |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 227 | } |
Eric Andersen | 8b1aa4d | 2002-06-22 17:20:50 +0000 | [diff] [blame] | 228 | paste_str(strflags, options); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 229 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 230 | if (comma) { |
| 231 | *comma = ','; |
| 232 | options = ++comma; |
| 233 | } else { |
| 234 | break; |
| 235 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 236 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 239 | static int mount_one(char *blockDevice, char *directory, char *filesystemType, |
| 240 | unsigned long flags, char *string_flags, int useMtab, |
| 241 | int fakeIt, char *mtab_opts, int whineOnErrors, |
| 242 | int mount_all) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 243 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 244 | int status = 0; |
Eric Andersen | 8acbf1d | 2001-10-18 04:10:22 +0000 | [diff] [blame] | 245 | if (strcmp(filesystemType, "auto") == 0) { |
| 246 | char buf[255]; |
Robert Griebl | 2a4a8d8 | 2002-07-24 01:41:30 +0000 | [diff] [blame] | 247 | FILE *f; |
| 248 | int read_proc = 0; |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 249 | |
| 250 | f = fopen("/etc/filesystems", "r"); |
| 251 | |
| 252 | if (f) { |
| 253 | while (fgets(buf, sizeof(buf), f)) { |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 254 | if (*buf == '*') { |
Robert Griebl | 2a4a8d8 | 2002-07-24 01:41:30 +0000 | [diff] [blame] | 255 | read_proc = 1; |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 256 | } else if (*buf == '#') { |
Robert Griebl | 2a4a8d8 | 2002-07-24 01:41:30 +0000 | [diff] [blame] | 257 | continue; |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 258 | } else { |
Robert Griebl | 2a4a8d8 | 2002-07-24 01:41:30 +0000 | [diff] [blame] | 259 | filesystemType = buf; |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 260 | |
| 261 | /* Add NULL termination to each line */ |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 262 | while (*filesystemType && !isspace(*filesystemType)) { |
Robert Griebl | 2a4a8d8 | 2002-07-24 01:41:30 +0000 | [diff] [blame] | 263 | filesystemType++; |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 264 | } |
Robert Griebl | 2a4a8d8 | 2002-07-24 01:41:30 +0000 | [diff] [blame] | 265 | *filesystemType = '\0'; |
Eric Andersen | 8acbf1d | 2001-10-18 04:10:22 +0000 | [diff] [blame] | 266 | |
Robert Griebl | 2a4a8d8 | 2002-07-24 01:41:30 +0000 | [diff] [blame] | 267 | filesystemType = buf; |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 268 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 269 | if (bb_strlen(filesystemType)) { |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 270 | status = |
| 271 | do_mount(blockDevice, directory, filesystemType, |
| 272 | flags | MS_MGC_VAL, string_flags, |
| 273 | useMtab, fakeIt, mtab_opts, mount_all); |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 274 | if (status) { |
Robert Griebl | 2a4a8d8 | 2002-07-24 01:41:30 +0000 | [diff] [blame] | 275 | break; |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 276 | } |
Robert Griebl | 2a4a8d8 | 2002-07-24 01:41:30 +0000 | [diff] [blame] | 277 | } |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 278 | |
Robert Griebl | 2a4a8d8 | 2002-07-24 01:41:30 +0000 | [diff] [blame] | 279 | } |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 280 | } |
| 281 | fclose(f); |
Robert Griebl | 2a4a8d8 | 2002-07-24 01:41:30 +0000 | [diff] [blame] | 282 | } |
Eric Andersen | 8acbf1d | 2001-10-18 04:10:22 +0000 | [diff] [blame] | 283 | |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 284 | if ((!f || read_proc) && !status) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 285 | f = bb_xfopen("/proc/filesystems", "r"); |
Eric Andersen | 8acbf1d | 2001-10-18 04:10:22 +0000 | [diff] [blame] | 286 | |
Robert Griebl | 2a4a8d8 | 2002-07-24 01:41:30 +0000 | [diff] [blame] | 287 | while (fgets(buf, sizeof(buf), f) != NULL) { |
Eric Andersen | 8acbf1d | 2001-10-18 04:10:22 +0000 | [diff] [blame] | 288 | filesystemType = buf; |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 289 | if (*filesystemType == '\t') { /* Not a nodev filesystem */ |
| 290 | |
| 291 | /* Add NULL termination to each line */ |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 292 | while (*filesystemType && *filesystemType != '\n') { |
Robert Griebl | 2a4a8d8 | 2002-07-24 01:41:30 +0000 | [diff] [blame] | 293 | filesystemType++; |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 294 | } |
Robert Griebl | 2a4a8d8 | 2002-07-24 01:41:30 +0000 | [diff] [blame] | 295 | *filesystemType = '\0'; |
Eric Andersen | 8acbf1d | 2001-10-18 04:10:22 +0000 | [diff] [blame] | 296 | |
Robert Griebl | 2a4a8d8 | 2002-07-24 01:41:30 +0000 | [diff] [blame] | 297 | filesystemType = buf; |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 298 | filesystemType++; /* hop past tab */ |
Robert Griebl | 2a4a8d8 | 2002-07-24 01:41:30 +0000 | [diff] [blame] | 299 | |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 300 | status = |
| 301 | do_mount(blockDevice, directory, filesystemType, |
| 302 | flags | MS_MGC_VAL, string_flags, useMtab, |
| 303 | fakeIt, mtab_opts, mount_all); |
| 304 | if (status) { |
Robert Griebl | 2a4a8d8 | 2002-07-24 01:41:30 +0000 | [diff] [blame] | 305 | break; |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 306 | } |
Robert Griebl | 2a4a8d8 | 2002-07-24 01:41:30 +0000 | [diff] [blame] | 307 | } |
Eric Andersen | 8acbf1d | 2001-10-18 04:10:22 +0000 | [diff] [blame] | 308 | } |
| 309 | } |
| 310 | fclose(f); |
Eric Andersen | deca106 | 2002-12-05 07:24:08 +0000 | [diff] [blame] | 311 | } else { |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 312 | status = |
| 313 | do_mount(blockDevice, directory, filesystemType, |
| 314 | flags | MS_MGC_VAL, string_flags, useMtab, fakeIt, |
| 315 | mtab_opts, mount_all); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 316 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 317 | |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 318 | if (!status) { |
Matt Kraai | 1f0c436 | 2001-12-20 23:13:26 +0000 | [diff] [blame] | 319 | if (whineOnErrors) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 320 | bb_perror_msg("Mounting %s on %s failed", blockDevice, directory); |
Erik Andersen | e132f4b | 2000-02-09 04:16:43 +0000 | [diff] [blame] | 321 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 322 | return (FALSE); |
| 323 | } |
| 324 | return (TRUE); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Robert Griebl | d0dd3d3 | 2002-07-25 14:17:19 +0000 | [diff] [blame] | 327 | static void show_mounts(char *onlytype) |
Matt Kraai | 1240082 | 2001-04-17 04:32:50 +0000 | [diff] [blame] | 328 | { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 329 | FILE *mountTable = setmntent(bb_path_mtab_file, "r"); |
Matt Kraai | 1240082 | 2001-04-17 04:32:50 +0000 | [diff] [blame] | 330 | |
| 331 | if (mountTable) { |
| 332 | struct mntent *m; |
| 333 | |
| 334 | while ((m = getmntent(mountTable)) != 0) { |
| 335 | char *blockDevice = m->mnt_fsname; |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 336 | |
Eric Andersen | 9d7f0f0 | 2003-06-20 09:36:49 +0000 | [diff] [blame^] | 337 | if (strcmp(blockDevice, "rootfs") == 0) { |
| 338 | continue; |
| 339 | } else if (strcmp(blockDevice, "/dev/root") == 0) { |
Eric Andersen | c911a43 | 2001-05-15 17:42:16 +0000 | [diff] [blame] | 340 | blockDevice = find_real_root_device_name(blockDevice); |
Matt Kraai | 1240082 | 2001-04-17 04:32:50 +0000 | [diff] [blame] | 341 | } |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 342 | if (!onlytype || (strcmp(m->mnt_type, onlytype) == 0)) { |
Robert Griebl | d0dd3d3 | 2002-07-25 14:17:19 +0000 | [diff] [blame] | 343 | printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir, |
| 344 | m->mnt_type, m->mnt_opts); |
| 345 | } |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 346 | #ifdef CONFIG_FEATURE_CLEAN_UP |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 347 | if (blockDevice != m->mnt_fsname) { |
Eric Andersen | c911a43 | 2001-05-15 17:42:16 +0000 | [diff] [blame] | 348 | free(blockDevice); |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 349 | } |
Eric Andersen | c911a43 | 2001-05-15 17:42:16 +0000 | [diff] [blame] | 350 | #endif |
Matt Kraai | 1240082 | 2001-04-17 04:32:50 +0000 | [diff] [blame] | 351 | } |
| 352 | endmntent(mountTable); |
| 353 | } else { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 354 | bb_perror_msg_and_die(bb_path_mtab_file); |
Matt Kraai | 1240082 | 2001-04-17 04:32:50 +0000 | [diff] [blame] | 355 | } |
| 356 | exit(EXIT_SUCCESS); |
Matt Kraai | 1240082 | 2001-04-17 04:32:50 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 359 | extern int mount_main(int argc, char **argv) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 360 | { |
Glenn L McGrath | 3aae100 | 2001-05-07 01:38:03 +0000 | [diff] [blame] | 361 | struct stat statbuf; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 362 | char *string_flags = bb_xstrdup(""); |
Eric Andersen | 8b1aa4d | 2002-06-22 17:20:50 +0000 | [diff] [blame] | 363 | char *extra_opts; |
Eric Andersen | e7413a9 | 2000-07-14 06:19:41 +0000 | [diff] [blame] | 364 | int flags = 0; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 365 | char *filesystemType = "auto"; |
Robert Griebl | d0dd3d3 | 2002-07-25 14:17:19 +0000 | [diff] [blame] | 366 | int got_filesystemType = 0; |
Glenn L McGrath | 3aae100 | 2001-05-07 01:38:03 +0000 | [diff] [blame] | 367 | char *device = xmalloc(PATH_MAX); |
| 368 | char *directory = xmalloc(PATH_MAX); |
Eric Andersen | 8b1aa4d | 2002-06-22 17:20:50 +0000 | [diff] [blame] | 369 | struct mntent *m = NULL; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 370 | int all = FALSE; |
| 371 | int fakeIt = FALSE; |
| 372 | int useMtab = TRUE; |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 373 | int rc = EXIT_FAILURE; |
Eric Andersen | 8b1aa4d | 2002-06-22 17:20:50 +0000 | [diff] [blame] | 374 | FILE *f = 0; |
Matt Kraai | a3045df | 2001-04-17 04:48:51 +0000 | [diff] [blame] | 375 | int opt; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 376 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 377 | /* Parse options */ |
Matt Kraai | a3045df | 2001-04-17 04:48:51 +0000 | [diff] [blame] | 378 | while ((opt = getopt(argc, argv, "o:rt:wafnv")) > 0) { |
| 379 | switch (opt) { |
| 380 | case 'o': |
Eric Andersen | 8b1aa4d | 2002-06-22 17:20:50 +0000 | [diff] [blame] | 381 | parse_mount_options(optarg, &flags, &string_flags); |
Matt Kraai | a3045df | 2001-04-17 04:48:51 +0000 | [diff] [blame] | 382 | break; |
| 383 | case 'r': |
| 384 | flags |= MS_RDONLY; |
| 385 | break; |
| 386 | case 't': |
| 387 | filesystemType = optarg; |
Robert Griebl | d0dd3d3 | 2002-07-25 14:17:19 +0000 | [diff] [blame] | 388 | got_filesystemType = 1; |
Matt Kraai | a3045df | 2001-04-17 04:48:51 +0000 | [diff] [blame] | 389 | break; |
| 390 | case 'w': |
| 391 | flags &= ~MS_RDONLY; |
| 392 | break; |
| 393 | case 'a': |
| 394 | all = TRUE; |
| 395 | break; |
| 396 | case 'f': |
| 397 | fakeIt = TRUE; |
| 398 | break; |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 399 | #ifdef CONFIG_FEATURE_MTAB_SUPPORT |
Matt Kraai | a3045df | 2001-04-17 04:48:51 +0000 | [diff] [blame] | 400 | case 'n': |
| 401 | useMtab = FALSE; |
| 402 | break; |
Eric Andersen | a9c95ea | 1999-11-15 17:33:30 +0000 | [diff] [blame] | 403 | #endif |
Matt Kraai | a3045df | 2001-04-17 04:48:51 +0000 | [diff] [blame] | 404 | case 'v': |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 405 | break; /* ignore -v */ |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 406 | } |
Matt Kraai | a3045df | 2001-04-17 04:48:51 +0000 | [diff] [blame] | 407 | } |
| 408 | |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 409 | if (!all && (optind == argc)) { |
| 410 | show_mounts(got_filesystemType ? filesystemType : NULL); |
| 411 | } |
Matt Kraai | 1240082 | 2001-04-17 04:32:50 +0000 | [diff] [blame] | 412 | |
Matt Kraai | e6bf66e | 2001-05-04 14:49:58 +0000 | [diff] [blame] | 413 | if (optind < argc) { |
Glenn L McGrath | 3aae100 | 2001-05-07 01:38:03 +0000 | [diff] [blame] | 414 | /* if device is a filename get its real path */ |
Glenn L McGrath | cc0aa0f | 2001-05-07 01:51:24 +0000 | [diff] [blame] | 415 | if (stat(argv[optind], &statbuf) == 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 416 | char *tmp = bb_simplify_path(argv[optind]); |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 417 | |
Eric Andersen | defd998 | 2002-04-13 13:47:39 +0000 | [diff] [blame] | 418 | safe_strncpy(device, tmp, PATH_MAX); |
Glenn L McGrath | 3aae100 | 2001-05-07 01:38:03 +0000 | [diff] [blame] | 419 | } else { |
Matt Kraai | e6bf66e | 2001-05-04 14:49:58 +0000 | [diff] [blame] | 420 | safe_strncpy(device, argv[optind], PATH_MAX); |
Glenn L McGrath | 3aae100 | 2001-05-07 01:38:03 +0000 | [diff] [blame] | 421 | } |
Matt Kraai | e6bf66e | 2001-05-04 14:49:58 +0000 | [diff] [blame] | 422 | } |
Matt Kraai | 3425111 | 2001-05-02 21:17:38 +0000 | [diff] [blame] | 423 | |
Matt Kraai | a7cecbc | 2001-08-10 15:05:27 +0000 | [diff] [blame] | 424 | if (optind + 1 < argc) |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 425 | directory = bb_simplify_path(argv[optind + 1]); |
Matt Kraai | a7cecbc | 2001-08-10 15:05:27 +0000 | [diff] [blame] | 426 | |
Matt Kraai | 1f0c436 | 2001-12-20 23:13:26 +0000 | [diff] [blame] | 427 | if (all || optind + 1 == argc) { |
Eric Andersen | 8b1aa4d | 2002-06-22 17:20:50 +0000 | [diff] [blame] | 428 | f = setmntent("/etc/fstab", "r"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 429 | |
Erik Andersen | 246cc6d | 2000-03-07 07:41:42 +0000 | [diff] [blame] | 430 | if (f == NULL) |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 431 | bb_perror_msg_and_die("\nCannot read /etc/fstab"); |
Erik Andersen | 246cc6d | 2000-03-07 07:41:42 +0000 | [diff] [blame] | 432 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 433 | while ((m = getmntent(f)) != NULL) { |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 434 | if (!all && (optind + 1 == argc) |
| 435 | && ((strcmp(device, m->mnt_fsname) != 0) |
| 436 | && (strcmp(device, m->mnt_dir) != 0))) { |
Eric Andersen | fdd5103 | 2000-08-02 18:48:26 +0000 | [diff] [blame] | 437 | continue; |
| 438 | } |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 439 | |
| 440 | if (all && ( /* If we're mounting 'all' */ |
| 441 | (strstr(m->mnt_opts, "noauto")) || /* and the file system isn't noauto, */ |
Eric Andersen | 5ef4482 | 2003-02-28 06:29:27 +0000 | [diff] [blame] | 442 | (strstr(m->mnt_type, "swap")))) /* and isn't swap, then mount it */ |
| 443 | { |
Eric Andersen | fdd5103 | 2000-08-02 18:48:26 +0000 | [diff] [blame] | 444 | continue; |
| 445 | } |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 446 | |
| 447 | if (all || flags == 0) { /* Allow single mount to override fstab flags */ |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 448 | flags = 0; |
Eric Andersen | 8b1aa4d | 2002-06-22 17:20:50 +0000 | [diff] [blame] | 449 | string_flags[0] = 0; |
| 450 | parse_mount_options(m->mnt_opts, &flags, &string_flags); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 451 | } |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 452 | |
Matt Kraai | 3425111 | 2001-05-02 21:17:38 +0000 | [diff] [blame] | 453 | strcpy(device, m->mnt_fsname); |
| 454 | strcpy(directory, m->mnt_dir); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 455 | filesystemType = bb_xstrdup(m->mnt_type); |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 456 | singlemount: |
Eric Andersen | 8b1aa4d | 2002-06-22 17:20:50 +0000 | [diff] [blame] | 457 | extra_opts = string_flags; |
Eric Andersen | d9d03b8 | 2000-12-12 23:20:37 +0000 | [diff] [blame] | 458 | rc = EXIT_SUCCESS; |
Eric Andersen | bdfd0d7 | 2001-10-24 05:00:29 +0000 | [diff] [blame] | 459 | #ifdef CONFIG_NFSMOUNT |
Eric Andersen | fcffa2c | 2002-04-06 05:17:57 +0000 | [diff] [blame] | 460 | if (strchr(device, ':') != NULL) { |
Pavel Roskin | 680d65a | 2000-06-06 17:03:55 +0000 | [diff] [blame] | 461 | filesystemType = "nfs"; |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 462 | if (nfsmount |
| 463 | (device, directory, &flags, &extra_opts, &string_flags, |
| 464 | 1)) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 465 | bb_perror_msg("nfsmount failed"); |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 466 | rc = EXIT_FAILURE; |
Eric Andersen | fdd5103 | 2000-08-02 18:48:26 +0000 | [diff] [blame] | 467 | } |
Eric Andersen | 252bacc | 2000-09-19 01:21:13 +0000 | [diff] [blame] | 468 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 469 | #endif |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 470 | if (!mount_one |
| 471 | (device, directory, filesystemType, flags, string_flags, |
| 472 | useMtab, fakeIt, extra_opts, TRUE, all)) { |
Matt Kraai | 92ed8a3 | 2000-12-06 15:55:23 +0000 | [diff] [blame] | 473 | rc = EXIT_FAILURE; |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 474 | } |
| 475 | if (!all) { |
Eric Andersen | fdd5103 | 2000-08-02 18:48:26 +0000 | [diff] [blame] | 476 | break; |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 477 | } |
Eric Andersen | fdd5103 | 2000-08-02 18:48:26 +0000 | [diff] [blame] | 478 | } |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 479 | if (f) { |
Eric Andersen | fdd5103 | 2000-08-02 18:48:26 +0000 | [diff] [blame] | 480 | endmntent(f); |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 481 | } |
| 482 | if (!all && f && m == NULL) { |
Eric Andersen | fdd5103 | 2000-08-02 18:48:26 +0000 | [diff] [blame] | 483 | fprintf(stderr, "Can't find %s in /etc/fstab\n", device); |
Glenn L McGrath | 8042f65 | 2002-08-23 06:17:46 +0000 | [diff] [blame] | 484 | } |
Matt Kraai | 93ba60f | 2001-02-28 15:33:12 +0000 | [diff] [blame] | 485 | return rc; |
Eric Andersen | fdd5103 | 2000-08-02 18:48:26 +0000 | [diff] [blame] | 486 | } |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 487 | |
Eric Andersen | fdd5103 | 2000-08-02 18:48:26 +0000 | [diff] [blame] | 488 | goto singlemount; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 489 | } |