当前位置:多学网学习教育电脑学习电脑技巧有关Linux文件系统的几个问题

有关Linux文件系统的几个问题

[08-23 23:21:31]   来源:http://www.duoxue8.com  电脑技巧   阅读:719
有关Linux文件系统的几个问题,标签:电脑技巧大全,电脑基础知识,http://www.duoxue8.com
问题一:如果要找某一个特定的文件,内核如何处理?
  
  答案:
  
  (1)在目录项缓存中查找,注意这里是通过哈西函数查找的,而且查找顺序为从右向左。
  
  e.g.
  
  处理/usr/src/jiawei.c,会从 jiawei.c 开始向上逐级查找,直到根目录,这样的效率很高。
  
  (2)如果缓存中没有,那么然后文件系统会从根目录开始找起,逐级查找。
  
  具体是这样,先找到/目录(根目录)的dentry(目录项),然后会找到它的inode,它的inode会有一项专门记录其下一级的所有 dentry,找到对应的 dentry,再如上述一样接着进行。然后就这样一直找到所要找的文件(注意 linux下面没有目录,因为目录也是文件)。
  
  问题二:dentry 结构体中的 d_inode 指向的的是哪个 inode?
  
  答案:
  
  切记这里指向的是本 dentry 的 inode,而不是下一级的 inode。
  
  问题三:vfs 中的 dentry 结构体中的 vunsigned 类型?
  
  答案:
  
  如下是在网上下载的源码(有我们自己的解释):
  
  struct dentry {
  
  atomic_t d_count; //目录项对象使用计数器
  
  unsigned int d_flags; //目录项标志
  
  struct inode * d_inode;//与文件名关联的索引节点,从该指针找到 inode,从而找到所要找的文件(应该是这样)
  
  struct dentry * d_parent;// 父目录的目录项对象
  
  struct list_head d_hash; //散列表表项的指针
  
  struct list_head d_lru; //未使用链表的指针
  
  struct list_head d_child; //父目录中目录项对象的链
  
  struct list_head d_subdirs;//对目录而言,表示子目录目录项对象的链表
  
  struct list_head d_alias; //相关索引节点(别名)的链表
  
  int d_mounted;//对于安装点而言,表示被安装文件系统根项
  
  struct qstr d_name; //文件名
  
  unsigned long d_time; /* used by d_revalidate*/
  
  struct dentry_operations *d_op;// 目录项方法
  
  struct super_block * d_sb; //文件的超级块对象
  
  vunsigned long d_vfs_flags;
  
  void * d_fsdata;//与文件系统相关的数据
  
  unsigned char d_iname [DNAME_INLINE_LEN]; //存放短文件名
  
  };
  
  事实上 kernel 早就不用这个数据类型了,你可以找找最近2.6 版的,找不到了,下面是 2.6.34.4 的 dentry 源码。
  
  struct dentry {
  
  atomic_t d_count;
  
  unsigned int d_flags; /* protected by d_lock */
  
  spinlock_t d_lock;/* per dentry lock */
  
  int d_mounted;
  
  struct inode *d_inode; /* Where the name belongs
  
  to - NULL is
  
  * negative */
  
  /*
  
  * The next three fields are touched by
  
  __d_lookup.Place them here
  
  * so they all fit in a cache line.
www.duoxue8.com   
  */
  
  struct hlist_node d_hash;/* lookup hash list */
  
  struct dentry *d_parent; /* parent directory */
  
  struct qstr d_name;
  
  struct list_head d_lru;/* LRU list */
  
  /*
  
  * d_child and d_rcu can share memory
  
  */
  
  union {
  
  struct list_head d_child/* child of parent list */
  
  truct rcu_head d_rcu;
  
  } d_u;
  
  struct list_head d_subdirs;/* our children */
  
  struct list_head d_alias;/* inode alias list */
  
  unsigned long d_time;/* used by d_revalidate */
  
  const struct dentry_operations *d_op;
  
  struct super_block *d_sb;/* The root of the dentry
  
  tree */
  
  void *d_fsdata;/* fs-specific data */
  
  unsigned char d_iname[DNAME_INLINE_LEN_MIN]; /*
  
  small names */
  
  };
  
  以上是我们网上讨论的几个问题,现在来给大家说一下我们讨论的结果。如果有异议,希望各位提出来,谢谢!
  
  本文来自 http://www.duoxue8.com 谢谢支


有关Linux文件系统的几个问题 结束。
Tag:电脑技巧电脑技巧大全,电脑基础知识电脑学习 - 电脑技巧
有关Linux文件系统的几个问题相关文章