Search

Creation of proc entry using proc_create_data in kernel version 3.10 and above.

In the post "Creating read only proc entry in kernel versions above 3.10. " we saw how to create a proc entry using the function proc_create.

Note: The following module is valid only of kernel version 3.10 and above.

Another function available in kernel version 3.10 and above for creation of proc entry is proc_create_data which is defined in proc_fs.hs 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.
data: If any data needs to be passed to the proc entry.

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



Along with creation of the entry we are also passing a function to the proc entry in using the porinter "msg".

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.



To access the data in the proc_dir_structure we need to make use of the function PDE_DATA to which we pass the file pointer. The function in turn returs a pointer to the data that was passed during the creation of the proc entry.

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 for creation of proc entry using proc_create_data is

proc_read_data.c



The makefile for the compilation of the modules are



Compile and load the module using



We can see the output by using the cat command

Related Posts:

Creating read only proc entry in kernel versions above 3.10.

For kernel version before 3.10

Creating a proc entry - 1

Creating a proc read entry


No comments:

Post a Comment