I wanted to create two entries in /proc through the kernel module; So, when the user reads either of them, some different output is printed from each of them. e.g:
cat /proc/entry1
>>>Hello World
cat /proc/entry2
>>> Goodbye World
Here's what i tried to do:
#include<linux/init.h>
#include<linux/module.h>
#include<linux/kernel.h>
#define PROC_NAME1 "entry1"
#define PROC_NAME2 "entry2"
#define BUFFER_SIZE 1024
ssize proc_read (struct file*,char __user*,size_t,loff_t*);
static struct file_operations fops
{
.read = proc_read
};
init_func()
{
create_proc(PROC_NAME1,0,NULL,&fops);
create_proc(PROC_NAME2,0,NULL,&fops);
}
exit_func()
{
remove_proc(PROC_NAME1,0,NULL);
remove_proc(PROC_NAME2,0,NULL);
}
ssize_t proc_read (struct file* file,char __user* usr_buf, size_t cout, loff_t *pos)
{
static char char_buffer[BUFFER_SIZE];
int ret;
static int done = 0;
if(done)
{
done = 0;
return 0;
}
done = 1;
ret = sprintf(chat_buffer,"some message");
raw_copy_to_user(usr_buf,char_buffer,ret);
return ret;
}
init_module(init_func);
exit_module(exit_func);
Here's my problem: I created two entries but I have no idea how to write two different strings (actually where to write them) so they are printed when one of the files is read. Anyone can help???