+%Character Devices
+%Thadeu Cascardo
+
# Introduction
Devices in POSIX Systems are files in /dev directory. As with any files
block devices or network devices. Both character and block devices have
identifying numbers, a major and a minor number.
-# Character devices allocation
-
-In Linux, major and minor numbers have to be requested or allocated. The
-calls to do that for character devices are:
-
-
-* int register\\_chrdev\\_region (dev\\_t first, unsigned int count, char
-*name);
-* int alloc\\_chrdev\\_region (dev\\_t *dev, unsigned int firstminor,
-unsigned int count, char *name);
-* void unregister\\_chrdev\\_region (dev\\_t dev, unsigned int count);
-
-
-
-
# VFS
# Introduction
files and others, we'll use some common structures. These include the
*struct file\\_operations*, *struct file* and *struct inode*.
+Do not forget to include linux/fs.h.
+
# File Operations
+* owner
* open
* release
+* flush
* read
* write
* ioctl
+* unlocked_ioctl
* llseek
* poll
* mmap
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.
+* include linux/kdev_t.h
* MAJOR
* MINOR
* MKDEV
-# Allocating numbers
+# Character devices allocation
-Use *register\\_chrdev\\_region* or *alloc\\_chrdev\\_region* to register or
-allocate device numbers.
+In Linux, major and minor numbers have to be requested or allocated. The
+calls to do that for character devices are:
-Use *unregister\\_chrdev\\_region* to unregister it.
+* int register\\_chrdev\\_region (dev\\_t first, unsigned int count, char
+*name);
+* int alloc\\_chrdev\\_region (dev\\_t *dev, unsigned int firstminor,
+unsigned int count, char *name);
+* void unregister\\_chrdev\\_region (dev\\_t dev, unsigned int count);
# cdev structure