此篇文章主要介绍下linux 文件系统下的主要对象及他们之间的关系。

1 inode

inode结构中主要包含对文件或者目录原信息的描述,原信息包括但不限于文件大小、文件在磁盘块中的位置信息、权限位、文件属性等。文件系统主要通过查找内存中是否有对应的inode来判断一个文件是否存在。

inode本质上分为两种,一种是磁盘文件系统确实存在的inode信息,这里暂叫disk_inode,另一种是内存中的inode,是根据disk_inode生成的,这里暂叫mm_inode。mm_inode中包含文件文件系统特殊管理的复杂数据信息,比对应disk_inode信息量大的多。这里注意,disk_inode并非每个磁盘文件系统都包含,但如前文所述,若想被挂载使用,必须模拟出对应的disk_inode(最终目的是mm_inode)。

inode 结构体定义:

  1. /include/linux/fs.h
  2. struct inode {
  3. struct hlist_node i_hash;
  4. struct list_head i_list;
  5. struct list_head i_dentry;//All the dentrys which point to this inode list together.
  6. unsigned long i_ino;//The inode id, unique in a certain fils system.Sometimes kernel use the i_ino to locate the inode structure
  7. atomic_t i_count;
  8. umode_t i_mode;
  9. unsigned int i_nlink;//How many dentrys points to this same inode.
  10. uid_t i_uid;
  11. gid_t i_gid;
  12. dev_t i_rdev;//if this inode standard for a specific device file, the region include major/minor device number.
  13. loff_t i_size;//The size of the data in this inode.
  14. struct timespec i_atime;
  15. struct timespec i_mtime;
  16. struct timespec i_ctime;
  17. unsigned int i_blkbits;
  18. unsigned long i_blksize;
  19. unsigned long i_version;
  20. unsigned long i_blocks;
  21. unsigned short i_bytes;
  22. unsigned char i_sock;
  23. spinlock_t i_lock; /* i_blocks, i_bytes, maybe i_size */
  24. struct semaphore i_sem;
  25. struct rw_semaphore i_alloc_sem;
  26. struct inode_operations *i_op;
  27. struct file_operations *i_fop; /* former ->i_op->default_file_ops */
  28. struct super_block *i_sb;
  29. struct file_lock *i_flock;
  30. struct address_space *i_mapping;
  31. struct address_space i_data;
  32. #ifdef CONFIG_QUOTA
  33. struct dquot *i_dquot[MAXQUOTAS];
  34. #endif
  35. /* These three should probably be a union */
  36. struct list_head i_devices;
  37. struct pipe_inode_info *i_pipe;
  38. struct block_device *i_bdev;
  39. struct cdev *i_cdev;
  40. int i_cindex;
  41.  
  42. __u32 i_generation;
  43.  
  44. #ifdef CONFIG_DNOTIFY
  45. unsigned long i_dnotify_mask; /* Directory notify events */
  46. struct dnotify_struct *i_dnotify; /* for directory notifications */
  47. #endif
  48.  
  49. unsigned long i_state;
  50. unsigned long dirtied_when; /* jiffies of first dirtying */
  51.  
  52. unsigned int i_flags;
  53.  
  54. atomic_t i_writecount;
  55. void *i_security;
  56. union {
  57. void *generic_ip;
  58. } u;
  59. #ifdef __NEED_I_SIZE_ORDERED
  60. seqcount_t i_size_seqcount;
  61. #endif
  62. };

2 dentry
dentry 表示目录项,这里注意目录项和目录的区分。目录中包含有文件和子目录。而目录项是文件系统逻辑概念,简单讲是一个全路径当中的字段,但这个字段必然代表某一文件系统下的目录或者文件。在文件路径名到具体文件的解析中dentry有重要应用。这里注意一个inode可能对应多个不同的dentry对象,但一个dentry能切只能指向一个inode对象。即多个文件路径指向同一个文件物理。

dentry结构体定义:

  1. /include/linux/dcache.h
  2. struct dentry {
  3. atomic_t d_count;
  4. unsigned int d_flags; /* protected by d_lock */
  5. spinlock_t d_lock; /* per dentry lock */
  6. struct inode *d_inode; /* Where the name belongs to - NULL is
  7. * negative */
  8. /*
  9. * The next three fields are touched by __d_lookup. Place them here
  10. * so they all fit in a 16-byte range, with 16-byte alignment.
  11. */
  12. struct dentry *d_parent; /* parent directory */
  13. struct qstr d_name;
  14.  
  15. struct list_head d_lru; /* LRU list */
  16. struct list_head d_child; /* child of parent list */
  17. struct list_head d_subdirs; /* our children */
  18. struct list_head d_alias; /* inode alias list */
  19. unsigned long d_time; /* used by d_revalidate */
  20. struct dentry_operations *d_op;
  21. struct super_block *d_sb; /* The root of the dentry tree */
  22. void *d_fsdata; /* fs-specific data */
  23. struct rcu_head d_rcu;
  24. struct dcookie_struct *d_cookie; /* cookie, if any */
  25. struct hlist_node d_hash; /* lookup hash list */
  26. int d_mounted;
  27. unsigned char d_iname[DNAME_INLINE_LEN_MIN]; /* small names */
  28. };

dentry结构有6个list_head(list_head既可以作为队列的头部,也可以将其数据结构挂入到某个队列中):

d_vfsmount:仅在该dentry结构是一个安装点时才可以使用

d_hash:一个dentry结构一旦建立就通过就通过d_hash挂入杂凑表dentry_hashtable中的某个队列中。

d_lru:当共享计数为0时,通过d_lru挂入LRU队列的dentry_unused中。

d_child:一个dentry通过d_child挂入其父节点的d_subdirs中。同时通过d_parent指向其父目录的dentry结构。

