- 论坛徽章:
- 0
|
- 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 - 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) //这个函数没看到将文件系统类型加到list里????
- {
- 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; //将filesystem静态变量指向fs
- write_unlock(&file_systems_lock); //解锁
- return res;
- }
- //------------------------------------------------------
- static inline void INIT_LIST_HEAD(struct list_head *list)
- {
- list->next = list;
- list->prev = list;
- }
- //------------------------------------------------------
- EXPORT_SYMBOL(register_filesystem);
- /**
- * unregister_filesystem - unregister a file system
- * @fs: filesystem to unregister
- *
- * Remove a file system that was previously successfully registered
- * with the kernel. An error is returned if the file system is not found.
- * Zero is returned on a success.
- *
- * Once this function has returned the &struct file_system_type structure
- * may be freed or reused.
- */
- int unregister_filesystem(struct file_system_type * fs)
- {
- struct file_system_type ** tmp;
- write_lock(&file_systems_lock);
- tmp = &file_systems;
- while (*tmp) { //对比上面的代码,这里将注册了的文件系统类型从list中移除了
- if (fs == *tmp) {
- *tmp = fs->next;
- fs->next = NULL;
- write_unlock(&file_systems_lock);
- return 0;
- }
- tmp = &(*tmp)->next;
- }
- write_unlock(&file_systems_lock);
- synchronize_rcu();
- return -EINVAL;
- }
- EXPORT_SYMBOL(unregister_filesystem)
复制代码 |
|