This chapter describes the functions that various kernel components use to populate the procfs with files, symlinks, device nodes, and directories.
A minor note before we start: if you want to use any of the procfs functions, be sure to include the correct header file! This should be one of the first lines in your code:
#include <linux/proc_fs.h>
struct proc_dir_entry* create_proc_entry
(const char* name, mode_t mode, struct proc_dir_entry* parent);
This function creates a regular file with the name name, file mode mode in the directory parent. To create a file in the root of the procfs, use NULL as parent parameter. When successful, the function will return a pointer to the freshly created struct proc_dir_entry; otherwise it will return NULL. Chapter 3 describes how to do something useful with regular files.
Note that it is specifically supported that you can pass a path that spans multiple directories. For example create_proc_entry("drivers/via0/info") will create the via0 directory if necessary, with standard 0755 permissions.
If you only want to be able to read the file, the function create_proc_read_entry described in the section called “Convenience functions” may be used to create and initialise the procfs entry in one single call.