下面在mount_root下断点的情形。
下图可以看出为0x1fa58的buffer_head结构中设备号为0x300,块号为0。既硬盘的第一个块。上面有分区信息。
高速缓存区块的地址为0x3ffc00。
上图可以看出硬盘的第一个块的分区信息,从第二行的最后两个字可以看出nr_sects为0x1d87f。
struct partition {
unsigned char boot_ind; /* 0x80 - active (unused) */ 80
unsigned char head; /* ? */ 01
unsigned char sector; /* ? */ 01
unsigned char cyl; /* ? */ 00
unsigned char sys_ind; /* ? */ 81
unsigned char end_head; /* ? */ 0f
unsigned char end_sector; /* ? */ 3f
unsigned char end_cyl; /* ? */ 77
unsigned int start_sect; /* starting sector counting from 0 */ 00000001
unsigned int nr_sects; /* nr of sectors in partition */ 0001d87f
};
下图可以看出hd[1].start_sect为1,hd[1].nr_sects为0x1d87f
在mount_root最后下断点,可以看出缓存头指针0x1fa7c和缓存头指针0x1fa58的hash值是一样的。
0x1fa58是sys_setup()还没有mount_root()的时候加入hash_table[154]的,mount_root的时候0x1fa7c又加入hash_table[154],并且0x1fa7c->next指向了0x1fa58,而0x1fa58->prev是0x1fa7c。
相关代码:
/* This may be used only once, enforced by 'static int callable' */
int sys_setup(void * BIOS)
{
...
for (drive=0 ; drive<NR_HD ; drive++) {
if (!(bh = bread(0x300 + drive*5,0))) {
printk("Unable to read partition table of drive %d\n\r",
drive);
panic("");
}
if (bh->b_data[510] != 0x55 || (unsigned char)
bh->b_data[511] != 0xAA) {
printk("Bad partition table on drive %d\n\r",drive);
panic("");
}
p = 0x1BE + (void *)bh->b_data;
for (i=1;i<5;i++,p++) {
hd[i+5*drive].start_sect = p->start_sect;
hd[i+5*drive].nr_sects = p->nr_sects;
}
brelse(bh);
}
if (NR_HD)
printk("Partition table%s ok.\n\r",(NR_HD>1)?"s":"");
rd_load();
mount_root();
return (0);
}