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