os-xv6分析-文件系统-fs.h 代码分析

os-xv6的fs.h头文件定义了文件系统的关键结构,包括超级块superblock,索引节点dinode和目录项dirent。文件系统布局包含启动块、超级块、日志、inode块、自由位图和数据块。超级块描述了磁盘布局的详细信息,如文件系统的大小、数据块和inode的数量等。dinode结构存储了文件类型、链接数和数据块地址。目录项结构则包含了inode号和文件名。
摘要由CSDN通过智能技术生成

os-xv6分析-文件系统-fs.h 代码分析

// fs.h 主要定义了超级块superblock、索引节点dinde和目录项dirent,其实声明//了文件系统中的常量。
// On-disk file system format. // 磁盘文件系统格式。
// Both the kernel and user programs use this header file.
// 内核和用户程序都使用这个头文件。

#define ROOTINO 1  // root i-number  // 根i数
#define BSIZE 512  // block size   // 块大小

// Disk layout:
// [ boot block | super block | log | inode blocks |
//                                          free bit map | data blocks]
//
// mkfs computes the super block and builds an initial file system. The
// super block describes the disk layout:
// 定义超级块superblock
struct superblock {
  uint size;         // Size of file system image (blocks)  
//文件系统映像的大小(块)
  uint nblocks;      // Number of data blocks
                  // 数据块的数量
  uint ninodes;      // Number of inodes.
                  //索引节点数。
  uint nlog;         // Number of log blocks   //日志块数
  uint logstart;     // Block number of first log block  //第一个日志块的块号
  uint inodestart;   // Block number of first inode block  //第一个inode块的块数
  uint bmapstart;    // Block number of first free map block 
// 第一个空闲地图块的块号
};

#define NDIRECT 12  //一级寻址的12个块大小
#define NINDIRECT (BSIZE / sizeof(uint)) 
#define MAXFILE (NDIRECT + NINDIRECT) //块大小
// On-disk inode structure //索引节点数据项
struct dinode {
  short type;           // File type  //文件类型
  short major;          // Major device number (T_DEV only) 
// 主要设备编号(仅限T_DEV)
  short minor;          // Minor device number (T_DEV only)  
// 次要设备编号(仅限T_DEV)
  short nlink;          // Number of links to inode in file system
                     // 文件系统中指向索引节点的链接数
  uint size;            // Size of file (bytes)  // 文件大小
  uint addrs[NDIRECT+1];   // Data block addresses //  数据块地址
};

// Inodes per block.
#define IPB           (BSIZE / sizeof(struct dinode)) 
                 // 每个盘块上可以记录的inode数量
// Block containing inode i
#define IBLOCK(i, sb)     ((i) / IPB + sb.inodestart)
              // 计算第i个inode位于哪个盘块
// Bitmap bits per block
#define BPB           (BSIZE*8) // 一个盘块的位数

// Block of free map containing bit for block b
#define BBLOCK(b, sb) (b/BPB + sb.bmapstart)
//  用于计算第b个数据盘块所对应的位图位所在的盘块号
// Directory is a file containing a sequence of dirent structures.
#define DIRSIZ 14 // 目录项中文件名字符串的大小

// 定义目录项数据结构
struct dirent {
  ushort inum;
  char name[DIRSIZ];
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值