mount: make it more readable

This commit is contained in:
Denis Vlasenko 2008-12-10 11:39:18 +00:00
parent 3f8f4b2a93
commit 6a2d0d9b8d

View File

@ -256,23 +256,22 @@ static int verbose_mount(const char *source, const char *target,
#define verbose_mount(...) mount(__VA_ARGS__) #define verbose_mount(...) mount(__VA_ARGS__)
#endif #endif
static int resolve_mount_spec(char **fsname) #if ENABLE_FEATURE_MOUNT_LABEL
static void resolve_mount_spec(char **fsname)
{ {
char *tmp = NULL; char *tmp = NULL;
#if ENABLE_FEATURE_MOUNT_LABEL
if (!strncmp(*fsname, "UUID=", 5)) if (!strncmp(*fsname, "UUID=", 5))
tmp = get_devname_from_uuid(*fsname + 5); tmp = get_devname_from_uuid(*fsname + 5);
else if (!strncmp(*fsname, "LABEL=", 6)) else if (!strncmp(*fsname, "LABEL=", 6))
tmp = get_devname_from_label(*fsname + 6); tmp = get_devname_from_label(*fsname + 6);
#endif
if (tmp) { if (tmp)
*fsname = tmp; *fsname = tmp;
return 1;
}
return 0;
} }
#else
#define resolve_mount_spec(fsname) ((void)0)
#endif
// Append mount options to string // Append mount options to string
static void append_mount_options(char **oldopts, const char *newopts) static void append_mount_options(char **oldopts, const char *newopts)
@ -1798,9 +1797,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
mtpair->mnt_dir = argv[1]; mtpair->mnt_dir = argv[1];
mtpair->mnt_type = fstype; mtpair->mnt_type = fstype;
mtpair->mnt_opts = cmdopts; mtpair->mnt_opts = cmdopts;
if (ENABLE_FEATURE_MOUNT_LABEL) {
resolve_mount_spec(&mtpair->mnt_fsname); resolve_mount_spec(&mtpair->mnt_fsname);
}
rc = singlemount(mtpair, 0); rc = singlemount(mtpair, 0);
return rc; return rc;
} }
@ -1881,12 +1878,12 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
if (nonroot) if (nonroot)
bb_error_msg_and_die(must_be_root); bb_error_msg_and_die(must_be_root);
// Mount this thing
if (ENABLE_FEATURE_MOUNT_LABEL)
resolve_mount_spec(&mtpair->mnt_fsname); resolve_mount_spec(&mtpair->mnt_fsname);
// NFS mounts want this to be xrealloc-able // NFS mounts want this to be xrealloc-able
mtcur->mnt_opts = xstrdup(mtcur->mnt_opts); mtcur->mnt_opts = xstrdup(mtcur->mnt_opts);
// Mount this thing
if (singlemount(mtcur, 1)) { if (singlemount(mtcur, 1)) {
// Count number of failed mounts // Count number of failed mounts
rc++; rc++;
@ -1911,9 +1908,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
// Mount the last thing we found // Mount the last thing we found
mtcur->mnt_opts = xstrdup(mtcur->mnt_opts); mtcur->mnt_opts = xstrdup(mtcur->mnt_opts);
append_mount_options(&(mtcur->mnt_opts), cmdopts); append_mount_options(&(mtcur->mnt_opts), cmdopts);
if (ENABLE_FEATURE_MOUNT_LABEL) {
resolve_mount_spec(&mtpair->mnt_fsname); resolve_mount_spec(&mtpair->mnt_fsname);
}
rc = singlemount(mtcur, 0); rc = singlemount(mtcur, 0);
if (ENABLE_FEATURE_CLEAN_UP) if (ENABLE_FEATURE_CLEAN_UP)
free(mtcur->mnt_opts); free(mtcur->mnt_opts);