ext4: fix initialization of UNINIT bitmap blocks
[linux-2.6/mini2440.git] / kernel / ksysfs.c
blobe53bc30e9ba5aa8b55311fd6700191b0f21a9597
1 /*
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>
6 *
7 * This file is release under the GPLv2
9 */
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)
46 return -ENOENT;
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';
51 return count;
53 KERNEL_ATTR_RW(uevent_helper);
54 #endif
56 #ifdef CONFIG_KEXEC
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);
93 return count;
96 static struct bin_attribute notes_attr = {
97 .attr = {
98 .name = "notes",
99 .mode = S_IRUGO,
101 .read = &notes_read,
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,
111 #endif
112 #ifdef CONFIG_KEXEC
113 &kexec_loaded_attr.attr,
114 &kexec_crash_loaded_attr.attr,
115 &vmcoreinfo_attr.attr,
116 #endif
117 NULL
120 static struct attribute_group kernel_attr_group = {
121 .attrs = kernel_attrs,
124 static int __init ksysfs_init(void)
126 int error;
128 kernel_kobj = kobject_create_and_add("kernel", NULL);
129 if (!kernel_kobj) {
130 error = -ENOMEM;
131 goto exit;
133 error = sysfs_create_group(kernel_kobj, &kernel_attr_group);
134 if (error)
135 goto kset_exit;
137 if (notes_size > 0) {
138 notes_attr.size = notes_size;
139 error = sysfs_create_bin_file(kernel_kobj, &notes_attr);
140 if (error)
141 goto group_exit;
144 /* create the /sys/kernel/uids/ directory */
145 error = uids_sysfs_init();
146 if (error)
147 goto notes_exit;
149 return 0;
151 notes_exit:
152 if (notes_size > 0)
153 sysfs_remove_bin_file(kernel_kobj, &notes_attr);
154 group_exit:
155 sysfs_remove_group(kernel_kobj, &kernel_attr_group);
156 kset_exit:
157 kobject_put(kernel_kobj);
158 exit:
159 return error;
162 core_initcall(ksysfs_init);