加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长百科 > 正文

Linux 的假造文件体系(真正领略“统统皆文件”)

发布时间:2019-06-16 01:14:35 所属栏目:站长百科 来源:cpp软件架构狮
导读:1,引言 Linux 中允许众多不同的文件系统共存,如 ext2, ext3, vfat 等。通过使用同一套文件 I/O 系统 调用即可对 Linux 中的任意文件进行操作而无需考虑其所在的具体文件系统格式;更进一步,对文件的 操作可以跨文件系统而执行。如图 1 所示,我们可以使

按照文件体系地址的物理介质和数据在物理介质上的组织方法来区分差异的文件体系范例的。 file_system_type布局用于描写详细的文件体系的范例信息。被Linux支持的文件体系,都有且仅有一 个file_system_type布局而不管它有零个或多个实例被安装到体系中。

而与此对应的是每当一个文件体系被现实安装,就有一个vfsmount布局体被建设,这个布局体对应一个安装点。

清单5. 和文件体系相干

  1. struct file_system_type { 
  2.  const char *name; /*文件体系的名字*/ 
  3.  struct subsystem subsys; /*sysfs子体系工具*/ 
  4.  int fs_flags; /*文件体系范例符号*/ 
  5.  /*在文件体系被安装时,从磁盘中读取超等块,在内存中组装超等块工具*/ 
  6.  struct super_block *(*get_sb) (struct file_system_type*,  
  7.  int, const char*, void *); 
  8.   
  9.  void (*kill_sb) (struct super_block *); /*终止会见超等块*/  
  10.  struct module *owner; /*文件体系模块*/ 
  11.  struct file_system_type * next; /*链表中的下一个文件体系范例*/ 
  12.  struct list_head fs_supers; /*具有统一种文件体系范例的超等块工具链表*/ 
  13. }; 
  14. struct vfsmount 
  15.  struct list_head mnt_hash; /*散列表*/ 
  16.  struct vfsmount *mnt_parent; /*父文件体系*/ 
  17.  struct dentry *mnt_mountpoint; /*安装点的目次项工具*/ 
  18.  struct dentry *mnt_root; /*该文件体系的根目次项工具*/ 
  19.  struct super_block *mnt_sb; /*该文件体系的超等块*/ 
  20.  struct list_head mnt_mounts; /*子文件辖档痛表*/ 
  21.  struct list_head mnt_child; /*子文件辖档痛表*/ 
  22.  atomic_t mnt_count; /*行使计数*/ 
  23.  int mnt_flags; /*安装符号*/ 
  24.  char *mnt_devname; /*装备文件名*/ 
  25.  struct list_head mnt_list; /*描写符链表*/ 
  26.  struct list_head mnt_fslink; /*详细文件体系的到期列表*/ 
  27.  struct namespace *mnt_namespace; /*相干的名字空间*/ 
  28. }; 

2.2.5.2 和历程相干

清单6. 打开的文件集

  1. struct files_struct {//打开的文件集 
  2.  atomic_t count; /*布局的行使计数*/ 
  3.  …… 
  4.  int max_fds; /*文件工具数的上限*/ 
  5.  int max_fdset; /*文件描写符的上限*/ 
  6.  int next_fd; /*下一个文件描写符*/ 
  7.  struct file ** fd; /*所有文件工具数组*/ 
  8.  …… 
  9.  }; 
  10. struct fs_struct {//成立历程与文件体系的相关 
  11.  atomic_t count; /*布局的行使计数*/ 
  12.  rwlock_t lock; /*掩护该布局体的锁*/ 
  13.  int umask; /*默认的文件会见权限*/ 
  14.  struct dentry * root; /*根目次的目次项工具*/ 
  15.  struct dentry * pwd; /*当前事变目次的目次项工具*/ 
  16.  struct dentry * altroot; /*可供选择的根目次的目次项工具*/ 
  17.  struct vfsmount * rootmnt; /*根目次的安装点工具*/ 
  18.  struct vfsmount * pwdmnt; /*pwd的安装点工具*/ 
  19.  struct vfsmount * altrootmnt;/*可供选择的根目次的安装点工具*/ 
  20. }; 

2.2.5.3 和路径查找相干

清单7. 帮助查找

  1. struct nameidata { 
  2.  struct dentry *dentry; /*目次项工具的地点*/ 
  3.  struct vfsmount *mnt; /*安装点的数据*/ 
  4.  struct qstr last; /*路径中的最后一个component*/ 
  5.  unsigned int flags; /*查找标识*/ 
  6.  int last_type; /*路径中的最后一个component的范例*/ 
  7.  unsigned depth; /*当前symbolic link的嵌套深度,不能大于6*/ 
  8.  char *saved_names[MAX_NESTED_LINKS + 1];/ 
  9.  /*和嵌套symbolic link 相干的pathname*/ 
  10.  union { 
  11.  struct open_intent open; /*声名文件该怎样会见*/ 
  12.  } intent; /*专用数据*/ 
  13. }; 

2.2.6 工具间的接洽

如上的数据布局并不是孤独存在的。正是通过它们的有机接洽,VFS才气正常事变。如下的几张图是对它们之间的接洽的描写。

(编辑:湖南网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读