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. |
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 |
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(). |
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. |
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! |
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(); |
All times are GMT -5. The time now is 03:47 PM. |