From d4c5d9c55bf173650883baaa38c670a3eb55d83d Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Sun, 16 May 2010 16:07:47 -0300 Subject: [PATCH] Added some more stuff from last LDD course. --- 04char/chrdev | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/04char/chrdev b/04char/chrdev index e66490f..e680075 100644 --- a/04char/chrdev +++ b/04char/chrdev @@ -87,3 +87,49 @@ files and others, we'll use some common structures. These include the The inode is a representation of the file as in its filesystem, including its major/minor numbers and pointers to the corresponding device representation. + + + + +# Character Devices + +# Device Number Macros + +Nowadays, major number is 12 bits and minor number is 20 bits. This may change +in the future, so macros should be used. + +* MAJOR +* MINOR +* 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. + +# 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. -- 2.20.1