0

I want to make a kernel module that writes to a file called /proc/myfile. For now I just want to write "hello" or some other junk in order to test it. What are the recommended functions to do this? From what I have gathered so far, it looks like I should call filp_open() followed by vfs_write().

Thank you.

Edit: Read/write files within a Linux kernel module answers my question.

jm567
  • 1
  • 1
  • Have you used your search engine to do some research? There are lots of useful results searching for terms like "procfs kernel module code". – kaylum Nov 10 '20 at 05:00
  • Does this answer your question? [Creating a simple write only proc entry in kernel](https://stackoverflow.com/questions/40985462/creating-a-simple-write-only-proc-entry-in-kernel) – Tsyvarev Nov 10 '20 at 08:30
  • 1
    Do you want the kernel module to create the file /proc/myfile so that it can be opened and read from userspace (reading information written by the kernel module)? Or do you want the kernel module to open a pre-existing file named /proc/myfile and write to it? – Ian Abbott Nov 10 '20 at 14:24
  • @Tsyvarev I have already implemented read/write handlers for the /proc/myfile file. My question, however, refers to explicitly writing to that file directly from the kernel module itself. – jm567 Nov 10 '20 at 14:43
  • @IanAbbott Hi, Ian. I am looking for the latter. I want to know what functions I need to call in order to write to /proc/myfile directly from within the kernel module itself. I have been googling but a lot of the results I am getting are somewhat obfuscated and seem to be directed towards an audience that already has experience writing LKMs. Thank you. – jm567 Nov 10 '20 at 14:46
  • 1
    "My question, however, refers to explicitly writing to that file directly from the kernel module itself." - Then you probably are looking for that question: https://stackoverflow.com/questions/1184274/read-write-files-within-a-linux-kernel-module. – Tsyvarev Nov 10 '20 at 19:09
  • @Tsyvarev Thank you that helped. – jm567 Nov 10 '20 at 22:16

0 Answers0