ksysfs.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. u64 uevent_seqnum;
  17. char uevent_helper[UEVENT_HELPER_PATH_LEN] = "/sbin/hotplug";
  18. #define KERNEL_ATTR_RO(_name) \
  19. static struct subsys_attribute _name##_attr = __ATTR_RO(_name)
  20. #define KERNEL_ATTR_RW(_name) \
  21. static struct subsys_attribute _name##_attr = \
  22. __ATTR(_name, 0644, _name##_show, _name##_store)
  23. #ifdef CONFIG_HOTPLUG
  24. /* current uevent sequence number */
  25. static ssize_t uevent_seqnum_show(struct subsystem *subsys, char *page)
  26. {
  27. return sprintf(page, "%llu\n", (unsigned long long)uevent_seqnum);
  28. }
  29. KERNEL_ATTR_RO(uevent_seqnum);
  30. /* uevent helper program, used during early boo */
  31. static ssize_t uevent_helper_show(struct subsystem *subsys, char *page)
  32. {
  33. return sprintf(page, "%s\n", uevent_helper);
  34. }
  35. static ssize_t uevent_helper_store(struct subsystem *subsys, const char *page, size_t count)
  36. {
  37. if (count+1 > UEVENT_HELPER_PATH_LEN)
  38. return -ENOENT;
  39. memcpy(uevent_helper, page, count);
  40. uevent_helper[count] = '\0';
  41. if (count && uevent_helper[count-1] == '\n')
  42. uevent_helper[count-1] = '\0';
  43. return count;
  44. }
  45. KERNEL_ATTR_RW(uevent_helper);
  46. #endif
  47. #ifdef CONFIG_KEXEC
  48. #include <asm/kexec.h>
  49. static ssize_t crash_notes_show(struct subsystem *subsys, char *page)
  50. {
  51. return sprintf(page, "%p\n", (void *)crash_notes);
  52. }
  53. KERNEL_ATTR_RO(crash_notes);
  54. #endif
  55. decl_subsys(kernel, NULL, NULL);
  56. EXPORT_SYMBOL_GPL(kernel_subsys);
  57. static struct attribute * kernel_attrs[] = {
  58. #ifdef CONFIG_HOTPLUG
  59. &uevent_seqnum_attr.attr,
  60. &uevent_helper_attr.attr,
  61. #endif
  62. #ifdef CONFIG_KEXEC
  63. &crash_notes_attr.attr,
  64. #endif
  65. NULL
  66. };
  67. static struct attribute_group kernel_attr_group = {
  68. .attrs = kernel_attrs,
  69. };
  70. static int __init ksysfs_init(void)
  71. {
  72. int error = subsystem_register(&kernel_subsys);
  73. if (!error)
  74. error = sysfs_create_group(&kernel_subsys.kset.kobj,
  75. &kernel_attr_group);
  76. return error;
  77. }
  78. core_initcall(ksysfs_init);