Let's answer the aforementioned question – how is it done in code? It's quite straightforward, really:
- First off, within the init code of the kernel module, we must create our procfs directory, naming it after the name of our kernel module:
static struct proc_dir_entry *gprocdir;
[...]
gprocdir = proc_mkdir(OURMODNAME, NULL);
- Again, within the init code of the kernel module, we must create the procfs file that controls the project's "debug level":
// ch2/procfs_simple_intf/procfs_simple_intf.c
[...]
#define PROC_FILE1 "llkdproc_debug_level"
#define PROC_FILE1_PERMS 0644
[...]
static int __init procfs_simple_intf_init(void)
{
int stat = 0;
[...]
/* 1. Create the PROC_FILE1 proc entry under the parent dir OURMODNAME;
* this will serve as the 'dynamically view/modify debug_level'
* (pseudo) file */
if (!proc_create(PROC_FILE1, PROC_FILE1_PERMS, gprocdir,
...