Pages

Creating proc read write function in linux kernel 5.3

In the post "Creating proc read and write entry (linux kernel 4.6)" we saw the details of creating a proc entry in linux kernel version 4.6 .The following is the code to create a simple proc entry to which we can write as well as read from it works with the linux kernel 5.3.

The only change in this as compared to the previous post for version 4.6 is the use of function "simple_read_from_buffer" which copies data from buffer, which is memory in the kernel space to user space. It returns the size of the data of bytes of data to read. The return type of function written to read the proc content is changed to ssize_t from int. Thus making the above two changes the read_proc function now looks like this



We use the temp variable to keep track of how much data is being transferred to the user space. count holds the number of bytes of data written by the write function of the proc entry. For writing data to proc entry we use the function and simple_write_to_buffer which write a message from user space to memory buffer in kernel space which will hold the data in the proc entry.The function meant to write data to proc entry is meant to return the size_t, the size of data written to the proc entry.



Thus the full code for creating the proc entry is



Save the file as proc_rw_5_3.c .

The make file required to compile the above code is



Compile and test the module using the following steps.




1 comment:

  1. I am really impressed your written a blog. Hope we are eagerly waiting for such post from your side. HATS OFF for the valuable information shared!
    Linux Training in Electronic City

    ReplyDelete