blob: 99af8b05eeaa754de098195a7299bff216040180 [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>
17
akpm@osdl.orgf743ca52005-11-22 23:36:13 -080018u64 uevent_seqnum;
19char uevent_helper[UEVENT_HELPER_PATH_LEN] = "/sbin/hotplug";
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#define KERNEL_ATTR_RO(_name) \
22static struct subsys_attribute _name##_attr = __ATTR_RO(_name)
23
24#define KERNEL_ATTR_RW(_name) \
25static struct subsys_attribute _name##_attr = \
26 __ATTR(_name, 0644, _name##_show, _name##_store)
27
28#ifdef CONFIG_HOTPLUG
Kay Sievers0f76e5a2005-11-11 04:58:04 +010029/* current uevent sequence number */
30static ssize_t uevent_seqnum_show(struct subsystem *subsys, char *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
Kay Sievers312c0042005-11-16 09:00:00 +010032 return sprintf(page, "%llu\n", (unsigned long long)uevent_seqnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033}
Kay Sievers0f76e5a2005-11-11 04:58:04 +010034KERNEL_ATTR_RO(uevent_seqnum);
35
36/* uevent helper program, used during early boo */
37static ssize_t uevent_helper_show(struct subsystem *subsys, char *page)
38{
Kay Sievers312c0042005-11-16 09:00:00 +010039 return sprintf(page, "%s\n", uevent_helper);
Kay Sievers0f76e5a2005-11-11 04:58:04 +010040}
41static ssize_t uevent_helper_store(struct subsystem *subsys, const char *page, size_t count)
42{
Kay Sievers312c0042005-11-16 09:00:00 +010043 if (count+1 > UEVENT_HELPER_PATH_LEN)
Kay Sievers0f76e5a2005-11-11 04:58:04 +010044 return -ENOENT;
Kay Sievers312c0042005-11-16 09:00:00 +010045 memcpy(uevent_helper, page, count);
46 uevent_helper[count] = '\0';
47 if (count && uevent_helper[count-1] == '\n')
48 uevent_helper[count-1] = '\0';
Kay Sievers0f76e5a2005-11-11 04:58:04 +010049 return count;
50}
51KERNEL_ATTR_RW(uevent_helper);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#endif
53
Vivek Goyal625f1c82005-06-25 14:58:12 -070054#ifdef CONFIG_KEXEC
55#include <asm/kexec.h>
56
57static ssize_t crash_notes_show(struct subsystem *subsys, char *page)
58{
59 return sprintf(page, "%p\n", (void *)crash_notes);
60}
61KERNEL_ATTR_RO(crash_notes);
62#endif
63
Linus Torvalds1da177e2005-04-16 15:20:36 -070064decl_subsys(kernel, NULL, NULL);
65EXPORT_SYMBOL_GPL(kernel_subsys);
66
67static struct attribute * kernel_attrs[] = {
68#ifdef CONFIG_HOTPLUG
Kay Sievers0f76e5a2005-11-11 04:58:04 +010069 &uevent_seqnum_attr.attr,
70 &uevent_helper_attr.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070071#endif
Vivek Goyal625f1c82005-06-25 14:58:12 -070072#ifdef CONFIG_KEXEC
73 &crash_notes_attr.attr,
74#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 NULL
76};
77
78static struct attribute_group kernel_attr_group = {
79 .attrs = kernel_attrs,
80};
81
82static int __init ksysfs_init(void)
83{
84 int error = subsystem_register(&kernel_subsys);
85 if (!error)
86 error = sysfs_create_group(&kernel_subsys.kset.kobj,
87 &kernel_attr_group);
88
89 return error;
90}
91
92core_initcall(ksysfs_init);