Blame view
kernel/ksysfs.c
3.83 KB
1da177e4c Linux-2.6.12-rc2 |
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 Linux-2.6.12-rc2 |
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 [PATCH] Add a sys... |
15 |
#include <linux/kexec.h> |
5cb350baf sched: group sche... |
16 |
#include <linux/sched.h> |
1da177e4c Linux-2.6.12-rc2 |
17 18 |
#define KERNEL_ATTR_RO(_name) \ |
386f275f5 Driver Core: swit... |
19 |
static struct kobj_attribute _name##_attr = __ATTR_RO(_name) |
1da177e4c Linux-2.6.12-rc2 |
20 21 |
#define KERNEL_ATTR_RW(_name) \ |
386f275f5 Driver Core: swit... |
22 |
static struct kobj_attribute _name##_attr = \ |
1da177e4c Linux-2.6.12-rc2 |
23 |
__ATTR(_name, 0644, _name##_show, _name##_store) |
f125b5611 [PATCH] fix build... |
24 |
#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET) |
0f76e5acf [PATCH] add ueven... |
25 |
/* current uevent sequence number */ |
386f275f5 Driver Core: swit... |
26 27 |
static ssize_t uevent_seqnum_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) |
1da177e4c Linux-2.6.12-rc2 |
28 |
{ |
386f275f5 Driver Core: swit... |
29 30 |
return sprintf(buf, "%llu ", (unsigned long long)uevent_seqnum); |
1da177e4c Linux-2.6.12-rc2 |
31 |
} |
0f76e5acf [PATCH] add ueven... |
32 33 34 |
KERNEL_ATTR_RO(uevent_seqnum); /* uevent helper program, used during early boo */ |
386f275f5 Driver Core: swit... |
35 36 |
static ssize_t uevent_helper_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) |
0f76e5acf [PATCH] add ueven... |
37 |
{ |
386f275f5 Driver Core: swit... |
38 39 |
return sprintf(buf, "%s ", uevent_helper); |
0f76e5acf [PATCH] add ueven... |
40 |
} |
386f275f5 Driver Core: swit... |
41 42 43 |
static ssize_t uevent_helper_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) |
0f76e5acf [PATCH] add ueven... |
44 |
{ |
312c004d3 [PATCH] driver co... |
45 |
if (count+1 > UEVENT_HELPER_PATH_LEN) |
0f76e5acf [PATCH] add ueven... |
46 |
return -ENOENT; |
386f275f5 Driver Core: swit... |
47 |
memcpy(uevent_helper, buf, count); |
312c004d3 [PATCH] driver co... |
48 49 50 51 |
uevent_helper[count] = '\0'; if (count && uevent_helper[count-1] == ' ') uevent_helper[count-1] = '\0'; |
0f76e5acf [PATCH] add ueven... |
52 53 54 |
return count; } KERNEL_ATTR_RW(uevent_helper); |
1da177e4c Linux-2.6.12-rc2 |
55 |
#endif |
c330dda90 [PATCH] Add a sys... |
56 |
#ifdef CONFIG_KEXEC |
386f275f5 Driver Core: swit... |
57 58 |
static ssize_t kexec_loaded_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) |
c330dda90 [PATCH] Add a sys... |
59 |
{ |
386f275f5 Driver Core: swit... |
60 61 |
return sprintf(buf, "%d ", !!kexec_image); |
c330dda90 [PATCH] Add a sys... |
62 63 |
} KERNEL_ATTR_RO(kexec_loaded); |
386f275f5 Driver Core: swit... |
64 65 |
static ssize_t kexec_crash_loaded_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) |
c330dda90 [PATCH] Add a sys... |
66 |
{ |
386f275f5 Driver Core: swit... |
67 68 |
return sprintf(buf, "%d ", !!kexec_crash_image); |
c330dda90 [PATCH] Add a sys... |
69 70 |
} KERNEL_ATTR_RO(kexec_crash_loaded); |
fd59d231f Add vmcoreinfo |
71 |
|
386f275f5 Driver Core: swit... |
72 73 |
static ssize_t vmcoreinfo_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) |
fd59d231f Add vmcoreinfo |
74 |
{ |
386f275f5 Driver Core: swit... |
75 76 |
return sprintf(buf, "%lx %x ", |
fd59d231f Add vmcoreinfo |
77 |
paddr_vmcoreinfo_note(), |
d768281e9 add-vmcore: clean... |
78 |
(unsigned int)vmcoreinfo_max_size); |
fd59d231f Add vmcoreinfo |
79 80 |
} KERNEL_ATTR_RO(vmcoreinfo); |
c330dda90 [PATCH] Add a sys... |
81 |
#endif /* CONFIG_KEXEC */ |
da1a679cd Add /sys/kernel/n... |
82 83 84 |
/* * Make /sys/kernel/notes give the raw contents of our kernel .notes section. */ |
0b1937ac0 FRV: Fix linkage ... |
85 86 |
extern const void __start_notes __attribute__((weak)); extern const void __stop_notes __attribute__((weak)); |
da1a679cd Add /sys/kernel/n... |
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
#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 kobject: convert ... |
103 104 |
struct kobject *kernel_kobj; EXPORT_SYMBOL_GPL(kernel_kobj); |
1da177e4c Linux-2.6.12-rc2 |
105 106 |
static struct attribute * kernel_attrs[] = { |
f125b5611 [PATCH] fix build... |
107 |
#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET) |
0f76e5acf [PATCH] add ueven... |
108 109 |
&uevent_seqnum_attr.attr, &uevent_helper_attr.attr, |
1da177e4c Linux-2.6.12-rc2 |
110 |
#endif |
c330dda90 [PATCH] Add a sys... |
111 112 113 |
#ifdef CONFIG_KEXEC &kexec_loaded_attr.attr, &kexec_crash_loaded_attr.attr, |
fd59d231f Add vmcoreinfo |
114 |
&vmcoreinfo_attr.attr, |
c330dda90 [PATCH] Add a sys... |
115 |
#endif |
1da177e4c Linux-2.6.12-rc2 |
116 117 118 119 120 121 122 123 124 |
NULL }; static struct attribute_group kernel_attr_group = { .attrs = kernel_attrs, }; static int __init ksysfs_init(void) { |
bd35b93d8 kset: convert ker... |
125 |
int error; |
1da177e4c Linux-2.6.12-rc2 |
126 |
|
0ff21e466 kobject: convert ... |
127 128 |
kernel_kobj = kobject_create_and_add("kernel", NULL); if (!kernel_kobj) { |
bd35b93d8 kset: convert ker... |
129 130 131 |
error = -ENOMEM; goto exit; } |
0ff21e466 kobject: convert ... |
132 |
error = sysfs_create_group(kernel_kobj, &kernel_attr_group); |
bd35b93d8 kset: convert ker... |
133 134 135 136 |
if (error) goto kset_exit; if (notes_size > 0) { |
da1a679cd Add /sys/kernel/n... |
137 |
notes_attr.size = notes_size; |
0ff21e466 kobject: convert ... |
138 |
error = sysfs_create_bin_file(kernel_kobj, ¬es_attr); |
bd35b93d8 kset: convert ker... |
139 140 |
if (error) goto group_exit; |
da1a679cd Add /sys/kernel/n... |
141 |
} |
eb41d9465 fix struct user_i... |
142 143 |
/* create the /sys/kernel/uids/ directory */ error = uids_sysfs_init(); |
bd35b93d8 kset: convert ker... |
144 145 146 147 148 149 150 |
if (error) goto notes_exit; return 0; notes_exit: if (notes_size > 0) |
0ff21e466 kobject: convert ... |
151 |
sysfs_remove_bin_file(kernel_kobj, ¬es_attr); |
bd35b93d8 kset: convert ker... |
152 |
group_exit: |
0ff21e466 kobject: convert ... |
153 |
sysfs_remove_group(kernel_kobj, &kernel_attr_group); |
bd35b93d8 kset: convert ker... |
154 |
kset_exit: |
78a2d906b Kobject: convert ... |
155 |
kobject_put(kernel_kobj); |
bd35b93d8 kset: convert ker... |
156 |
exit: |
1da177e4c Linux-2.6.12-rc2 |
157 158 159 160 |
return error; } core_initcall(ksysfs_init); |