summaryrefslogtreecommitdiff
path: root/util-linux/mount.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-03-18 02:58:11 +0000
committerRob Landley <rob@landley.net>2006-03-18 02:58:11 +0000
commiteaa34ca5b4babe9887f36a14764bc94f26f90d0e (patch)
tree5246e5cf174de47e0685de00ee05ead46521ec31 /util-linux/mount.c
parentaae8b3405e9f8f911a57aa3b127056e307977e9f (diff)
downloadbusybox-w32-eaa34ca5b4babe9887f36a14764bc94f26f90d0e.tar.gz
busybox-w32-eaa34ca5b4babe9887f36a14764bc94f26f90d0e.tar.bz2
busybox-w32-eaa34ca5b4babe9887f36a14764bc94f26f90d0e.zip
More fixes. Type "auto" should mean unspecified from fstab as well as the
command line, initialize singlemount's rc to an error value so it doesn't think it succeeded when it didn't, use absolute path when associating a loop device (and the previous FEATURE_CLEAN_UP logic related to that was freeing the wrong thing), move reading of /proc/filesystems to where we can re-read it (when it's empty) for every entry on a "mount -a" so that when /proc is mounted as the first entry, the later filesystems can autodetect filesystem type.
Diffstat (limited to 'util-linux/mount.c')
-rw-r--r--util-linux/mount.c48
1 files changed, 30 insertions, 18 deletions
diff --git a/util-linux/mount.c b/util-linux/mount.c
index c5aec74fa..5ddf54cb1 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -201,6 +201,7 @@ static int mount_it_now(struct mntent *mp, int vfsflags)
201 char *filteropts = 0; 201 char *filteropts = 0;
202 202
203 parse_mount_options(mp->mnt_opts, &filteropts); 203 parse_mount_options(mp->mnt_opts, &filteropts);
204
204 // Mount, with fallback to read-only if necessary. 205 // Mount, with fallback to read-only if necessary.
205 206
206 for(;;) { 207 for(;;) {
@@ -261,13 +262,17 @@ static int mount_it_now(struct mntent *mp, int vfsflags)
261 262
262static int singlemount(struct mntent *mp) 263static int singlemount(struct mntent *mp)
263{ 264{
264 int rc = 0, vfsflags; 265 int rc = 1, vfsflags;
265 char *loopFile = 0; 266 char *loopFile = 0;
266 llist_t *fl = 0; 267 llist_t *fl = 0;
267 struct stat st; 268 struct stat st;
268 269
269 vfsflags = parse_mount_options(mp->mnt_opts, 0); 270 vfsflags = parse_mount_options(mp->mnt_opts, 0);
270 271
272 // Treat fstype "auto" as unspecified.
273
274 if (mp->mnt_type && !strcmp(mp->mnt_type,"auto")) mp->mnt_type = 0;
275
271 // Might this be an NFS filesystem? 276 // Might this be an NFS filesystem?
272 277
273 if (ENABLE_FEATURE_MOUNT_NFS && 278 if (ENABLE_FEATURE_MOUNT_NFS &&
@@ -294,7 +299,7 @@ static int singlemount(struct mntent *mp)
294 // Do we need to allocate a loopback device for it? 299 // Do we need to allocate a loopback device for it?
295 300
296 if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) { 301 if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) {
297 loopFile = mp->mnt_fsname; 302 loopFile = bb_simplify_path(mp->mnt_fsname);
298 mp->mnt_fsname = 0; 303 mp->mnt_fsname = 0;
299 switch(set_loop(&(mp->mnt_fsname), loopFile, 0)) { 304 switch(set_loop(&(mp->mnt_fsname), loopFile, 0)) {
300 case 0: 305 case 0:
@@ -306,7 +311,7 @@ static int singlemount(struct mntent *mp)
306 : "Couldn't setup loop device"); 311 : "Couldn't setup loop device");
307 return errno; 312 return errno;
308 } 313 }
309 314
310 // Autodetect bind mounts 315 // Autodetect bind mounts
311 316
312 } else if (S_ISDIR(st.st_mode) && !mp->mnt_type) vfsflags |= MS_BIND; 317 } else if (S_ISDIR(st.st_mode) && !mp->mnt_type) vfsflags |= MS_BIND;
@@ -320,18 +325,34 @@ static int singlemount(struct mntent *mp)
320 325
321 // Loop through filesystem types until mount succeeds or we run out 326 // Loop through filesystem types until mount succeeds or we run out
322 327
323 else for (fl = fslist; fl; fl = fl->link) { 328 else {
324 mp->mnt_type = fl->data; 329
330 /* Initialize list of block backed filesystems. This has to be
331 * done here so that during "mount -a", mounts after /proc shows up
332 * can autodetect. */
333
334 if (!fslist) {
335 fslist = get_block_backed_filesystems();
336 if (ENABLE_FEATURE_CLEAN_UP && fslist)
337 atexit(delete_block_backed_filesystems);
338 }
339
340 for (fl = fslist; fl; fl = fl->link) {
341 mp->mnt_type = fl->data;
325 342
326 if (!(rc = mount_it_now(mp,vfsflags))) break; 343 if (!(rc = mount_it_now(mp,vfsflags))) break;
327 344
328 mp->mnt_type = 0; 345 mp->mnt_type = 0;
346 }
329 } 347 }
330 348
331 // Mount failed. Clean up 349 // Mount failed. Clean up
332 if (rc && loopFile) { 350 if (rc && loopFile) {
333 del_loop(mp->mnt_fsname); 351 del_loop(mp->mnt_fsname);
334 if(ENABLE_FEATURE_CLEAN_UP) free(loopFile); 352 if(ENABLE_FEATURE_CLEAN_UP) {
353 free(loopFile);
354 free(mp->mnt_fsname);
355 }
335 } 356 }
336 return rc; 357 return rc;
337} 358}
@@ -389,10 +410,6 @@ int mount_main(int argc, char **argv)
389 } 410 }
390 } 411 }
391 412
392 // Ignore type "auto".
393
394 if (fstype && !strcmp(fstype, "auto")) fstype = NULL;
395
396 // Three or more non-option arguments? Die with a usage message. 413 // Three or more non-option arguments? Die with a usage message.
397 414
398 if (optind-argc>2) bb_show_usage(); 415 if (optind-argc>2) bb_show_usage();
@@ -421,11 +438,6 @@ int mount_main(int argc, char **argv)
421 } 438 }
422 } 439 }
423 440
424 /* Initialize list of block backed filesystems */
425
426 fslist = get_block_backed_filesystems();
427 if (ENABLE_FEATURE_CLEAN_UP) atexit(delete_block_backed_filesystems);
428
429 // When we have two arguments, the second is the directory and we can 441 // When we have two arguments, the second is the directory and we can
430 // skip looking at fstab entirely. We can always abspath() the directory 442 // skip looking at fstab entirely. We can always abspath() the directory
431 // argument when we get it. 443 // argument when we get it.
@@ -483,7 +495,7 @@ int mount_main(int argc, char **argv)
483 } 495 }
484 break; 496 break;
485 } 497 }
486 498
487 /* If we're trying to mount something specific and this isn't it, 499 /* If we're trying to mount something specific and this isn't it,
488 * skip it. Note we must match both the exact text in fstab (ala 500 * skip it. Note we must match both the exact text in fstab (ala
489 * "proc") or a full path from root */ 501 * "proc") or a full path from root */