⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 blk.h.bak

📁 一份精简的linux内核源代码
💻 BAK
字号:
#ifndef _BLK_H#define _BLK_H#define NR_BLK_DEV	7/*块设备数量*//* * 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) */#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. */struct request {/*请求项*/	int dev;		/* -1 if no request *//*设备号*/	int cmd;		/* READ or WRITE */	int errors;     /*操作时的出错数*/	unsigned long sector;/*起始扇区*/	unsigned long nr_sectors;/*读写扇区数*/	char * buffer;    /*读写缓冲区*/	struct task_struct * waiting;	struct buffer_head * bh;/*缓冲区头指针*/	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);/*该块设备的相应处理程序*/	struct request * current_request;/*该块设备当前正在处理的请求*/};extern struct blk_dev_struct blk_dev[NR_BLK_DEV];/*块设备表数组*/extern struct request request[NR_REQUEST];/*请求项队列数组*/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 disk */#define DEVICE_NAME "ramdisk"#define DEVICE_REQUEST do_rd_request#define DEVICE_NR(device) ((device) & 7)/*设备号*/#define DEVICE_ON(device) /*开启设备*/#define DEVICE_OFF(device)/*关闭设备*/#elif (MAJOR_NR == 2)/* floppy */#define DEVICE_NAME "floppy"#define DEVICE_INTR do_floppy#define DEVICE_REQUEST do_fd_request#define DEVICE_NR(device) ((device) & 3)#define DEVICE_ON(device) floppy_on(DEVICE_NR(device))#define DEVICE_OFF(device) floppy_off(DEVICE_NR(device))#elif (MAJOR_NR == 3)/*是硬盘*//* harddisk */#define DEVICE_NAME "harddisk"#define DEVICE_INTR do_hd#define DEVICE_REQUEST do_hd_request#define DEVICE_NR(device) (MINOR(device)/5)/*每个硬盘可有4个分区*/#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)/*指定主设备号的当前请求项指针*/#define CURRENT_DEV DEVICE_NR(CURRENT->dev)/*当前请求项中的设备*/#ifdef DEVICE_INTRvoid (*DEVICE_INTR)(void) = NULL;#endifstatic void (DEVICE_REQUEST)(void);extern inline void unlock_buffer(struct buffer_head * bh)/*解锁缓冲区,并唤醒等待该缓冲区的进程*/{	if (!bh->b_lock)		printk(DEVICE_NAME ": free buffer being unlocked\n");	bh->b_lock=0;	wake_up(&bh->b_wait);}extern inline void end_request(int uptodate)/*结束请求处理*/{	DEVICE_OFF(CURRENT->dev);/*关闭设备*/	if (CURRENT->bh) {		CURRENT->bh->b_uptodate = uptodate;		unlock_buffer(CURRENT->bh);	}	if (!uptodate) {		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) \ /*无需要处理的请求项*/		return; \	if (MAJOR(CURRENT->dev) != MAJOR_NR) \ /*出错*/		panic(DEVICE_NAME ": request list destroyed"); \	if (CURRENT->bh) { \ /*出错*/		if (!CURRENT->bh->b_lock) \			panic(DEVICE_NAME ": block not locked"); \	}#endif#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -