static int debugfs_create_by_name(const char *name, mode_t mode, struct dentry *parent, struct dentry **dentry) { int error = 0; /* If the parent is not specified, we create it in the root. * We need the root dentry to do this, which is in the super * block. A pointer to that is in the struct vfsmount that we * have around. */ if (!parent ) { if (debugfs_mount && debugfs_mount->mnt_sb) { parent = debugfs_mount->mnt_sb->s_root; } } if (!parent) { pr_debug("debugfs: Ah! can not find a parent!\n"); return -EFAULT; } *dentry = NULL; mutex_lock(&parent->d_inode->i_mutex); *dentry = lookup_one_len(name, parent, strlen(name)); if (!IS_ERR(dentry)) { if ((mode & S_IFMT) == S_IFDIR) error = debugfs_mkdir(parent->d_inode, *dentry, mode); else error = debugfs_create(parent->d_inode, *dentry, mode); } else error = PTR_ERR(dentry); mutex_unlock(&parent->d_inode->i_mutex); return error; }
struct dentry *__create_file(const char *name, umode_t mode, struct dentry *parent, void *data, const struct file_operations *fops) { struct dentry *dentry = NULL; int error; pr_debug("debugfs: creating file '%s'\n",name); error = simple_pin_fs(&debug_fs_type, &debugfs_mount, &debugfs_mount_count); if (error) goto exit; /* If the parent is not specified, we create it in the root. * We need the root dentry to do this, which is in the super * block. A pointer to that is in the struct vfsmount that we * have around. */ if (!parent) parent = debugfs_mount->mnt_root; dentry = NULL; mutex_lock(&parent->d_inode->i_mutex); dentry = lookup_one_len(name, parent, strlen(name)); if (!IS_ERR(dentry)) { switch (mode & S_IFMT) { case S_IFDIR: error = debugfs_mkdir(parent->d_inode, dentry, mode); break; case S_IFLNK: error = debugfs_link(parent->d_inode, dentry, mode, data); break; default: error = debugfs_create(parent->d_inode, dentry, mode, data, fops); break; } dput(dentry); } else error = PTR_ERR(dentry); mutex_unlock(&parent->d_inode->i_mutex); if (error) { dentry = NULL; simple_release_fs(&debugfs_mount, &debugfs_mount_count); } exit: return dentry; }
static int debugfs_create_by_name(const char *name, mode_t mode, struct dentry *parent, struct dentry **dentry, void *data, const struct file_operations *fops) { int error = 0; /* If the parent is not specified, we create it in the root. * We need the root dentry to do this, which is in the super * block. A pointer to that is in the struct vfsmount that we * have around. */ if (!parent) { if (debugfs_mount && debugfs_mount->mnt_sb) { parent = debugfs_mount->mnt_sb->s_root; } } if (!parent) { pr_debug("debugfs: Ah! can not find a parent!\n"); return -EFAULT; } *dentry = NULL; mutex_lock(&parent->d_inode->i_mutex); *dentry = lookup_one_len(name, parent, strlen(name)); if (!IS_ERR(*dentry)) { switch (mode & S_IFMT) { case S_IFDIR: error = debugfs_mkdir(parent->d_inode, *dentry, mode, data, fops); break; case S_IFLNK: error = debugfs_link(parent->d_inode, *dentry, mode, data, fops); break; default: error = debugfs_create(parent->d_inode, *dentry, mode, data, fops); break; } dput(*dentry); } else error = PTR_ERR(*dentry); mutex_unlock(&parent->d_inode->i_mutex); return error; }