Regarding how the parameters to the read function is passed in simple char driver
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Regarding how the parameters to the read function is passed in simple char driver
Hi everyone,
I am newbei to driver programming i am started writing the simple char driver
which i have attached . Then i created special file for my char driver mknod /dev/simple-driver c 250 0 .when it type cat /dev/simple-driver. it shows the string "Hello world tamil_vanan!". i know that function
*possition += count;
return count;
}
is get called . This is mapped to (*read) in file_opreation structure of my driver .My question is how this function is get called , how the parameters like struct file,char,count, offset are passed bcoz is i simply typed cat command ..Please elabroate how this happening
means you want to print the contents of "/dev/simple_driver", that means you want to read, so your read function is called. it same as
fd = open("/dev/simple_driver");
nr = read(fd, buf, 80);
similarly if you do
echo "write to simple driver" > /dev/simple_driver will call your write function.
Kernel knows this as you specified the name of the device(simple_device) during char device registering in init function.
Ya thanks for the information. i know the that read and write requested are redirected to driver read ,write functions. but i like to know how its happening and how the read operation in my driver gets all the four parameters.
You will probably be best served by looking in the kernel sources to find the answer to that. Or ask on a forum or mailing list where the inhabitants deal specifically in kernel internals.
A more general answer is that the kernel maps the device node to your driver when you load your driver. When a userspace system call is made for reading or writing your device, the kernel uses the association it has previously remembered, and dispatches the accordant function in your driver. The cat and echo commands are userspace applications that do read and write system calls, and these result in the calls that you are witnessing. Any application that calls read(), write(), open(), close(), seek(), ioctl(), stat(), etc on a device supported by your driver will cause the respective function in your driver to be invoked.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.