Blame view
kernel/ksysfs.c
4.52 KB
1da177e4c
|
1 2 3 4 5 6 7 8 9 |
/* * kernel/ksysfs.c - sysfs attributes in /sys/kernel, which * are not related to any other subsystem * * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org> * * This file is release under the GPLv2 * */ |
1da177e4c
|
10 11 12 13 14 |
#include <linux/kobject.h> #include <linux/string.h> #include <linux/sysfs.h> #include <linux/module.h> #include <linux/init.h> |
c330dda90
|
15 |
#include <linux/kexec.h> |
22b8ce947
|
16 |
#include <linux/profile.h> |
5cb350baf
|
17 |
#include <linux/sched.h> |
1da177e4c
|
18 19 |
#define KERNEL_ATTR_RO(_name) \ |
386f275f5
|
20 |
static struct kobj_attribute _name##_attr = __ATTR_RO(_name) |
1da177e4c
|
21 22 |
#define KERNEL_ATTR_RW(_name) \ |
386f275f5
|
23 |
static struct kobj_attribute _name##_attr = \ |
1da177e4c
|
24 |
__ATTR(_name, 0644, _name##_show, _name##_store) |
cd3772e68
|
25 |
#if defined(CONFIG_HOTPLUG) |
0f76e5acf
|
26 |
/* current uevent sequence number */ |
386f275f5
|
27 28 |
static ssize_t uevent_seqnum_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) |
1da177e4c
|
29 |
{ |
386f275f5
|
30 31 |
return sprintf(buf, "%llu ", (unsigned long long)uevent_seqnum); |
1da177e4c
|
32 |
} |
0f76e5acf
|
33 34 35 |
KERNEL_ATTR_RO(uevent_seqnum); /* uevent helper program, used during early boo */ |
386f275f5
|
36 37 |
static ssize_t uevent_helper_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) |
0f76e5acf
|
38 |
{ |
386f275f5
|
39 40 |
return sprintf(buf, "%s ", uevent_helper); |
0f76e5acf
|
41 |
} |
386f275f5
|
42 43 44 |
static ssize_t uevent_helper_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) |
0f76e5acf
|
45 |
{ |
312c004d3
|
46 |
if (count+1 > UEVENT_HELPER_PATH_LEN) |
0f76e5acf
|
47 |
return -ENOENT; |
386f275f5
|
48 |
memcpy(uevent_helper, buf, count); |
312c004d3
|
49 50 51 52 |
uevent_helper[count] = '\0'; if (count && uevent_helper[count-1] == ' ') uevent_helper[count-1] = '\0'; |
0f76e5acf
|
53 54 55 |
return count; } KERNEL_ATTR_RW(uevent_helper); |
1da177e4c
|
56 |
#endif |
22b8ce947
|
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
#ifdef CONFIG_PROFILING static ssize_t profiling_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { return sprintf(buf, "%d ", prof_on); } static ssize_t profiling_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) { int ret; if (prof_on) return -EEXIST; /* * This eventually calls into get_option() which * has a ton of callers and is not const. It is * easiest to cast it away here. */ profile_setup((char *)buf); ret = profile_init(); if (ret) return ret; ret = create_proc_profile(); if (ret) return ret; return count; } KERNEL_ATTR_RW(profiling); #endif |
c330dda90
|
88 |
#ifdef CONFIG_KEXEC |
386f275f5
|
89 90 |
static ssize_t kexec_loaded_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) |
c330dda90
|
91 |
{ |
386f275f5
|
92 93 |
return sprintf(buf, "%d ", !!kexec_image); |
c330dda90
|
94 95 |
} KERNEL_ATTR_RO(kexec_loaded); |
386f275f5
|
96 97 |
static ssize_t kexec_crash_loaded_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) |
c330dda90
|
98 |
{ |
386f275f5
|
99 100 |
return sprintf(buf, "%d ", !!kexec_crash_image); |
c330dda90
|
101 102 |
} KERNEL_ATTR_RO(kexec_crash_loaded); |
fd59d231f
|
103 |
|
386f275f5
|
104 105 |
static ssize_t vmcoreinfo_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) |
fd59d231f
|
106 |
{ |
386f275f5
|
107 108 |
return sprintf(buf, "%lx %x ", |
fd59d231f
|
109 |
paddr_vmcoreinfo_note(), |
d768281e9
|
110 |
(unsigned int)vmcoreinfo_max_size); |
fd59d231f
|
111 112 |
} KERNEL_ATTR_RO(vmcoreinfo); |
c330dda90
|
113 |
#endif /* CONFIG_KEXEC */ |
da1a679cd
|
114 115 116 |
/* * Make /sys/kernel/notes give the raw contents of our kernel .notes section. */ |
0b1937ac0
|
117 118 |
extern const void __start_notes __attribute__((weak)); extern const void __stop_notes __attribute__((weak)); |
da1a679cd
|
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
#define notes_size (&__stop_notes - &__start_notes) static ssize_t notes_read(struct kobject *kobj, struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { memcpy(buf, &__start_notes + off, count); return count; } static struct bin_attribute notes_attr = { .attr = { .name = "notes", .mode = S_IRUGO, }, .read = ¬es_read, }; |
0ff21e466
|
135 136 |
struct kobject *kernel_kobj; EXPORT_SYMBOL_GPL(kernel_kobj); |
1da177e4c
|
137 138 |
static struct attribute * kernel_attrs[] = { |
cd3772e68
|
139 |
#if defined(CONFIG_HOTPLUG) |
0f76e5acf
|
140 141 |
&uevent_seqnum_attr.attr, &uevent_helper_attr.attr, |
1da177e4c
|
142 |
#endif |
22b8ce947
|
143 144 145 |
#ifdef CONFIG_PROFILING &profiling_attr.attr, #endif |
c330dda90
|
146 147 148 |
#ifdef CONFIG_KEXEC &kexec_loaded_attr.attr, &kexec_crash_loaded_attr.attr, |
fd59d231f
|
149 |
&vmcoreinfo_attr.attr, |
c330dda90
|
150 |
#endif |
1da177e4c
|
151 152 153 154 155 156 157 158 159 |
NULL }; static struct attribute_group kernel_attr_group = { .attrs = kernel_attrs, }; static int __init ksysfs_init(void) { |
bd35b93d8
|
160 |
int error; |
1da177e4c
|
161 |
|
0ff21e466
|
162 163 |
kernel_kobj = kobject_create_and_add("kernel", NULL); if (!kernel_kobj) { |
bd35b93d8
|
164 165 166 |
error = -ENOMEM; goto exit; } |
0ff21e466
|
167 |
error = sysfs_create_group(kernel_kobj, &kernel_attr_group); |
bd35b93d8
|
168 169 170 171 |
if (error) goto kset_exit; if (notes_size > 0) { |
da1a679cd
|
172 |
notes_attr.size = notes_size; |
0ff21e466
|
173 |
error = sysfs_create_bin_file(kernel_kobj, ¬es_attr); |
bd35b93d8
|
174 175 |
if (error) goto group_exit; |
da1a679cd
|
176 |
} |
eb41d9465
|
177 178 |
/* create the /sys/kernel/uids/ directory */ error = uids_sysfs_init(); |
bd35b93d8
|
179 180 181 182 183 184 185 |
if (error) goto notes_exit; return 0; notes_exit: if (notes_size > 0) |
0ff21e466
|
186 |
sysfs_remove_bin_file(kernel_kobj, ¬es_attr); |
bd35b93d8
|
187 |
group_exit: |
0ff21e466
|
188 |
sysfs_remove_group(kernel_kobj, &kernel_attr_group); |
bd35b93d8
|
189 |
kset_exit: |
78a2d906b
|
190 |
kobject_put(kernel_kobj); |
bd35b93d8
|
191 |
exit: |
1da177e4c
|
192 193 194 195 |
return error; } core_initcall(ksysfs_init); |