ksysfs.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. decl_subsys(kernel, NULL, NULL);
  48. EXPORT_SYMBOL_GPL(kernel_subsys);
  49. static struct attribute * kernel_attrs[] = {
  50. #ifdef CONFIG_HOTPLUG
  51. &uevent_seqnum_attr.attr,
  52. &uevent_helper_attr.attr,
  53. #endif
  54. NULL
  55. };
  56. static struct attribute_group kernel_attr_group = {
  57. .attrs = kernel_attrs,
  58. };
  59. static int __init ksysfs_init(void)
  60. {
  61. int error = subsystem_register(&kernel_subsys);
  62. if (!error)
  63. error = sysfs_create_group(&kernel_subsys.kset.kobj,
  64. &kernel_attr_group);
  65. return error;
  66. }
  67. core_initcall(ksysfs_init);