d_subdirs:该dentry自己的所有子目录挂在该队列下。

d_alias:在inode结构中有个队列i_dentry,凡是代表这个文件的所有目录项头通过d_alias挂入相应inode结构中的i_dentry队列。

一个有效的dentry必然关联一个inode,然而反过来一个inode却可能对应着不止一个dentry结构。也就是说一个文件可能有不止一个路径名(因为一个已建立的文件可以被link到其他的文件名)

3 File

4 Super_block
5 他们之间连接的数据结构

文件系统系列学习笔记 - inode/dentry/file/super(2)的更多相关文章

  1. 文件系统VFS数据结构(超级块 inode dentry file)(收集整理)

    Linux虚拟文件系统四大对象: 1)超级块(super block) 2)索引节点(inode) 3)目录项(dentry) 4)文件对象(file) 一个进程在对一个文件进行操作时各种对象的引用过 ...

  2. 21.TFS文件系统搭建笔记

    TFS文件系统搭建笔记 参考地址: https://github.com/alibaba/tfs/blob/master/INSTALL.md https://github.com/alibaba/t ...

  3. Linux文件系统中的inode节点详细介绍

    这篇文章主要介绍了Linux文件系统中的inode节点,详细讲解了inode是什么.inode包含的信息.inode号码的相关资料等,需要的朋友可以参考下 一.inode是什么? 理解inode,要从 ...

  4. Zynq Fatfs文件系统应用笔记

    Zynq Fatfs文件系统应用笔 Hello,panda 笔记介绍基于所描写叙述的Zynq Fatfs基于Xilinx xilffsv3.0和Sdpsv2.4,文件系统採用在Bare-Metal和轻 ...

  5. MVA Universal Windows Apps系列学习笔记1

    昨天晚上看了微软的Build 2015大会第一天第一场演讲,时间还挺长,足足3个小时,不过也挺震撼的.里面提到了windows 10.Microsoft edge浏览器.Azure云平台.Office ...

  6. Java基础知识强化之IO流笔记09:File类功能

    详见如下: Android(java)学习笔记87:File类使用

  7. 《Machine Learning》系列学习笔记之第一周

    <Machine Learning>系列学习笔记 第一周 第一部分 Introduction The definition of machine learning (1)older, in ...

  8. lesson - 4 笔记 /inode / suid / sgid / sbit / chmod /umask / chown / rwx / wc /grep / tr / sort / cut /which / whereis / locate / find / ln /

    一.帮助+基本文件管理+用户管理 1.怎么查看命令帮助 ls --help man ls :查看命令/man 5 file:查看配置文件 二.基本文件管理,通过{查,建,删,改} 四个维度介绍了不同的 ...

  9. block(data block,directory block)、inode、块位图、inode位图和super block概念详解【转】

    本文转载自:https://blog.csdn.net/jhndiuowehu/article/details/50788287 一.基本概念:      1.block:文件系统中存储数据的最小单元 ...

随机推荐

  1. [cf1491H]Yuezheng Ling and Dynamic Tree

    将其按照区间分块(即$[(i-1)K+1,iK]$作为一个块),并定义$f_{x}$表示$x$的祖先中编号最小且与$x$在同一个块内的节点,$f_{x}$可以通过$f_{a_{x}}$转移,即$f_{ ...

  2. 第02章_MySQL环境搭建

    第02章_MySQL环境搭建 1. MySQL的卸载 步骤1:停止MySQL服务 在卸载之前,先停止MySQL8.0的服务.按键盘上的"Ctrl + Alt + Delete"组合 ...

  3. 从零开始,使用Dapr简化微服务

    序言 现有的微服务模式需要再业务代码中集成大量基础设施模块,比如注册中心,服务发现,服务调用链路追踪,请求熔断,重试限流等等,使得系统过于臃肿重量级. Dapr作为新一代微服务模式,使用sidecar ...

  4. C#.NET 操作Windows服务(安装、卸载)

    注意点: 1.安装时要请求到管理员权限. 2.卸载前,一定要停止掉Windows服务,否则需要重启或注销电脑.代码无法停止服务时,使用services.msc来停止. 开始: 1.新建一个名为&quo ...

  5. Gin 如何动态生成模型 swagger 文档

    在做 API 接口开发时, 一般会统一 API 返回格式, 例如 { "code": 200, "data": { //xxxxx //xxxxx }, &qu ...

  6. Codeforces 375C - Circling Round Treasures(状压 dp+最短路转移)

    题面传送门 注意到这题中宝藏 \(+\) 炸弹个数最多只有 \(8\) 个,故考虑状压,设 \(dp[x][y][S]\) 表示当前坐标为 \((x,y)\),有且仅有 \(S\) 当中的物品被包围在 ...

  7. 55张图吃透Nacos,妹子都能看懂!

    大家好,我是不才陈某~ 这是<Spring Cloud 进阶>第1篇文章,往期文章如下: 五十五张图告诉你微服务的灵魂摆渡者Nacos究竟有多强? openFeign夺命连环9问,这谁受得 ...

  8. R数据科学-1

    R数据科学(R for Data Science) Part 1:探索 by: PJX for 查漏补缺 exercise: https://jrnold.github.io/r4ds-exercis ...

  9. 【R】clusterProfiler的GO/KEGG富集分析用法小结

    前言 关于clusterProfiler这个R包就不介绍了,网红教授宣传得很成功,功能也比较强大,主要是做GO和KEGG的功能富集及其可视化.简单总结下用法,以后用时可直接找来用. 首先考虑一个问题: ...

  10. js判断undefined nan等

    1,js判断undefined 主要用typeof(),typeof的返回值有:undefined,object,boolean,number,string,symbol,function等, if( ...