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;
    }
    
  • 相关阅读:
    (转)Delphi写COM+的心得体会
    delphi透明组件(控件)开发
    Delphi 常用组件常见属性说明
    DELPHI方面输入EDIT
    BYTE 转字符串
    椭圆按纽制作
    数据库实例学生名册管理系统(DAO的使用实验)
    数据库如何快速创建连接字符串
    数据库使用DataReader的简单实例(两种办法)
    数据库ADO.NET的结构
  • 原文地址:https://www.cnblogs.com/linengier/p/2990342.html
Copyright © 2011-2022 走看看