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;
    }
    
  • 相关阅读:
    云小课 | 华为云KYON之VPC终端节点
    华为云专家向宇:工欲善其事必先利其器,才能做数据的“管家”
    NB-IoT四大关键特性及实现告诉你,为啥NB
    Base64 原理
    netty系列之:轻轻松松搭个支持中文的服务器
    轻松让你的nginx服务器支持HTTP2协议
    是的你没看错,HTTP3来了
    HTTP协议之:HTTP/1.1和HTTP/2
    netty系列之:在netty中使用protobuf协议
    protocol buffer的高效编码方式
  • 原文地址:https://www.cnblogs.com/linengier/p/2990342.html
Copyright © 2011-2022 走看看