Reputation: 229
I have a kernel module which implements a timer and it works. At the same time I am able to create a new kernel module to write and read from proc. What I don't understand is how to combine the two operations in the same kernel module.
My application works in this way. A user program writes to the kernel module a number n
which is used to create a timer that will expire in n
milliseconds. To do so I implemented the write
and read
functions and I linked them to the struct file_operations
which I use in the init
function to register my character device (the timer).
Now for the proc
file I need to declare a write
and read
function as well which should handle the requests from the user program. This is what confuses me, I cannot understand how to combine everything together.
Upvotes: 0
Views: 755
Reputation: 1094
As Tsyvarev mentioned use different file_operations
static struct proc_dir_entry *procfs;
static const struct file_operations proc_fops = {
.owner = THIS_MODULE,
.open = open_proc_fn,
.read = read_proc_fn,
};
static const struct file_operations char_fops = {
.owner = THIS_MODULE,
.open = open_char_fn,
.read = read_char_fn,
.write = write_char_fn,
};
int __init init_mod (void) {
procfs = proc_create("filename", 0, NULL, &proc_fops);
if(!proc)
return -1;
<Register char device with &char_fops >
return 0;
}
Upvotes: 1