uclinux内核的文件系统类型

快乐虾

http://blog.csdn.net/lights_joy/

lights@hb165.com

  

本文适用于

ADSP-BF561

优视BF561EVB开发板

uclinux-2008r1.5-rc3

Visual DSP++ 5.0(update 5)

  

欢迎转载,但请保留作者信息

 

文件系统类型用于表示各种不同的文件系统,如fat, sysfs, proc等等,对于每个不同的文件系统,都以struct file_system_type进行描述,内核将它们以单链表的形式链接起来,其表头由全局变量file_systems表示。

与此相关的代码都在fs/filesystems.c文件中。

1.1    数据结构:file_system_type

此结构体定义了文件系统的类型,每种文件系统都必须定义一个此结构体并通过register_filesystem进行注册。

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;

     struct lock_class_key s_lock_key;

     struct lock_class_key s_umount_key;

};

l         name

文件系统的名称,在定义struct file_system_type的变量时指定且不再更改。

l         fs_flags

一些特殊标记,但允许此值为0。支持的几个标记用宏定义表示为:

/* public flags for file_system_type */

#define FS_REQUIRES_DEV 1

#define FS_BINARY_MOUNTDATA 2

#define FS_HAS_SUBTYPE 4

#define FS_REVAL_DOT   16384    /* Check the paths ".", ".." for staleness */

#define FS_RENAME_DOES_D_MOVE    32768    /* FS will handle d_move()

                        * during rename() internally.

                        */

l         get_sb

这个回调函数将在kern_mount函数中调用,用于取得本文件系统(分区)super_block,并将之填充到struct vfsmountmnt_sb成员中。

l         next

这个成员用以将系统内所有的file_system_type以单链表的形式链接起来,单链表的表头由全局变量file_systems表示。

l         fs_supers

这是一个双链表的表头,由此也可以看出同一个文件系统类型可以有很多个对应的super_block

 

 

1.2    文件系统注册

每个文件系统都必须使用register_filesystem向内核注册后才可以使用,此函数为:

/**

 *   register_filesystem - register a new filesystem

 *   @fs: the file system structure

 *

 *   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.

 *

 *   The &struct file_system_type that is passed is linked into the kernel

 *   structures and must not be freed until the file system has been

 *   unregistered.

 */

 

int register_filesystem(struct file_system_type * fs)

{

     int res = 0;

     struct file_system_type ** p;

 

     BUG_ON(strchr(fs->name, '.'));

     if (fs->next)

         return -EBUSY;

     INIT_LIST_HEAD(&fs->fs_supers);

     write_lock(&file_systems_lock);

     p = find_filesystem(fs->name, strlen(fs->name));

     if (*p)

         res = -EBUSY;

     else

         *p = fs;

     write_unlock(&file_systems_lock);

     return res;

}

注意这里的find_filesystem函数,它将查找一个合适的用于存放struct file_system_type 指针的位置,当第一次调用时,它将返回

static struct file_system_type *file_systems;

这一变量的地址,再通过赋值语句,file_systems就可以指向链表的第一个元素了。

看看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;

}

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嵌云阁主

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值