Search code examples
linuxkernelkernel-moduleproc

How do I call my kernel module which writes to a proc file?


I copied and pasted the code from this url: http://linux.die.net/lkmpg/x769.html

I replaced the outdated &proc_root foolery and commented out the "Our_Proc_File->owner = THIS_MODULE;" line on account that it gave me trouble while building.

I then made an appropriate makefile, compiled the .ko and did the deed with insmod.

Two questions:

  1. How do I read from the procfile?

  2. Also, I see an entry for the file is made at module load, but when is this file written?

BONUS These questions may root from a misunderstanding of proc. It is my impression that proc "files" are written to upon file read to deliver up-to-date info.

  1. Is that wrong?

Solution

    1. With read(2). cat can do this for you from the shell.
    2. Never. The contents are created dynamically when the file is read. This is why we specify a read callback for the file.