学习笔记5

第十一章

EXT2文件系统

  • 创建虚拟磁盘
    mke2fs [-b blksize -N ninodes] device nblocks
  • 虚拟磁盘布局

    Block#0:引导块 B0是引导块,文件系统不使用
  • 超级块
    • Block#1 超级块 B1是超级块,用于容纳整个文件系统的信息
    • 超级块的重要字段
    u32 s_inodes_count://文件系统中节点总数
    u32 s_blocks_count://文件系统中块总数
    u32 s_r_blocks_count://为超级用户保留的块数
    u32 s_free_blocks_count: //文件系统中空闲块总数
    u32 s_mtime://文件系统的挂接时间
    u32 s_wtime://最后一次对该超级块进行写操作的时间
    u32 s_magic ://魔数签名,用于确定文件系统版本的标志
    u32 s_inodes_per_group://表示每个组块的inode数目,查找文件inode所在块的位置很重要
    u32 s_mnt_count://文件系统挂接计数
    u32 s_max_mnt_count://文件系统最大挂接计数
    u32 s_state://文件系统的状态
  • 块组描述符
    Block#2 块组描述符块 EXT2将磁盘分成几个组,每个组有8192个块,每组用一个块组描述符结构体来描述
struct ext2_group_desc{
   u32	bg_block_bitmap;	//Bmap block number
   u32	bg_inode_bicmap;	//Imap block number
   u32	bg_inode_table;	        //Inodes begin block number
   ul6	bg_free_blocks_count;	//THESE are OBVIOUS
   U16	bg_free_inodes_count;		
   U16	bg_used_dirs_count;		
   ul6	bg_pad;	                //ignore these
   u32	bg_reserved(3);	
};			
  • 块和索引节点图
    • Block#8: 块位图(Bmap)(bg_block_bitmap)位图是用来表示某种项的位序列,例如 磁盘块或索引节点。位图用于分配和回收项。
    • Block#9:索引节点位图(Imap)(bg_inode_bitmap)一个索引节点就是用来代表一个文件的数据结构。
  • 索引节点
    • Block#10:索引(开始)节点(bginode_able)每个文件都用一个128字节(EXT4中 是256字节)的唯一索引节点结构体表示。
struct ext2_inode {
   ul6	i_mode;   	//16 bits = |tttt|ugs|rwx|rwx|rwx|
   ul6	i_uid;	        //owner uid
   u32	i_size;	        //file size in bytes
   u32	i_atime;	//time fields in seconds
   u32	i_ctime;	//since 00:00:00,1-1-1970
   u32	i_mtime;		
   u32	i__dtime;		
   U16	i_gid;	        //group ID
   u16	i_links_count;	//hard-link count
   u32	i_blocks;	//number of 512-byte sectors
   u32	i_flags;	//IGNORE
   u32	i_reserved1;	//IGNORE
   u32	i_block[15];	//See details below
   u32  i_pad[7];;	//for inode size = 128 bytes
}	

i_block[l5]数组包含指向文件磁盘块的指针,这些磁盘块有:
* 直接块:i_block[0] Mi_block[ll],指向直接磁盘块。
* 间接块:i_block[12]指向一个包含256个块编号(对于1KB BLKSIZE)的磁盘块,每个块编号指向一个磁盘块。
* 双重间接块:i_block[13]指向一个指向256个块的块,每个块指向256个磁盘块。
* 三重间接块:**i_block[14]是三重间接块。对于“小型” EXT2文件系统,可以忽略它。

  • 数据块
    紧跟在索引节点块后面的是文件存储数据块。
    目录条目
    目录包含dir_entry结构,即
struct ext2_dir_entry_2{
   U32 inode;                       //inode number; count from 1; NOT 0
   U16 rec_len;                     //this entry's length in bytes
   U8 name_len;                     //name length in bytes
   u8 file_type;                    //not used
   char name[EXT2_NAME_LEN];        //name:1-255 chars, no ending NULL

dir_entry是一种可扩充结构。名称字段包含1到255个字符,不含终止NULL。

  • 邮差算法
Linear_address LA = N*block + house;
Block_address BA = (LA/N,LA%N);

3级文件系统

3级文件系统支持文件系统的挂载、卸载和文件保护。

  • 挂载算法
    mount filesys mount_point
    可将某个文件系统挂载到mount_point目录上
  • 卸载算法
    卸载文件系统操作可卸载已挂载的文件系统,将挂载的文件系统与挂载点分开。
  • 交叉挂载点
    • 向下遍历
    • 向上遍历
  • 文件保护
    9个权限位
    • owner
      • r w x
    • group
      • r w x
    • other
      • r w x
  • 文件系统项目拓展
    多个组-4KB大小块-管道文件-I/O缓冲

苏格拉底挑战




posted @ 2023-10-15 11:08  gaozheng08  阅读(4)  评论(0编辑  收藏  举报