Skip to Content
Linux Device Drivers, Second Edition
book

Linux Device Drivers, Second Edition

by Jonathan Corbet, Alessandro Rubini
June 2001
Intermediate to advanced
592 pages
19h 20m
English
O'Reilly Media, Inc.
Content preview from Linux Device Drivers, Second Edition

Quick Reference

The most important functions and macros used in writing block drivers are summarized here. To save space, however, we do not list the fields of struct request, struct buffer_head, or struct genhd, and we omit the predefined ioctl commands.

#include <linux/fs.h> , int register_blkdev(unsigned int major, const char *name, struct block_device_operations *bdops); , int unregister_blkdev(unsigned int major, const char *name);

These functions are in charge of device registration in the module’s initialization function and device removal in the cleanup function.

#include <linux/blkdev.h> , blk_init_queue(request_queue_t *queue, request_fn_proc *request); , blk_cleanup_queue(request_queue_t *queue);

The first function initializes a queue and establishes the request function; the second is used at cleanup time.

BLK_DEFAULT_QUEUE(major)

This macro returns a default I/O request queue for a given major number.

struct blk_dev_struct blk_dev[MAX_BLKDEV];

This array is used by the kernel to find the proper queue for a given request.

int read_ahead[]; , int max_readahead[][];

read_ahead contains 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_readahead contains filesystem-level read-ahead values for every major and minor number, and is not usually changed from the system default.

int max_sectors[][];

This array, indexed by both major and ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Linux Device Drivers, 3rd Edition

Linux Device Drivers, 3rd Edition

Jonathan Corbet, Alessandro Rubini, Greg Kroah-Hartman

Publisher Resources

ISBN: 0596000081Supplemental ContentCatalog PageErrata