Search

Creating read only proc entry in kernel versions above 3.10.

The creation of proc entries has undergone a considerable change in kernel version 3.10 and above. In this post we will see one of the methods we can use in linux kernel version 3.10 and above let us see how we can create proc entries in version 3.10 and above.

The function is defined in proc_fs.h as



Where:

name: The name of the proc entry
mode: The access mode for proc entry
parent: The name of the parent directory under /proc
proc_fops: The structure in which the file operations for the proc entry will be created.

For example to create a proc entry by the name "hello" under /proc the above function will be defined are



Now we need to create file_operations structure proc_fops in which we can map the read function for the proc entry.



Next we need to add the function read_proc which will give to the user space the data that we want to export from the kernel space.



The message that we want to display will be defined in the function create_new_proc_entry in which we will also call the fuction for creation of proc entry.



The init and clean up functions for the module are



The full code of module for creation of proc entry using proc_create is



The makefile for the compilation of the module is



Compile and load the module using



We can see the output by using the cat command

We can see that the message that we passed in the read function of the module is being displayed when the proc entry is read.

Related Posts :

For kernel version before 3.10

Creating a proc entry - 1

Creating a proc read entry

No comments:

Post a Comment