1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * sysfs.h - definitions for the device driver filesystem 4 * 5 * Copyright (c) 2001,2002 Patrick Mochel 6 * Copyright (c) 2004 Silicon Graphics, Inc. 7 * Copyright (c) 2007 SUSE Linux Products GmbH 8 * Copyright (c) 2007 Tejun Heo <[email protected]> 9 * 10 * Please see Documentation/filesystems/sysfs.rst for more information. 11 */ 12 13 #ifndef _SYSFS_H_ 14 #define _SYSFS_H_ 15 16 #include <linux/kernfs.h> 17 #include <linux/compiler.h> 18 #include <linux/errno.h> 19 #include <linux/list.h> 20 #include <linux/lockdep.h> 21 #include <linux/kobject_ns.h> 22 #include <linux/stat.h> 23 #include <linux/atomic.h> 24 25 struct kobject; 26 struct module; 27 struct bin_attribute; 28 enum kobj_ns_type; 29 30 struct attribute { 31 const char *name; 32 umode_t mode; 33 #ifdef CONFIG_DEBUG_LOCK_ALLOC 34 bool ignore_lockdep:1; 35 struct lock_class_key *key; 36 struct lock_class_key skey; 37 #endif 38 }; 39 40 /** 41 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute 42 * @attr: struct attribute to initialize 43 * 44 * Initialize a dynamically allocated struct attribute so we can 45 * make lockdep happy. This is a new requirement for attributes 46 * and initially this is only needed when lockdep is enabled. 47 * Lockdep gives a nice error when your attribute is added to 48 * sysfs if you don't have this. 49 */ 50 #ifdef CONFIG_DEBUG_LOCK_ALLOC 51 #define sysfs_attr_init(attr) \ 52 do { \ 53 static struct lock_class_key __key; \ 54 \ 55 (attr)->key = &__key; \ 56 } while (0) 57 #else 58 #define sysfs_attr_init(attr) do {} while (0) 59 #endif 60 61 /** 62 * struct attribute_group - data structure used to declare an attribute group. 63 * @name: Optional: Attribute group name 64 * If specified, the attribute group will be created in a 65 * new subdirectory with this name. Additionally when a 66 * group is named, @is_visible and @is_bin_visible may 67 * return SYSFS_GROUP_INVISIBLE to control visibility of 68 * the directory itself. 69 * @is_visible: Optional: Function to return permissions associated with an 70 * attribute of the group. Will be called repeatedly for 71 * each non-binary attribute in the group. Only read/write 72 * permissions as well as SYSFS_PREALLOC are accepted. Must 73 * return 0 if an attribute is not visible. The returned 74 * value will replace static permissions defined in struct 75 * attribute. Use SYSFS_GROUP_VISIBLE() when assigning this 76 * callback to specify separate _group_visible() and 77 * _attr_visible() handlers. 78 * @is_bin_visible: 79 * Optional: Function to return permissions associated with a 80 * binary attribute of the group. Will be called repeatedly 81 * for each binary attribute in the group. Only read/write 82 * permissions as well as SYSFS_PREALLOC (and the 83 * visibility flags for named groups) are accepted. Must 84 * return 0 if a binary attribute is not visible. The 85 * returned value will replace static permissions defined 86 * in struct bin_attribute. If @is_visible is not set, Use 87 * SYSFS_GROUP_VISIBLE() when assigning this callback to 88 * specify separate _group_visible() and _attr_visible() 89 * handlers. 90 * @bin_size: 91 * Optional: Function to return the size of a binary attribute 92 * of the group. Will be called repeatedly for each binary 93 * attribute in the group. Overwrites the size field embedded 94 * inside the attribute itself. 95 * @attrs: Pointer to NULL terminated list of attributes. 96 * @bin_attrs: Pointer to NULL terminated list of binary attributes. 97 * Either attrs or bin_attrs or both must be provided. 98 */ 99 struct attribute_group { 100 const char *name; 101 umode_t (*is_visible)(struct kobject *, 102 struct attribute *, int); 103 umode_t (*is_bin_visible)(struct kobject *, 104 const struct bin_attribute *, int); 105 size_t (*bin_size)(struct kobject *, 106 const struct bin_attribute *, 107 int); 108 struct attribute **attrs; 109 struct bin_attribute **bin_attrs; 110 }; 111 112 #define SYSFS_PREALLOC 010000 113 #define SYSFS_GROUP_INVISIBLE 020000 114 115 /* 116 * DEFINE_SYSFS_GROUP_VISIBLE(name): 117 * A helper macro to pair with the assignment of ".is_visible = 118 * SYSFS_GROUP_VISIBLE(name)", that arranges for the directory 119 * associated with a named attribute_group to optionally be hidden. 120 * This allows for static declaration of attribute_groups, and the 121 * simplification of attribute visibility lifetime that implies, 122 * without polluting sysfs with empty attribute directories. 123 * Ex. 124 * 125 * static umode_t example_attr_visible(struct kobject *kobj, 126 * struct attribute *attr, int n) 127 * { 128 * if (example_attr_condition) 129 * return 0; 130 * else if (ro_attr_condition) 131 * return 0444; 132 * return a->mode; 133 * } 134 * 135 * static bool example_group_visible(struct kobject *kobj) 136 * { 137 * if (example_group_condition) 138 * return false; 139 * return true; 140 * } 141 * 142 * DEFINE_SYSFS_GROUP_VISIBLE(example); 143 * 144 * static struct attribute_group example_group = { 145 * .name = "example", 146 * .is_visible = SYSFS_GROUP_VISIBLE(example), 147 * .attrs = &example_attrs, 148 * }; 149 * 150 * Note that it expects <name>_attr_visible and <name>_group_visible to 151 * be defined. For cases where individual attributes do not need 152 * separate visibility consideration, only entire group visibility at 153 * once, see DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(). 154 */ 155 #define DEFINE_SYSFS_GROUP_VISIBLE(name) \ 156 static inline umode_t sysfs_group_visible_##name( \ 157 struct kobject *kobj, struct attribute *attr, int n) \ 158 { \ 159 if (n == 0 && !name##_group_visible(kobj)) \ 160 return SYSFS_GROUP_INVISIBLE; \ 161 return name##_attr_visible(kobj, attr, n); \ 162 } 163 164 /* 165 * DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(name): 166 * A helper macro to pair with SYSFS_GROUP_VISIBLE() that like 167 * DEFINE_SYSFS_GROUP_VISIBLE() controls group visibility, but does 168 * not require the implementation of a per-attribute visibility 169 * callback. 170 * Ex. 171 * 172 * static bool example_group_visible(struct kobject *kobj) 173 * { 174 * if (example_group_condition) 175 * return false; 176 * return true; 177 * } 178 * 179 * DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(example); 180 * 181 * static struct attribute_group example_group = { 182 * .name = "example", 183 * .is_visible = SYSFS_GROUP_VISIBLE(example), 184 * .attrs = &example_attrs, 185 * }; 186 */ 187 #define DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(name) \ 188 static inline umode_t sysfs_group_visible_##name( \ 189 struct kobject *kobj, struct attribute *a, int n) \ 190 { \ 191 if (n == 0 && !name##_group_visible(kobj)) \ 192 return SYSFS_GROUP_INVISIBLE; \ 193 return a->mode; \ 194 } 195 196 /* 197 * Same as DEFINE_SYSFS_GROUP_VISIBLE, but for groups with only binary 198 * attributes. If an attribute_group defines both text and binary 199 * attributes, the group visibility is determined by the function 200 * specified to is_visible() not is_bin_visible() 201 */ 202 #define DEFINE_SYSFS_BIN_GROUP_VISIBLE(name) \ 203 static inline umode_t sysfs_group_visible_##name( \ 204 struct kobject *kobj, const struct bin_attribute *attr, int n) \ 205 { \ 206 if (n == 0 && !name##_group_visible(kobj)) \ 207 return SYSFS_GROUP_INVISIBLE; \ 208 return name##_attr_visible(kobj, attr, n); \ 209 } 210 211 #define DEFINE_SIMPLE_SYSFS_BIN_GROUP_VISIBLE(name) \ 212 static inline umode_t sysfs_group_visible_##name( \ 213 struct kobject *kobj, const struct bin_attribute *a, int n) \ 214 { \ 215 if (n == 0 && !name##_group_visible(kobj)) \ 216 return SYSFS_GROUP_INVISIBLE; \ 217 return a->mode; \ 218 } 219 220 #define SYSFS_GROUP_VISIBLE(fn) sysfs_group_visible_##fn 221 222 /* 223 * Use these macros to make defining attributes easier. 224 * See include/linux/device.h for examples.. 225 */ 226 227 #define __ATTR(_name, _mode, _show, _store) { \ 228 .attr = {.name = __stringify(_name), \ 229 .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \ 230 .show = _show, \ 231 .store = _store, \ 232 } 233 234 #define __ATTR_PREALLOC(_name, _mode, _show, _store) { \ 235 .attr = {.name = __stringify(_name), \ 236 .mode = SYSFS_PREALLOC | VERIFY_OCTAL_PERMISSIONS(_mode) },\ 237 .show = _show, \ 238 .store = _store, \ 239 } 240 241 #define __ATTR_RO(_name) { \ 242 .attr = { .name = __stringify(_name), .mode = 0444 }, \ 243 .show = _name##_show, \ 244 } 245 246 #define __ATTR_RO_MODE(_name, _mode) { \ 247 .attr = { .name = __stringify(_name), \ 248 .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \ 249 .show = _name##_show, \ 250 } 251 252 #define __ATTR_RW_MODE(_name, _mode) { \ 253 .attr = { .name = __stringify(_name), \ 254 .mode = VERIFY_OCTAL_PERMISSIONS(_mode) }, \ 255 .show = _name##_show, \ 256 .store = _name##_store, \ 257 } 258 259 #define __ATTR_WO(_name) { \ 260 .attr = { .name = __stringify(_name), .mode = 0200 }, \ 261 .store = _name##_store, \ 262 } 263 264 #define __ATTR_RW(_name) __ATTR(_name, 0644, _name##_show, _name##_store) 265 266 #define __ATTR_NULL { .attr = { .name = NULL } } 267 268 #ifdef CONFIG_DEBUG_LOCK_ALLOC 269 #define __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) { \ 270 .attr = {.name = __stringify(_name), .mode = _mode, \ 271 .ignore_lockdep = true }, \ 272 .show = _show, \ 273 .store = _store, \ 274 } 275 #else 276 #define __ATTR_IGNORE_LOCKDEP __ATTR 277 #endif 278 279 #define __ATTRIBUTE_GROUPS(_name) \ 280 static const struct attribute_group *_name##_groups[] = { \ 281 &_name##_group, \ 282 NULL, \ 283 } 284 285 #define ATTRIBUTE_GROUPS(_name) \ 286 static const struct attribute_group _name##_group = { \ 287 .attrs = _name##_attrs, \ 288 }; \ 289 __ATTRIBUTE_GROUPS(_name) 290 291 #define BIN_ATTRIBUTE_GROUPS(_name) \ 292 static const struct attribute_group _name##_group = { \ 293 .bin_attrs = _name##_attrs, \ 294 }; \ 295 __ATTRIBUTE_GROUPS(_name) 296 297 struct file; 298 struct vm_area_struct; 299 struct address_space; 300 301 struct bin_attribute { 302 struct attribute attr; 303 size_t size; 304 void *private; 305 struct address_space *(*f_mapping)(void); 306 ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *, 307 char *, loff_t, size_t); 308 ssize_t (*write)(struct file *, struct kobject *, struct bin_attribute *, 309 char *, loff_t, size_t); 310 loff_t (*llseek)(struct file *, struct kobject *, const struct bin_attribute *, 311 loff_t, int); 312 int (*mmap)(struct file *, struct kobject *, const struct bin_attribute *attr, 313 struct vm_area_struct *vma); 314 }; 315 316 /** 317 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute 318 * @attr: struct bin_attribute to initialize 319 * 320 * Initialize a dynamically allocated struct bin_attribute so we 321 * can make lockdep happy. This is a new requirement for 322 * attributes and initially this is only needed when lockdep is 323 * enabled. Lockdep gives a nice error when your attribute is 324 * added to sysfs if you don't have this. 325 */ 326 #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr) 327 328 /* macros to create static binary attributes easier */ 329 #define __BIN_ATTR(_name, _mode, _read, _write, _size) { \ 330 .attr = { .name = __stringify(_name), .mode = _mode }, \ 331 .read = _read, \ 332 .write = _write, \ 333 .size = _size, \ 334 } 335 336 #define __BIN_ATTR_RO(_name, _size) { \ 337 .attr = { .name = __stringify(_name), .mode = 0444 }, \ 338 .read = _name##_read, \ 339 .size = _size, \ 340 } 341 342 #define __BIN_ATTR_WO(_name, _size) { \ 343 .attr = { .name = __stringify(_name), .mode = 0200 }, \ 344 .write = _name##_write, \ 345 .size = _size, \ 346 } 347 348 #define __BIN_ATTR_RW(_name, _size) \ 349 __BIN_ATTR(_name, 0644, _name##_read, _name##_write, _size) 350 351 #define __BIN_ATTR_NULL __ATTR_NULL 352 353 #define BIN_ATTR(_name, _mode, _read, _write, _size) \ 354 struct bin_attribute bin_attr_##_name = __BIN_ATTR(_name, _mode, _read, \ 355 _write, _size) 356 357 #define BIN_ATTR_RO(_name, _size) \ 358 struct bin_attribute bin_attr_##_name = __BIN_ATTR_RO(_name, _size) 359 360 #define BIN_ATTR_WO(_name, _size) \ 361 struct bin_attribute bin_attr_##_name = __BIN_ATTR_WO(_name, _size) 362 363 #define BIN_ATTR_RW(_name, _size) \ 364 struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size) 365 366 367 #define __BIN_ATTR_ADMIN_RO(_name, _size) { \ 368 .attr = { .name = __stringify(_name), .mode = 0400 }, \ 369 .read = _name##_read, \ 370 .size = _size, \ 371 } 372 373 #define __BIN_ATTR_ADMIN_RW(_name, _size) \ 374 __BIN_ATTR(_name, 0600, _name##_read, _name##_write, _size) 375 376 #define BIN_ATTR_ADMIN_RO(_name, _size) \ 377 struct bin_attribute bin_attr_##_name = __BIN_ATTR_ADMIN_RO(_name, _size) 378 379 #define BIN_ATTR_ADMIN_RW(_name, _size) \ 380 struct bin_attribute bin_attr_##_name = __BIN_ATTR_ADMIN_RW(_name, _size) 381 382 #define __BIN_ATTR_SIMPLE_RO(_name, _mode) { \ 383 .attr = { .name = __stringify(_name), .mode = _mode }, \ 384 .read = sysfs_bin_attr_simple_read, \ 385 } 386 387 #define BIN_ATTR_SIMPLE_RO(_name) \ 388 struct bin_attribute bin_attr_##_name = __BIN_ATTR_SIMPLE_RO(_name, 0444) 389 390 #define BIN_ATTR_SIMPLE_ADMIN_RO(_name) \ 391 struct bin_attribute bin_attr_##_name = __BIN_ATTR_SIMPLE_RO(_name, 0400) 392 393 struct sysfs_ops { 394 ssize_t (*show)(struct kobject *, struct attribute *, char *); 395 ssize_t (*store)(struct kobject *, struct attribute *, const char *, size_t); 396 }; 397 398 #ifdef CONFIG_SYSFS 399 400 int __must_check sysfs_create_dir_ns(struct kobject *kobj, const void *ns); 401 void sysfs_remove_dir(struct kobject *kobj); 402 int __must_check sysfs_rename_dir_ns(struct kobject *kobj, const char *new_name, 403 const void *new_ns); 404 int __must_check sysfs_move_dir_ns(struct kobject *kobj, 405 struct kobject *new_parent_kobj, 406 const void *new_ns); 407 int __must_check sysfs_create_mount_point(struct kobject *parent_kobj, 408 const char *name); 409 void sysfs_remove_mount_point(struct kobject *parent_kobj, 410 const char *name); 411 412 int __must_check sysfs_create_file_ns(struct kobject *kobj, 413 const struct attribute *attr, 414 const void *ns); 415 int __must_check sysfs_create_files(struct kobject *kobj, 416 const struct attribute * const *attr); 417 int __must_check sysfs_chmod_file(struct kobject *kobj, 418 const struct attribute *attr, umode_t mode); 419 struct kernfs_node *sysfs_break_active_protection(struct kobject *kobj, 420 const struct attribute *attr); 421 void sysfs_unbreak_active_protection(struct kernfs_node *kn); 422 void sysfs_remove_file_ns(struct kobject *kobj, const struct attribute *attr, 423 const void *ns); 424 bool sysfs_remove_file_self(struct kobject *kobj, const struct attribute *attr); 425 void sysfs_remove_files(struct kobject *kobj, const struct attribute * const *attr); 426 427 int __must_check sysfs_create_bin_file(struct kobject *kobj, 428 const struct bin_attribute *attr); 429 void sysfs_remove_bin_file(struct kobject *kobj, 430 const struct bin_attribute *attr); 431 432 int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target, 433 const char *name); 434 int __must_check sysfs_create_link_nowarn(struct kobject *kobj, 435 struct kobject *target, 436 const char *name); 437 void sysfs_remove_link(struct kobject *kobj, const char *name); 438 439 int sysfs_rename_link_ns(struct kobject *kobj, struct kobject *target, 440 const char *old_name, const char *new_name, 441 const void *new_ns); 442 443 void sysfs_delete_link(struct kobject *dir, struct kobject *targ, 444 const char *name); 445 446 int __must_check sysfs_create_group(struct kobject *kobj, 447 const struct attribute_group *grp); 448 int __must_check sysfs_create_groups(struct kobject *kobj, 449 const struct attribute_group **groups); 450 int __must_check sysfs_update_groups(struct kobject *kobj, 451 const struct attribute_group **groups); 452 int sysfs_update_group(struct kobject *kobj, 453 const struct attribute_group *grp); 454 void sysfs_remove_group(struct kobject *kobj, 455 const struct attribute_group *grp); 456 void sysfs_remove_groups(struct kobject *kobj, 457 const struct attribute_group **groups); 458 int sysfs_add_file_to_group(struct kobject *kobj, 459 const struct attribute *attr, const char *group); 460 void sysfs_remove_file_from_group(struct kobject *kobj, 461 const struct attribute *attr, const char *group); 462 int sysfs_merge_group(struct kobject *kobj, 463 const struct attribute_group *grp); 464 void sysfs_unmerge_group(struct kobject *kobj, 465 const struct attribute_group *grp); 466 int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name, 467 struct kobject *target, const char *link_name); 468 void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name, 469 const char *link_name); 470 int compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj, 471 struct kobject *target_kobj, 472 const char *target_name, 473 const char *symlink_name); 474 475 void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr); 476 477 int __must_check sysfs_init(void); 478 479 static inline void sysfs_enable_ns(struct kernfs_node *kn) 480 { 481 return kernfs_enable_ns(kn); 482 } 483 484 int sysfs_file_change_owner(struct kobject *kobj, const char *name, kuid_t kuid, 485 kgid_t kgid); 486 int sysfs_change_owner(struct kobject *kobj, kuid_t kuid, kgid_t kgid); 487 int sysfs_link_change_owner(struct kobject *kobj, struct kobject *targ, 488 const char *name, kuid_t kuid, kgid_t kgid); 489 int sysfs_groups_change_owner(struct kobject *kobj, 490 const struct attribute_group **groups, 491 kuid_t kuid, kgid_t kgid); 492 int sysfs_group_change_owner(struct kobject *kobj, 493 const struct attribute_group *groups, kuid_t kuid, 494 kgid_t kgid); 495 __printf(2, 3) 496 int sysfs_emit(char *buf, const char *fmt, ...); 497 __printf(3, 4) 498 int sysfs_emit_at(char *buf, int at, const char *fmt, ...); 499 500 ssize_t sysfs_bin_attr_simple_read(struct file *file, struct kobject *kobj, 501 struct bin_attribute *attr, char *buf, 502 loff_t off, size_t count); 503 504 #else /* CONFIG_SYSFS */ 505 506 static inline int sysfs_create_dir_ns(struct kobject *kobj, const void *ns) 507 { 508 return 0; 509 } 510 511 static inline void sysfs_remove_dir(struct kobject *kobj) 512 { 513 } 514 515 static inline int sysfs_rename_dir_ns(struct kobject *kobj, 516 const char *new_name, const void *new_ns) 517 { 518 return 0; 519 } 520 521 static inline int sysfs_move_dir_ns(struct kobject *kobj, 522 struct kobject *new_parent_kobj, 523 const void *new_ns) 524 { 525 return 0; 526 } 527 528 static inline int sysfs_create_mount_point(struct kobject *parent_kobj, 529 const char *name) 530 { 531 return 0; 532 } 533 534 static inline void sysfs_remove_mount_point(struct kobject *parent_kobj, 535 const char *name) 536 { 537 } 538 539 static inline int sysfs_create_file_ns(struct kobject *kobj, 540 const struct attribute *attr, 541 const void *ns) 542 { 543 return 0; 544 } 545 546 static inline int sysfs_create_files(struct kobject *kobj, 547 const struct attribute * const *attr) 548 { 549 return 0; 550 } 551 552 static inline int sysfs_chmod_file(struct kobject *kobj, 553 const struct attribute *attr, umode_t mode) 554 { 555 return 0; 556 } 557 558 static inline struct kernfs_node * 559 sysfs_break_active_protection(struct kobject *kobj, 560 const struct attribute *attr) 561 { 562 return NULL; 563 } 564 565 static inline void sysfs_unbreak_active_protection(struct kernfs_node *kn) 566 { 567 } 568 569 static inline void sysfs_remove_file_ns(struct kobject *kobj, 570 const struct attribute *attr, 571 const void *ns) 572 { 573 } 574 575 static inline bool sysfs_remove_file_self(struct kobject *kobj, 576 const struct attribute *attr) 577 { 578 return false; 579 } 580 581 static inline void sysfs_remove_files(struct kobject *kobj, 582 const struct attribute * const *attr) 583 { 584 } 585 586 static inline int sysfs_create_bin_file(struct kobject *kobj, 587 const struct bin_attribute *attr) 588 { 589 return 0; 590 } 591 592 static inline void sysfs_remove_bin_file(struct kobject *kobj, 593 const struct bin_attribute *attr) 594 { 595 } 596 597 static inline int sysfs_create_link(struct kobject *kobj, 598 struct kobject *target, const char *name) 599 { 600 return 0; 601 } 602 603 static inline int sysfs_create_link_nowarn(struct kobject *kobj, 604 struct kobject *target, 605 const char *name) 606 { 607 return 0; 608 } 609 610 static inline void sysfs_remove_link(struct kobject *kobj, const char *name) 611 { 612 } 613 614 static inline int sysfs_rename_link_ns(struct kobject *k, struct kobject *t, 615 const char *old_name, 616 const char *new_name, const void *ns) 617 { 618 return 0; 619 } 620 621 static inline void sysfs_delete_link(struct kobject *k, struct kobject *t, 622 const char *name) 623 { 624 } 625 626 static inline int sysfs_create_group(struct kobject *kobj, 627 const struct attribute_group *grp) 628 { 629 return 0; 630 } 631 632 static inline int sysfs_create_groups(struct kobject *kobj, 633 const struct attribute_group **groups) 634 { 635 return 0; 636 } 637 638 static inline int sysfs_update_groups(struct kobject *kobj, 639 const struct attribute_group **groups) 640 { 641 return 0; 642 } 643 644 static inline int sysfs_update_group(struct kobject *kobj, 645 const struct attribute_group *grp) 646 { 647 return 0; 648 } 649 650 static inline void sysfs_remove_group(struct kobject *kobj, 651 const struct attribute_group *grp) 652 { 653 } 654 655 static inline void sysfs_remove_groups(struct kobject *kobj, 656 const struct attribute_group **groups) 657 { 658 } 659 660 static inline int sysfs_add_file_to_group(struct kobject *kobj, 661 const struct attribute *attr, const char *group) 662 { 663 return 0; 664 } 665 666 static inline void sysfs_remove_file_from_group(struct kobject *kobj, 667 const struct attribute *attr, const char *group) 668 { 669 } 670 671 static inline int sysfs_merge_group(struct kobject *kobj, 672 const struct attribute_group *grp) 673 { 674 return 0; 675 } 676 677 static inline void sysfs_unmerge_group(struct kobject *kobj, 678 const struct attribute_group *grp) 679 { 680 } 681 682 static inline int sysfs_add_link_to_group(struct kobject *kobj, 683 const char *group_name, struct kobject *target, 684 const char *link_name) 685 { 686 return 0; 687 } 688 689 static inline void sysfs_remove_link_from_group(struct kobject *kobj, 690 const char *group_name, const char *link_name) 691 { 692 } 693 694 static inline int compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj, 695 struct kobject *target_kobj, 696 const char *target_name, 697 const char *symlink_name) 698 { 699 return 0; 700 } 701 702 static inline void sysfs_notify(struct kobject *kobj, const char *dir, 703 const char *attr) 704 { 705 } 706 707 static inline int __must_check sysfs_init(void) 708 { 709 return 0; 710 } 711 712 static inline void sysfs_enable_ns(struct kernfs_node *kn) 713 { 714 } 715 716 static inline int sysfs_file_change_owner(struct kobject *kobj, 717 const char *name, kuid_t kuid, 718 kgid_t kgid) 719 { 720 return 0; 721 } 722 723 static inline int sysfs_link_change_owner(struct kobject *kobj, 724 struct kobject *targ, 725 const char *name, kuid_t kuid, 726 kgid_t kgid) 727 { 728 return 0; 729 } 730 731 static inline int sysfs_change_owner(struct kobject *kobj, kuid_t kuid, kgid_t kgid) 732 { 733 return 0; 734 } 735 736 static inline int sysfs_groups_change_owner(struct kobject *kobj, 737 const struct attribute_group **groups, 738 kuid_t kuid, kgid_t kgid) 739 { 740 return 0; 741 } 742 743 static inline int sysfs_group_change_owner(struct kobject *kobj, 744 const struct attribute_group *groups, 745 kuid_t kuid, kgid_t kgid) 746 { 747 return 0; 748 } 749 750 __printf(2, 3) 751 static inline int sysfs_emit(char *buf, const char *fmt, ...) 752 { 753 return 0; 754 } 755 756 __printf(3, 4) 757 static inline int sysfs_emit_at(char *buf, int at, const char *fmt, ...) 758 { 759 return 0; 760 } 761 762 static inline ssize_t sysfs_bin_attr_simple_read(struct file *file, 763 struct kobject *kobj, 764 struct bin_attribute *attr, 765 char *buf, loff_t off, 766 size_t count) 767 { 768 return 0; 769 } 770 #endif /* CONFIG_SYSFS */ 771 772 static inline int __must_check sysfs_create_file(struct kobject *kobj, 773 const struct attribute *attr) 774 { 775 return sysfs_create_file_ns(kobj, attr, NULL); 776 } 777 778 static inline void sysfs_remove_file(struct kobject *kobj, 779 const struct attribute *attr) 780 { 781 sysfs_remove_file_ns(kobj, attr, NULL); 782 } 783 784 static inline int sysfs_rename_link(struct kobject *kobj, struct kobject *target, 785 const char *old_name, const char *new_name) 786 { 787 return sysfs_rename_link_ns(kobj, target, old_name, new_name, NULL); 788 } 789 790 static inline void sysfs_notify_dirent(struct kernfs_node *kn) 791 { 792 kernfs_notify(kn); 793 } 794 795 static inline struct kernfs_node *sysfs_get_dirent(struct kernfs_node *parent, 796 const char *name) 797 { 798 return kernfs_find_and_get(parent, name); 799 } 800 801 static inline struct kernfs_node *sysfs_get(struct kernfs_node *kn) 802 { 803 kernfs_get(kn); 804 return kn; 805 } 806 807 static inline void sysfs_put(struct kernfs_node *kn) 808 { 809 kernfs_put(kn); 810 } 811 812 #endif /* _SYSFS_H_ */ 813