- open
- called when device opened
- prepares actual device for use (initalize it, enable interrupts ...)
- every open gets its own
filp
(this allow virtual devices: one for each open)
- release
- called when device is finally closed (once)
- multiple close (
fork
, dup
) avoided by ref counting.
- flush is called for every
close()
, but seldomly used.
- does cleanup (stop device, free memory, ...)
- Problem: how identify which device has been opened?
-
imajor()
, iminor()
- use
container_of
macro to find superstructure from inode->i_cdev
API
open and release:
int open(struct inode *i, struct file *filp)
int release(struct inode *i, struct file *filp)
find device numbers given an inode:
unsigned int imajor(struct inode* i);
unsigned int iminor(struct inode* i);
find containing structure:
container_of(container_field_ptr, container_type, name_of_container_field);