^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) .. SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) .. include:: <isonum.txt>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) =======
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) DebugFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) =======
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) Copyright |copy| 2009 Jonathan Corbet <corbet@lwn.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) Debugfs exists as a simple way for kernel developers to make information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) available to user space. Unlike /proc, which is only meant for information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) about a process, or sysfs, which has strict one-value-per-file rules,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) debugfs has no rules at all. Developers can put any information they want
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) there. The debugfs filesystem is also intended to not serve as a stable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) ABI to user space; in theory, there are no stability constraints placed on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) files exported there. The real world is not always so simple, though [1]_;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) even debugfs interfaces are best designed with the idea that they will need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) to be maintained forever.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) Debugfs is typically mounted with a command like::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) mount -t debugfs none /sys/kernel/debug
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) (Or an equivalent /etc/fstab line).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) The debugfs root directory is accessible only to the root user by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) default. To change access to the tree the "uid", "gid" and "mode" mount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) options can be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) Note that the debugfs API is exported GPL-only to modules.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) Code using debugfs should include <linux/debugfs.h>. Then, the first order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) of business will be to create at least one directory to hold a set of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) debugfs files::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct dentry *debugfs_create_dir(const char *name, struct dentry *parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) This call, if successful, will make a directory called name underneath the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) indicated parent directory. If parent is NULL, the directory will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) created in the debugfs root. On success, the return value is a struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) dentry pointer which can be used to create files in the directory (and to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) clean it up at the end). An ERR_PTR(-ERROR) return value indicates that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) something went wrong. If ERR_PTR(-ENODEV) is returned, that is an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) indication that the kernel has been built without debugfs support and none
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) of the functions described below will work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) The most general way to create a file within a debugfs directory is with::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct dentry *debugfs_create_file(const char *name, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct dentry *parent, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) const struct file_operations *fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) Here, name is the name of the file to create, mode describes the access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) permissions the file should have, parent indicates the directory which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) should hold the file, data will be stored in the i_private field of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) resulting inode structure, and fops is a set of file operations which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) implement the file's behavior. At a minimum, the read() and/or write()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) operations should be provided; others can be included as needed. Again,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) the return value will be a dentry pointer to the created file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) ERR_PTR(-ERROR) on error, or ERR_PTR(-ENODEV) if debugfs support is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) missing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) Create a file with an initial size, the following function can be used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) instead::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) void debugfs_create_file_size(const char *name, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct dentry *parent, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) const struct file_operations *fops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) loff_t file_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) file_size is the initial file size. The other parameters are the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) as the function debugfs_create_file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) In a number of cases, the creation of a set of file operations is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) actually necessary; the debugfs code provides a number of helper functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) for simple situations. Files containing a single integer value can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) created with any of::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) void debugfs_create_u8(const char *name, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct dentry *parent, u8 *value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) void debugfs_create_u16(const char *name, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct dentry *parent, u16 *value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) void debugfs_create_u32(const char *name, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct dentry *parent, u32 *value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) void debugfs_create_u64(const char *name, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct dentry *parent, u64 *value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) These files support both reading and writing the given value; if a specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) file should not be written to, simply set the mode bits accordingly. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) values in these files are in decimal; if hexadecimal is more appropriate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) the following functions can be used instead::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) void debugfs_create_x8(const char *name, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) struct dentry *parent, u8 *value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) void debugfs_create_x16(const char *name, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct dentry *parent, u16 *value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) void debugfs_create_x32(const char *name, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) struct dentry *parent, u32 *value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) void debugfs_create_x64(const char *name, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct dentry *parent, u64 *value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) These functions are useful as long as the developer knows the size of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) value to be exported. Some types can have different widths on different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) architectures, though, complicating the situation somewhat. There are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) functions meant to help out in such special cases::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) void debugfs_create_size_t(const char *name, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct dentry *parent, size_t *value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) As might be expected, this function will create a debugfs file to represent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) a variable of type size_t.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) Similarly, there are helpers for variables of type unsigned long, in decimal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) and hexadecimal::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct dentry *debugfs_create_ulong(const char *name, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct dentry *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) unsigned long *value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) void debugfs_create_xul(const char *name, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct dentry *parent, unsigned long *value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) Boolean values can be placed in debugfs with::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct dentry *debugfs_create_bool(const char *name, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct dentry *parent, bool *value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) A read on the resulting file will yield either Y (for non-zero values) or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) N, followed by a newline. If written to, it will accept either upper- or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) lower-case values, or 1 or 0. Any other input will be silently ignored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) Also, atomic_t values can be placed in debugfs with::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) void debugfs_create_atomic_t(const char *name, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct dentry *parent, atomic_t *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) A read of this file will get atomic_t values, and a write of this file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) will set atomic_t values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) Another option is exporting a block of arbitrary binary data, with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) this structure and function::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct debugfs_blob_wrapper {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) void *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) unsigned long size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct dentry *debugfs_create_blob(const char *name, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct dentry *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct debugfs_blob_wrapper *blob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) A read of this file will return the data pointed to by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) debugfs_blob_wrapper structure. Some drivers use "blobs" as a simple way
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) to return several lines of (static) formatted text output. This function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) can be used to export binary information, but there does not appear to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) any code which does so in the mainline. Note that all files created with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) debugfs_create_blob() are read-only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) If you want to dump a block of registers (something that happens quite
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) often during development, even if little such code reaches mainline.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) Debugfs offers two functions: one to make a registers-only file, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) another to insert a register block in the middle of another sequential
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) file::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct debugfs_reg32 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) unsigned long offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct debugfs_regset32 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) const struct debugfs_reg32 *regs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) int nregs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) void __iomem *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct device *dev; /* Optional device for Runtime PM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) debugfs_create_regset32(const char *name, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct dentry *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct debugfs_regset32 *regset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) int nregs, void __iomem *base, char *prefix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) The "base" argument may be 0, but you may want to build the reg32 array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) using __stringify, and a number of register names (macros) are actually
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) byte offsets over a base for the register block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) If you want to dump an u32 array in debugfs, you can create file with::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct debugfs_u32_array {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) u32 *array;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) u32 n_elements;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) void debugfs_create_u32_array(const char *name, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) struct dentry *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct debugfs_u32_array *array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) The "array" argument wraps a pointer to the array's data and the number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) of its elements. Note: Once array is created its size can not be changed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) There is a helper function to create device related seq_file::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) void debugfs_create_devm_seqfile(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) struct dentry *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) int (*read_fn)(struct seq_file *s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) void *data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) The "dev" argument is the device related to this debugfs file, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) the "read_fn" is a function pointer which to be called to print the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) seq_file content.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) There are a couple of other directory-oriented helper functions::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct dentry *debugfs_rename(struct dentry *old_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct dentry *old_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) struct dentry *new_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) const char *new_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) struct dentry *debugfs_create_symlink(const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) struct dentry *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) const char *target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) A call to debugfs_rename() will give a new name to an existing debugfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) file, possibly in a different directory. The new_name must not exist prior
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) to the call; the return value is old_dentry with updated information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) Symbolic links can be created with debugfs_create_symlink().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) There is one important thing that all debugfs users must take into account:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) there is no automatic cleanup of any directories created in debugfs. If a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) module is unloaded without explicitly removing debugfs entries, the result
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) will be a lot of stale pointers and no end of highly antisocial behavior.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) So all debugfs users - at least those which can be built as modules - must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) be prepared to remove all files and directories they create there. A file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) can be removed with::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) void debugfs_remove(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) The dentry value can be NULL or an error value, in which case nothing will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) be removed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) Once upon a time, debugfs users were required to remember the dentry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) pointer for every debugfs file they created so that all files could be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) cleaned up. We live in more civilized times now, though, and debugfs users
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) can call::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) void debugfs_remove_recursive(struct dentry *dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) If this function is passed a pointer for the dentry corresponding to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) top-level directory, the entire hierarchy below that directory will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) removed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) .. [1] http://lwn.net/Articles/309298/