The most important functions and macros used in writing block drivers
are summarized here. To save space, however, we do not list the
struct buffer_head, or
struct genhd, and we omit
the predefined ioctl commands.
int register_blkdev(unsigned int major, const char *name, struct block_device_operations *bdops);,
int unregister_blkdev(unsigned int major, const char *name);
blk_init_queue(request_queue_t *queue, request_fn_proc *request);,
struct blk_dev_struct blk_dev[MAX_BLKDEV];
read_aheadcontains block-level read-ahead values for every major number. A value of 8 is reasonable for devices like hard disks; the value should be greater for slower media.
max_readaheadcontains filesystem-level read-ahead values for every major and minor number, and is not usually changed from the system default.
These two-dimensional arrays are indexed by major and minor number. The driver is responsible for allocating and deallocating the row in the matrix associated with its major number. The arrays represent the size of device blocks in bytes (it usually is 1 KB), the size of each minor device in kilobytes (not blocks), and the size of the hardware sector in bytes.
These macros must be defined by the driver before it includes
<linux/blk.h>, because they are used within that file.
MAJOR_NRis the major number for the device,
DEVICE_NAMEis the name of the device to be used in error messages,
DEVICE_NRreturns the minor number of the physical device referred to by a device number, and
DEVICE_INTRis a little-used symbol that points to the device’s bottom-half interrupt handler.
struct request *CURRENT;
struct request *blkdev_entry_next_request(struct list_head *head);,
struct request *blkdev_next_request(struct request *req);,
struct request *blkdev_prev_request(struct request *req);,
blkdev_dequeue_request(struct request *req);,
blkdev_release_request(struct request *req);
blk_queue_headactive(request_queue_t *queue, int active);
void blk_queue_make_request(request_queue_t *queue, make_request_fn *func);
end_that_request_first(struct request *req, int status, char *name);,
end_that_request_last(struct request *req);
bh->b_end_io(struct buffer_head *bh, int status);
int blk_ioctl(kdev_t dev, unsigned int cmd, unsigned long arg);
int check_disk_change(kdev_t dev);
struct gendisk *gendisk_head;
The generic hard disk allows Linux to support partitionable devices easily. The
gendiskstructure describes a generic disk;
gendisk_headis the beginning of a linked list of structures describing all of the disks on the system.
void register_disk(struct gendisk *gd, int drive, unsigned minors, struct block_device_operations *ops, long size);