Question: Write a linux kernel module that creates an entry in the /proc file system . Use the following code skeleton to write the module and
Write a linux kernel module that creates an entry in the /proc file system. Use the following code skeleton to write the module and replace the commented lines with the right code:
#include
static struct proc_dir_entry *proc_entry; static char *info; static int write_index; static int read_index ; int init_module (void) { int ret = 0; //allocated memory space for the proc entry info = (char *)vmalloc (MAX_LEN);
memset (info, 0, MAX_LEN);
//create the entry write_index = 0; read_index = 0; //register the write and read callback functions proc_entry?>read_proc = read_info; proc_entry?>write_proc = write_info; printk (KERN_INFO " test_proc created. "); return ret; } void cleanup_module (void) { //remove the proc entry and free info space }
ssize_t write_info (struct file *filp, const char __user *buff , unsigned long len , void *data) { //copy the written data from user space and save it in info return len; } int read_info(char *page, char **start, off_t off , int count , int *eof , void *data) { //output the content of info to users buffer pointed by page return l e n ; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
