0

i have started to learn ioctl

i got this example

http://tldp.org/LDP/lkmpg/2.6/html/x892.html

i got total working of ioctal but i am not getting why and where we need to define ioctal for our driver.?

For that example

Instead of calling ioctl(file_desc, IOCTL_SET_MSG, message);

why we can not direct use

device_write(file, message, size, 0); 

3 Answers 3

1

The point is that ioctl can be called from user space but device_write can only be called from inside the kernel.

Sign up to request clarification or add additional context in comments.

Comments

1

I'm pretty certain that's just because of its tutorial nature. It's trying to show you how to use ioctl. In reality, ioctl would be used for configuring the device driver or device behind it and you would write data using the "normal" method (probably write).

And, in fact, that's what the code does in that link you provide, it simply passes the information on to device_write which is something the kernel does after it copies your data into kernel space.

Comments

1

The ioctl is mainly used to set or get specific parameters or flags about the device, things like reading or writing device registers.

Imagine you have an old floppy drive. It has special registers to control things like "turn motor on or off", "bits per sector", etc. To set those registers you use the ioctl function. To write to the actual disk you use e.g. device_write.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.