Linux Kernel – Debug File System

The Linux Debug File System is a virtual memory File system that was developed so that debug kernel information can be accessed in user space whenever desired. It is a RAM based File system.

The Debug File system will be enabled in the Linux kernel build if “CONFIG_DEBUG_FS” is enabled in the kernel config. The debug file system is mounted at mount point “/sys/kernel/debug”.

The Debug File System can be mounted dynamically with a command like –

  • mount -t debugfs none /sys/kernel/debug

a couple properties of the Debug File System is provided below

  • debugFS directory is only accessible to root user
  • Unlike procfs and sysfs which has one value per file rule, debugfs does not have such a limitation

To create a debug File System access to a kernel module, APIs are present. A few APIs are provided below 

Debug FS API

Description

struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)

This will create a directory called “name” underneath the indicated parent directory.

struct dentry *debugfs_create_file(const char *name, umode_t mode,  struct dentry *parent, void *data, const struct file_operations *fops);

Creates a debug file in the “parent” directory

struct dentry *debugfs_create_file_size(const char *name, umode_t mode,  struct dentry *parent, void *data, const struct file_operations *fops, loff_t file_size);

Create a debug File with an initial File size

void debugfs_remove(struct dentry *dentry);

Remove an entry from debug FS

void debugfs_remove_recursive(struct dentry *dentry);

Remove the entire hierarchy of files

struct dentry *debugfs_create_u8(const char *name, mode_t mode,                                      struct dentry *parent, u8 *value);

 

Create an entry to export a u8 value

struct dentry *debugfs_create_u16(const char *name, mode_t mode, struct dentry *parent, u16 *value);

 

Create an entry to export a u16 value

struct dentry *debugfs_create_u32(const char *name, mode_t mode, struct dentry *parent, u32 *value);

 

Create an entry to export a u32 value

 

struct dentry *debugfs_create_bool(const char *name, mode_t mode, struct dentry *parent, u32 *value);

 

Create an entry to export a bool value

In addition, a number of support APIs are provided to create specific file types. The below links provide the interested reader with a list of the different APIs that are supported and further information on debugfs.

  Linux Kernel – Adding DebugFS support to a Linux kernel module

Comments

  1. Pingback: Linux – Proc File system – Part 2 | Hitch Hiker's Guide to Learning

  2. Pingback: sysfs APIs and sample sysfs implementation in the Linux Kernel | Hitch Hiker's Guide to Learning

Leave a Reply

Your email address will not be published. Required fields are marked *