code:struct inode - ikarishinjieva/unixV6-code-analyze-chs GitHub Wiki

Source

  • 磁盘INODE结构

5600 /*

5601  * Inode structure as it appears on

5602  * the disk. Not used by the system,

5603  * but by things like check, df, dump.

5604  */

5605 struct inode

5606 {

5607     int i_mode;

5608     char i_nlink;

5609     char i_uid;

5610     char i_gid;

5611     char i_size0;

5612     char *i_size1;

5613     int i_addr[8];

5614     int i_atime[2];

5615     int i_mtime[2];

5616 };

5617 /* ------------------------- */

  • 核心代码使用的INODE结构,作为磁盘INODE的内存缓存
  • inode定义为磁盘INODE的内存缓存数组
  • NINODE 定义在param.h 0131行,值为 100

5650 /* The I node is the focus of all

5651  * file activity in unix. There is a unique

5652  * inode allocated for each active file,

5653  * each current directory, each mounted-on

5654  * file, text file, and the root. An inode is ’named’

5655  * by its dev/inumber pair. (iget/iget.c)

5656  * Data, from mode on, is read in

5657  * from permanent inode on volume.

5658  */

5659 struct inode

5660 {

5661     char i_flag;

  • 标志位
    • IACC : 该INODE已被存取
    • IUPD : 该INODE已被修改
5662     char i_count; /* reference count */
5663     int i_dev; /* device where inode resides */
  • 对应的设备的设备号
5664     int i_number; /* i number, 1-to-1 with device

5665                     address */

  • 该INODE在设备INODE区的序号,从1开始
5666     int i_mode;
5667     char i_nlink; /* directory entries */
5668     char i_uid; /* owner */
  • 该文件/目录的拥有者
5669     char i_gid; /* group of owner */
  • 该文件/目录的拥有组
5670     char i_size0; /* most significant of size */

5671     char *i_size1; /* least sig */

  • 该文件/目录的大小
5672     int i_addr[8];/* device addresses constituting file */
5673     int i_lastr; /* last logical block read (for

5674                     read-ahead) */

  • 最后读取的块号
  • 用于预读(breada)判断
5675 } inode[NINODE];

5676 /* ------------------------- */

Ref

Caller

⚠️ **GitHub.com Fallback** ⚠️