标签:des blog http io ar for sp strong 文件
一:根文件系统(rootfs)
1,rootfs文件系统的注册
在linux kernel初始化阶段会调用int __init init_rootfs(void)向内核注册rootfs文件系统,
init_rootfs()的核心的函数为register_filesystem();这个函数将结构file_system_type?注册在内核一 个单链表中,
- 307 int __init init_rootfs(void)
- 308 {
- 309 int err;
- 311 err = bdi_init(&ramfs_backing_dev_info);
- 312 if (err)
- 313 return err;
- 315 err = register_filesystem(&rootfs_fs_type);
- 316 if (err)
- 317 bdi_destroy(&ramfs_backing_dev_info);
- 319 return err;
- 320 }
-
- 288 static struct file_system_type rootfs_fs_type = {
- 289 .name = "rootfs",
- 290 .mount = rootfs_mount,
- 291 .kill_sb = kill_litter_super,
- 292 };
2,rootfs_mount()函数解析
static struct dentry *rootfs_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data)
rootfs_mount()函数首先会调用mount_nodev()函数,mount_nodev()函数原型如下:mount_nodev(fs_type, flags, data, ramfs_fill_super);
- 1060 struct dentry *mount_nodev(struct file_system_type *fs_type,
- 1061 int flags, void *data,
- 1062 int (*fill_super)(struct super_block *, void *, int))
- 1063 {
- 1064 int error;
- 1065 struct super_block *s = sget(fs_type, NULL, set_anon_super, NULL);
- 1067 if (IS_ERR(s))
- 1068 return ERR_CAST(s);
- 1069
- 1070 s->s_flags = flags;
- 1072 error = fill_super(s, data, flags & MS_SILENT ? 1 : 0);
- 1073 if (error) {
- 1074 deactivate_locked_super(s);
- 1075 return ERR_PTR(error);
- 1076 }
- 1077 s->s_flags |= MS_ACTIVE;
- 1078 return dget(s->s_root);
- 1079 }
上述函数sget()函数的作用主要是分配一个超级快(super_block)的实例,并.通过s_list加入链表super_blocks,然后通过s_instances加入链表typer->fs_supers。
fill_super()函数调用到ramfs_fill_super()函数,ramfs_fill_super()函数的定义如下:
- 209 int ramfs_fill_super(struct super_block *sb, void *data, int silent)
- 210 {
- 211 struct ramfs_fs_info *fsi;
- 212 struct inode *inode;
- 213 int err;
- 215 save_mount_options(sb, data);
- 217 fsi = kzalloc(sizeof(struct ramfs_fs_info), GFP_KERNEL);
- 218 sb->s_fs_info = fsi;
- 219 if (!fsi)
- 220 return -ENOMEM;
- 222 err = ramfs_parse_options(data, &fsi->mount_opts);
- 223 if (err)
- 224 return err;
- 226 sb->s_maxbytes = MAX_LFS_FILESIZE;
- 227 sb->s_blocksize = PAGE_CACHE_SIZE;
- 228 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
- 229 sb->s_magic = RAMFS_MAGIC;
- 230 sb->s_op = &ramfs_ops;
- 231 sb->s_time_gran = 1;
- 233 inode = ramfs_get_inode(sb, NULL, S_IFDIR | fsi->mount_opts.mode, 0);
- 234 sb->s_root = d_make_root(inode);
- 235 if (!sb->s_root)
- 236 return -ENOMEM;
- 238 return 0;
- 239 }
-
- 54 struct inode *ramfs_get_inode(struct super_block *sb,
- 55 const struct inode *dir, umode_t mode, dev_t dev)
- 56 {
- 57 struct inode * inode = new_inode(sb);
- 59 if (inode) {
- 60 inode->i_ino = get_next_ino();
- 61 inode_init_owner(inode, dir, mode);
- 62 inode->i_mapping->a_ops = &ramfs_aops;
- 63 inode->i_mapping->backing_dev_info = &ramfs_backing_dev_info;
- 64 mapping_set_gfp_mask(inode->i_mapping, GFP_HIGHUSER);
- 65 mapping_set_unevictable(inode->i_mapping);
- 66 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
- 67 switch (mode & S_IFMT) {
- 68 default:
- 69 init_special_inode(inode, mode, dev);
- 70 break;
- 71 case S_IFREG:
- 72 inode->i_op = &ramfs_file_inode_operations;
- 73 inode->i_fop = &ramfs_file_operations;
- 74 break;
- 75 case S_IFDIR:
- 76 inode->i_op = &ramfs_dir_inode_operations;
- 77 inode->i_fop = &simple_dir_operations;
- 79
- 80 inc_nlink(inode);
- 81 break;
- 82 case S_IFLNK:
- 83 inode->i_op = &page_symlink_inode_operations;
- 84 break;
- 85 }
- 86 }
- 87 return inode;
- 88 }
[文件系统]文件系统学习笔记(九)---rootfs
标签:des blog http io ar for sp strong 文件
原文地址:http://www.cnblogs.com/zhiliao112/p/4067848.html