Results 1 to 2 of 2
Hi.
I'm trying to copy a struct from the a kernel module to userland. I can copy a struct from userland to the module doing this in the user program:
...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 03-19-2006 #1Just Joined!
- Join Date
- Feb 2006
- Location
- Ireland
- Posts
- 9
Copying a struct from kernel(module) to userland using /proc, how?
Hi.
I'm trying to copy a struct from the a kernel module to userland. I can copy a struct from userland to the module doing this in the user program:
and this in the kernel(note, theres a function called automatically when the proc file is written to):void write_procfile() /* Test for struct copy */
{
FILE *fp;
int i;
if((fp = fopen("/proc/nf_lb", "wb")) == NULL)
{
printf("Error opening /proc/nf_lb for writing.\n");
exit(1);
} /* open /proc/nf_lb for writing */
if((fwrite(&input, sizeof (struct user_input), 1, fp)) != 1)
{
printf("An error has occured. Please make sure to specify correct options.\n");
}
fclose(fp); /* close the file */
}
But, I do not know how to send a struct from the module to userland.../* write data to the buffer*/
if (copy_from_user((char *) &input, buffer, sizeof(struct user_input)))
{
return -EFAULT;
}
Any ideas? I suppose I'm looking for a function like userlands fwrite().
Thanks for any help,
Cormac Redmond
- 03-27-2006 #2
Did you try with copy_to_user? That appears to be the standar way to write data from kernel space to user space. At least it works with plain text.
Best regards!


Reply With Quote
