Character Device Basics (Livehacking Screenplay)¶
Major and Minor Numbers¶
register_chrdev_region()
ininit()
, andunregister_chrdev_region()
inexit()
Caveat: kernel development just happens. The following methods predate the
cdev
API; still used by old drivers.Not
register_chrdev()
- that doescdev_add()
implicitlyNot
unregister_chrdev()
- that leaves the major number registered, at least.
Hardcode major and minor numbers to
(1,1)
initially ⟶ error in logs (KERN_ERR
)Emphasize on error handling (
return -EINVAL
)Take
(42,1)
, finally worksSee how major shows up in
/proc/devices
Character Device¶
cdev_init()
,cdev_add()
(ininit()
)cdev_del()
(inexit()
)Empty
file_operations
⟶ laterCreate node …
# mknod my_driver_henkel c 42 0
cat my_driver_henkel
⟶ EINVALstrace cat my_driver_henkel
⟶ Aha