character device drivers
play

Character device drivers Praktikum Kernel Programming December 17, - PowerPoint PPT Presentation

Character device drivers Praktikum Kernel Programming December 17, 2014 - Albrecht Oster, Walter Knig Outline What is a character device driver? How can we use it? What does it look like? Lets write our own! 2 What is


  1. Character device drivers Praktikum „Kernel Programming“ December 17, 2014 - Albrecht Oster, Walter König

  2. Outline • What is a character device driver? • How can we use it? • What does it look like? • Let’s write our own! 2

  3. What is a character device driver? • two common types: character devices and block devices • character devices are byte-oriented • transfers a stream of bytes directly from kernel to user space • unbuffered and synchronous access • basic I/O (real serial devices, virtual devices) 3

  4. Examples for character devices • most common type of device driver • is represented as a device file (e.g. /dev/ttyS0 ) • can be used like a regular file from user space • open, read, write, close 4

  5. How does it fit in the Linux architecture? • remains in kernel space • used by user space apps through the device file in the VFS • usual file operations • outcome may differ • the driver has final low level access to the actual device 5

  6. How does it fit in the Linux architecture? • four entities involved • user space app • character device file (virtual file system) • character device driver (kernel space) • actual character device 6

  7. Loading / Unloading • module_init(function_ref) • module_exit(function_ref) • insmod loads the driver • rmmod unloads the driver 7

  8. Registering a device file • devices are referred to by major and minor numbers • int register_chrdev(unsigned int major, const char *name, struct file_operations *fops); • driver is registered to one major number several instances of the same driver are distinguished by minor • numbers can define file operations it supports • 8

  9. ioctl • represents a way to control the device itself • every device can have its own ioctl commands • defined in file operations struct • used by a user space app with a file descriptor and macro from header files • int ioctl(int file_handle, int request, char *data); 9

  10. • blocking I/O • restricting access to the device • single-user lock • system-wide lock • „device busy“ 10

  11. Literature • „Character Device Drivers“ 
 http://linux.die.net/lkmpg/x569.html • „Enhanced Char Driver Operations" 
 http://www.xml.com/ldd/chapter/book/ch05.html • Wikipedia: „Device File“ 
 http://en.wikipedia.org/wiki/Device_file • „Decoding Character Device File Operations" 
 http://www.opensourceforu.com/2011/05/decoding-character-device-file-operations/ • „I/O Control in Linux“ 
 http://www.opensourceforu.com/2011/08/io-control-in-linux/ • „Mknod" 
 http://linuxwiki.de/mknod 11

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend