Quick Reference

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 ...

Get Linux Device Drivers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.