blob: f119e098e67b1758c3ceffdb095cfdcc40232b2c [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
18#define KERNEL_ATTR_RO(_name) \
19static struct subsys_attribute _name##_attr = __ATTR_RO(_name)
20
21#define KERNEL_ATTR_RW(_name) \
22static struct subsys_attribute _name##_attr = \
23 __ATTR(_name, 0644, _name##_show, _name##_store)
24
Andrew Mortonf125b562006-03-24 03:18:44 -080025#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Kay Sievers0f76e5a2005-11-11 04:58:04 +010026/* current uevent sequence number */
27static ssize_t uevent_seqnum_show(struct subsystem *subsys, char *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028{
Kay Sievers312c0042005-11-16 09:00:00 +010029 return sprintf(page, "%llu\n", (unsigned long long)uevent_seqnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030}
Kay Sievers0f76e5a2005-11-11 04:58:04 +010031KERNEL_ATTR_RO(uevent_seqnum);
32
33/* uevent helper program, used during early boo */
34static ssize_t uevent_helper_show(struct subsystem *subsys, char *page)
35{
Kay Sievers312c0042005-11-16 09:00:00 +010036 return sprintf(page, "%s\n", uevent_helper);
Kay Sievers0f76e5a2005-11-11 04:58:04 +010037}
38static ssize_t uevent_helper_store(struct subsystem *subsys, const char *page, size_t count)
39{
Kay Sievers312c0042005-11-16 09:00:00 +010040 if (count+1 > UEVENT_HELPER_PATH_LEN)
Kay Sievers0f76e5a2005-11-11 04:58:04 +010041 return -ENOENT;
Kay Sievers312c0042005-11-16 09:00:00 +010042 memcpy(uevent_helper, page, count);
43 uevent_helper[count] = '\0';
44 if (count && uevent_helper[count-1] == '\n')
45 uevent_helper[count-1] = '\0';
Kay Sievers0f76e5a2005-11-11 04:58:04 +010046 return count;
47}
48KERNEL_ATTR_RW(uevent_helper);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#endif
50
51decl_subsys(kernel, NULL, NULL);
52EXPORT_SYMBOL_GPL(kernel_subsys);
53
54static struct attribute * kernel_attrs[] = {
Andrew Mortonf125b562006-03-24 03:18:44 -080055#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
Kay Sievers0f76e5a2005-11-11 04:58:04 +010056 &uevent_seqnum_attr.attr,
57 &uevent_helper_attr.attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 NULL
60};
61
62static struct attribute_group kernel_attr_group = {
63 .attrs = kernel_attrs,
64};
65
66static int __init ksysfs_init(void)
67{
68 int error = subsystem_register(&kernel_subsys);
69 if (!error)
70 error = sysfs_create_group(&kernel_subsys.kset.kobj,
71 &kernel_attr_group);
72
73 return error;
74}
75
76core_initcall(ksysfs_init);