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 | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 6 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 7 | * Copyright (C) 2005-2006 by Rob Landley <rob@landley.net> |
Eric Andersen | 596e546 | 1999-10-07 08:30:23 +0000 | [diff] [blame] | 8 | * |
Rob Landley | 7b363fd | 2005-12-20 17:18:01 +0000 | [diff] [blame] | 9 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Erik Andersen | b7cc49d | 2000-01-13 06:38:14 +0000 | [diff] [blame] | 10 | */ |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 11 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 12 | /* todo: |
| 13 | * bb_getopt_ulflags(); |
| 14 | */ |
| 15 | |
Rob Landley | 22d26fc | 2006-06-15 15:49:36 +0000 | [diff] [blame] | 16 | /* Design notes: There is no spec for mount. Remind me to write one. |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 17 | |
| 18 | mount_main() calls singlemount() which calls mount_it_now(). |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 19 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 20 | mount_main() can loop through /etc/fstab for mount -a |
| 21 | singlemount() can loop through /etc/filesystems for fstype detection. |
| 22 | mount_it_now() does the actual mount. |
| 23 | */ |
| 24 | |
Rob Landley | 22d26fc | 2006-06-15 15:49:36 +0000 | [diff] [blame] | 25 | #include "busybox.h" |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 26 | #include <mntent.h> |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 27 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 28 | // Not real flags, but we want to be able to check for this. |
| 29 | #define MOUNT_NOAUTO (1<<29) |
| 30 | #define MOUNT_SWAP (1<<30) |
Rob Landley | 3ba7bd1 | 2006-08-09 19:51:13 +0000 | [diff] [blame] | 31 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 32 | /* Standard mount options (from -o options or --options), with corresponding |
| 33 | * flags */ |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 34 | |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 35 | struct { |
Rob Landley | e3781b7 | 2006-08-08 01:39:49 +0000 | [diff] [blame] | 36 | char *name; |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 37 | long flags; |
Rob Landley | e3781b7 | 2006-08-08 01:39:49 +0000 | [diff] [blame] | 38 | } static mount_options[] = { |
| 39 | // MS_FLAGS set a bit. ~MS_FLAGS disable that bit. 0 flags are NOPs. |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 40 | |
Rob Landley | e3781b7 | 2006-08-08 01:39:49 +0000 | [diff] [blame] | 41 | USE_FEATURE_MOUNT_LOOP( |
| 42 | {"loop", 0}, |
| 43 | ) |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 44 | |
Rob Landley | e3781b7 | 2006-08-08 01:39:49 +0000 | [diff] [blame] | 45 | USE_FEATURE_MOUNT_FSTAB( |
| 46 | {"defaults", 0}, |
| 47 | {"quiet", 0}, |
| 48 | {"noauto",MOUNT_NOAUTO}, |
| 49 | {"swap",MOUNT_SWAP}, |
| 50 | ) |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 51 | |
Rob Landley | e3781b7 | 2006-08-08 01:39:49 +0000 | [diff] [blame] | 52 | USE_FEATURE_MOUNT_FLAGS( |
| 53 | // vfs flags |
| 54 | {"nosuid", MS_NOSUID}, |
| 55 | {"suid", ~MS_NOSUID}, |
| 56 | {"dev", ~MS_NODEV}, |
| 57 | {"nodev", MS_NODEV}, |
| 58 | {"exec", ~MS_NOEXEC}, |
| 59 | {"noexec", MS_NOEXEC}, |
| 60 | {"sync", MS_SYNCHRONOUS}, |
| 61 | {"async", ~MS_SYNCHRONOUS}, |
| 62 | {"atime", ~MS_NOATIME}, |
| 63 | {"noatime", MS_NOATIME}, |
| 64 | {"diratime", ~MS_NODIRATIME}, |
| 65 | {"nodiratime", MS_NODIRATIME}, |
| 66 | {"loud", ~MS_SILENT}, |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 67 | |
Rob Landley | e3781b7 | 2006-08-08 01:39:49 +0000 | [diff] [blame] | 68 | // action flags |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 69 | |
Rob Landley | e3781b7 | 2006-08-08 01:39:49 +0000 | [diff] [blame] | 70 | {"bind", MS_BIND}, |
| 71 | {"move", MS_MOVE}, |
| 72 | {"shared", MS_SHARED}, |
| 73 | {"slave", MS_SLAVE}, |
| 74 | {"private", MS_PRIVATE}, |
| 75 | {"unbindable", MS_UNBINDABLE}, |
| 76 | {"rshared", MS_SHARED|MS_RECURSIVE}, |
| 77 | {"rslave", MS_SLAVE|MS_RECURSIVE}, |
| 78 | {"rprivate", MS_SLAVE|MS_RECURSIVE}, |
| 79 | {"runbindable", MS_UNBINDABLE|MS_RECURSIVE}, |
| 80 | ) |
| 81 | |
| 82 | // Always understood. |
| 83 | |
| 84 | {"ro", MS_RDONLY}, // vfs flag |
| 85 | {"rw", ~MS_RDONLY}, // vfs flag |
| 86 | {"remount", MS_REMOUNT}, // action flag |
| 87 | |
| 88 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 91 | /* Append mount options to string */ |
| 92 | static void append_mount_options(char **oldopts, char *newopts) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 93 | { |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 94 | if(*oldopts && **oldopts) { |
Denis Vlasenko | 39e93cc | 2006-09-10 18:38:17 +0000 | [diff] [blame] | 95 | char *temp = xasprintf("%s,%s",*oldopts,newopts); |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 96 | free(*oldopts); |
Denis Vlasenko | 39e93cc | 2006-09-10 18:38:17 +0000 | [diff] [blame] | 97 | *oldopts = temp; |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 98 | } else { |
| 99 | if (ENABLE_FEATURE_CLEAN_UP) free(*oldopts); |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 100 | *oldopts = xstrdup(newopts); |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
| 104 | /* Use the mount_options list to parse options into flags. |
| 105 | * Return list of unrecognized options in *strflags if strflags!=NULL */ |
| 106 | static int parse_mount_options(char *options, char **unrecognized) |
| 107 | { |
| 108 | int flags = MS_SILENT; |
| 109 | |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 110 | // Loop through options |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 111 | for (;;) { |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 112 | int i; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 113 | char *comma = strchr(options, ','); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 114 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 115 | if (comma) *comma = 0; |
Eric Andersen | 3ae0c78 | 1999-11-04 01:13:21 +0000 | [diff] [blame] | 116 | |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 117 | // Find this option in mount_options |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 118 | for (i = 0; i < (sizeof(mount_options) / sizeof(*mount_options)); i++) { |
| 119 | if (!strcasecmp(mount_options[i].name, options)) { |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 120 | long fl = mount_options[i].flags; |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 121 | if(fl < 0) flags &= fl; |
| 122 | else flags |= fl; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 123 | break; |
| 124 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 125 | } |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 126 | // If unrecognized not NULL, append unrecognized mount options */ |
| 127 | if (unrecognized |
| 128 | && i == (sizeof(mount_options) / sizeof(*mount_options))) |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 129 | { |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 130 | // Add it to strflags, to pass on to kernel |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 131 | i = *unrecognized ? strlen(*unrecognized) : 0; |
| 132 | *unrecognized = xrealloc(*unrecognized, i+strlen(options)+2); |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 133 | |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 134 | // Comma separated if it's not the first one |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 135 | if (i) (*unrecognized)[i++] = ','; |
| 136 | strcpy((*unrecognized)+i, options); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 137 | } |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 138 | |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 139 | // Advance to next option, or finish |
| 140 | if(comma) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 141 | *comma = ','; |
| 142 | options = ++comma; |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 143 | } else break; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 144 | } |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 145 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 146 | return flags; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 149 | // Return a list of all block device backed filesystems |
Matt Kraai | 1240082 | 2001-04-17 04:32:50 +0000 | [diff] [blame] | 150 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 151 | static llist_t *get_block_backed_filesystems(void) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 152 | { |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 153 | char *fs, *buf, |
| 154 | *filesystems[] = {"/etc/filesystems", "/proc/filesystems", 0}; |
| 155 | llist_t *list = 0; |
| 156 | int i; |
| 157 | FILE *f; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 158 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 159 | for(i = 0; filesystems[i]; i++) { |
| 160 | if(!(f = fopen(filesystems[i], "r"))) continue; |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 161 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 162 | for(fs = buf = 0; (fs = buf = bb_get_chomped_line_from_file(f)); |
| 163 | free(buf)) |
| 164 | { |
| 165 | if(!strncmp(buf,"nodev",5) && isspace(buf[5])) continue; |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 166 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 167 | while(isspace(*fs)) fs++; |
| 168 | if(*fs=='#' || *fs=='*') continue; |
| 169 | if(!*fs) continue; |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 170 | |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 171 | llist_add_to_end(&list,xstrdup(fs)); |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 172 | } |
| 173 | if (ENABLE_FEATURE_CLEAN_UP) fclose(f); |
| 174 | } |
| 175 | |
| 176 | return list; |
| 177 | } |
| 178 | |
| 179 | llist_t *fslist = 0; |
| 180 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 181 | #if ENABLE_FEATURE_CLEAN_UP |
| 182 | static void delete_block_backed_filesystems(void) |
| 183 | { |
Rob Landley | a6b5b60 | 2006-05-08 19:03:07 +0000 | [diff] [blame] | 184 | llist_free(fslist, free); |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 185 | } |
Rob Landley | fe908fd | 2006-03-29 14:30:49 +0000 | [diff] [blame] | 186 | #else |
| 187 | void delete_block_backed_filesystems(void); |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 188 | #endif |
| 189 | |
| 190 | #if ENABLE_FEATURE_MTAB_SUPPORT |
| 191 | static int useMtab; |
Eric Andersen | 19b5b8f | 2006-03-20 18:07:13 +0000 | [diff] [blame] | 192 | static int fakeIt; |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 193 | #else |
| 194 | #define useMtab 0 |
Eric Andersen | 19b5b8f | 2006-03-20 18:07:13 +0000 | [diff] [blame] | 195 | #define fakeIt 0 |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 196 | #endif |
| 197 | |
| 198 | // Perform actual mount of specific filesystem at specific location. |
| 199 | |
Rob Landley | fe908fd | 2006-03-29 14:30:49 +0000 | [diff] [blame] | 200 | static int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts) |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 201 | { |
| 202 | int rc; |
Rob Landley | eaa34ca | 2006-03-18 02:58:11 +0000 | [diff] [blame] | 203 | |
Eric Andersen | 19b5b8f | 2006-03-20 18:07:13 +0000 | [diff] [blame] | 204 | if (fakeIt) { return 0; } |
| 205 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 206 | // Mount, with fallback to read-only if necessary. |
| 207 | |
| 208 | for(;;) { |
| 209 | rc = mount(mp->mnt_fsname, mp->mnt_dir, mp->mnt_type, |
| 210 | vfsflags, filteropts); |
| 211 | if(!rc || (vfsflags&MS_RDONLY) || (errno!=EACCES && errno!=EROFS)) |
| 212 | break; |
| 213 | bb_error_msg("%s is write-protected, mounting read-only", |
| 214 | mp->mnt_fsname); |
| 215 | vfsflags |= MS_RDONLY; |
| 216 | } |
| 217 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 218 | // Abort entirely if permission denied. |
| 219 | |
| 220 | if (rc && errno == EPERM) |
| 221 | bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); |
| 222 | |
| 223 | /* If the mount was successful, and we're maintaining an old-style |
| 224 | * mtab file by hand, add the new entry to it now. */ |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 225 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 226 | if(ENABLE_FEATURE_MTAB_SUPPORT && useMtab && !rc) { |
| 227 | FILE *mountTable = setmntent(bb_path_mtab_file, "a+"); |
| 228 | int i; |
| 229 | |
| 230 | if(!mountTable) |
Denis Vlasenko | 6d655be | 2006-09-06 19:02:46 +0000 | [diff] [blame] | 231 | bb_error_msg("No %s",bb_path_mtab_file); |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 232 | |
| 233 | // Add vfs string flags |
| 234 | |
| 235 | for(i=0; mount_options[i].flags != MS_REMOUNT; i++) |
| 236 | if (mount_options[i].flags > 0) |
Rob Landley | e3781b7 | 2006-08-08 01:39:49 +0000 | [diff] [blame] | 237 | append_mount_options(&(mp->mnt_opts), mount_options[i].name); |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 238 | |
| 239 | // Remove trailing / (if any) from directory we mounted on |
| 240 | |
| 241 | i = strlen(mp->mnt_dir); |
| 242 | if(i>1 && mp->mnt_dir[i-1] == '/') mp->mnt_dir[i-1] = 0; |
| 243 | |
| 244 | // Write and close. |
| 245 | |
| 246 | if(!mp->mnt_type || !*mp->mnt_type) mp->mnt_type="--bind"; |
| 247 | addmntent(mountTable, mp); |
| 248 | endmntent(mountTable); |
| 249 | if (ENABLE_FEATURE_CLEAN_UP) |
| 250 | if(strcmp(mp->mnt_type,"--bind")) mp->mnt_type = 0; |
| 251 | } |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 252 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 253 | return rc; |
| 254 | } |
| 255 | |
Rob Landley | 4cb035d | 2006-09-05 14:00:21 +0000 | [diff] [blame] | 256 | // Mount one directory. Handles CIFS, NFS, loopback, autobind, and filesystem |
| 257 | // type detection. Returns 0 for success, nonzero for failure. |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 258 | |
Rob Landley | 0cc2c2c | 2006-06-21 03:53:33 +0000 | [diff] [blame] | 259 | static int singlemount(struct mntent *mp, int ignore_busy) |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 260 | { |
Rob Landley | 0cc2c2c | 2006-06-21 03:53:33 +0000 | [diff] [blame] | 261 | int rc = -1, vfsflags; |
Rob Landley | fe908fd | 2006-03-29 14:30:49 +0000 | [diff] [blame] | 262 | char *loopFile = 0, *filteropts = 0; |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 263 | llist_t *fl = 0; |
| 264 | struct stat st; |
| 265 | |
Rob Landley | fe908fd | 2006-03-29 14:30:49 +0000 | [diff] [blame] | 266 | vfsflags = parse_mount_options(mp->mnt_opts, &filteropts); |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 267 | |
Rob Landley | eaa34ca | 2006-03-18 02:58:11 +0000 | [diff] [blame] | 268 | // Treat fstype "auto" as unspecified. |
| 269 | |
| 270 | if (mp->mnt_type && !strcmp(mp->mnt_type,"auto")) mp->mnt_type = 0; |
| 271 | |
Rob Landley | 89d9d4d | 2006-09-01 08:10:44 +0000 | [diff] [blame] | 272 | // Might this be an CIFS filesystem? |
| 273 | |
| 274 | if(ENABLE_FEATURE_MOUNT_CIFS && |
| 275 | (!mp->mnt_type || !strcmp(mp->mnt_type,"cifs")) && |
| 276 | (mp->mnt_fsname[0]==mp->mnt_fsname[1] && (mp->mnt_fsname[0]=='/' || mp->mnt_fsname[0]=='\\'))) |
| 277 | { |
| 278 | struct hostent *he; |
| 279 | char ip[32], *s; |
| 280 | |
| 281 | rc = 1; |
| 282 | // Replace '/' with '\' and verify that unc points to "//server/share". |
| 283 | |
| 284 | for (s = mp->mnt_fsname; *s; ++s) |
| 285 | if (*s == '/') *s = '\\'; |
| 286 | |
| 287 | // get server IP |
| 288 | |
| 289 | s = strrchr(mp->mnt_fsname, '\\'); |
| 290 | if (s == mp->mnt_fsname+1) goto report_error; |
| 291 | *s = 0; |
| 292 | he = gethostbyname(mp->mnt_fsname+2); |
| 293 | *s = '\\'; |
| 294 | if (!he) goto report_error; |
| 295 | |
| 296 | // Insert ip=... option into string flags. (NOTE: Add IPv6 support.) |
| 297 | |
| 298 | sprintf(ip, "ip=%d.%d.%d.%d", he->h_addr[0], he->h_addr[1], |
| 299 | he->h_addr[2], he->h_addr[3]); |
| 300 | parse_mount_options(ip, &filteropts); |
| 301 | |
| 302 | // compose new unc '\\server-ip\share' |
| 303 | |
Rob Landley | 4cb035d | 2006-09-05 14:00:21 +0000 | [diff] [blame] | 304 | s = xasprintf("\\\\%s%s",ip+3,strchr(mp->mnt_fsname+2,'\\')); |
Rob Landley | 89d9d4d | 2006-09-01 08:10:44 +0000 | [diff] [blame] | 305 | if (ENABLE_FEATURE_CLEAN_UP) free(mp->mnt_fsname); |
| 306 | mp->mnt_fsname = s; |
| 307 | |
| 308 | // lock is required |
| 309 | vfsflags |= MS_MANDLOCK; |
| 310 | |
| 311 | mp->mnt_type = "cifs"; |
| 312 | rc = mount_it_now(mp, vfsflags, filteropts); |
| 313 | goto report_error; |
| 314 | } |
| 315 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 316 | // Might this be an NFS filesystem? |
| 317 | |
| 318 | if (ENABLE_FEATURE_MOUNT_NFS && |
| 319 | (!mp->mnt_type || !strcmp(mp->mnt_type,"nfs")) && |
| 320 | strchr(mp->mnt_fsname, ':') != NULL) |
| 321 | { |
Rob Landley | fe908fd | 2006-03-29 14:30:49 +0000 | [diff] [blame] | 322 | if (nfsmount(mp->mnt_fsname, mp->mnt_dir, &vfsflags, &filteropts, 1)) { |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 323 | bb_perror_msg("nfsmount failed"); |
Rob Landley | fe908fd | 2006-03-29 14:30:49 +0000 | [diff] [blame] | 324 | } else { |
| 325 | // Strangely enough, nfsmount() doesn't actually mount() anything. |
Rob Landley | 19af279 | 2006-04-05 01:43:39 +0000 | [diff] [blame] | 326 | mp->mnt_type = "nfs"; |
Rob Landley | fe908fd | 2006-03-29 14:30:49 +0000 | [diff] [blame] | 327 | rc = mount_it_now(mp, vfsflags, filteropts); |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 328 | } |
Rob Landley | 89d9d4d | 2006-09-01 08:10:44 +0000 | [diff] [blame] | 329 | goto report_error; |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 330 | } |
| 331 | |
Rob Landley | ab87360 | 2006-04-04 16:56:04 +0000 | [diff] [blame] | 332 | // Look at the file. (Not found isn't a failure for remount, or for |
| 333 | // a synthetic filesystem like proc or sysfs.) |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 334 | |
Rob Landley | 3ba7bd1 | 2006-08-09 19:51:13 +0000 | [diff] [blame] | 335 | if (!lstat(mp->mnt_fsname, &st) && !(vfsflags & (MS_REMOUNT | MS_BIND | MS_MOVE))) |
Rob Landley | e3781b7 | 2006-08-08 01:39:49 +0000 | [diff] [blame] | 336 | { |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 337 | // Do we need to allocate a loopback device for it? |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 338 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 339 | if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) { |
Rob Landley | eaa34ca | 2006-03-18 02:58:11 +0000 | [diff] [blame] | 340 | loopFile = bb_simplify_path(mp->mnt_fsname); |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 341 | mp->mnt_fsname = 0; |
| 342 | switch(set_loop(&(mp->mnt_fsname), loopFile, 0)) { |
| 343 | case 0: |
| 344 | case 1: |
| 345 | break; |
| 346 | default: |
| 347 | bb_error_msg( errno == EPERM || errno == EACCES |
| 348 | ? bb_msg_perm_denied_are_you_root |
Denis Vlasenko | 39e93cc | 2006-09-10 18:38:17 +0000 | [diff] [blame] | 349 | : "cannot setup loop device"); |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 350 | return errno; |
| 351 | } |
Rob Landley | eaa34ca | 2006-03-18 02:58:11 +0000 | [diff] [blame] | 352 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 353 | // Autodetect bind mounts |
| 354 | |
Denis Vlasenko | 39e93cc | 2006-09-10 18:38:17 +0000 | [diff] [blame] | 355 | } else if (S_ISDIR(st.st_mode) && !mp->mnt_type) |
| 356 | vfsflags |= MS_BIND; |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | /* If we know the fstype (or don't need to), jump straight |
| 360 | * to the actual mount. */ |
| 361 | |
| 362 | if (mp->mnt_type || (vfsflags & (MS_REMOUNT | MS_BIND | MS_MOVE))) |
Rob Landley | fe908fd | 2006-03-29 14:30:49 +0000 | [diff] [blame] | 363 | rc = mount_it_now(mp, vfsflags, filteropts); |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 364 | |
| 365 | // Loop through filesystem types until mount succeeds or we run out |
| 366 | |
Rob Landley | eaa34ca | 2006-03-18 02:58:11 +0000 | [diff] [blame] | 367 | else { |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 368 | |
Rob Landley | eaa34ca | 2006-03-18 02:58:11 +0000 | [diff] [blame] | 369 | /* Initialize list of block backed filesystems. This has to be |
| 370 | * done here so that during "mount -a", mounts after /proc shows up |
| 371 | * can autodetect. */ |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 372 | |
Rob Landley | eaa34ca | 2006-03-18 02:58:11 +0000 | [diff] [blame] | 373 | if (!fslist) { |
| 374 | fslist = get_block_backed_filesystems(); |
| 375 | if (ENABLE_FEATURE_CLEAN_UP && fslist) |
| 376 | atexit(delete_block_backed_filesystems); |
| 377 | } |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 378 | |
Rob Landley | eaa34ca | 2006-03-18 02:58:11 +0000 | [diff] [blame] | 379 | for (fl = fslist; fl; fl = fl->link) { |
| 380 | mp->mnt_type = fl->data; |
| 381 | |
Rob Landley | fe908fd | 2006-03-29 14:30:49 +0000 | [diff] [blame] | 382 | if (!(rc = mount_it_now(mp,vfsflags, filteropts))) break; |
Rob Landley | eaa34ca | 2006-03-18 02:58:11 +0000 | [diff] [blame] | 383 | |
| 384 | mp->mnt_type = 0; |
| 385 | } |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Rob Landley | fe908fd | 2006-03-29 14:30:49 +0000 | [diff] [blame] | 388 | // If mount failed, clean up loop file (if any). |
| 389 | |
Bernhard Reutner-Fischer | 08421e1 | 2006-05-26 14:05:48 +0000 | [diff] [blame] | 390 | if (ENABLE_FEATURE_MOUNT_LOOP && rc && loopFile) { |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 391 | del_loop(mp->mnt_fsname); |
Rob Landley | fe908fd | 2006-03-29 14:30:49 +0000 | [diff] [blame] | 392 | if (ENABLE_FEATURE_CLEAN_UP) { |
Rob Landley | eaa34ca | 2006-03-18 02:58:11 +0000 | [diff] [blame] | 393 | free(loopFile); |
| 394 | free(mp->mnt_fsname); |
| 395 | } |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 396 | } |
Rob Landley | 89d9d4d | 2006-09-01 08:10:44 +0000 | [diff] [blame] | 397 | |
Rob Landley | 0cc2c2c | 2006-06-21 03:53:33 +0000 | [diff] [blame] | 398 | report_error: |
Rob Landley | 89d9d4d | 2006-09-01 08:10:44 +0000 | [diff] [blame] | 399 | if (ENABLE_FEATURE_CLEAN_UP) free(filteropts); |
| 400 | |
Rob Landley | 0cc2c2c | 2006-06-21 03:53:33 +0000 | [diff] [blame] | 401 | if (rc && errno == EBUSY && ignore_busy) rc = 0; |
| 402 | if (rc < 0) |
Denis Vlasenko | 39e93cc | 2006-09-10 18:38:17 +0000 | [diff] [blame] | 403 | bb_perror_msg("mounting %s on %s failed", mp->mnt_fsname, mp->mnt_dir); |
Rob Landley | 0cc2c2c | 2006-06-21 03:53:33 +0000 | [diff] [blame] | 404 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 405 | return rc; |
| 406 | } |
| 407 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 408 | // Parse options, if necessary parse fstab/mtab, and call singlemount for |
| 409 | // each directory to be mounted. |
| 410 | |
| 411 | int mount_main(int argc, char **argv) |
| 412 | { |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 413 | char *cmdopts = xstrdup(""), *fstabname, *fstype=0, *storage_path=0; |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 414 | FILE *fstab; |
Rob Landley | 0cc2c2c | 2006-06-21 03:53:33 +0000 | [diff] [blame] | 415 | int i, opt, all = FALSE, rc = 0; |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 416 | struct mntent mtpair[2], *mtcur = mtpair; |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 417 | |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 418 | /* parse long options, like --bind and --move. Note that -o option |
| 419 | * and --option are synonymous. Yes, this means --remount,rw works. */ |
| 420 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 421 | for (i = opt = 0; i < argc; i++) { |
| 422 | if (argv[i][0] == '-' && argv[i][1] == '-') { |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 423 | append_mount_options(&cmdopts,argv[i]+2); |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 424 | } else argv[opt++] = argv[i]; |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 425 | } |
| 426 | argc = opt; |
| 427 | |
| 428 | // Parse remaining options |
| 429 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 430 | while ((opt = getopt(argc, argv, "o:t:rwavnf")) > 0) { |
Matt Kraai | a3045df | 2001-04-17 04:48:51 +0000 | [diff] [blame] | 431 | switch (opt) { |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 432 | case 'o': |
| 433 | append_mount_options(&cmdopts, optarg); |
| 434 | break; |
| 435 | case 't': |
| 436 | fstype = optarg; |
| 437 | break; |
| 438 | case 'r': |
| 439 | append_mount_options(&cmdopts, "ro"); |
| 440 | break; |
| 441 | case 'w': |
| 442 | append_mount_options(&cmdopts, "rw"); |
| 443 | break; |
| 444 | case 'a': |
| 445 | all = TRUE; |
| 446 | break; |
| 447 | case 'n': |
| 448 | USE_FEATURE_MTAB_SUPPORT(useMtab = FALSE;) |
| 449 | break; |
| 450 | case 'f': |
| 451 | USE_FEATURE_MTAB_SUPPORT(fakeIt = FALSE;) |
| 452 | break; |
| 453 | case 'v': |
| 454 | break; // ignore -v |
| 455 | default: |
| 456 | bb_show_usage(); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 457 | } |
Matt Kraai | a3045df | 2001-04-17 04:48:51 +0000 | [diff] [blame] | 458 | } |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 459 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 460 | // Three or more non-option arguments? Die with a usage message. |
| 461 | |
| 462 | if (optind-argc>2) bb_show_usage(); |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 463 | |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 464 | // If we have no arguments, show currently mounted filesystems |
| 465 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 466 | if (optind == argc) { |
| 467 | if (!all) { |
| 468 | FILE *mountTable = setmntent(bb_path_mtab_file, "r"); |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 469 | |
Denis Vlasenko | 39e93cc | 2006-09-10 18:38:17 +0000 | [diff] [blame] | 470 | if(!mountTable) bb_error_msg_and_die("no %s",bb_path_mtab_file); |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 471 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 472 | while (getmntent_r(mountTable,mtpair,bb_common_bufsiz1, |
| 473 | sizeof(bb_common_bufsiz1))) |
| 474 | { |
| 475 | // Don't show rootfs. |
| 476 | if (!strcmp(mtpair->mnt_fsname, "rootfs")) continue; |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 477 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 478 | if (!fstype || !strcmp(mtpair->mnt_type, fstype)) |
| 479 | printf("%s on %s type %s (%s)\n", mtpair->mnt_fsname, |
| 480 | mtpair->mnt_dir, mtpair->mnt_type, |
| 481 | mtpair->mnt_opts); |
| 482 | } |
| 483 | if (ENABLE_FEATURE_CLEAN_UP) endmntent(mountTable); |
| 484 | return EXIT_SUCCESS; |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 485 | } |
Rob Landley | 4d609cb | 2006-09-04 19:43:26 +0000 | [diff] [blame] | 486 | } else storage_path = bb_simplify_path(argv[optind]); |
Matt Kraai | 1240082 | 2001-04-17 04:32:50 +0000 | [diff] [blame] | 487 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 488 | // When we have two arguments, the second is the directory and we can |
| 489 | // skip looking at fstab entirely. We can always abspath() the directory |
| 490 | // argument when we get it. |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 491 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 492 | if (optind+2 == argc) { |
| 493 | mtpair->mnt_fsname = argv[optind]; |
| 494 | mtpair->mnt_dir = argv[optind+1]; |
| 495 | mtpair->mnt_type = fstype; |
| 496 | mtpair->mnt_opts = cmdopts; |
Rob Landley | 0cc2c2c | 2006-06-21 03:53:33 +0000 | [diff] [blame] | 497 | rc = singlemount(mtpair, 0); |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 498 | goto clean_up; |
| 499 | } |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 500 | |
Rob Landley | 3ba7bd1 | 2006-08-09 19:51:13 +0000 | [diff] [blame] | 501 | // If we have a shared subtree flag, don't worry about fstab or mtab. |
| 502 | i = parse_mount_options(cmdopts,0); |
| 503 | if (ENABLE_FEATURE_MOUNT_FLAGS && |
| 504 | (i & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE ))) |
| 505 | { |
| 506 | rc = mount("", argv[optind], "", i, ""); |
| 507 | if (rc) bb_perror_msg_and_die("%s", argv[optind]); |
| 508 | goto clean_up; |
| 509 | } |
| 510 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 511 | // Open either fstab or mtab |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 512 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 513 | if (parse_mount_options(cmdopts,0) & MS_REMOUNT) |
Rob Landley | 721b46e | 2006-08-08 12:54:02 +0000 | [diff] [blame] | 514 | fstabname = bb_path_mtab_file; |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 515 | else fstabname="/etc/fstab"; |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 516 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 517 | if (!(fstab=setmntent(fstabname,"r"))) |
Denis Vlasenko | 39e93cc | 2006-09-10 18:38:17 +0000 | [diff] [blame] | 518 | bb_perror_msg_and_die("cannot read %s",fstabname); |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 519 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 520 | // Loop through entries until we find what we're looking for. |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 521 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 522 | memset(mtpair,0,sizeof(mtpair)); |
| 523 | for (;;) { |
| 524 | struct mntent *mtnext = mtpair + (mtcur==mtpair ? 1 : 0); |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 525 | |
| 526 | // Get next fstab entry |
| 527 | |
Rob Landley | 20fef96 | 2006-04-01 17:32:52 +0000 | [diff] [blame] | 528 | if (!getmntent_r(fstab, mtcur, bb_common_bufsiz1 |
| 529 | + (mtcur==mtpair ? sizeof(bb_common_bufsiz1)/2 : 0), |
| 530 | sizeof(bb_common_bufsiz1)/2)) |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 531 | { |
| 532 | // Were we looking for something specific? |
| 533 | |
| 534 | if (optind != argc) { |
| 535 | |
| 536 | // If we didn't find anything, complain. |
| 537 | |
| 538 | if (!mtnext->mnt_fsname) |
Denis Vlasenko | 39e93cc | 2006-09-10 18:38:17 +0000 | [diff] [blame] | 539 | bb_error_msg_and_die("can't find %s in %s", |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 540 | argv[optind], fstabname); |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 541 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 542 | // Mount the last thing we found. |
| 543 | |
| 544 | mtcur = mtnext; |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 545 | mtcur->mnt_opts = xstrdup(mtcur->mnt_opts); |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 546 | append_mount_options(&(mtcur->mnt_opts),cmdopts); |
Rob Landley | 0cc2c2c | 2006-06-21 03:53:33 +0000 | [diff] [blame] | 547 | rc = singlemount(mtcur, 0); |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 548 | free(mtcur->mnt_opts); |
| 549 | } |
Rob Landley | 0cc2c2c | 2006-06-21 03:53:33 +0000 | [diff] [blame] | 550 | goto clean_up; |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 551 | } |
Rob Landley | eaa34ca | 2006-03-18 02:58:11 +0000 | [diff] [blame] | 552 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 553 | /* If we're trying to mount something specific and this isn't it, |
| 554 | * skip it. Note we must match both the exact text in fstab (ala |
| 555 | * "proc") or a full path from root */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 556 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 557 | if (optind != argc) { |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 558 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 559 | // Is this what we're looking for? |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 560 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 561 | if(strcmp(argv[optind],mtcur->mnt_fsname) && |
| 562 | strcmp(storage_path,mtcur->mnt_fsname) && |
| 563 | strcmp(argv[optind],mtcur->mnt_dir) && |
| 564 | strcmp(storage_path,mtcur->mnt_dir)) continue; |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 565 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 566 | // Remember this entry. Something later may have overmounted |
| 567 | // it, and we want the _last_ match. |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 568 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 569 | mtcur = mtnext; |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 570 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 571 | // If we're mounting all. |
Rob Landley | 6a6798b | 2005-08-10 20:35:54 +0000 | [diff] [blame] | 572 | |
Glenn L McGrath | 3aae100 | 2001-05-07 01:38:03 +0000 | [diff] [blame] | 573 | } else { |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 574 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 575 | // Do we need to match a filesystem type? |
| 576 | if (fstype && strcmp(mtcur->mnt_type,fstype)) continue; |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 577 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 578 | // Skip noauto and swap anyway. |
| 579 | |
| 580 | if (parse_mount_options(mtcur->mnt_opts,0) |
| 581 | & (MOUNT_NOAUTO | MOUNT_SWAP)) continue; |
| 582 | |
| 583 | // Mount this thing. |
| 584 | |
Rob Landley | 0cc2c2c | 2006-06-21 03:53:33 +0000 | [diff] [blame] | 585 | if (singlemount(mtcur, 1)) { |
| 586 | /* Count number of failed mounts */ |
| 587 | rc++; |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 588 | } |
Glenn L McGrath | 3aae100 | 2001-05-07 01:38:03 +0000 | [diff] [blame] | 589 | } |
Eric Andersen | fdd5103 | 2000-08-02 18:48:26 +0000 | [diff] [blame] | 590 | } |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 591 | if (ENABLE_FEATURE_CLEAN_UP) endmntent(fstab); |
Glenn L McGrath | 9fef17d | 2002-08-22 18:41:20 +0000 | [diff] [blame] | 592 | |
Rob Landley | dc0955b | 2006-03-14 18:16:25 +0000 | [diff] [blame] | 593 | clean_up: |
| 594 | |
| 595 | if (ENABLE_FEATURE_CLEAN_UP) { |
| 596 | free(storage_path); |
| 597 | free(cmdopts); |
Rob Landley | 7b363fd | 2005-12-20 17:18:01 +0000 | [diff] [blame] | 598 | } |
Eric Andersen | 9601a1c | 2006-03-20 18:07:50 +0000 | [diff] [blame] | 599 | |
Rob Landley | 6e98521 | 2005-08-14 18:46:34 +0000 | [diff] [blame] | 600 | return rc; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 601 | } |