Blame view
kernel/ksysfs.c
2.98 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> |
1da177e4c Linux-2.6.12-rc2 |
16 17 18 19 20 21 22 |
#define KERNEL_ATTR_RO(_name) \ static struct subsys_attribute _name##_attr = __ATTR_RO(_name) #define KERNEL_ATTR_RW(_name) \ static struct subsys_attribute _name##_attr = \ __ATTR(_name, 0644, _name##_show, _name##_store) |
f125b5611 [PATCH] fix build... |
23 |
#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET) |
0f76e5acf [PATCH] add ueven... |
24 |
/* current uevent sequence number */ |
823bccfc4 remove "struct su... |
25 |
static ssize_t uevent_seqnum_show(struct kset *kset, char *page) |
1da177e4c Linux-2.6.12-rc2 |
26 |
{ |
312c004d3 [PATCH] driver co... |
27 28 |
return sprintf(page, "%llu ", (unsigned long long)uevent_seqnum); |
1da177e4c Linux-2.6.12-rc2 |
29 |
} |
0f76e5acf [PATCH] add ueven... |
30 31 32 |
KERNEL_ATTR_RO(uevent_seqnum); /* uevent helper program, used during early boo */ |
823bccfc4 remove "struct su... |
33 |
static ssize_t uevent_helper_show(struct kset *kset, char *page) |
0f76e5acf [PATCH] add ueven... |
34 |
{ |
312c004d3 [PATCH] driver co... |
35 36 |
return sprintf(page, "%s ", uevent_helper); |
0f76e5acf [PATCH] add ueven... |
37 |
} |
823bccfc4 remove "struct su... |
38 |
static ssize_t uevent_helper_store(struct kset *kset, const char *page, size_t count) |
0f76e5acf [PATCH] add ueven... |
39 |
{ |
312c004d3 [PATCH] driver co... |
40 |
if (count+1 > UEVENT_HELPER_PATH_LEN) |
0f76e5acf [PATCH] add ueven... |
41 |
return -ENOENT; |
312c004d3 [PATCH] driver co... |
42 43 44 45 46 |
memcpy(uevent_helper, page, count); uevent_helper[count] = '\0'; if (count && uevent_helper[count-1] == ' ') uevent_helper[count-1] = '\0'; |
0f76e5acf [PATCH] add ueven... |
47 48 49 |
return count; } KERNEL_ATTR_RW(uevent_helper); |
1da177e4c Linux-2.6.12-rc2 |
50 |
#endif |
c330dda90 [PATCH] Add a sys... |
51 |
#ifdef CONFIG_KEXEC |
823bccfc4 remove "struct su... |
52 |
static ssize_t kexec_loaded_show(struct kset *kset, char *page) |
c330dda90 [PATCH] Add a sys... |
53 54 55 56 57 |
{ return sprintf(page, "%d ", !!kexec_image); } KERNEL_ATTR_RO(kexec_loaded); |
823bccfc4 remove "struct su... |
58 |
static ssize_t kexec_crash_loaded_show(struct kset *kset, char *page) |
c330dda90 [PATCH] Add a sys... |
59 60 61 62 63 64 |
{ return sprintf(page, "%d ", !!kexec_crash_image); } KERNEL_ATTR_RO(kexec_crash_loaded); #endif /* CONFIG_KEXEC */ |
da1a679cd Add /sys/kernel/n... |
65 66 67 |
/* * Make /sys/kernel/notes give the raw contents of our kernel .notes section. */ |
0b1937ac0 FRV: Fix linkage ... |
68 69 |
extern const void __start_notes __attribute__((weak)); extern const void __stop_notes __attribute__((weak)); |
da1a679cd Add /sys/kernel/n... |
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
#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, }; |
1da177e4c Linux-2.6.12-rc2 |
86 87 88 89 |
decl_subsys(kernel, NULL, NULL); EXPORT_SYMBOL_GPL(kernel_subsys); static struct attribute * kernel_attrs[] = { |
f125b5611 [PATCH] fix build... |
90 |
#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET) |
0f76e5acf [PATCH] add ueven... |
91 92 |
&uevent_seqnum_attr.attr, &uevent_helper_attr.attr, |
1da177e4c Linux-2.6.12-rc2 |
93 |
#endif |
c330dda90 [PATCH] Add a sys... |
94 95 96 97 |
#ifdef CONFIG_KEXEC &kexec_loaded_attr.attr, &kexec_crash_loaded_attr.attr, #endif |
1da177e4c Linux-2.6.12-rc2 |
98 99 100 101 102 103 104 105 106 107 108 |
NULL }; static struct attribute_group kernel_attr_group = { .attrs = kernel_attrs, }; static int __init ksysfs_init(void) { int error = subsystem_register(&kernel_subsys); if (!error) |
823bccfc4 remove "struct su... |
109 |
error = sysfs_create_group(&kernel_subsys.kobj, |
1da177e4c Linux-2.6.12-rc2 |
110 |
&kernel_attr_group); |
da1a679cd Add /sys/kernel/n... |
111 112 113 114 115 |
if (!error && notes_size > 0) { notes_attr.size = notes_size; error = sysfs_create_bin_file(&kernel_subsys.kobj, ¬es_attr); } |
1da177e4c Linux-2.6.12-rc2 |
116 117 118 119 |
return error; } core_initcall(ksysfs_init); |