LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 12-22-2010, 03:58 AM   #1
Vermidias
Member
 
Registered: Dec 2010
Location: GERMANY
Posts: 32

Rep: Reputation: 2
fops question


I have a little question. I dont realy understand what fops does and what is it good for? Can anybody explain it for me.

static struct file_operations fops = {
.read = device_read,
.write = device_write,
.ioctl = device_ioctl,
...
};
 
Old 12-22-2010, 05:45 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
The G-man found me this
 
1 members found this post helpful.
Old 12-22-2010, 07:41 AM   #3
Vermidias
Member
 
Registered: Dec 2010
Location: GERMANY
Posts: 32

Original Poster
Rep: Reputation: 2
not really but thanks for your try. I already know what the functions inside fops does but I have no clue how a request could be made or what the kernel does with fops at initialization.

major = register_chrdev(0, "my_device", &fops);
 
Old 12-22-2010, 04:05 PM   #4
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Quote:
Originally Posted by Vermidias View Post
major = register_chrdev(0, "my_device", &fops);
Ah sorry. Is that the line from the kernel whose function you are trying to understand?

EDIT:

AHA! This seems to explain the whole process... I haven't actually read it, but skimming it seems to suggest it explains all the functions in struct which you need. The same tutorial's chapter's "Quick summary" seems to suggest that the register_chrdev() function is deprecated as of Kernel 2.6, so presumably the method they outline is more up-to-date

Last edited by Snark1994; 12-22-2010 at 04:19 PM.
 
1 members found this post helpful.
Old 12-23-2010, 05:35 AM   #5
Vermidias
Member
 
Registered: Dec 2010
Location: GERMANY
Posts: 32

Original Poster
Rep: Reputation: 2
Ok if I am right fops is just an abstrakt open file that points to the functions of the driver that a userspace programm can use.

example:
i declare .open and .unlocked_ioctl in the modul
and use open() and ioctl() in a userspace program to use the functions of the modul

ok if i am right that not that hard to understand ... but what is with code like

.name = "helloworld",

is there a way to read this information from Userspace? Thank you anyway for clearing my confused mind.

Last edited by Vermidias; 12-23-2010 at 05:37 AM.
 
Old 12-24-2010, 12:28 AM   #6
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
Yes, I think that's more or less the case.

Are you looking at a specific example of a driver? Because I was under the impression you only put pointers to functions in a file_operations struct... Obviously, you request the major/minor numbers for the device (in the driver code itself) then you pass a char* with the driver name in it, but I didn't think it was a member (if that's the right term for it) of the file_operations struct itself.
 
1 members found this post helpful.
  


Reply



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
basic html question - download link to files on my webpage question Davno Linux - Server 5 12-25-2009 07:24 AM
fops in linux device drivers avyadavnitw Linux - Newbie 1 04-24-2009 11:39 PM
error: variable ‘fops’ has initializer but incomplete type rajkumar_halle Programming 1 08-24-2008 08:57 AM
error :variable fops has initializer but incomplete type in compile device driver saffari62 Programming 1 04-06-2008 01:53 PM
Question, Apples Contribution to Open Source + MacOs file structure question Higgy3k Other *NIX 5 07-25-2005 04:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:44 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration