【Linux102】40-kernel/blk_drv/blk.h


公粽号「专注Linux」,专注Linux内核开发

大地点

Linux102系列会详细讲解Linux0.11版本中的102个文件,本文讲解linux0.11的第40个文件【Linux102】40-kernel/blk_drv/blk.h的文件源码。

1. blk.h的主要作用

这是有关硬盘块设备参数的头文件,因为只用于块设备,所以与块设备代码放在同一个地方。

其中主要定义了请求等待队列项的数据结构request,用宏语句定义了电梯搜索算法,并对内核目前支持的虚拟盘硬盘软盘三种块设备,根据它们各自的主设备号分别设定了常数值


2.源码用到的文件

NO

3.源码版

#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) & 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值