ksysfs.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * kernel/ksysfs.c - sysfs attributes in /sys/kernel, which
  3. * are not related to any other subsystem
  4. *
  5. * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
  6. *
  7. * This file is release under the GPLv2
  8. *
  9. */
  10. #include <linux/config.h>
  11. #include <linux/kobject.h>
  12. #include <linux/string.h>
  13. #include <linux/sysfs.h>
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #define KERNEL_ATTR_RO(_name) \
  17. static struct subsys_attribute _name##_attr = __ATTR_RO(_name)
  18. #define KERNEL_ATTR_RW(_name) \
  19. static struct subsys_attribute _name##_attr = \
  20. __ATTR(_name, 0644, _name##_show, _name##_store)
  21. #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
  22. /* current uevent sequence number */
  23. static ssize_t uevent_seqnum_show(struct subsystem *subsys, char *page)
  24. {
  25. return sprintf(page, "%llu\n", (unsigned long long)uevent_seqnum);
  26. }
  27. KERNEL_ATTR_RO(uevent_seqnum);
  28. /* uevent helper program, used during early boo */
  29. static ssize_t uevent_helper_show(struct subsystem *subsys, char *page)
  30. {
  31. return sprintf(page, "%s\n", uevent_helper);
  32. }
  33. static ssize_t uevent_helper_store(struct subsystem *subsys, const char *page, size_t count)
  34. {
  35. if (count+1 > UEVENT_HELPER_PATH_LEN)
  36. return -ENOENT;
  37. memcpy(uevent_helper, page, count);
  38. uevent_helper[count] = '\0';
  39. if (count && uevent_helper[count-1] == '\n')
  40. uevent_helper[count-1] = '\0';
  41. return count;
  42. }
  43. KERNEL_ATTR_RW(uevent_helper);
  44. #endif
  45. decl_subsys(kernel, NULL, NULL);
  46. EXPORT_SYMBOL_GPL(kernel_subsys);
  47. static struct attribute * kernel_attrs[] = {
  48. #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
  49. &uevent_seqnum_attr.attr,
  50. &uevent_helper_attr.attr,
  51. #endif
  52. NULL
  53. };
  54. static struct attribute_group kernel_attr_group = {
  55. .attrs = kernel_attrs,
  56. };
  57. static int __init ksysfs_init(void)
  58. {
  59. int error = subsystem_register(&kernel_subsys);
  60. if (!error)
  61. error = sysfs_create_group(&kernel_subsys.kset.kobj,
  62. &kernel_attr_group);
  63. return error;
  64. }
  65. core_initcall(ksysfs_init);