linux-0.11调试教程,mkfs.c源代码分析(3)
2013-01-29 18:18
405 查看
如果mkfs命令加-c选项会执行check_blocks()函数当然会很费时。大约2分钟。
check_blocks()函数通过逐个读取块的内容,如果不能读取,算出哪个块不能读取,既是坏块,计算出坏块的块号既current_block,然后把对应的逻辑块位图中的位置位,表示已经损坏,在make_bad_inode()函数运行的时候会根据逻辑块位图中的位是否被置1换算成坏块的块号放到坏块文件中的i_zone[]中。
void check_blocks(void)
{
unsigned int current_block=0;
int try,got;
static char buffer[BLOCK_SIZE * TEST_BUFFER_BLOCKS];
while (current_block < ZONES) {
if (lseek(DEV,current_block*BLOCK_SIZE,SEEK_SET) !=
current_block*BLOCK_SIZE)
die("seek failed in check_blocks");
try = TEST_BUFFER_BLOCKS;
if (current_block + try > ZONES)
try = ZONES-current_block;
got = read(DEV, buffer, try * BLOCK_SIZE);
if (got<0)
got = 0;
if (got & (BLOCK_SIZE-1))
printf("Weird values in check_blocks: probably bugs\n");
got /= BLOCK_SIZE;
current_block += got;
if (got == try)
continue;
if (current_block < FIRSTZONE)
die("bad blocks before data-area: cannot make fs");
mark_zone(current_block);
badblocks++;
current_block++;
}
if (badblocks)
printf("%d bad block%s\n",badblocks,(badblocks>1)?"s":"");
}
write_tables()函数把超级块和i节点位图块和逻辑块位图块和i节点缓存写到设备中。
void write_tables(void)
{
if (BLOCK_SIZE != lseek(DEV, BLOCK_SIZE, SEEK_SET))
die("seek failed in write_tables");
if (BLOCK_SIZE != write(DEV, super_block_buffer, BLOCK_SIZE))
die("unable to write super-block");
if (IMAPS*BLOCK_SIZE != write(DEV,inode_map,IMAPS*BLOCK_SIZE))
die("Unable to write inode map");
if (ZMAPS*BLOCK_SIZE != write(DEV,zone_map,ZMAPS*BLOCK_SIZE))
die("Unable to write zone map");
if (INODE_BUFFER_SIZE != write(DEV,inode_buffer,INODE_BUFFER_SIZE))
die("Unable to write inodes");
}
check_blocks()函数通过逐个读取块的内容,如果不能读取,算出哪个块不能读取,既是坏块,计算出坏块的块号既current_block,然后把对应的逻辑块位图中的位置位,表示已经损坏,在make_bad_inode()函数运行的时候会根据逻辑块位图中的位是否被置1换算成坏块的块号放到坏块文件中的i_zone[]中。
void check_blocks(void)
{
unsigned int current_block=0;
int try,got;
static char buffer[BLOCK_SIZE * TEST_BUFFER_BLOCKS];
while (current_block < ZONES) {
if (lseek(DEV,current_block*BLOCK_SIZE,SEEK_SET) !=
current_block*BLOCK_SIZE)
die("seek failed in check_blocks");
try = TEST_BUFFER_BLOCKS;
if (current_block + try > ZONES)
try = ZONES-current_block;
got = read(DEV, buffer, try * BLOCK_SIZE);
if (got<0)
got = 0;
if (got & (BLOCK_SIZE-1))
printf("Weird values in check_blocks: probably bugs\n");
got /= BLOCK_SIZE;
current_block += got;
if (got == try)
continue;
if (current_block < FIRSTZONE)
die("bad blocks before data-area: cannot make fs");
mark_zone(current_block);
badblocks++;
current_block++;
}
if (badblocks)
printf("%d bad block%s\n",badblocks,(badblocks>1)?"s":"");
}
write_tables()函数把超级块和i节点位图块和逻辑块位图块和i节点缓存写到设备中。
void write_tables(void)
{
if (BLOCK_SIZE != lseek(DEV, BLOCK_SIZE, SEEK_SET))
die("seek failed in write_tables");
if (BLOCK_SIZE != write(DEV, super_block_buffer, BLOCK_SIZE))
die("unable to write super-block");
if (IMAPS*BLOCK_SIZE != write(DEV,inode_map,IMAPS*BLOCK_SIZE))
die("Unable to write inode map");
if (ZMAPS*BLOCK_SIZE != write(DEV,zone_map,ZMAPS*BLOCK_SIZE))
die("Unable to write zone map");
if (INODE_BUFFER_SIZE != write(DEV,inode_buffer,INODE_BUFFER_SIZE))
die("Unable to write inodes");
}
相关文章推荐
- linux-0.11调试教程,mkfs.c源代码分析(1)
- linux-0.11调试教程,mkfs.c源代码分析(2)
- linux-0.11调试教程,fflush()函数实现分析和FILE类型定义
- linux-0.11调试教程,bash-1.12源代码分析readline.a和termcap.a的连接
- linux-0.11调试教程,df.c源代码分析,自己写了个super for linux-0.11
- linux-0.11调试教程,终端的初始化init_terminal_io ()函数分析
- linux-0.11调试教程,update_line()函数分析,和update_line()函数的数据模型
- linux-0.11调试教程 tty_table
- linux-0.11调试教程,img文件的分区和格式化,写了个fdisk1可以新建一个分区
- linux-0.11调试教程,readline ()函数中,ECHO的关闭和开启
- linux-0.11调试教程,源起,从linux内核完全注释的几处错误说起
- linux-0.11调试教程,task2
- linux-0.11调试教程,显示strat minix后不能进入保护模式的原因,看bochsout.txt
- linux-0.11调试教程,load_history ()调用过程
- linux-0.11调试教程,bootsect.s文件调试,Loading system ...
- linux-0.11调试教程,系统调用sys_write的调用过程
- linux-0.11调试教程,update_line()函数中的按下字符键对应的缓冲区
- linux-0.11调试教程,findipn根据i节点号返回路径和文件名
- linux-0.11调试教程,minix文件系统1.0上篇(01),硬盘基本参数hd_info
- linux-0.11内核 调试教程+GCC源代码