/** * sysfs_pathname - return full path to sysfs dirent * @kn: kernfs_node whose path we want * @path: caller allocated buffer of size PATH_MAX * * Gives the name "/" to the sysfs_root entry; any path returned * is relative to wherever sysfs is mounted. */ static char *sysfs_pathname(struct kernfs_node *kn, char *path) { if (kn->parent) { sysfs_pathname(kn->parent, path); strlcat(path, "/", PATH_MAX); } strlcat(path, kn->name, PATH_MAX); return path; }
/** * sysfs_pathname - return full path to sysfs dirent * @sd: sysfs_dirent whose path we want * @path: caller allocated buffer of size PATH_MAX * * Gives the name "/" to the sysfs_root entry; any path returned * is relative to wherever sysfs is mounted. */ static char *sysfs_pathname(struct sysfs_dirent *sd, char *path) { if (sd->s_parent) { sysfs_pathname(sd->s_parent, path); strlcat(path, "/", PATH_MAX); } strlcat(path, sd->s_name, PATH_MAX); return path; }
void sysfs_warn_dup(struct sysfs_dirent *parent, const char *name) { char *path; path = kzalloc(PATH_MAX, GFP_KERNEL); if (path) { sysfs_pathname(parent, path); strlcat(path, "/", PATH_MAX); strlcat(path, name, PATH_MAX); } WARN(1, KERN_WARNING "sysfs: cannot create duplicate filename '%s'\n", path ? path : name); kfree(path); }
/** * sysfs_add_one - add sysfs_dirent to parent * @acxt: addrm context to use * @sd: sysfs_dirent to be added * * Get @acxt->parent_sd and set sd->s_parent to it and increment * nlink of parent inode if @sd is a directory and link into the * children list of the parent. * * This function should be called between calls to * sysfs_addrm_start() and sysfs_addrm_finish() and should be * passed the same @acxt as passed to sysfs_addrm_start(). * * LOCKING: * Determined by sysfs_addrm_start(). * * RETURNS: * 0 on success, -EEXIST if entry with the given name already * exists. */ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd) { int ret; ret = __sysfs_add_one(acxt, sd); if (ret == -EEXIST) { char *path = kzalloc(PATH_MAX, GFP_KERNEL); WARN(1, KERN_WARNING "sysfs: cannot create duplicate filename '%s'\n", (path == NULL) ? sd->s_name : strcat(strcat(sysfs_pathname(acxt->parent_sd, path), "/"), sd->s_name)); kfree(path); } return ret; }