Lines Matching +full:- +full:grp

1 // SPDX-License-Identifier: GPL-2.0
3 * fs/sysfs/group.c - Operations for adding/removing multiple files at once.
7 * Copyright (c) 2013 Greg Kroah-Hartman
21 const struct attribute_group *grp) in remove_files() argument
26 if (grp->attrs) in remove_files()
27 for (attr = grp->attrs; *attr; attr++) in remove_files()
28 kernfs_remove_by_name(parent, (*attr)->name); in remove_files()
29 if (grp->bin_attrs) in remove_files()
30 for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++) in remove_files()
31 kernfs_remove_by_name(parent, (*bin_attr)->attr.name); in remove_files()
36 const struct attribute_group *grp, int update) in create_files() argument
42 if (grp->attrs) { in create_files()
43 for (i = 0, attr = grp->attrs; *attr && !error; i++, attr++) { in create_files()
44 umode_t mode = (*attr)->mode; in create_files()
49 * re-adding (if required) the file. in create_files()
52 kernfs_remove_by_name(parent, (*attr)->name); in create_files()
53 if (grp->is_visible) { in create_files()
54 mode = grp->is_visible(kobj, *attr, i); in create_files()
61 (*attr)->name, mode); in create_files()
70 remove_files(parent, grp); in create_files()
75 if (grp->bin_attrs) { in create_files()
76 for (i = 0, bin_attr = grp->bin_attrs; *bin_attr; i++, bin_attr++) { in create_files()
77 umode_t mode = (*bin_attr)->attr.mode; in create_files()
81 (*bin_attr)->attr.name); in create_files()
82 if (grp->is_bin_visible) { in create_files()
83 mode = grp->is_bin_visible(kobj, *bin_attr, i); in create_files()
90 (*bin_attr)->attr.name, mode); in create_files()
100 remove_files(parent, grp); in create_files()
108 const struct attribute_group *grp) in internal_create_group() argument
115 if (WARN_ON(!kobj || (!update && !kobj->sd))) in internal_create_group()
116 return -EINVAL; in internal_create_group()
119 if (unlikely(update && !kobj->sd)) in internal_create_group()
120 return -EINVAL; in internal_create_group()
122 if (!grp->attrs && !grp->bin_attrs) { in internal_create_group()
124 kobj->name, grp->name ?: ""); in internal_create_group()
129 if (grp->name) { in internal_create_group()
131 kn = kernfs_find_and_get(kobj->sd, grp->name); in internal_create_group()
133 pr_warn("Can't update unknown attr grp name: %s/%s\n", in internal_create_group()
134 kobj->name, grp->name); in internal_create_group()
135 return -EINVAL; in internal_create_group()
138 kn = kernfs_create_dir_ns(kobj->sd, grp->name, in internal_create_group()
142 if (PTR_ERR(kn) == -EEXIST) in internal_create_group()
143 sysfs_warn_dup(kobj->sd, grp->name); in internal_create_group()
148 kn = kobj->sd; in internal_create_group()
152 error = create_files(kn, kobj, uid, gid, grp, update); in internal_create_group()
154 if (grp->name) in internal_create_group()
159 if (grp->name && update) in internal_create_group()
166 * sysfs_create_group - given a directory kobject, create an attribute group
168 * @grp: The attribute group to create
176 const struct attribute_group *grp) in sysfs_create_group() argument
178 return internal_create_group(kobj, 0, grp); in sysfs_create_group()
194 while (--i >= 0) in internal_create_groups()
203 * sysfs_create_groups - given a directory kobject, create a bunch of attribute groups
223 * sysfs_update_groups - given a directory kobject, create a bunch of attribute groups
241 * sysfs_update_group - given a directory kobject, update an attribute group
243 * @grp: The attribute group to update
259 const struct attribute_group *grp) in sysfs_update_group() argument
261 return internal_create_group(kobj, 1, grp); in sysfs_update_group()
268 * @grp: group to remove
274 const struct attribute_group *grp) in sysfs_remove_group() argument
276 struct kernfs_node *parent = kobj->sd; in sysfs_remove_group()
279 if (grp->name) { in sysfs_remove_group()
280 kn = kernfs_find_and_get(parent, grp->name); in sysfs_remove_group()
284 grp->name, kobject_name(kobj)); in sysfs_remove_group()
292 remove_files(kn, grp); in sysfs_remove_group()
293 if (grp->name) in sysfs_remove_group()
301 * sysfs_remove_groups - remove a list of groups
321 * sysfs_merge_group - merge files into a pre-existing attribute group.
323 * @grp: The files to create and the attribute group they belong to.
330 const struct attribute_group *grp) in sysfs_merge_group() argument
339 parent = kernfs_find_and_get(kobj->sd, grp->name); in sysfs_merge_group()
341 return -ENOENT; in sysfs_merge_group()
345 for ((i = 0, attr = grp->attrs); *attr && !error; (++i, ++attr)) in sysfs_merge_group()
346 error = sysfs_add_file_mode_ns(parent, *attr, (*attr)->mode, in sysfs_merge_group()
349 while (--i >= 0) in sysfs_merge_group()
350 kernfs_remove_by_name(parent, (*--attr)->name); in sysfs_merge_group()
359 * sysfs_unmerge_group - remove files from a pre-existing attribute group.
361 * @grp: The files to remove and the attribute group they belong to.
364 const struct attribute_group *grp) in sysfs_unmerge_group() argument
369 parent = kernfs_find_and_get(kobj->sd, grp->name); in sysfs_unmerge_group()
371 for (attr = grp->attrs; *attr; ++attr) in sysfs_unmerge_group()
372 kernfs_remove_by_name(parent, (*attr)->name); in sysfs_unmerge_group()
379 * sysfs_add_link_to_group - add a symlink to an attribute group.
391 parent = kernfs_find_and_get(kobj->sd, group_name); in sysfs_add_link_to_group()
393 return -ENOENT; in sysfs_add_link_to_group()
403 * sysfs_remove_link_from_group - remove a symlink from an attribute group.
413 parent = kernfs_find_and_get(kobj->sd, group_name); in sysfs_remove_link_from_group()
422 * compat_only_sysfs_link_entry_to_kobj - add a symlink to a kobject pointing
445 target = target_kobj->sd; in compat_only_sysfs_link_entry_to_kobj()
450 return -ENOENT; in compat_only_sysfs_link_entry_to_kobj()
455 return -ENOENT; in compat_only_sysfs_link_entry_to_kobj()
461 link = kernfs_create_link(kobj->sd, symlink_name, entry); in compat_only_sysfs_link_entry_to_kobj()
462 if (PTR_ERR(link) == -EEXIST) in compat_only_sysfs_link_entry_to_kobj()
463 sysfs_warn_dup(kobj->sd, symlink_name); in compat_only_sysfs_link_entry_to_kobj()
472 const struct attribute_group *grp, in sysfs_group_attrs_change_owner() argument
478 if (grp->attrs) { in sysfs_group_attrs_change_owner()
481 for (attr = grp->attrs; *attr; attr++) { in sysfs_group_attrs_change_owner()
482 kn = kernfs_find_and_get(grp_kn, (*attr)->name); in sysfs_group_attrs_change_owner()
484 return -ENOENT; in sysfs_group_attrs_change_owner()
493 if (grp->bin_attrs) { in sysfs_group_attrs_change_owner()
496 for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++) { in sysfs_group_attrs_change_owner()
497 kn = kernfs_find_and_get(grp_kn, (*bin_attr)->attr.name); in sysfs_group_attrs_change_owner()
499 return -ENOENT; in sysfs_group_attrs_change_owner()
512 * sysfs_group_change_owner - change owner of an attribute group.
514 * @grp: The attribute group.
521 const struct attribute_group *grp, kuid_t kuid, in sysfs_group_change_owner() argument
532 if (!kobj->state_in_sysfs) in sysfs_group_change_owner()
533 return -EINVAL; in sysfs_group_change_owner()
535 if (grp->name) { in sysfs_group_change_owner()
536 grp_kn = kernfs_find_and_get(kobj->sd, grp->name); in sysfs_group_change_owner()
538 kernfs_get(kobj->sd); in sysfs_group_change_owner()
539 grp_kn = kobj->sd; in sysfs_group_change_owner()
542 return -ENOENT; in sysfs_group_change_owner()
546 error = sysfs_group_attrs_change_owner(grp_kn, grp, &newattrs); in sysfs_group_change_owner()
555 * sysfs_groups_change_owner - change owner of a set of attribute groups.
569 if (!kobj->state_in_sysfs) in sysfs_groups_change_owner()
570 return -EINVAL; in sysfs_groups_change_owner()