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