• 文件系统类型注册


    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;
    }
    
  • 相关阅读:
    高并发的一些处理意见
    TP5单元测试
    你真的会玩SQL吗?和平大使 内连接、外连接
    微信公众号第三方平台开发概况
    MVC的基类
    Android TextView中显示图片
    Android之assets资源
    通用分页存储过程
    到处都是坑的微信支付V3之 微信支付回调页面
    微信公众平台无高级接口账号获取用户基本信息
  • 原文地址:https://www.cnblogs.com/linengier/p/2990342.html
Copyright © 2020-2023  润新知