- 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)
- called when device is finally closed (once)
- multiple close (
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?
container_of macro to find superstructure from
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);