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
majorand thenamestring 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
inodestructure.-
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_tdata item from the major and minor numbers.-
SET_MODULE_OWNER(struct file_operations *fops) This macro sets the
ownerfield in the givenfile_operationsstructure.-
#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.
Read now
Unlock full access