OK6410A 开发板 (八) 113 linux-5.11 OK6410A rootfs 文件系统


struct file_system_type rootfs_fs_type = {                                       
    .name       = "rootfs",                                                      
    .init_fs_context = rootfs_init_fs_context,                                   
    .kill_sb    = kill_litter_super,                                             
};

start_kernel
	vfs_caches_init
		mnt_init
			shmem_init
			init_rootfs
				根据各个全局变量初始化 is_tmpfs
				一般 is_tmpfs = false
			init_mount_tree
				vfs_kern_mount(&rootfs_fs_type, 0, "rootfs", NULL);
					fs_context_for_mount
					fc_mount
						vfs_get_tree
							fc->ops->get_tree//即ramfs_get_tree
								get_tree_nodev(fc, ramfs_fill_super);
									vfs_get_super
										sb = sget_fc
											if (!s) s = alloc_super
										fc->root = dget(sb->s_root);
										ramfs_fill_super
											
						vfs_create_mount
							
						
				alloc_mnt_ns(&init_user_ns, false);
				...
				set_fs_pwd(current->fs, &root);
				set_fs_root(current->fs, &root);
第一个问题:挂载

我们关注以下两个内容
	1. super_block 的填充			: ramfs_fill_super
		// 1. 申请 inode 结构体,该inode 为"目录文件"
		// 2. 创建 该inode 对应的 dentry
		// 3. 将 dentry 赋给 sb->s_root
		
		// inode 是 通过 ramfs_get_inode->new_inode->new_inode_pseudo->alloc_inode 获取的 
	2. mnt结构体链接到内核的过程   	: vfs_create_mount
		// 1. 申请一个 struct mount 结构体
		// 2. 赋值 mnt 的成员
		// 3. list_add_tail(&mnt->mnt_instance, &mnt->mnt.mnt_sb->s_mounts);


// $3 是 rootfs 此次挂载的 struct mount 结构体
// 其 mnt_mountpoint 是 创建的 dentry
// 其 mnt_parent  指向了 自己,看样子,是自己挂载到了自己

$3 = (struct mount *) 0x80cb80c0
$3 = {
    mnt_hash = {
        next = 0x0,
        pprev = 0x0
    },
    mnt_parent = 0x80cb80c0,
    mnt_mountpoint = 0x81002088,
    mnt = {
        mnt_root = 0x81002088,
        mnt_sb = 0x80cac800,
        mnt_flags = 0
    },
    {
        mnt_rcu = {
            next = 0x0,
            func = 0x0
        },
        mnt_llist = {
            next = 0x0
        }
    },
    mnt_pcp = 0x80a78e74,
    mnt_mounts = {
        next = 0x80cb80e8,
        prev = 0x80cb80e8
    },
    mnt_child = {
        next = 0x80cb80f0,
        prev = 0x80cb80f0
    },
    mnt_instance = {
        next = 0x80cac86c,
        prev = 0x80cac86c
    },
    mnt_devname = 0x808eb808 "none",
    mnt_list = {
        next = 0x80cb8104,
        prev = 0x80cb8104
    },
    mnt_expire = {
        next = 0x80cb810c,
        prev = 0x80cb810c
    },
    mnt_share = {
        next = 0x80cb8114,
        prev = 0x80cb8114
    },
    mnt_slave_list = {
        next = 0x80cb811c,
        prev = 0x80cb811c
    },
    mnt_slave = {
        next = 0x80cb8124,
        prev = 0x80cb8124
    },
    mnt_master = 0x0,
    mnt_ns = 0x0,
    mnt_mp = 0x0,
    {
        mnt_mp_list = {
            next = 0x0,
            pprev = 0x0
        },
        mnt_umount = {
            next = 0x0,
            pprev = 0x0
        }
    },
    mnt_umounting = {
        next = 0x80cb8140,
        prev = 0x80cb8140
    },
    mnt_fsnotify_marks = 0x0,
    mnt_fsnotify_mask = 0,
    mnt_id = 1,
    mnt_group_id = 0,
    mnt_expiry_mark = 0,
    mnt_pins = {
        first = 0x0
    },
    mnt_stuck_children = {
        first = 0x0
    }
}

	
第二个问题:文件操作
ramfs_get_inode
	switch (mode & S_IFMT) {
		case S_IFDIR:
			inode->i_op = &ramfs_dir_inode_operations;
	}

static const struct inode_operations ramfs_dir_inode_operations = {
	.create     = ramfs_create,
	.lookup     = simple_lookup,
	.link       = simple_link,
	.unlink     = simple_unlink,
	.symlink    = ramfs_symlink,
	.mkdir      = ramfs_mkdir,
	.rmdir      = simple_rmdir,
	.mknod      = ramfs_mknod,
	.rename     = simple_rename,

第三个问题 search及真实文件系统中层级目录的维护
我们知道 ext4 是 文件系统层级目录的维护是通过解析 "磁盘文件系统中的 inode节点的 数据信息" 来 获取的
那么 现在的 呢?
第四个问题 文件IO
ramfs_get_inode
	switch (mode & S_IFMT) {
		case S_IFREG:
			inode->i_fop = &ramfs_file_operations;
	}

const struct file_operations ramfs_file_operations = {                           
    .read_iter  = generic_file_read_iter,                                        
    .write_iter = generic_file_write_iter,                                       
    .mmap       = generic_file_mmap,                                             
    .fsync      = noop_fsync,                                                    
    .splice_read    = generic_file_splice_read,                                  
    .splice_write   = iter_file_splice_write,                                    
    .llseek     = generic_file_llseek,                                           
    .get_unmapped_area  = ramfs_mmu_get_unmapped_area,                           
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值