X-Git-Url: http://git.cascardo.eti.br/?a=blobdiff_plain;f=04char%2Fchrdev;fp=04char%2Fchrdev;h=5b6f7e915f6f6aab8a5a4aed282d299062896278;hb=8584382bae04cef7df11999fcf0aac6e019f2caa;hp=0000000000000000000000000000000000000000;hpb=50ac4667b6dc6b958e3e2f18e73bb0e9d5d86b8f;p=cascardo%2Fkernel%2Fslides%2F.git 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);