📄 hd.c
字号:
//////////////////////////////////////////////////////////////////////////////
#include "general.h"
#include "sti_cli.h"
#include "in_order.h"
#include "hd_info_struct.h"
#include "dir_entry.h"
#include "msdos_dir_entry.h"
#include "d_inode.h"
#include "m_inode.h"
#include "buffer_head.h"
#include "fat_cache.h"
#include "file.h"
#include "hd_request_struct.h"
#include "super_block.h"
#include "common_head.h"
//////////////////////////////////////////////////////////////////////////////
int ll_rw_block_h0(struct buffer_head * bh)
{
unsigned int temp_dev,temp_block,temp_block_0;
unsigned int temp_cyl,temp_head,temp_sec;
struct hd_request_struct * temp_req , * temp_req_0;
////////////////////////////////////////////////////////////////////////////////////////////
temp_dev = bh->b_dev;
temp_block = bh->b_blocknr << 1;
if ((temp_dev >= nr_super_blocks) || (temp_block + 2 > the_super_block[temp_dev].nr_sects))
return -1;
temp_block += the_super_block[temp_dev].start_sect;
temp_block_0 = temp_block;
temp_dev = 0;
temp_sec = temp_block % hd_info[temp_dev].sect;
temp_block = temp_block / hd_info[temp_dev].sect;
temp_head = temp_block % hd_info[temp_dev].head;
temp_cyl = temp_block / hd_info[temp_dev].head;
////////////////////////////////////////////////////////////////////////////////////////////
temp_req = current_req;
do {
if (temp_req->hd < 0){
current_req = temp_req;
break;
}
temp_req++;
if (temp_req == hd_request + NR_REQUEST)
temp_req = hd_request;
} while (temp_req != current_req);
if (temp_req->hd >= 0)
return 0;
bh->b_lock = 1;
temp_req->hd = temp_dev;
temp_req->block = temp_block_0;
temp_req->cyl = temp_cyl;
temp_req->head = temp_head;
temp_req->sector = temp_sec + 1;
temp_req->nsector = 2;
temp_req->cmd = WIN_WRITE;
temp_req->errors = 0;
temp_req->bh = bh;
temp_req->next = NULL;
if (start_request_h0 == NULL){
start_request_h0 = temp_req;
end_request_h0 = temp_req;
return 1;
}
if IN_ORDER(temp_req,start_request_h0){
temp_req->next = start_request_h0;
start_request_h0 = temp_req;
return 1;
}
temp_req_0 = start_request_h0;
while ((temp_req_0->next) && !IN_ORDER(temp_req,temp_req_0->next))
temp_req_0 = temp_req_0->next;
temp_req->next = temp_req_0->next;
temp_req_0->next = temp_req;
if (temp_req->next == NULL)
end_request_h0 = temp_req;
return 1;
}
void ll_rw_block_h1(void)
{
int temp_flag;
if (!start_request_h0)
return;
temp_flag = 0;
cli();
if (!end_request_h){
start_request_h = start_request_h0;
end_request_h = end_request_h0;
temp_flag = 1;
}
else{
end_request_h->next = start_request_h0;
end_request_h = end_request_h0;
}
sti();
start_request_h0 = NULL;
end_request_h0 = NULL;
if (temp_flag)
do_request_1();
return;
}
int ll_rw_block_h2(struct buffer_head * bh)
{
unsigned int temp_dev,temp_block,temp_block_0;
unsigned int temp_cyl,temp_head,temp_sec;
struct hd_request_struct * temp_req;
int temp_flag;
////////////////////////////////////////////////////////////////////////////////////////////
temp_dev = bh->b_dev;
temp_block = bh->b_blocknr << 1;
if ((temp_dev >= nr_super_blocks) || (temp_block + 2 > the_super_block[temp_dev].nr_sects))
return -1;
temp_block += the_super_block[temp_dev].start_sect;
temp_block_0 = temp_block;
temp_dev = 0;
temp_sec = temp_block % hd_info[temp_dev].sect;
temp_block = temp_block / hd_info[temp_dev].sect;
temp_head = temp_block % hd_info[temp_dev].head;
temp_cyl = temp_block / hd_info[temp_dev].head;
////////////////////////////////////////////////////////////////////////////////////////////
temp_req = current_req;
while (temp_req->hd >= 0){
temp_req++;
if (temp_req == hd_request + NR_REQUEST)
temp_req = hd_request;
}
current_req = temp_req;
bh->b_lock = 1;
temp_req->hd = temp_dev;
temp_req->block = temp_block_0;
temp_req->cyl = temp_cyl;
temp_req->head = temp_head;
temp_req->sector = temp_sec + 1;
temp_req->nsector = 2;
temp_req->cmd = WIN_READ;
temp_req->errors = 0;
temp_req->bh = bh;
temp_req->next = NULL;
temp_flag = 0;
cli();
if (!start_request_h){
start_request_h = temp_req;
end_request_h = temp_req;
temp_flag = 1;
}
else{
temp_req->next = start_request_h->next;
start_request_h->next = temp_req;
if (temp_req->next == NULL)
end_request_h = temp_req;
}
sti();
if (temp_flag)
do_request_1();
return 1;
}
//////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -