Added some more stuff from last LDD course.
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sun, 16 May 2010 19:07:47 +0000 (16:07 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sun, 16 May 2010 19:07:47 +0000 (16:07 -0300)
04char/chrdev

index e66490f..e680075 100644 (file)
@@ -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.