zoukankan      html  css  js  c++  java
  • 文件系统类型注册

    1.file_system_type结构体说明:

    /include/linux/fs.h

    struct file_system_type {
    	const char *name; //文件系统名
    	int fs_flags;     //文件系统类型标识
    	int (*get_sb) (struct file_system_type *, int, const char *, void *, struct vfsmount *);//读超级块的方法
    	void (*kill_sb) (struct super_block *);//删除超级块的方法
    	struct module *owner;          //指向实现文件系统的模块的指针
    	struct file_system_type * next;    //指向文件系统类型链表的下一个元素的指针
    	struct list_head fs_supers;           //具有相同文件系统类型的超级块对象链表的头部
    };
    

    get_sb字段指向依赖于文件系统类型的函数,该函数分配一个新的超级块对象并初始化它;

    2.register_filesystem()

     linux/fs/filesystems.c定义了一个全局变量,用于保存系统类型链表;

    static struct file_system_type *file_systems;

    Adds the file system passed to the list of file systems the kernel is aware of for mount and other syscalls. Returns 0 on success,  or a negative errno code on an error.

    函数实现:

    int register_filesystem(struct file_system_type * fs)
    {
    	int res = 0;
    	struct file_system_type ** p;
    	BUG_ON(strchr(fs->name, '.'));
    	if (fs->next) //新插入元素,next必须为NULL
    		return -EBUSY;
    	INIT_LIST_HEAD(&fs->fs_supers);
    	write_lock(&file_systems_lock);
    	p = find_filesystem(fs->name, strlen(fs->name));//自上而下遍历file_systems全局变量,最终返回最后一个节点的next;
    	if (*p)
    		res = -EBUSY;
    	else
    		*p = fs;
    	write_unlock(&file_systems_lock);
    	return res;
    }
    

     find_filesystem:

    static struct file_system_type **find_filesystem(const char *name, unsigned len)
    {
    	struct file_system_type **p;
    	for (p=&file_systems; *p; p=&(*p)->next)
    		if (strlen((*p)->name) == len &&
    		    strncmp((*p)->name, name, len) == 0)
    			break;
    	return p;
    }
    
  • 相关阅读:
    样条之CatmullRom
    分形之树(Tree)
    B样条
    样条之贝塞尔(Bezier)
    插值与样条
    windows 下的Python虚拟环境(vitrualen)pycharm创建Django项目
    VS2010专业版和旗舰版(中文版)下载
    PHP课程环境安装总结文档
    原码、反码、补码知识详细讲解(此作者是我找到的讲的最细最明白的一个)
    C语言中size_t类型详细说明【转载】
  • 原文地址:https://www.cnblogs.com/linengier/p/2990342.html
Copyright © 2011-2022 走看看