user25108
user25108

Reputation: 393

What exactly is a character driver ?

I know the definition

A character device driver is one that transfers data directly to and from a user process.

But can some one explain this in a more intutive way? First of all there should be a device. What is the device in the above definition?

If you say it can be a file, then can we say file reading and putting the data on the console an example of character driver?

Upvotes: 3

Views: 7353

Answers (4)

JuicyKitty
JuicyKitty

Reputation: 438

There is 2 types of drivers: block driver and char driver. The difference is that first one handles with blocks of data and second one receives/transmits data byte by byte.

Ok, for example you have a device and you want to talk to it, how to do it?

You have a driver, simply a number of functions, that will be called by the kernel at the right time. Driver itself can't do anything (neither send data, nor receive data), you need to say your driver what it should do. As you should know so far, you can't discretely communicate with a kernel from user space. There are some tricks that you can use. What you are talking about named as device file. Your driver generates a file for your device and when you write something to this file from user space, driver is notified that it is some information to handle, it takes this information and provide this data to write function, that will transmit data to your device(in this case byte by bite).

Hopefully, this what you wanted to know.

Upvotes: 0

dips
dips

Reputation: 114

According to my knowledge,

The device can be your own private structure or system object.

The driver is said to be a char driver because the data read and write is in byte range

If you are writing your char driver you can use char buffer or kfifo to read and write into the device.

you can create your device file in procfs, and can read/write as u wish and this is accomplished though your char driver

I hope that my answer helps you

Upvotes: 1

user113883
user113883

Reputation: 21

What exactly is a character driver ?

Device driver is Integration of two pieces of code. First piece of code is how the driver services are made available to the application.(user space)

Second piece of code is the hardware access part. Instructions to carry out physical operation on target hardware.

Based on first piece of code we have three models. Character model, Block model, Network model. we can say character driver, block driver, Network driver.

First piece of code is totally kernel specific. what Interface kernel provides to access the hardware. Implementing first piece of code on Linux,windows on other os may be different. we should know what inteface it offers to provide services to application .

In linux From user perspective everyhardware is a file. Why means at boot time all the hardware devices present are detected and added to device tree. Based on hardware corresponding device node gets created automatically in /dev directory. As mentioned above if it is char device---> character device node. Block device---> block device node gets created.

To write character driver. we create a device node in /dev directory , assigning a major no and application usually performing read/write operations on device file.

We implement driver operations and assign driver operations to file structure (fops) pointer.

Device file request received by VFS. VFS turns device file operations into your corresponding driver operations.

APP--->dev file----> fops--->driver---->device.

dev file ---> interface between application and driver.

driver interacts ----> device

You can refer http://lwn.net/images/pdf/LDD3/ch03.pdf.

Upvotes: 1

vishwakarma09
vishwakarma09

Reputation: 364

Think of device driver as abstraction of various hardware that the kernel has to deal with. The device driver knows the details of hardware it is communicating with. So the kernel reads and writes data as it would do with any other filesystem file.

If you can make some reading on Device Drivers, you will find out that the system calls of fopen, read, write, fclose are all mapped to driver specific function calls.

Upvotes: 0

Related Questions