LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-23-2008, 09:37 PM   #1
rockballad
LQ Newbie
 
Registered: Nov 2007
Distribution: Fedora 8/Ubuntu 7.10
Posts: 23

Rep: Reputation: 15
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
 
Old 01-23-2008, 11:01 PM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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

Last edited by paulsm4; 01-23-2008 at 11:04 PM.
 
Old 01-24-2008, 12:25 AM   #3
rockballad
LQ Newbie
 
Registered: Nov 2007
Distribution: Fedora 8/Ubuntu 7.10
Posts: 23

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by paulsm4 View Post
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can a kernel module call the function of another kernel module sceadu Programming 3 05-02-2011 02:22 AM
implicit declaration of function ‘in_aton in kernel module mathimca05 Linux - Kernel 0 01-22-2008 05:49 AM
Corrupt Kernel? CPU Overload McKittrick Slackware 3 05-07-2006 03:14 AM
hot ot overload a function in c? ypzhuang Programming 3 08-11-2004 11:56 AM
2.6.3 kernel ArtsD wont start, overload slackwarefan Slackware 3 03-04-2004 02:08 PM


All times are GMT -5. The time now is 05:18 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration