register_filesystem: register a new filesystem.
1.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.
2.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;
-
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;
-
}
其中9与15行是保证对
-
static struct file_system_type *file_systems;
写操作的唯一性。
其中10行,从file_system中查找是否有与&fs同名字文件系统,如果有返回指向结构的指针的指针,如果没有返回返回执行file_systems单链表最后元素的(*
file_system_type)->next的地址。
-
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;
-
}
总结:从上面源码的分析可知,register_filesystem(fs);功能是将fs对象添加到全局的
file_systems对象链表中。如果file_systems对象链表中有与fs同名字的对象,则返回错误的值,否则返回0.
阅读(1050) | 评论(0) | 转发(0) |