LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How is the data passed between user space and kernel (https://www.linuxquestions.org/questions/programming-9/how-is-the-data-passed-between-user-space-and-kernel-753762/)

dongbo 09-09-2009 01:53 AM

How is the data passed between user space and kernel
 
I am trying to pass some parameters from user space to kernel when reading a proc file. Firstly, I clear the buffer in user space and put some special tokens inside, but it seems that all the tokens are gone when I print the buffer in kernel. Does this mean when the proc read function in kernel is called, kernel will allocate memory without initializing it and when the read function exits, the memory will be copied into the user space buffer?

Is there any good method to pass parameter when calling proc read function?

karlatLQ 09-09-2009 09:02 PM

Sounds like the vars get out of scope.

jiml8 09-09-2009 11:55 PM

In linux, everything is a file - including the entries in /proc. If you want to pass data to the kernel, you have to open your /proc entry like it was a file, then write() to it.

The driver, or portion of the kernel, that puts up the pseudo-file in /proc has to have a routine available to read that data when your userspace program writes it.

dongbo 09-11-2009 04:08 AM

Thanks to both of you, I think it is my mistake to use the read file to pass information to the file. The device is actually not as simple as a file with only read and write functionality. Therefore, I add it as a char device. When read the device, all the available data will be passed (several bytes). When user would like to write it. A structure will be given indicating which register and what the value is.


All times are GMT -5. The time now is 03:23 PM.