16 #include <linux/module.h>
25 #include <linux/string.h>
28 #include <linux/magic.h>
29 #include <linux/slab.h>
31 #define DEBUGFS_DEFAULT_MODE 0700
33 static struct vfsmount *debugfs_mount;
34 static int debugfs_mount_count;
35 static bool debugfs_registered;
84 inode = debugfs_get_inode(dir->
i_sb, mode, dev, data, fops);
93 static int debugfs_mkdir(
struct inode *dir,
struct dentry *dentry,
umode_t mode)
98 res = debugfs_mknod(dir, dentry, mode, 0,
NULL,
NULL);
101 fsnotify_mkdir(dir, dentry);
106 static int debugfs_link(
struct inode *dir,
struct dentry *dentry,
umode_t mode,
110 return debugfs_mknod(dir, dentry, mode, 0, data,
NULL);
113 static int debugfs_create(
struct inode *dir,
struct dentry *dentry,
umode_t mode,
119 res = debugfs_mknod(dir, dentry, mode, 0, data, fops);
121 fsnotify_create(dir, dentry);
125 static inline int debugfs_positive(
struct dentry *dentry)
127 return dentry->
d_inode && !d_unhashed(dentry);
205 struct inode *inode = sb->
s_root->d_inode;
222 err = debugfs_parse_options(data, &fsi->
mount_opts);
226 debugfs_apply_options(sb);
232 static int debugfs_show_options(
struct seq_file *
m,
struct dentry *root)
251 .remount_fs = debugfs_remount,
252 .show_options = debugfs_show_options,
255 static int debug_fill_super(
struct super_block *sb,
void *data,
int silent)
257 static struct tree_descr debug_files[] = {{
""}};
270 err = debugfs_parse_options(data, &fsi->
mount_opts);
278 sb->
s_op = &debugfs_super_operations;
280 debugfs_apply_options(sb);
291 int flags,
const char *dev_name,
294 return mount_single(fs_type, flags, data, debug_fill_super);
300 .mount = debug_mount,
304 static struct dentry *__create_file(
const char *
name,
umode_t mode,
305 struct dentry *parent,
void *data,
308 struct dentry *dentry =
NULL;
311 pr_debug(
"debugfs: creating file '%s'\n",name);
314 &debugfs_mount_count);
329 if (!IS_ERR(dentry)) {
332 error = debugfs_mkdir(parent->
d_inode, dentry, mode);
336 error = debugfs_link(parent->
d_inode, dentry, mode,
340 error = debugfs_create(parent->
d_inode, dentry, mode,
346 error = PTR_ERR(dentry);
384 struct dentry *parent,
void *data,
395 return __create_file(name, mode, parent, data, fops);
464 static int __debugfs_remove(
struct dentry *dentry,
struct dentry *parent)
468 if (debugfs_positive(dentry)) {
505 struct dentry *parent;
508 if (IS_ERR_OR_NULL(dentry))
512 if (!parent || !parent->
d_inode)
516 ret = __debugfs_remove(dentry, parent);
537 struct dentry *
child;
538 struct dentry *parent;
540 if (IS_ERR_OR_NULL(dentry))
544 if (!parent || !parent->
d_inode)
557 if (parent == dentry)
576 __debugfs_remove(child, parent);
600 __debugfs_remove(dentry, parent);
626 struct dentry *new_dir,
const char *new_name)
629 struct dentry *dentry =
NULL, *
trap;
630 const char *old_name;
637 if (!old_dentry->
d_inode || old_dentry == trap ||
638 d_mountpoint(old_dentry))
642 if (IS_ERR(dentry) || dentry == trap || dentry->
d_inode)
645 old_name = fsnotify_oldname_init(old_dentry->
d_name.name);
650 fsnotify_oldname_free(old_name);
653 d_move(old_dentry, dentry);
657 fsnotify_oldname_free(old_name);
662 if (dentry && !IS_ERR(dentry))
674 return debugfs_registered;
679 static struct kobject *debug_kobj;
681 static int __init debugfs_init(
void)
693 debugfs_registered =
true;