ksysfs.c 2.4 KB

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