Results 1 to 3 of 3
Hi everybody,
I really am a newbie in kernel development and I have this question.
I am developing an application that need to read some informations from the kernel. More ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 01-28-2012 #1Just Joined!
- Join Date
- Jan 2012
- Posts
- 2
exchange data from kernel to process
Hi everybody,
I really am a newbie in kernel development and I have this question.
I am developing an application that need to read some informations from the kernel. More specifically these informations regard the TCP part of the kernel.
I thought I could use the /proc filesystem in order to make the kernel write those informations in a specific file.
But until now I didn't find a complete guide that explains how to do this.
In any guide (I can't post URLs), for example, it is said that we need to create a module and when the module is loaded the function create_proc_entry() will be called.
The problem is that the part of kernel which need to write my informations, is a static part, so I don't need to create that module.
But in that case, who will call the create_proc_entry? And where do I put all the functions mentioned in the guide then?
Can you please clarify this to me?
Thanks,
Riccardo
- 02-01-2012 #2Just Joined!
- Join Date
- Jan 2007
- Posts
- 9
I have written a simple driver to write content to some user space file.
Please change this as per your need.
Your MakefileCode:/* *Module.c */ #include <linux/module.h> // Needed by all modules #include <linux/kernel.h> // Needed for KERN_INFO #include <linux/fs.h> // Needed by filp #include <linux/string.h> #include <asm/uaccess.h> // Needed by segment descriptors int init_module(void) { // Create variables struct file *f; char buf[128]; mm_segment_t fs; int i; // Init the buffer for(i=0;i<128;i++) buf[i] = 0; printk(KERN_INFO "My module is loaded\n"); //Open the file f = filp_open("/etc/testFile", O_CREAT|O_WRONLY|O_APPEND, 0); if(f == NULL) printk(KERN_ALERT "filp_open error!!.\n"); else { // Get current segment descriptor fs = get_fs(); // Set segment descriptor associated to kernel space set_fs(get_ds()); // Write to buf strcpy(buf,"I love my country"); // Write to the file f->f_op->write(f, buf, strlen(buf), &f->f_pos); // Restore segment descriptor set_fs(fs); } //close the file filp_close(f,NULL); return 0; } void cleanup_module(void) { printk(KERN_INFO "My module is unloaded, so now check your new file content\n"); }
Let me know for any issue.Code:obj-m += module.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
Regards,
Barun Parichha
- 02-01-2012 #3Just Joined!
- Join Date
- Jan 2012
- Posts
- 2
Hi barunparichha,
I have solved my problem now, because I modified an already existing proc file, instead of creating a new one.
Still your module is very useful and rather simple to understand, so I am sure it will come in handy sooner or later.
Thank you,
Riccardo


Reply With Quote
