October 2017
Intermediate to advanced
586 pages
14h 8m
English
For each open performed on your character device, the callback function will be given a struct inode as a parameter, which is the kernel lower-level representation of the file. That struct inode structure has a field named i_cdev, which points to the cdev we have allocated in the init function. By embedding the struct cdev in our device-specific data, as in struct pcf2127 in the following example, we will be able to get a pointer on that specific data using the container_of macro. Here is an open method sample.
The following is our data structure:
struct pcf2127 {
struct cdev cdev;
unsigned char *sram_data;
struct i2c_client *client;
int sram_size;
[...]
};
Given this data structure, the open method would look like this: ...
Read now
Unlock full access