?? blk.h
字號:
#ifndef _BLK_H#define _BLK_H#define NR_BLK_DEV 7 /* 塊設備的數(shù)量*//** NR_REQUEST is the number of entries in the request-queue.* NOTE that writes may use only the low 2/3 of these: reads* take precedence.** 32 seems to be a reasonable number: enough to get some benefit* from the elevator-mechanism, but not so much as to lock a lot of* buffers when they are in the queue. 64 seems to be too many (easily* long pauses in reading when heavy writing/syncing is going on)*//** 下面定義的NR_REQUEST 是請求隊列中所包含的項數(shù)。* 注意,讀操作僅使用這些項低端的2/3;讀操作優(yōu)先處理。** 32 項好象是一個合理的數(shù)字:已經(jīng)足夠從電梯算法中獲得好處,* 但當緩沖區(qū)在隊列中而鎖住時又不顯得是很大的數(shù)。64 就看上* 去太大了(當大量的寫/同步操作運行時很容易引起長時間的暫停)。*/#define NR_REQUEST 32/** Ok, this is an expanded form so that we can use the same* request for paging requests when that is implemented. In* paging, 'bh' is NULL, and 'waiting' is used to wait for* read/write completion.*//** OK,下面是request 結構的一個擴展形式,因而當實現(xiàn)以后,我們就可以在分頁請求中* 使用同樣的request 結構。在分頁處理中,'bh'是NULL,而'waiting'則用于等待讀/寫的完成。*/// 下面是請求隊列中項的結構。其中如果dev=-1,則表示該項沒有被使用。struct request{ int dev; /* -1 if no request */// 使用的設備號。 int cmd; /* READ or WRITE */// 命令(READ 或WRITE)。 int errors; /* 操作時產(chǎn)生的錯誤次數(shù)。*/ unsigned long sector; /* 起始扇區(qū)。(1 塊=2 扇區(qū))*/ unsigned long nr_sectors; /* 讀/寫扇區(qū)數(shù)。*/ char *buffer; /* 數(shù)據(jù)緩沖區(qū)。*/ struct task_struct *waiting; /* 任務等待操作執(zhí)行完成的地方。*/ struct buffer_head *bh; /* 緩沖區(qū)頭指針(include/linux/fs.h,68)。*/ struct request *next; /* 指向下一請求項。*/};/** This is used in the elevator algorithm: Note that* reads always go before writes. This is natural: reads* are much more time-critical than writes.*//** 下面的定義用于電梯算法:注意讀操作總是在寫操作之前進行。* 這是很自然的:讀操作對時間的要求要比寫嚴格得多。*/#define IN_ORDER(s1,s2) \((s1)->cmd<(s2)->cmd || (s1)->cmd==(s2)->cmd && \((s1)->dev < (s2)->dev || ((s1)->dev == (s2)->dev && \(s1)->sector < (s2)->sector)))// 塊設備結構。struct blk_dev_struct{ void (*request_fn) (void); /* 請求操作的函數(shù)指針。*/ struct request *current_request; /* 請求信息結構。*/};extern struct blk_dev_struct blk_dev[NR_BLK_DEV]; /* 塊設備數(shù)組,每種塊設備占用一項*/extern struct request request[NR_REQUEST]; /* 請求隊列數(shù)組*/extern struct task_struct *wait_for_request; /* 等待請求的任務結構*/#ifdef MAJOR_NR /* 主設備號*//** Add entries as needed. Currently the only block devices* supported are hard-disks and floppies.*//** 需要時加入條目。目前塊設備僅支持硬盤和軟盤(還有虛擬盤)。*/#if (MAJOR_NR == 1) /* RAM 盤的主設備號是1。根據(jù)這里的定義可以推理內(nèi)存塊主設備號也為1 */ /* ram disk *//* RAM 盤(內(nèi)存虛擬盤) */#define DEVICE_NAME "ramdisk" /* 設備名稱ramdisk */#define DEVICE_REQUEST do_rd_request /* 設備請求函數(shù)do_rd_request() */#define DEVICE_NR(device) ((device) & 7) /* 設備號(0--7) */#define DEVICE_ON(device) /* 開啟設備。虛擬盤無須開啟和關閉*/#define DEVICE_OFF(device) /* 關閉設備*/#elif (MAJOR_NR == 2) /* 軟驅的主設備號是2 *//* floppy */#define DEVICE_NAME "floppy" /* 設備名稱floppy */#define DEVICE_INTR do_floppy /* 設備中斷處理程序do_floppy() */#define DEVICE_REQUEST do_fd_request /* 設備請求函數(shù)do_fd_request() */#define DEVICE_NR(device) ((device) & 3) /* 設備號(0--3) */#define DEVICE_ON(device) floppy_on(DEVICE_NR(device)) /* 開啟設備函數(shù)floppyon() */#define DEVICE_OFF(device) floppy_off(DEVICE_NR(device)) /* 關閉設備函數(shù)floppyoff() */#elif (MAJOR_NR == 3) /* 硬盤主設備號是3 *//* harddisk */#define DEVICE_NAME "harddisk" /* 硬盤名稱harddisk */#define DEVICE_INTR do_hd /* 設備中斷處理程序do_hd() */#define DEVICE_REQUEST do_hd_request /* 設備請求函數(shù)do_hd_request() */#define DEVICE_NR(device) (MINOR(device)/5) /* 設備號(0--1)。每個硬盤可以有4 個分區(qū)*/#define DEVICE_ON(device) /* 硬盤一直在工作,無須開啟和關閉*/#define DEVICE_OFF(device)#elif/* unknown blk device *//* 未知塊設備 */#error "unknown blk device"#endif#define CURRENT (blk_dev[MAJOR_NR].current_request)/* CURRENT 為指定主設備號的當前請求結構*/#define CURRENT_DEV DEVICE_NR(CURRENT->dev) /* CURRENT_DEV 為CURRENT 的設備號*/#ifdef DEVICE_INTRvoid (*DEVICE_INTR) (void) = NULL;#endifstatic void (DEVICE_REQUEST) (void);// 釋放鎖定的緩沖區(qū)。extern inline void unlock_buffer (struct buffer_head *bh){ if (!bh->b_lock) /* 如果指定的緩沖區(qū)bh 并沒有被上鎖,則顯示警告信息*/ intk (DEVICE_NAME ": free buffer being unlocked\n"); bh->b_lock = 0; /* 否則將該緩沖區(qū)解鎖*/ wake_up (&bh->b_wait); /* 喚醒等待該緩沖區(qū)的進程*/}// 結束請求。extern inline void end_request (int uptodate){ DEVICE_OFF (CURRENT->dev); /* 關閉設備*/ if (CURRENT->bh) { /* CURRENT 為指定主設備號的當前請求結構*/ CURRENT->bh->b_uptodate = uptodate; /* 置更新標志*/ unlock_buffer (CURRENT->bh); /* 解鎖緩沖區(qū)*/ } if (!uptodate) { /* 如果更新標志為0 則顯示設備錯誤信息*/ printk (DEVICE_NAME " I/O error\n\r"); printk ("dev %04x, block %d\n\r", CURRENT->dev, CURRENT->bh->b_blocknr); } wake_up (&CURRENT->waiting); /* 喚醒等待該請求項的進程*/ wake_up (&wait_for_request); /* 喚醒等待請求的進程*/ CURRENT->dev = -1; /* 釋放該請求項*/ CURRENT = CURRENT->next; /* 從請求鏈表中刪除該請求項*/}// 定義初始化請求宏。#define INIT_REQUEST \repeat: \if (!CURRENT) \ /* 如果當前請求結構指針為null 則返回*/ return;if (MAJOR (CURRENT->dev) != MAJOR_NR)\ /* 如果當前設備的主設備號不對則死機*/ panic (DEVICE_NAME ": request list destroyed");if (CURRENT->bh){ if (!CURRENT->bh->b_lock) \ /* 如果在進行請求操作時緩沖區(qū)沒鎖定則死機*/ panic (DEVICE_NAME ": block not locked"); }#endif#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -