ramfsを読んでみる。

ソースはlxrの2.6.31

まずは、初期化から。

 295static int __init init_ramfs_fs(void)
 296{
 297        return register_filesystem(&ramfs_fs_type);
 298}

init_ramfs_fs()は特別なことは一切しなくて、register_filesystem()をコールして、自分自身を登録する。

ramfs_fs_typeは3フィールドだけ設定している。
sbはきっとSuper Blockの略。

 284static struct file_system_type ramfs_fs_type = {
 285        .name           = "ramfs",
 286        .get_sb         = ramfs_get_sb,
 287        .kill_sb        = ramfs_kill_sb,
 288};

file_system_type構造体はこんな形(include/linux/fs.h)

1741struct file_system_type {
1742        const char *name;
1743        int fs_flags;
1744        int (*get_sb) (struct file_system_type *, int,
1745                       const char *, void *, struct vfsmount *);
1746        void (*kill_sb) (struct super_block *);
1747        struct module *owner;
1748        struct file_system_type * next;
1749        struct list_head fs_supers;
1750
1751        struct lock_class_key s_lock_key;
1752        struct lock_class_key s_umount_key;
1753
1754        struct lock_class_key i_lock_key;
1755        struct lock_class_key i_mutex_key;
1756        struct lock_class_key i_mutex_dir_key;
1757        struct lock_class_key i_alloc_sem_key;
1758};

そんなわけで、file_system_type構造体からramfsに関係する関数呼び出しは、get_sb()とkill_sb()だけ。
ramfs_get_sb()はこのような関数。

 265int ramfs_get_sb(struct file_system_type *fs_type,
 266        int flags, const char *dev_name, void *data, struct vfsmount *mnt)
 267{
 268        return get_sb_nodev(fs_type, flags, data, ramfs_fill_super, mnt);
 269}

これも1行だけの関数で、get_sb_nodev()をコールして戻り値を返す。
これの引数のうち、4番めの引数は関数へのポインタで、2番め・3番めの引数はramfs_fill_super()に渡す引数になっている。

get_sb_nodev()はfs/super.cfs/super.cにいる。

 801int get_sb_nodev(struct file_system_type *fs_type,
 802        int flags, void *data,
 803        int (*fill_super)(struct super_block *, void *, int),
 804        struct vfsmount *mnt)
 805{
 806        int error;
 807        struct super_block *s = sget(fs_type, NULL, set_anon_super, NULL);
 808
 809        if (IS_ERR(s))
 810                return PTR_ERR(s);
 811
 812        s->s_flags = flags;
 813
 814        error = fill_super(s, data, flags & MS_SILENT ? 1 : 0);
 815        if (error) {
 816                deactivate_locked_super(s);
 817                return error;
 818        }
 819        s->s_flags |= MS_ACTIVE;
 820        simple_set_mnt(mnt, s);
 821        return 0;
 822}

sget()とかを深く追っていくとVFSの実装をちゃんと調べる必要が出てくるので深追いはしないwww
今日はここまでにして、今度はfill_super()というかramfs_fill_super()を見ていこう。