Chardev.c


 
Thread Tools Search this Thread
Operating Systems Linux Chardev.c
# 1  
Old 03-08-2013
Chardev.c

referring to tldp.org/LDP/lkmpg/2.6/html/x569.html
pls explain --> 4.1.5. chardev.c example 4.1

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

Smilie Smilie Smilie Smilie
# 2  
Old 03-08-2013
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.
# 3  
Old 03-10-2013
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 ??
# 4  
Old 03-10-2013
Quote:
Originally Posted by blair15
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 ??
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.
Quote:
2. what is ioctl ?
The userspace ioctl function. It can do a variety of things, often a way to configure a device. See man ioctl.
Quote:
also why in device_write function the operation isn't supported ??
To keep the example simple.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 03-10-2013
oh.. thank u.. but pls explain ioctl more.. or give a example like when it can be used ??
# 6  
Old 03-10-2013
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.
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question