linux-0.11调试教程,mkfs.c源代码分析(3)
来源:互联网 发布:视频录播软件 编辑:程序博客网 时间:2024/06/10 05:00
如果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");
}
- linux-0.11调试教程,mkfs.c源代码分析(3)
- linux-0.11调试教程,mkfs.c源代码分析(1)
- linux-0.11调试教程,mkfs.c源代码分析(2)
- linux-0.11调试教程,df.c源代码分析,自己写了个super for linux-0.11
- xv6分析--mkfs源代码注释
- linux-0.11调试教程,bash-1.12源代码分析readline.a和termcap.a的连接
- linux-0.11调试教程,终端的初始化init_terminal_io ()函数分析
- Linux内核源代码中的C语言代码(Linux内核源代码情景分析读书笔记连载)
- linux-0.11调试教程 tty_table
- linux-0.11调试教程,task2
- linux-0.11调试教程,task4
- Linux mkfs --格式化磁盘
- 【Linux】硬盘格式化--mkfs
- RTMPdump源代码分析: AMF编码(amf.c)(3)
- linux 3.4.10 内核内存管理源代码分析1:源代码阅读工具,编译及调试
- linux 3.4.10 内核内存管理源代码分析1:源代码阅读工具,编译及调试
- telnetd源代码分析之如何调试源代码?
- Linux下C语言调试(3)
- [LeetCode] 3Sum
- UILabel 根据文字长度自动调整
- php逻辑操作符中&和&&的异同
- 动态规划解题法
- 喝水老呛的原因及。。。
- linux-0.11调试教程,mkfs.c源代码分析(3)
- JS作用域链(转载)
- building bootloader and kernel for pandaboard
- [LeetCode] 3Sum Closest
- hive 0.10.0 杂记
- Hoj 1288 Bridging Signals
- BIT1024 载重问题
- 回溯解题方法
- Unicode和ascii