LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 12-29-2010, 05:43 PM   #1
mrshanim
Member
 
Registered: Aug 2009
Posts: 30

Rep: Reputation: 16
kernel module - write to user space


I have a kernel module which get some of the parameters of the system call. I want to write those parameters to user space.
I am new to kernel programming, any suggestions will be appreciated.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 12-30-2010, 01:48 AM   #2
bsat
Member
 
Registered: Feb 2009
Posts: 347

Rep: Reputation: 72
one of the simplest way to put data out of kernel space is using "printk".
Other options you can explore are
creating a proc entry
creating an ioctl call
 
Old 12-30-2010, 02:52 AM   #3
Deep Narayan Dubey
LQ Newbie
 
Registered: Dec 2010
Location: Allahabad, India
Posts: 11

Rep: Reputation: 8
Hi,
I think you want to copy some data from kernel space to user space. To do this you can use copy_to_user() function defined in asm/uaccess.h to copy the parameters to user space buffer. This user space buffer can be provided as an argument to the system call. That buffer will be filled inside the system call using copy_to_user().
 
2 members found this post helpful.
Old 12-30-2010, 01:37 PM   #4
mrshanim
Member
 
Registered: Aug 2009
Posts: 30

Original Poster
Rep: Reputation: 16
Printk n proc wont be helpful because I want to dump all the data (from kernel space) to write in a txt file in user space. I think copy_to_user() will be appropriate, am I right?

Thanks for suggestions n help.
 
Old 12-30-2010, 10:58 PM   #5
Aquarius_Girl
Senior Member
 
Registered: Dec 2008
Posts: 4,731
Blog Entries: 29

Rep: Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940Reputation: 940
This will help, I think:
http://www.gnugeneration.com/books/l...20/kernel-api/

Look out for the keyword "User Space Memory Access" in the above link!
 
Old 12-31-2010, 11:25 AM   #6
Deep Narayan Dubey
LQ Newbie
 
Registered: Dec 2010
Location: Allahabad, India
Posts: 11

Rep: Reputation: 8
Hi,
You want to write the data in a file. According to your earlier post I have assumed you want to copy the data. It is right you should first copy the data from kernel space to user space using copy_to_user() and then for creating a file you can use filp_open() call. This function is used to create a file or to open a file from kernel module. Then you get a struct file * from this function. This function return not NULL value on successful return.
You can write using vfs_write() function.
mm_segment_t user_fs;
user_fs = get_fs(); // Necessary for before segment for KERNEL
set_fs(KERNEL_DS); // set the segment to KERNEL Data Segment
struct file * filp = filp_open(filename, O_CREAT | O_RDWR, 0644);
vfs_write(filp,buf,size,filp->f_pos);
set_fs(user_fs);

You can copy the data in buffer using
copy_to_user();
 
  


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
how to send events from kernel module to user space process yugandhar Linux - Kernel 2 02-21-2011 10:39 AM
[SOLVED] Does a kernel module run in kernel or user space? paliga Linux - General 4 10-31-2010 07:22 AM
Write into File from Kernel and read the same file from User space saurabhchokshi Programming 0 05-01-2009 02:26 PM
linking .o files built in user space against kernel module using kbuild santigopal_mondal Linux - Newbie 1 01-03-2009 02:42 PM
Kernel Module to send Message to User Space Application hnshashi Linux - Newbie 2 08-22-2008 12:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 11:24 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