Debugfs, being deliberately designed with a "no particular rules" mindset, makes it the ideal interface to use for debug purposes. Why? It allows you to construct any arbitrary byte stream and send it off to the user space, including a binary "blob" with the debugfs_create_blob() API.
Our previous example kernel modules with procfs and sysfs constructed and used three to four (pseudo) files. For a quick demo with debugfs, we shall just stick to two "files":
- llkd_dbgfs_show_drvctx: As you'll have no doubt guessed, when read, it will cause the current content of our (by now familiar) "driver context" data structure to be dumped to the console; we shall ensure the pseudo file's mode is read-only (by root).
- llkd_dbgfs_debug_level: This file's mode shall be read-write (by root only); when read, it will display the current value of debug_level; when an integer is written to it, we shall update...