Пример #1
0
static int get_filesystems(const char *filename, char ***filesystems, const char *pattern)
{
	int rc = 0;
	FILE *f;
	char line[128];

	f = fopen(filename, "r");
	if (!f)
		return 1;

	DBG(UTILS, mnt_debug("reading filesystems list from: %s", filename));

	while (fgets(line, sizeof(line), f)) {
		char name[sizeof(line)];

		if (*line == '#' || strncmp(line, "nodev", 5) == 0)
			continue;
		if (sscanf(line, " %128[^\n ]\n", name) != 1)
			continue;
		if (strcmp(name, "*") == 0) {
			rc = 1;
			break;		/* end of the /etc/filesystems */
		}
		if (pattern && !mnt_match_fstype(name, pattern))
			continue;
		rc = add_filesystem(filesystems, name);
		if (rc)
			break;
	}

	fclose(f);
	return rc;
}
Пример #2
0
// 初始化VFS目录树
static void init_mount_tree(struct vfsmount *mount)
{
        // 添加根文件系统
        add_filesystem(&fs_ramfs);

        INIT_LIST_HEAD(&(fs_ramfs.fs_supers));

        // 获取根文件系统的超级块结构
        struct super_block *sb = alloc_super_block();
        bzero(sb, sizeof(struct super_block));
        
        // 将 super_block 添加到文件系统控制信息下
        list_add(&(sb->s_list), &(fs_ramfs.fs_supers));

        // 为根文件系统初始化超级块
        fs_ramfs.read_super(sb);

        // 初始化根结点 inode
        struct inode *inode = alloc_inode();
        bzero(inode, sizeof(struct inode));
        inode->i_sb = sb;

        // 初始化根结点 dentry
        struct dentry *dentry = alloc_dentry();
        atomic_set(&(dentry->d_count), 0);
        INIT_LIST_HEAD(&(dentry->d_subdirs));
        INIT_LIST_HEAD(&(dentry->d_child));

        dentry->d_status = 1;
        dentry->d_parent = NULL;
        dentry->d_sb = sb;
        dentry->d_inode = inode;
        dentry->is_mounted = 0;
        strcpy(dentry->d_name, "/");
        
        // 链接根节点 dentry
        sb->s_root = dentry;

        mount->mnt_devname = "RAM";
        mount->mnt_sb = sb;
        mount->mnt_root = dentry;
        mount->mnt_mountpoint = dentry;
        mount->mnt_parent = NULL;
}