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.
This commit is contained in:
Rob Landley 2006-03-18 02:58:11 +00:00
parent aae8b3405e
commit eaa34ca5b4

View File

@ -201,6 +201,7 @@ static int mount_it_now(struct mntent *mp, int vfsflags)
char *filteropts = 0; char *filteropts = 0;
parse_mount_options(mp->mnt_opts, &filteropts); parse_mount_options(mp->mnt_opts, &filteropts);
// Mount, with fallback to read-only if necessary. // Mount, with fallback to read-only if necessary.
for(;;) { for(;;) {
@ -261,13 +262,17 @@ static int mount_it_now(struct mntent *mp, int vfsflags)
static int singlemount(struct mntent *mp) static int singlemount(struct mntent *mp)
{ {
int rc = 0, vfsflags; int rc = 1, vfsflags;
char *loopFile = 0; char *loopFile = 0;
llist_t *fl = 0; llist_t *fl = 0;
struct stat st; struct stat st;
vfsflags = parse_mount_options(mp->mnt_opts, 0); vfsflags = parse_mount_options(mp->mnt_opts, 0);
// Treat fstype "auto" as unspecified.
if (mp->mnt_type && !strcmp(mp->mnt_type,"auto")) mp->mnt_type = 0;
// Might this be an NFS filesystem? // Might this be an NFS filesystem?
if (ENABLE_FEATURE_MOUNT_NFS && if (ENABLE_FEATURE_MOUNT_NFS &&
@ -294,7 +299,7 @@ static int singlemount(struct mntent *mp)
// Do we need to allocate a loopback device for it? // Do we need to allocate a loopback device for it?
if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) { if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) {
loopFile = mp->mnt_fsname; loopFile = bb_simplify_path(mp->mnt_fsname);
mp->mnt_fsname = 0; mp->mnt_fsname = 0;
switch(set_loop(&(mp->mnt_fsname), loopFile, 0)) { switch(set_loop(&(mp->mnt_fsname), loopFile, 0)) {
case 0: case 0:
@ -320,18 +325,34 @@ static int singlemount(struct mntent *mp)
// Loop through filesystem types until mount succeeds or we run out // Loop through filesystem types until mount succeeds or we run out
else for (fl = fslist; fl; fl = fl->link) { else {
/* Initialize list of block backed filesystems. This has to be
* done here so that during "mount -a", mounts after /proc shows up
* can autodetect. */
if (!fslist) {
fslist = get_block_backed_filesystems();
if (ENABLE_FEATURE_CLEAN_UP && fslist)
atexit(delete_block_backed_filesystems);
}
for (fl = fslist; fl; fl = fl->link) {
mp->mnt_type = fl->data; mp->mnt_type = fl->data;
if (!(rc = mount_it_now(mp,vfsflags))) break; if (!(rc = mount_it_now(mp,vfsflags))) break;
mp->mnt_type = 0; mp->mnt_type = 0;
} }
}
// Mount failed. Clean up // Mount failed. Clean up
if (rc && loopFile) { if (rc && loopFile) {
del_loop(mp->mnt_fsname); del_loop(mp->mnt_fsname);
if(ENABLE_FEATURE_CLEAN_UP) free(loopFile); if(ENABLE_FEATURE_CLEAN_UP) {
free(loopFile);
free(mp->mnt_fsname);
}
} }
return rc; return rc;
} }
@ -389,10 +410,6 @@ int mount_main(int argc, char **argv)
} }
} }
// Ignore type "auto".
if (fstype && !strcmp(fstype, "auto")) fstype = NULL;
// Three or more non-option arguments? Die with a usage message. // Three or more non-option arguments? Die with a usage message.
if (optind-argc>2) bb_show_usage(); if (optind-argc>2) bb_show_usage();
@ -421,11 +438,6 @@ int mount_main(int argc, char **argv)
} }
} }
/* Initialize list of block backed filesystems */
fslist = get_block_backed_filesystems();
if (ENABLE_FEATURE_CLEAN_UP) atexit(delete_block_backed_filesystems);
// When we have two arguments, the second is the directory and we can // When we have two arguments, the second is the directory and we can
// skip looking at fstab entirely. We can always abspath() the directory // skip looking at fstab entirely. We can always abspath() the directory
// argument when we get it. // argument when we get it.