Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 10: Filesystems without Persistent Storage


struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
const char *dest);

Unsurprisingly, a filesystem object can either be a regular file, a directory, or a symbolic link. Two addi-
tional operations allow for renaming and removing files:

<debugfs.h>
void debugfs_remove(struct dentry *dentry);

struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
struct dentry *new_dir, const char *new_name);

When kernel code is being debugged, the need to export and manipulate a single elementary value like
anintor alongoften arises. Debugfs also provides several functions that create a new file that allows
for reading the value from userspace and passing a new value into the kernel. They all share a common
prototype:

<debugfs.h>
struct dentry *debugfs_create_XX(const char *name, mode_t mode,
struct dentry *parent, XX *value);

nameandmodedenote the filename and access mode, whileparentpoints to thedentryinstance of the
parent directory.valueis most important: It points to the value that is exported and can be modified by
writing into the file. The function is available for several data types.

IfXXis replaced by any of the standard kernel data typesu8,u16,u32,oru64, a file that allows for reading
but forbids changing the value is created. Ifx8,x16,orx32is used, the value can also be changed from
userspace.

A file that presents a Boolean value can be created bydebugfs_create_bool:

<debugfs.h>
struct dentry *debugfs_create_bool(const char *name, mode_t mode,
struct dentry *parent, u32 *value)

Finally, it is also possible to exchange short portions of binary data (conventionally calledbinary blobs)
with userspace. The following function is provided for this purpose:

<debugfs.h>
struct dentry *debugfs_create_blob(const char *name, mode_t mode,
struct dentry *parent,
struct debugfs_blob_wrapper *blob);

The binary data are represented by a special data structure containing a pointer to the memory location
that holds the data and the data length:

<debugfs.h>
struct debugfs_blob_wrapper {
void *data;
unsigned long size;
};
Free download pdf