Filesystems/ramfs

From Linux Drivers
Jump to: navigation, search

Contents

Overview

Ramfs is a RAM-based filesystem. There is no backing store.

The block size of the filesystem is PAGE_CACHE_SIZE which is same as PAGE_SIZE. Thus each file occupies at least one page of memory.

mounting options

It supports following options.

  • mode=[octal mode value]: used to specify mode of root directory of ramfs

Implementation

ramfs is implemented by files under fs/ramfs/ directory. There are three source files in this directory.

  • inode.c: This interfaces with Linux VFS (virtual filesystem).
  • file-mmu.c: This implements file operation, inode operation, and address space operation for most systems.
  • file-nommu.c: This implements file operation, inode operation, and address space operation for systems without MMU (memory management unit).

Registration of ramfs filesystem

When ramfs module is loaded, it registers ramfs filesystem. inode.c defines an initialization function for the module.

static int __init init_ramfs_fs(void)
{
        return register_filesystem(&ramfs_fs_type);
}

module_init(init_ramfs_fs)

ramfs_fs_type is defined as follows.

static struct file_system_type ramfs_fs_type = {
        .name           = "ramfs",
        .mount          = ramfs_mount,
        .kill_sb        = ramfs_kill_sb,
};

Mounting ramfs

ramfs doesn't require a device as a backing store. When mounting ramfs, mount_nodev() function is used as it doesn't require a device.

struct dentry *ramfs_mount(struct file_system_type *fs_type,
        int flags, const char *dev_name, void *data)
{
        return mount_nodev(fs_type, flags, data, ramfs_fill_super);
}

ramfs_fill_super() creates ramfs specific filesystem information block (sb->s_fs_info is set to ramfs_fs_info structure), allocate an inode for root directory, and fills superblock information.

int ramfs_fill_super(struct super_block *sb, void *data, int silent)
{
        ......
        fsi = kzalloc(sizeof(struct ramfs_fs_info), GFP_KERNEL);
        sb->s_fs_info = fsi;
        ......
        sb->s_maxbytes          = MAX_LFS_FILESIZE;
        sb->s_blocksize         = PAGE_CACHE_SIZE;
        sb->s_blocksize_bits    = PAGE_CACHE_SHIFT;
        sb->s_magic             = RAMFS_MAGIC;
        sb->s_op                = &ramfs_ops;
        sb->s_time_gran         = 1;
        ......
        sb->s_root = root;
        ......
}

Reference

  • Kernel documents: [[1]]
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox