From: Thadeu Lima de Souza Cascardo Date: Mon, 7 Dec 2009 05:08:01 +0000 (-0200) Subject: Some more about implementing simple character devices. X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Fkernel%2Fold_slides%2F.git;a=commitdiff_plain;h=b62e702e2029289facee0ed967dfce253b582897 Some more about implementing simple character devices. --- diff --git a/03.char/03.char.xml b/03.char/03.char.xml index 3c9f8cd..43a871a 100644 --- a/03.char/03.char.xml +++ b/03.char/03.char.xml @@ -31,10 +31,58 @@ MKDEV + +Allocating numbers + +Use register\_chrdev\_region or +alloc\_chrdev\_region to register or allocate device +numbers. + + +Use unregister\_chrdev\_region to unregister it. + + + + +cdev structure + +Use cdev\_alloc or cdev\_init to +allocate or initalize a cdev structure. + + +Use cdev\_add and cdev\_del to +register and unregister it. + + + + +Open/Release + +Implementing open and release should be very simple for many devices. They +usually allocate data, and multiplex devices by minor number. + + + Inode structure -Use imajor and iminor to get the major and minor number from an inode structure. +Use imajor and iminor to get the major +and minor number from an inode structure. + + + + +Read + +Read may write to user space less bytes than requested. + + + + +Write + +Write is very similar to read. Only problem is that many applications misbehave +when driver writes less bytes than requested.