The most important functions and macros used in writing block
drivers are summarized below. To save space, however, I’m
not listing the fields of struct request
or
struct genhd
, and I’m omitting the predefined ioctl commands.
int register_blkdev(unsigned int major, const char *name,
,
struct file_operations *fops);
,
int unregister_blkdev(unsigned int major, const char *name);
These functions are in charge of device registration in init_module and device removal in cleanup_module.
struct blk_dev_struct blk_dev[MAX_BLKDEV];
This array is used for request passing between the kernel
and the driver. blk_dev[major].request_fn
should be
assigned at load time to point to the ``request function for
the current request.''
int read_ahead[];
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.
int blksize_size[][];
,
int blk_size[][];
,
int hardsect_size[][];
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 1KB), the size of each minor device in kilobytes (not blocks), and the size of the hardware sector in bytes. Currently, sector sizes other than 512 are not supported, despite the fact that there’s a hook in the code.
MAJOR_NR
,
DEVICE_NAME
,
DEVICE_NR(kdev_t device)
,
DEVICE_INTR
,
#include <linux/blk.h>
These macros must be defined by the driver before it includes the header, as most of the header uses them.
struct request *CURRENT
This macro points to the current request. The request structure describes a data chunk to be transferred and is used by the request_fn for the current driver.
#include<linux/gendisk.h>
,
struct genhd;
The generic hard disk allows Linux to support partitionable devices easily.
void resetup_one_dev(struct gendisk *genhd, int drive);
This function scans the partition table of the disk and
rewrites genhd->part
to reflect the new
partitioning.
3.141.24.134