Re: how device driver functions work from user space?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



bunty wrote:
> 
> 
> Hello,
>      I want to know when i write a kernel module which contains I/O functions like read,write,open,close on a file created by kernel module. how can those functions be called automatically when i use normal functions in user program to read/write a file?
>      why standard open,read,write,close will not be called?
> 
> regards,
> parag.

hi Bunty,
           when you open a device file (for that matter any file)  you get a file descriptor , and this file descriptor
is an index into an array of struct file *  maintained in the process descriptor (struct task_struct) of your process.
And your file oprations table you pass to register_chrdev (in case of char devices)  function would be sitting at that
index. So now when you call read(fd, buffer, 100) -----> it would finally call sys_read and look at the value of fd ,
and index into your fd_array maintained in task_struct and call the corresponding device_read you have defined.
hope i was clear.
Allesandro Rubini's book - Linux Device Drivers explains this with a diagram, check that out for a more clearer
explanation.

cheers,
Amith

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux