Character device data structure introduction
A character device driver represents the most basic device driver in the kernel sources. Character devices are represented in the kernel as instances of struct cdev
, declared in include/linux/cdev.h
:
struct cdev { struct kobject kobj; struct module *owner; const struct file_operations *ops; dev_t dev; [...] };
The preceding excerpt has listed elements of our interest only. The following shows the meaning of these elements in this data structure:
kobj
: This is the underlying kernel object for this character device object, used to enforce the Linux device model. We will discuss this in Chapter 14, Introduction to the Linux Device Model.owner
: This should be set with theTHIS_MODULE
macro.ops
: This is the set of file operations associated with this character device.dev
: This is the character device identifier.