Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9729
  • 博文数量: 4
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 40
  • 用 户 组: 普通用户
  • 注册时间: 2014-09-03 21:26
文章分类
文章存档

2015年(4)

我的朋友

分类: LINUX

2015-07-01 16:28:46

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.

点击(此处)折叠或打开

  1. int register_filesystem(struct file_system_type * fs)
  2. {
  3.     int res = 0;
  4.     struct file_system_type ** p;

  5.     BUG_ON(strchr(fs->name, '.'));
  6.     if (fs->next)
  7.         return -EBUSY;
  8.     write_lock(&file_systems_lock);
  9.     p = find_filesystem(fs->name, strlen(fs->name));
  10.     if (*p)
  11.         res = -EBUSY;
  12.     else
  13.         *p = fs;
  14.     write_unlock(&file_systems_lock);
  15.     return res;
  16. }
    其中9与15行是保证对

点击(此处)折叠或打开

  1. static struct file_system_type *file_systems;
写操作的唯一性。
    其中10行,从file_system中查找是否有与&fs同名字文件系统,如果有返回指向结构的指针的指针,如果没有返回返回执行file_systems单链表最后元素的(*file_system_type)->next的地址。
    

点击(此处)折叠或打开

  1. static struct file_system_type **find_filesystem(const char *name, unsigned len)
  2. {
  3.     struct file_system_type **p;
  4.     for (p=&file_systems; *p; p=&(*p)->next)
  5.         if (strlen((*p)->name) == len &&
  6.          strncmp((*p)->name, name, len) == 0)
  7.             break;
  8.     return p;
  9. }

总结:从上面源码的分析可知,register_filesystem(fs);功能是将fs对象添加到全局的file_systems对象链表中。如果file_systems对象链表中有与fs同名字的对象,则返回错误的值,否则返回0.





阅读(1050) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:kern_mount函数解析

给主人留下些什么吧!~~