# Linux Kernel Module Cheat

#### 17.7.1. debugfs

Debugfs is the simplest pseudo filesystem to play around with:

    ./debugfs.sh
    echo $?

Outcome: the test passes:

    0

Sources:

- kernel_modules/debugfs.c

- rootfs_overlay/lkmc/debugfs.sh

Debugfs is made specifically to help test kernel stuff. Just mount, set File operations, and we are done.

For this reason, it is the filesystem that we use whenever possible in our tests.

`debugfs.sh` explicitly mounts a debugfs at a custom location, but the most common mount point is `/sys/kernel/debug`.

This mount not done automatically by the kernel however: we, like most distros, do it from userland with our fstab.

Debugfs support requires the kernel to be compiled with `CONFIG_DEBUG_FS=y`.

Only the more basic file operations can be implemented in debugfs, e.g. `mmap` never gets called:

- https://patchwork.kernel.org/patch/9252557/

- https://github.com/torvalds/linux/blob/v4.9/fs/debugfs/file.c#L212

Bibliography: https://github.com/chadversary/debugfs-tutorial