What does a user-space application generally do w.r.t the other file-system resource (other then interacting with user)? Reading some configuration file, or flushing logs. Let's say we are browsing internet in our chrome, then chrome would be ultimately operating on the network socket files (there may be some hierarchy). Let's say we played some song in VLC player, ultimately our VLC will read the mp3 file, write the data to some audio device file, after which the audio driver will get the data and configs the corresponding CODEC register to get the audio output. Now, for all the operation above, for an user-space the resources (mp3, device file, socket file, log file) will look like a file. Thus the application would do nothing more then calling open, read, write which are file based operations. For a user-space application, a kernel device driver also looks like a file ( /dev/demochardrv ) In this article we will focus on how to achieve these file based operation i
To start with writing a linux kernel driver, we need to know about some of the fundamentals. This post (or series of post) will deal with starting with a basic kernel module with writing Kconfig, IOCTL's. memory address (virtual & physical), dynamic memory allocation, mutex/spinlock way of synchronization, kernel data structure, sys/class interface of a module, etc. 1. Types of Linux kernel Drivers Based on the access of amount of data, the Kernel drivers are classified into two types: Character Driver Block Driver Character driver provides access of data only as a stream, generally of character i.e bytes. Block Driver on the other hand are addressable in device specific chunks (also called blocks). Example of Character driver may be an I2C driver, which provides data at a byte at a time. On the other hand a filesystem driver (say ext3, ext4) is a good example of a block driver where access of data is done on chunk basis like 1KB, 512MB etc. Infact all the d