blob: 9e28478a17a50a0081503f7ae54cd25eb6142d44 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * kernel/ksysfs.c - sysfs attributes in /sys/kernel, which
3 * are not related to any other subsystem
4 *
5 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
6 *
7 * This file is release under the GPLv2
8 *
9 */
10
11#include <linux/config.h>
12#include <linux/kobject.h>
13#include <linux/string.h>
14#include <linux/sysfs.h>
15#include <linux/module.h>
16#include <linux/init.h>
Jeff Moyerc330dda2006-06-23 02:05:07 -070017#include <linux/kexec.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19#define KERNEL_ATTR_RO(_name) \
20static struct subsys_attribute _name##_attr = __ATTR_RO(_name)
21
22#define KERNEL_ATTR_RW(_name) \
23static struct subsys_attribute _name##_attr = \
24 __ATTR(_name, 0644, _name##_show, _name##_store)
25
Andrew Mortonf125b562006-03-24 03:18:44 -080026#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Kay Sievers0f76e5a2005-11-11 04:58:04 +010027/* current uevent sequence number */
28static ssize_t uevent_seqnum_show(struct subsystem *subsys, char *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029{
Kay Sievers312c0042005-11-16 09:00:00 +010030 return sprintf(page, "%llu\n", (unsigned long long)uevent_seqnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031}
Kay Sievers0f76e5a2005-11-11 04:58:04 +010032KERNEL_ATTR_RO(uevent_seqnum);
33
34/* uevent helper program, used during early boo */
35static ssize_t uevent_helper_show(struct subsystem *subsys, char *page)
36{
Kay Sievers312c0042005-11-16 09:00:00 +010037 return sprintf(page, "%s\n", uevent_helper);
Kay Sievers0f76e5a2005-11-11 04:58:04 +010038}
39static ssize_t uevent_helper_store(struct subsystem *subsys, const char *page, size_t count)
40{
Kay Sievers312c0042005-11-16 09:00:00 +010041 if (count+1 > UEVENT_HELPER_PATH_LEN)
Kay Sievers0f76e5a2005-11-11 04:58:04 +010042 return -ENOENT;
Kay Sievers312c0042005-11-16 09:00:00 +010043 memcpy(uevent_helper, page, count);
44 uevent_helper[count] = '\0';
45 if (count && uevent_helper[count-1] == '\n')
46 uevent_helper[count-1] = '\0';
Kay Sievers0f76e5a2005-11-11 04:58:04 +010047 return count;
48}
49KERNEL_ATTR_RW(uevent_helper);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#endif
51
Jeff Moyerc330dda2006-06-23 02:05:07 -070052#ifdef CONFIG_KEXEC
53static ssize_t kexec_loaded_show(struct subsystem *subsys, char *page)
54{
55 return sprintf(page, "%d\n", !!kexec_image);
56}
57KERNEL_ATTR_RO(kexec_loaded);
58
59static ssize_t kexec_crash_loaded_show(struct subsystem *subsys, char *page)
60{
61 return sprintf(page, "%d\n", !!kexec_crash_image);
62}
63KERNEL_ATTR_RO(kexec_crash_loaded);
64#endif /* CONFIG_KEXEC */
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066decl_subsys(kernel, NULL, NULL);
67EXPORT_SYMBOL_GPL(kernel_subsys);
68
69static struct attribute * kernel_attrs[] = {
Andrew Mortonf125b562006-03-24 03:18:44 -080070#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Kay Sievers0f76e5a2005-11-11 04:58:04 +010071 &uevent_seqnum_attr.attr,
72 &uevent_helper_attr.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#endif
Jeff Moyerc330dda2006-06-23 02:05:07 -070074#ifdef CONFIG_KEXEC
75 &kexec_loaded_attr.attr,
76 &kexec_crash_loaded_attr.attr,
77#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 NULL
79};
80
81static struct attribute_group kernel_attr_group = {
82 .attrs = kernel_attrs,
83};
84
85static int __init ksysfs_init(void)
86{
87 int error = subsystem_register(&kernel_subsys);
88 if (!error)
89 error = sysfs_create_group(&kernel_subsys.kset.kobj,
90 &kernel_attr_group);
91
92 return error;
93}
94
95core_initcall(ksysfs_init);