Skip to content

Commit

Permalink
initmpfs: move rootfs code from fs/ramfs/ to init/
Browse files Browse the repository at this point in the history
When the rootfs code was a wrapper around ramfs, having them in the same
file made sense.  Now that it can wrap another filesystem type, move it in
with the init code instead.

This also allows a subsequent patch to access rootfstype= command line
arg.

Signed-off-by: Rob Landley <[email protected]>
Cc: Jeff Layton <[email protected]>
Cc: Jens Axboe <[email protected]>
Cc: Stephen Warren <[email protected]>
Cc: Rusty Russell <[email protected]>
Cc: Jim Cromie <[email protected]>
Cc: Sam Ravnborg <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: "Eric W. Biederman" <[email protected]>
Cc: Alexander Viro <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
landley authored and torvalds committed Sep 11, 2013
1 parent 4bbee76 commit 57f150a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 33 deletions.
2 changes: 1 addition & 1 deletion fs/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <linux/security.h>
#include <linux/idr.h>
#include <linux/acct.h> /* acct_auto_close_mnt */
#include <linux/ramfs.h> /* init_rootfs */
#include <linux/init.h> /* init_rootfs */
#include <linux/fs_struct.h> /* get_fs_root et.al. */
#include <linux/fsnotify.h> /* fsnotify_vfsmount_delete */
#include <linux/uaccess.h>
Expand Down
32 changes: 1 addition & 31 deletions fs/ramfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,17 +244,6 @@ struct dentry *ramfs_mount(struct file_system_type *fs_type,
return mount_nodev(fs_type, flags, data, ramfs_fill_super);
}

static struct dentry *rootfs_mount(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
{
static unsigned long once;

if (test_and_set_bit(0, &once))
return ERR_PTR(-ENODEV);

return mount_nodev(fs_type, flags, data, ramfs_fill_super);
}

static void ramfs_kill_sb(struct super_block *sb)
{
kfree(sb->s_fs_info);
Expand All @@ -267,13 +256,8 @@ static struct file_system_type ramfs_fs_type = {
.kill_sb = ramfs_kill_sb,
.fs_flags = FS_USERNS_MOUNT,
};
static struct file_system_type rootfs_fs_type = {
.name = "rootfs",
.mount = rootfs_mount,
.kill_sb = kill_litter_super,
};

static int __init init_ramfs_fs(void)
int __init init_ramfs_fs(void)
{
static unsigned long once;
int err;
Expand All @@ -292,17 +276,3 @@ static int __init init_ramfs_fs(void)
return err;
}
module_init(init_ramfs_fs)

int __init init_rootfs(void)
{
int err = register_filesystem(&rootfs_fs_type);

if (err)
return err;

err = init_ramfs_fs();
if (err)
unregister_filesystem(&rootfs_fs_type);

return err;
}
1 change: 1 addition & 0 deletions include/linux/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ extern unsigned int reset_devices;
void setup_arch(char **);
void prepare_namespace(void);
void __init load_default_modules(void);
int __init init_rootfs(void);

extern void (*late_time_init)(void);

Expand Down
2 changes: 1 addition & 1 deletion include/linux/ramfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern int ramfs_nommu_mmap(struct file *file, struct vm_area_struct *vma);

extern const struct file_operations ramfs_file_operations;
extern const struct vm_operations_struct generic_file_vm_ops;
extern int __init init_rootfs(void);
extern int __init init_ramfs_fs(void);

int ramfs_fill_super(struct super_block *sb, void *data, int silent);

Expand Down
32 changes: 32 additions & 0 deletions init/do_mounts.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <linux/async.h>
#include <linux/fs_struct.h>
#include <linux/slab.h>
#include <linux/ramfs.h>

#include <linux/nfs_fs.h>
#include <linux/nfs_fs_sb.h>
Expand Down Expand Up @@ -588,3 +589,34 @@ void __init prepare_namespace(void)
sys_mount(".", "/", NULL, MS_MOVE, NULL);
sys_chroot(".");
}

static struct dentry *rootfs_mount(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
{
static unsigned long once;

if (test_and_set_bit(0, &once))
return ERR_PTR(-ENODEV);

return mount_nodev(fs_type, flags, data, ramfs_fill_super);
}

static struct file_system_type rootfs_fs_type = {
.name = "rootfs",
.mount = rootfs_mount,
.kill_sb = kill_litter_super,
};

int __init init_rootfs(void)
{
int err = register_filesystem(&rootfs_fs_type);

if (err)
return err;

err = init_ramfs_fs();
if (err)
unregister_filesystem(&rootfs_fs_type);

return err;
}

0 comments on commit 57f150a

Please sign in to comment.