LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How to overload function in a kernel module (https://www.linuxquestions.org/questions/programming-9/how-to-overload-function-in-a-kernel-module-615873/)

rockballad 01-23-2008 09:37 PM

How to overload function in a kernel module
 
Hi there,

I'm trying to write a USB kernel driver. When I look at a simple code of a skeleton module, I see there's a function called "qusb_read". No matter what its name, because there's a structure to specify the relation:

static struct file_operations qusb_fops = {
.owner = THIS_MODULE,
.read = qusb_read,
.write = qusb_write,
.open = qusb_open,
.release = qusb_release,
};

It's similar to write function.

In this "read" func, they use "usb_bulk_msg" that transfers bulk transfer. How can I implement with usb_control_msg that works with contron transfer? Could these functions co-exist? I mean overload functions?

Thanks in advance.
Jakov

paulsm4 01-23-2008 11:01 PM

Hi -

Read this:
http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html

The answer to your specific question (about "fops" and how it works) is in section 4.1.1. C++ handles polymorphic functions with a "vtable". You can think of fops as being similar to a vtable: it allows you to to provide a "polymorphic" set of standard operations (open, read, write, close, etc) specific to a particular device.

'Hope that helps .. PSM

rockballad 01-24-2008 12:25 AM

Quote:

Originally Posted by paulsm4 (Post 3033354)
Hi -

Read this:
http://tldp.org/LDP/lkmpg/2.6/html/lkmpg.html

The answer to your specific question (about "fops" and how it works) is in section 4.1.1. C++ handles polymorphic functions with a "vtable". You can think of fops as being similar to a vtable: it allows you to to provide a "polymorphic" set of standard operations (open, read, write, close, etc) specific to a particular device.

'Hope that helps .. PSM

Thanks very much! I'll read it up.

Best regards,
Jakov


All times are GMT -5. The time now is 02:40 PM.