Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 11 | #include <linux/config.h> |
| 12 | #include <linux/kobject.h> |
| 13 | #include <linux/string.h> |
| 14 | #include <linux/sysfs.h> |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/init.h> |
| 17 | |
| 18 | #define KERNEL_ATTR_RO(_name) \ |
| 19 | static struct subsys_attribute _name##_attr = __ATTR_RO(_name) |
| 20 | |
| 21 | #define KERNEL_ATTR_RW(_name) \ |
| 22 | static struct subsys_attribute _name##_attr = \ |
| 23 | __ATTR(_name, 0644, _name##_show, _name##_store) |
| 24 | |
| 25 | #ifdef CONFIG_HOTPLUG |
Kay Sievers | 0f76e5a | 2005-11-11 04:58:04 +0100 | [diff] [blame] | 26 | /* current uevent sequence number */ |
| 27 | static ssize_t uevent_seqnum_show(struct subsystem *subsys, char *page) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | { |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame^] | 29 | return sprintf(page, "%llu\n", (unsigned long long)uevent_seqnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | } |
Kay Sievers | 0f76e5a | 2005-11-11 04:58:04 +0100 | [diff] [blame] | 31 | KERNEL_ATTR_RO(uevent_seqnum); |
| 32 | |
| 33 | /* uevent helper program, used during early boo */ |
| 34 | static ssize_t uevent_helper_show(struct subsystem *subsys, char *page) |
| 35 | { |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame^] | 36 | return sprintf(page, "%s\n", uevent_helper); |
Kay Sievers | 0f76e5a | 2005-11-11 04:58:04 +0100 | [diff] [blame] | 37 | } |
| 38 | static ssize_t uevent_helper_store(struct subsystem *subsys, const char *page, size_t count) |
| 39 | { |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame^] | 40 | if (count+1 > UEVENT_HELPER_PATH_LEN) |
Kay Sievers | 0f76e5a | 2005-11-11 04:58:04 +0100 | [diff] [blame] | 41 | return -ENOENT; |
Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame^] | 42 | memcpy(uevent_helper, page, count); |
| 43 | uevent_helper[count] = '\0'; |
| 44 | if (count && uevent_helper[count-1] == '\n') |
| 45 | uevent_helper[count-1] = '\0'; |
Kay Sievers | 0f76e5a | 2005-11-11 04:58:04 +0100 | [diff] [blame] | 46 | return count; |
| 47 | } |
| 48 | KERNEL_ATTR_RW(uevent_helper); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #endif |
| 50 | |
Vivek Goyal | 625f1c82 | 2005-06-25 14:58:12 -0700 | [diff] [blame] | 51 | #ifdef CONFIG_KEXEC |
| 52 | #include <asm/kexec.h> |
| 53 | |
| 54 | static ssize_t crash_notes_show(struct subsystem *subsys, char *page) |
| 55 | { |
| 56 | return sprintf(page, "%p\n", (void *)crash_notes); |
| 57 | } |
| 58 | KERNEL_ATTR_RO(crash_notes); |
| 59 | #endif |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | decl_subsys(kernel, NULL, NULL); |
| 62 | EXPORT_SYMBOL_GPL(kernel_subsys); |
| 63 | |
| 64 | static struct attribute * kernel_attrs[] = { |
| 65 | #ifdef CONFIG_HOTPLUG |
Kay Sievers | 0f76e5a | 2005-11-11 04:58:04 +0100 | [diff] [blame] | 66 | &uevent_seqnum_attr.attr, |
| 67 | &uevent_helper_attr.attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #endif |
Vivek Goyal | 625f1c82 | 2005-06-25 14:58:12 -0700 | [diff] [blame] | 69 | #ifdef CONFIG_KEXEC |
| 70 | &crash_notes_attr.attr, |
| 71 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | NULL |
| 73 | }; |
| 74 | |
| 75 | static struct attribute_group kernel_attr_group = { |
| 76 | .attrs = kernel_attrs, |
| 77 | }; |
| 78 | |
| 79 | static int __init ksysfs_init(void) |
| 80 | { |
| 81 | int error = subsystem_register(&kernel_subsys); |
| 82 | if (!error) |
| 83 | error = sysfs_create_group(&kernel_subsys.kset.kobj, |
| 84 | &kernel_attr_group); |
| 85 | |
| 86 | return error; |
| 87 | } |
| 88 | |
| 89 | core_initcall(ksysfs_init); |