LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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-29-2003, 07:44 PM   #1
jooboo
LQ Newbie
 
Registered: Nov 2003
Location: Thailand
Posts: 4

Rep: Reputation: 0
How can I read regular file in kernel module


Hi ..
I wrote the kernel module and I want to read regular file for get the context in that file to do something and I have a problem, How to read file from kernel module ??

Please help me for suggetion , I'm newbie.
Thanks you.
 
Old 12-30-2003, 07:45 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 110Reputation: 110
I know very little about programming kernel modules, but isn't it possible to just call open(2) and read(2). They are system calls, and as such in the kernel, after all.
 
Old 12-30-2003, 10:08 AM   #3
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
it doesnt make sense to call open from the kernel because open returns a file descriptor which is specific to a process but the kernel isnt a process. eg every process has file descriptor STDOUT_FILENO which is 1, but they go to different places this can only work because they are in different processes, the kernel isnt a process and therefore it cant have file descriptors. (i dont think ive explained this very well if someone can explain better please do)

im sure its possible to concoct some method of opening a file from inside the kernel but i wouldnt reccommend it as it will most likely cause security problems/race conditions/etc...

my suggestion is to use the proc interface or run a user mode daemon to talk to your module.
 
Old 12-30-2003, 12:46 PM   #4
jspenguin
Member
 
Registered: Feb 2003
Location: Wichita, KS
Distribution: Heavily modified Redhat
Posts: 194

Rep: Reputation: 30
If the function in your module is called from a system call, then any file descriptors will be in the context of the process that made the system call. For instance, if it is in your init function, then it will be in the context of the insmod process. As long as you read the file and close it before the function returns, you should be all right. You should probably make a module option to specify the file to read. What is the file? Config, data, etc.?
 
Old 12-30-2003, 03:36 PM   #5
jooboo
LQ Newbie
 
Registered: Nov 2003
Location: Thailand
Posts: 4

Original Poster
Rep: Reputation: 0
That file is data file such as content data
 
Old 12-30-2003, 08:11 PM   #6
jspenguin
Member
 
Registered: Feb 2003
Location: Wichita, KS
Distribution: Heavily modified Redhat
Posts: 194

Rep: Reputation: 30
If it doesn't ever change, try converting the file to an array in a header. That way, it will be built right into the module itself. Almost all of the raw data in the kernel is done this way. It shouldn't be too difficult to create a program to convert a binary to a char array.
 
  


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
editing a kernel module make file shanenin Linux - Software 1 11-10-2005 10:00 AM
read routing table in kernel module? cranium2004 Programming 0 03-15-2005 08:15 AM
How to read from /proc entry in another kernel module? linux_lover2005 Programming 0 01-14-2005 06:44 AM
Building kernel module from multiple source file in 2.6 kernel yogeshwar_s Programming 1 12-20-2004 10:31 AM
read file from running kernel b123coder Programming 1 11-18-2004 05:05 AM

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

All times are GMT -5. The time now is 08:12 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration