]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 <[email protected]> | |
6 | * | |
7 | * This file is release under the GPLv2 | |
8 | * | |
9 | */ | |
10 | ||
1da177e4 LT |
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> | |
c330dda9 | 16 | #include <linux/kexec.h> |
5cb350ba | 17 | #include <linux/sched.h> |
1da177e4 LT |
18 | |
19 | #define KERNEL_ATTR_RO(_name) \ | |
386f275f | 20 | static struct kobj_attribute _name##_attr = __ATTR_RO(_name) |
1da177e4 LT |
21 | |
22 | #define KERNEL_ATTR_RW(_name) \ | |
386f275f | 23 | static struct kobj_attribute _name##_attr = \ |
1da177e4 LT |
24 | __ATTR(_name, 0644, _name##_show, _name##_store) |
25 | ||
f125b561 | 26 | #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET) |
0f76e5ac | 27 | /* current uevent sequence number */ |
386f275f KS |
28 | static ssize_t uevent_seqnum_show(struct kobject *kobj, |
29 | struct kobj_attribute *attr, char *buf) | |
1da177e4 | 30 | { |
386f275f | 31 | return sprintf(buf, "%llu\n", (unsigned long long)uevent_seqnum); |
1da177e4 | 32 | } |
0f76e5ac KS |
33 | KERNEL_ATTR_RO(uevent_seqnum); |
34 | ||
35 | /* uevent helper program, used during early boo */ | |
386f275f KS |
36 | static ssize_t uevent_helper_show(struct kobject *kobj, |
37 | struct kobj_attribute *attr, char *buf) | |
0f76e5ac | 38 | { |
386f275f | 39 | return sprintf(buf, "%s\n", uevent_helper); |
0f76e5ac | 40 | } |
386f275f KS |
41 | static ssize_t uevent_helper_store(struct kobject *kobj, |
42 | struct kobj_attribute *attr, | |
43 | const char *buf, size_t count) | |
0f76e5ac | 44 | { |
312c004d | 45 | if (count+1 > UEVENT_HELPER_PATH_LEN) |
0f76e5ac | 46 | return -ENOENT; |
386f275f | 47 | memcpy(uevent_helper, buf, count); |
312c004d KS |
48 | uevent_helper[count] = '\0'; |
49 | if (count && uevent_helper[count-1] == '\n') | |
50 | uevent_helper[count-1] = '\0'; | |
0f76e5ac KS |
51 | return count; |
52 | } | |
53 | KERNEL_ATTR_RW(uevent_helper); | |
1da177e4 LT |
54 | #endif |
55 | ||
c330dda9 | 56 | #ifdef CONFIG_KEXEC |
386f275f KS |
57 | static ssize_t kexec_loaded_show(struct kobject *kobj, |
58 | struct kobj_attribute *attr, char *buf) | |
c330dda9 | 59 | { |
386f275f | 60 | return sprintf(buf, "%d\n", !!kexec_image); |
c330dda9 JM |
61 | } |
62 | KERNEL_ATTR_RO(kexec_loaded); | |
63 | ||
386f275f KS |
64 | static ssize_t kexec_crash_loaded_show(struct kobject *kobj, |
65 | struct kobj_attribute *attr, char *buf) | |
c330dda9 | 66 | { |
386f275f | 67 | return sprintf(buf, "%d\n", !!kexec_crash_image); |
c330dda9 JM |
68 | } |
69 | KERNEL_ATTR_RO(kexec_crash_loaded); | |
fd59d231 | 70 | |
386f275f KS |
71 | static ssize_t vmcoreinfo_show(struct kobject *kobj, |
72 | struct kobj_attribute *attr, char *buf) | |
fd59d231 | 73 | { |
386f275f | 74 | return sprintf(buf, "%lx %x\n", |
fd59d231 | 75 | paddr_vmcoreinfo_note(), |
d768281e | 76 | (unsigned int)vmcoreinfo_max_size); |
fd59d231 KO |
77 | } |
78 | KERNEL_ATTR_RO(vmcoreinfo); | |
79 | ||
c330dda9 JM |
80 | #endif /* CONFIG_KEXEC */ |
81 | ||
da1a679c RM |
82 | /* |
83 | * Make /sys/kernel/notes give the raw contents of our kernel .notes section. | |
84 | */ | |
0b1937ac DH |
85 | extern const void __start_notes __attribute__((weak)); |
86 | extern const void __stop_notes __attribute__((weak)); | |
da1a679c RM |
87 | #define notes_size (&__stop_notes - &__start_notes) |
88 | ||
89 | static ssize_t notes_read(struct kobject *kobj, struct bin_attribute *bin_attr, | |
90 | char *buf, loff_t off, size_t count) | |
91 | { | |
92 | memcpy(buf, &__start_notes + off, count); | |
93 | return count; | |
94 | } | |
95 | ||
96 | static struct bin_attribute notes_attr = { | |
97 | .attr = { | |
98 | .name = "notes", | |
99 | .mode = S_IRUGO, | |
100 | }, | |
101 | .read = ¬es_read, | |
102 | }; | |
103 | ||
0ff21e46 GKH |
104 | struct kobject *kernel_kobj; |
105 | EXPORT_SYMBOL_GPL(kernel_kobj); | |
1da177e4 LT |
106 | |
107 | static struct attribute * kernel_attrs[] = { | |
f125b561 | 108 | #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET) |
0f76e5ac KS |
109 | &uevent_seqnum_attr.attr, |
110 | &uevent_helper_attr.attr, | |
c330dda9 JM |
111 | #endif |
112 | #ifdef CONFIG_KEXEC | |
113 | &kexec_loaded_attr.attr, | |
114 | &kexec_crash_loaded_attr.attr, | |
fd59d231 | 115 | &vmcoreinfo_attr.attr, |
1da177e4 LT |
116 | #endif |
117 | NULL | |
118 | }; | |
119 | ||
120 | static struct attribute_group kernel_attr_group = { | |
121 | .attrs = kernel_attrs, | |
122 | }; | |
123 | ||
124 | static int __init ksysfs_init(void) | |
125 | { | |
bd35b93d | 126 | int error; |
1da177e4 | 127 | |
0ff21e46 GKH |
128 | kernel_kobj = kobject_create_and_add("kernel", NULL); |
129 | if (!kernel_kobj) { | |
bd35b93d GKH |
130 | error = -ENOMEM; |
131 | goto exit; | |
132 | } | |
0ff21e46 | 133 | error = sysfs_create_group(kernel_kobj, &kernel_attr_group); |
bd35b93d GKH |
134 | if (error) |
135 | goto kset_exit; | |
136 | ||
137 | if (notes_size > 0) { | |
da1a679c | 138 | notes_attr.size = notes_size; |
0ff21e46 | 139 | error = sysfs_create_bin_file(kernel_kobj, ¬es_attr); |
bd35b93d GKH |
140 | if (error) |
141 | goto group_exit; | |
da1a679c RM |
142 | } |
143 | ||
eb41d946 KS |
144 | /* create the /sys/kernel/uids/ directory */ |
145 | error = uids_sysfs_init(); | |
bd35b93d GKH |
146 | if (error) |
147 | goto notes_exit; | |
148 | ||
149 | return 0; | |
150 | ||
151 | notes_exit: | |
152 | if (notes_size > 0) | |
0ff21e46 | 153 | sysfs_remove_bin_file(kernel_kobj, ¬es_attr); |
bd35b93d | 154 | group_exit: |
0ff21e46 | 155 | sysfs_remove_group(kernel_kobj, &kernel_attr_group); |
bd35b93d | 156 | kset_exit: |
78a2d906 | 157 | kobject_put(kernel_kobj); |
bd35b93d | 158 | exit: |
1da177e4 LT |
159 | return error; |
160 | } | |
161 | ||
162 | core_initcall(ksysfs_init); |