Search

Creating directory under /proc in kernel 3.10 and above

In the post Creating a read write proc entry in kernel versions above 3.10 we saw the creation of read write proc entry. In the post we will see how to create folder under /proc and then create a entry under it.

To create a directory under /proc we can make use of the function



Where

name: is the name of the directory to be created. parent: parent is the name of directory under which the new directory has to be created.

To create a directory named "newparent" under /proc we will first declare a string having the name of the new folder





The NULL is passed for parent as we are creating the folder under /proc.

Once the new folder has been created we need to pass the pointer to struct proc_dir_entry to proc_create. The use of proc_create can be seen in the post



The full code for the module along with proc creation will be as shown below. Please refer to the post Creating a read write proc entry in kernel versions above 3.10 for more details

proc_dir.c



The makefile for the same



Compile and load the module using



If there are no errors then we can find the new proc entry under /proc



Thus we can see that under /proc a new folder called newparent has been created in which the proc entry hello has been created. We can read write to this proc entry like other proc entries



Related posts

Creating a read write proc entry in kernel versions above 3.10

Creating read only proc entry in kernel versions above 3.10.

Creating a proc entry - 1

2 comments:

  1. Why are we removing "temp1".

    I did not find any use of this line:

    remove_proc_entry("temp1",NULL);

    ReplyDelete
    Replies
    1. Because the entry created by the module needs to be removed by the module when it is removed from the kernel

      Delete