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

This chapter introduced the following symbols and header files. The list of the fields in struct file_operations and struct file is not repeated here.

#include <linux/fs.h>

The “file system” header is the header required for writing device drivers. All the important functions are declared in here.

int register_chrdev(unsigned int major, const char *name, struct file_operations *fops);

Registers a character device driver. If the major number is not 0, it is used unchanged; if the number is 0, then a dynamic number is assigned for this device.

int unregister_chrdev(unsigned int major, const char *name);

Unregisters the driver at unload time. Both major and the name string must contain the same values that were used to register the driver.

kdev_t inode->i_rdev;

The device “number” for the current device is accessible from the inode structure.

int MAJOR(kdev_t dev); , int MINOR(kdev_t dev);

These macros extract the major and minor numbers from a device item.

kdev_t MKDEV(int major, int minor);

This macro builds a kdev_t data item from the major and minor numbers.

SET_MODULE_OWNER(struct file_operations *fops)

This macro sets the owner field in the given file_operations structure.

#include <asm/semaphore.h>

Defines functions and types for the use of semaphores.

void sema_init (struct semaphore *sem, int val);

Initializes a semaphore to a known value. Mutual exclusion semaphores are usually initialized to a value of 1.

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