ksysfs.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. static ssize_t hotplug_seqnum_show(struct subsystem *subsys, char *page)
  23. {
  24. return sprintf(page, "%llu\n", (unsigned long long)hotplug_seqnum);
  25. }
  26. KERNEL_ATTR_RO(hotplug_seqnum);
  27. #endif
  28. #ifdef CONFIG_KEXEC
  29. #include <asm/kexec.h>
  30. static ssize_t crash_notes_show(struct subsystem *subsys, char *page)
  31. {
  32. return sprintf(page, "%p\n", (void *)crash_notes);
  33. }
  34. KERNEL_ATTR_RO(crash_notes);
  35. #endif
  36. decl_subsys(kernel, NULL, NULL);
  37. EXPORT_SYMBOL_GPL(kernel_subsys);
  38. static struct attribute * kernel_attrs[] = {
  39. #ifdef CONFIG_HOTPLUG
  40. &hotplug_seqnum_attr.attr,
  41. #endif
  42. #ifdef CONFIG_KEXEC
  43. &crash_notes_attr.attr,
  44. #endif
  45. NULL
  46. };
  47. static struct attribute_group kernel_attr_group = {
  48. .attrs = kernel_attrs,
  49. };
  50. static int __init ksysfs_init(void)
  51. {
  52. int error = subsystem_register(&kernel_subsys);
  53. if (!error)
  54. error = sysfs_create_group(&kernel_subsys.kset.kobj,
  55. &kernel_attr_group);
  56. return error;
  57. }
  58. core_initcall(ksysfs_init);