aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCurt Wohlgemuth <curtw@google.com>2012-03-08 15:11:31 -0800
committerH. Peter Anvin <hpa@linux.intel.com>2012-05-15 15:29:44 -0700
commit1ec1ce94c3f4d92c11a57d3670f09865d210ff10 (patch)
treeec2eda8d137599983ab20e987791352c2648e438
parenta0127d3dbd482a709711f8cd16643325883dcc3f (diff)
downloadklibc-1ec1ce94c3f4d92c11a57d3670f09865d210ff10.tar.gz
[klibc] kinit: Create block device for mount commands if needed.
For mount commands coming from the "kinit_mount=" option or from an embedded /etc/fstab, try to create the block device before we issue the mount() command. Tested: Tested with a variety of mount commands (cmdline + fstab), using both block devices and 9p mounts. Signed-off-by: Curt Wohlgemuth <curtw@google.com> Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
-rw-r--r--usr/kinit/do_mounts.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/usr/kinit/do_mounts.c b/usr/kinit/do_mounts.c
index 9c149fd8def8cb..d12b07a6a65835 100644
--- a/usr/kinit/do_mounts.c
+++ b/usr/kinit/do_mounts.c
@@ -21,6 +21,24 @@ int create_dev(const char *name, dev_t dev)
return mknod(name, S_IFBLK | 0600, dev);
}
+
+/*
+ * If there is not a block device for the input 'name', try to create one; if
+ * we can't that's okay.
+ */
+static void create_dev_if_not_present(const char *name)
+{
+ struct stat st;
+ dev_t dev;
+
+ if (stat(name, &st) == 0) /* file present; we're done */
+ return;
+ dev = name_to_dev_t(name);
+ if (dev)
+ (void) create_dev(name, dev);
+}
+
+
/* mount a filesystem, possibly trying a set of different types */
const char *mount_block(const char *source, const char *target,
const char *type, unsigned long flags,
@@ -32,9 +50,15 @@ const char *mount_block(const char *source, const char *target,
int fd;
if (type) {
- dprintf("kinit: trying to mount %s on %s with type %s\n",
- source, target, type);
+ dprintf("kinit: trying to mount %s on %s "
+ "with type %s, flags 0x%lx, data '%s'\n",
+ source, target, type, flags, (char *)data);
int rv = mount(source, target, type, flags, data);
+
+ if (rv != 0)
+ dprintf("kinit: mount %s on %s failed "
+ "with errno = %d\n",
+ source, target, errno);
/* Mount readonly if necessary */
if (rv == -1 && errno == EACCES && !(flags & MS_RDONLY))
rv = mount(source, target, type, flags | MS_RDONLY,
@@ -274,6 +298,7 @@ int do_cmdline_mounts(int argc, char *argv[])
new_dir = prepend_root_dir(fs_dir);
if (! new_dir)
return -ENOMEM;
+ create_dev_if_not_present(fs_dev);
if (!mount_block(fs_dev, new_dir, fs_type,
flags, new_fs_opts))
@@ -293,6 +318,7 @@ int do_fstab_mounts(FILE *fp)
new_dir = prepend_root_dir(ent->mnt_dir);
if (! new_dir)
return -ENOMEM;
+ create_dev_if_not_present(ent->mnt_fsname);
if (!mount_block(ent->mnt_fsname,
new_dir,
ent->mnt_type,