Where does the actual write happens when writing to a proc file?
Hi everyone,
I wanted to create a proc file in my driver which will be updated every time a certain event happens. I have read about this http://linux.die.net/lkmpg/x769.html Here is the code in that site: Code:
/** It looks simple but I cannot see the point where the actual write happens. The internal buffer used, procfs_buffer, is where the data from user space buffer is copied. I'm not sure if I am missing anything but procfs_buffer is not used anywhere aside from that. I was expecting a transfer from procfs_buffer to another address probably a member of the proc_dir_entry but there isn't any. Regards, archieval |
This may be less details than you like..it's a high-level overview of how proc works:
There is no actual file there, or write happening. What that snippet of code does is hook to /proc/<foo>, and whenever a user 'writes'(using echo, a pipe, or some other mechanism), that code executes procfile_write(), which is passed directly what the user wrote. The reverse happens if a user reads(cat, less, etc) that /proc/<foo> entry, the kernel calls procfile_read(), and returns whatever value that function returns. Hopefully that makes sense...the summary is that there is no actual reading/writing. When you think of the file as being read or written to, it's really the respective read/write function being called and storing/returning a value. This is very similar to writing a kernel module that utilizes /dev/<foo>, you define a read/write function that corresponds to userspace reading or writing to /dev, and you communicate with userspace using the same method the code snippet above uses. |
You need modify procfile_write function to write new value to local variable in driver module after you get new value from user space.
|
Ok, now I think I get it a bit. The proc file above can only be modified by a user space application. After you create it initially, it has no value, so reading from it, will transfer empty content of procfs_buffer to the user space buffer. When no user space program writes to it, it will never have any value. When a program writes into it, it is stored in procfs_buffer, then will be used when a program reads it. Why the hell am I thinking too complicated when it was actually too simple! So the purpose of this whole code is for storage of data only. I should have gone read the previous topic before that, which changes the content of the proc file internally. And I should have not thought of a proc file as a "regular text file", but something more like a "device" (with the /proc/myfile as device file). And the code above is a device driver that will communicate with the "storage device" to store or read data from it. A "device driver" for no actual device!
So to integrate it to my actual device driver that updates something when an event happens, I would only need the read part since the procfs_buffer will be updated internally. Thanks everyone! Regards, archieval |
/proc is a virtual filesystem. It's just values within the kernel or links to device files.
|
All times are GMT -5. The time now is 10:42 AM. |