From 8584382bae04cef7df11999fcf0aac6e019f2caa Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Sun, 16 May 2010 15:52:52 -0300 Subject: [PATCH] Imported some slides from last LDD course. --- 04char/chrdev | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 04char/chrdev diff --git a/04char/chrdev b/04char/chrdev new file mode 100644 index 0000000..5b6f7e9 --- /dev/null +++ b/04char/chrdev @@ -0,0 +1,41 @@ +# Introduction + +Devices in POSIX Systems are files in /dev directory. As with any files +in POSIX, they may be opened, closed, read from, written to, seeked, +ioctl'd, and others. + +Examples of device files: + +* /dev/sda - A SCSI block device +* /dev/ttyS0 - A Serial terminal device + +# POSIX I/O calls + +POSIX systems have some standard calls for I/O. Since devices are files, +these same system calls are used to work with devices. We are gonna work +with the following calls: + +* open +* read +* write +* close +* lseek +* ioctl + +# Device types and numbers + +Linux devices may be of different types, including character devices, +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); -- 2.20.1