LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices



Reply
 
Search this Thread
Old 08-05-2008, 05:33 AM   #1
xiaozhe2000
LQ Newbie
 
Registered: May 2008
Posts: 5

Rep: Reputation: 0
how to avoid write file from a kernel module


There are lots of data I want to output from my module. Generally, I'll use the method that write these data to a file. But It seems that kernel developer don't recommend this way.
So I want to know whether we have a better method to deal with that case, if not write file from kernel module.
Thanks!
 
Old 08-05-2008, 03:44 PM   #2
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 115Reputation: 115
You cannot do a write from a kernel module.

Look into the copy_to_user() command. You might also want to consider memory mapping.

You do your writes from a user program, not a kernel module. The user program first reads the data using your module, then writes it as required.
 
Old 08-05-2008, 10:43 PM   #3
xiaozhe2000
LQ Newbie
 
Registered: May 2008
Posts: 5

Original Poster
Rep: Reputation: 0
thanks, and could you please explain more about "memory mapping"? May be I could write my data to kernel space memory and map it to user space. I think that is the thing I need. Is there a good article depicting that technique?
 
Old 09-17-2008, 08:09 AM   #4
liri
LQ Newbie
 
Registered: Jul 2007
Posts: 11

Rep: Reputation: 0
performing file operations from within a kernel driver

Quote:
Originally Posted by jiml8 View Post
You cannot do a write from a kernel module.

Look into the copy_to_user() command. You might also want to consider memory mapping.
Well, I wouldn't say that it's impossible.
But I'm now finding myself in the same situation where I need to perform some file operations from within my kernel driver.


I was pondering about performing file operations from inside the
kernel. Say we talk about a driver that is compiled within the kernel or an LKM which is loadable - it is possible to perform file operations such as open, read and write from inside the kernel using the provided sys_* functions such as sys_open and the rest.


My question is, how is it possible to specify to the open syscall upon
which user permissions to use?
If you investigate the sys_open function you'll see that at some point
(allocation) it uses the current pointer to grab the uid and gid upon which to check for permissions.


How is this a problem?
Well if the sys_open is called from a user process then that's normal
because the user process has been interrupted and THAT process will be what the current pointer address to, but if we're doing it all in kernel then the current point will be of some random process which we have no affiliation with...


So, what do you think? is it possible to explicitly provide a
task_struct of a dummy process which I created on my own to functions like sys_open?


I'd be happy to hear your thoughts and ideas about this.


Regards,
Liran.
 
  


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
want to avoid 777 permission, but want to write on folder suruchiparimu Linux - Newbie 10 02-09-2006 04:25 AM
How to write makefile for module in 2.6 kernel which builds and uses libraries videsh Linux - Distributions 1 01-19-2006 03:57 PM
How to write a kernel module(kernel object, .ko) on linux-2.6.0? oskernel Programming 1 10-21-2003 03:20 PM
How to write a kernel module(kernel object, .ko) on linux-2.6.0? oskernel Linux - Software 2 10-18-2003 07:04 AM


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