Representing Character Devices

Recall that character devices are represented by struct cdev. We have seen how the kernel keeps a database of all active cdev instances, but have not yet looked into the content of the structure. It is defined as follows:

struct cdev {

struct kobject kobj;

struct module *owner;

const struct file_operations *ops;

struct list_head list;

dev_t dev;

unsigned int count;

kobj is a kernel object embedded in the structure. As usual, it is used for general management of the data structure. owner points to the module (if any) that provides the driver, and ops is a list of file operations that implement specific operations to communicate with the hardware. dev specifies the device number, and count denotes how many minors are associated with the device. list allows for implementing a list of all inodes that represent device special files for the device.

Initially, the file operations for character devices are limited to just a single method for opening the associated device file (always the first action when using a driver). Logically, let's examine this method first.

Continue reading here: Opening Device Files

Was this article helpful?

0 0