2 * kernel/ksysfs.c - sysfs attributes in /sys/kernel, which
3 * are not related to any other subsystem
5 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
7 * This file is release under the GPLv2
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 #include <linux/kexec.h>
17 #include <linux/sched.h>
19 #define KERNEL_ATTR_RO(_name) \
20 static struct kobj_attribute _name##_attr = __ATTR_RO(_name)
22 #define KERNEL_ATTR_RW(_name) \
23 static struct kobj_attribute _name##_attr = \
24 __ATTR(_name, 0644, _name##_show, _name##_store)
26 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
27 /* current uevent sequence number */
28 static ssize_t
uevent_seqnum_show(struct kobject
*kobj
,
29 struct kobj_attribute
*attr
, char *buf
)
31 return sprintf(buf
, "%llu\n", (unsigned long long)uevent_seqnum
);
33 KERNEL_ATTR_RO(uevent_seqnum
);
35 /* uevent helper program, used during early boo */
36 static ssize_t
uevent_helper_show(struct kobject
*kobj
,
37 struct kobj_attribute
*attr
, char *buf
)
39 return sprintf(buf
, "%s\n", uevent_helper
);
41 static ssize_t
uevent_helper_store(struct kobject
*kobj
,
42 struct kobj_attribute
*attr
,
43 const char *buf
, size_t count
)
45 if (count
+1 > UEVENT_HELPER_PATH_LEN
)
47 memcpy(uevent_helper
, buf
, count
);
48 uevent_helper
[count
] = '\0';
49 if (count
&& uevent_helper
[count
-1] == '\n')
50 uevent_helper
[count
-1] = '\0';
53 KERNEL_ATTR_RW(uevent_helper
);
57 static ssize_t
kexec_loaded_show(struct kobject
*kobj
,
58 struct kobj_attribute
*attr
, char *buf
)
60 return sprintf(buf
, "%d\n", !!kexec_image
);
62 KERNEL_ATTR_RO(kexec_loaded
);
64 static ssize_t
kexec_crash_loaded_show(struct kobject
*kobj
,
65 struct kobj_attribute
*attr
, char *buf
)
67 return sprintf(buf
, "%d\n", !!kexec_crash_image
);
69 KERNEL_ATTR_RO(kexec_crash_loaded
);
71 static ssize_t
vmcoreinfo_show(struct kobject
*kobj
,
72 struct kobj_attribute
*attr
, char *buf
)
74 return sprintf(buf
, "%lx %x\n",
75 paddr_vmcoreinfo_note(),
76 (unsigned int)vmcoreinfo_max_size
);
78 KERNEL_ATTR_RO(vmcoreinfo
);
80 #endif /* CONFIG_KEXEC */
83 * Make /sys/kernel/notes give the raw contents of our kernel .notes section.
85 extern const void __start_notes
__attribute__((weak
));
86 extern const void __stop_notes
__attribute__((weak
));
87 #define notes_size (&__stop_notes - &__start_notes)
89 static ssize_t
notes_read(struct kobject
*kobj
, struct bin_attribute
*bin_attr
,
90 char *buf
, loff_t off
, size_t count
)
92 memcpy(buf
, &__start_notes
+ off
, count
);
96 static struct bin_attribute notes_attr
= {
104 struct kobject
*kernel_kobj
;
105 EXPORT_SYMBOL_GPL(kernel_kobj
);
107 static struct attribute
* kernel_attrs
[] = {
108 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
109 &uevent_seqnum_attr
.attr
,
110 &uevent_helper_attr
.attr
,
113 &kexec_loaded_attr
.attr
,
114 &kexec_crash_loaded_attr
.attr
,
115 &vmcoreinfo_attr
.attr
,
120 static struct attribute_group kernel_attr_group
= {
121 .attrs
= kernel_attrs
,
124 static int __init
ksysfs_init(void)
128 kernel_kobj
= kobject_create_and_add("kernel", NULL
);
133 error
= sysfs_create_group(kernel_kobj
, &kernel_attr_group
);
137 if (notes_size
> 0) {
138 notes_attr
.size
= notes_size
;
139 error
= sysfs_create_bin_file(kernel_kobj
, ¬es_attr
);
144 /* create the /sys/kernel/uids/ directory */
145 error
= uids_sysfs_init();
153 sysfs_remove_bin_file(kernel_kobj
, ¬es_attr
);
155 sysfs_remove_group(kernel_kobj
, &kernel_attr_group
);
157 kobject_put(kernel_kobj
);
162 core_initcall(ksysfs_init
);