Chardev.c

referring to Character Device Drivers
pls explain --> 4.1.5. chardev.c example 4.1

i haven't understood the article.. pls explain it in simple lang....

:confused: :confused: :confused: :confused:

In short, a kernel module is a list of functions. When the device is opened, it calls your kernel module's own personal open() function. When the device is read from, it calls your kernel module's own personal read() function. You give them private names like device_open and device_read, and tell the kernel which one is close() by filling out the right values in the file_operations structure.

Ask more specific questions and we can give more specific answers.

thank u so much for replying..
i have a few doubts--

  1. where should i call these functions(device_read, device_open,..) in user or kernel space module ? or are these invoked automatically when corresponding action is performed ??

  2. what is ioctl ?

---------- Post updated at 10:49 PM ---------- Previous update was at 01:53 PM ----------

also why in device_write function the operation isn't supported ??

They are invoked automatically when the corresponding userspace action happens. That's why you have to pile them all into a structure, so the kernel can load them.

The userspace ioctl function. It can do a variety of things, often a way to configure a device. See man ioctl.

To keep the example simple.

1 Like

oh.. thank u.. but pls explain ioctl more.. or give a example like when it can be used ??

It's used for hundreds of device control things where the usual system calls don't quite fit. It's hard to give an "average" example since it's almost guaranteed to not make sense out of context.

There are ioctl's to make a cdrom play or pause.

There are ioctl's to set the format of a floppy drive.

There are ioctl's to get the geometry of a hard drive.

There are ioctl's to control a linux PPP network device.

There are ioctl's to control sound cards.

There are ioctl's to set or clear lines on a serial port.

etc, etc.