文章目录
  1. 1. 文件系统注册
    1. 1.1. ramfs注册

文件系统注册

一般文件系统的注册都是通过 module_init 宏

ramfs注册

注册ramfs文件系统。module_init->init_ramfs_fs->register_filesystem

module_init(init_ramfs_fs)

static struct file_system_type ramfs_fs_type = {
    .name        = "ramfs",
    .get_sb        = ramfs_get_sb,
    .kill_sb    = kill_litter_super,
};

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

把ramfs挂在到全局file_systems链表上。

int register_filesystem(struct file_system_type * fs)
{
    int res = 0;
    struct file_system_type ** p;

    if (!fs)
        return -EINVAL;
    if (fs->next)
        return -EBUSY;
    INIT_LIST_HEAD(&fs->fs_supers);
    write_lock(&file_systems_lock);
    p = find_filesystem(fs->name);
    if (*p)
        res = -EBUSY;
    else
        *p = fs;
    write_unlock(&file_systems_lock);
    return res;
}

static struct file_system_type *file_systems;
static struct file_system_type **find_filesystem(const char *name)
{
    struct file_system_type **p;
    for (p=&file_systems; *p; p=&(*p)->next)
        if (strcmp((*p)->name,name) == 0)
            break;
    return p;
}