momo zone

调核人的blog

关于do_hd_request中sec调整的疑惑

在这段代码里:
void do_hd_request(void)
{
    int i,r = 0;
    unsigned int block,dev;
    unsigned int sec,head,cyl;
    unsigned int nsect;

    INIT_REQUEST;
    dev = MINOR(CURRENT->dev);
    block = CURRENT->sector;
    if (dev >= 5*NR_HD || block+2 > hd[dev].nr_sects) {
        end_request(0);
        goto repeat;
    }
    block += hd[dev].start_sect;
    dev /= 5;
    __asm__("divl %4":"=a" (block),"=d" (sec):"0" (block),"1" (0),
        "r" (hd_info[dev].sect));
    __asm__("divl %4":"=a" (cyl),"=d" (head):"0" (block),"1" (0),
        "r" (hd_info[dev].head));
    sec++;
    nsect = CURRENT->nr_sectors;
……
}
在获得绝对磁头,柱面和扇区号 后进行了 sec++ 。起初疑惑不解,不过很快我想到一个困惑我很久的问题:0磁头,0柱面,0扇区 还是0磁头,0柱面,1扇区?我的意思是磁盘的绝对的0扇区应该是0磁头,0柱面,1扇区吧。换句话说,每磁道扇区的范围是1-63,还是0-63?抱歉,这真的是一个常识性问题,但确实出乎意料,因为答案是63 。也就是整块磁盘的起始都是0磁头,0柱面,1扇区。
于是这个sec++的问题也就不难理解了,因为后面的hd_out要按照CHS的规矩去定位扇区(从1开始),而do_hd_request是按照从0开始的规则,这里要+1 修正哦。用gdb 调试一下就看得出来。
Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: