Reputation: 16837
I have a LKM module which creates a proc entry using create_proc_entry(). I have to send some complex data (I am thinking of a structure) from user space program and store it in the /proc entry so that the LKM can receive it.
Right now, I am puzzled on how to convert structure data into buffered output using something like fwrite() because the callback for write from user space to /proc entry has the data argument in form of a buffer.
// fwrite prototype
size_t fwrite ( const void * ptr, size_t size, size_t count, FILE * stream );
// user space write to /proc entry call back prototype
int mod_write( struct file *filp, const char __user *buff,
unsigned long len, void *data );
Any suggestions ?
Thanks.
Upvotes: 1
Views: 2298
Reputation: 16441
You should be able to simply write the data. Something like this:
struct my_data s = { initialization... };
fwrite(&s, sizeof(s), 1, stream);
fflush(stream);
Then mod_write
would get a pointer to s
and would copy it into kernel space.
You may also use write
, and then you won't need to flush it.
If your structure contains pointers, things get more complicated.
Upvotes: 1