ksysfs.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #ifdef CONFIG_HOTPLUG
  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. #ifdef CONFIG_KEXEC
  46. #include <asm/kexec.h>
  47. static ssize_t crash_notes_show(struct subsystem *subsys, char *page)
  48. {
  49. return sprintf(page, "%p\n", (void *)crash_notes);
  50. }
  51. KERNEL_ATTR_RO(crash_notes);
  52. #endif
  53. decl_subsys(kernel, NULL, NULL);
  54. EXPORT_SYMBOL_GPL(kernel_subsys);
  55. static struct attribute * kernel_attrs[] = {
  56. #ifdef CONFIG_HOTPLUG
  57. &uevent_seqnum_attr.attr,
  58. &uevent_helper_attr.attr,
  59. #endif
  60. #ifdef CONFIG_KEXEC
  61. &crash_notes_attr.attr,
  62. #endif
  63. NULL
  64. };
  65. static struct attribute_group kernel_attr_group = {
  66. .attrs = kernel_attrs,
  67. };
  68. static int __init ksysfs_init(void)
  69. {
  70. int error = subsystem_register(&kernel_subsys);
  71. if (!error)
  72. error = sysfs_create_group(&kernel_subsys.kset.kobj,
  73. &kernel_attr_group);
  74. return error;
  75. }
  76. core_initcall(ksysfs_init);