2 * kernel/ksysfs.c - sysfs attributes in /sys/kernel, which
3 * are not related to any other subsystem
5 * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
7 * This file is release under the GPLv2
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>
18 #define KERNEL_ATTR_RO(_name) \
19 static struct subsys_attribute _name##_attr = __ATTR_RO(_name)
21 #define KERNEL_ATTR_RW(_name) \
22 static struct subsys_attribute _name##_attr = \
23 __ATTR(_name, 0644, _name##_show, _name##_store)
25 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
26 /* current uevent sequence number */
27 static ssize_t
uevent_seqnum_show(struct subsystem
*subsys
, char *page
)
29 return sprintf(page
, "%llu\n", (unsigned long long)uevent_seqnum
);
31 KERNEL_ATTR_RO(uevent_seqnum
);
33 /* uevent helper program, used during early boo */
34 static ssize_t
uevent_helper_show(struct subsystem
*subsys
, char *page
)
36 return sprintf(page
, "%s\n", uevent_helper
);
38 static ssize_t
uevent_helper_store(struct subsystem
*subsys
, const char *page
, size_t count
)
40 if (count
+1 > UEVENT_HELPER_PATH_LEN
)
42 memcpy(uevent_helper
, page
, count
);
43 uevent_helper
[count
] = '\0';
44 if (count
&& uevent_helper
[count
-1] == '\n')
45 uevent_helper
[count
-1] = '\0';
48 KERNEL_ATTR_RW(uevent_helper
);
51 decl_subsys(kernel
, NULL
, NULL
);
52 EXPORT_SYMBOL_GPL(kernel_subsys
);
54 static struct attribute
* kernel_attrs
[] = {
55 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
56 &uevent_seqnum_attr
.attr
,
57 &uevent_helper_attr
.attr
,
62 static struct attribute_group kernel_attr_group
= {
63 .attrs
= kernel_attrs
,
66 static int __init
ksysfs_init(void)
68 int error
= subsystem_register(&kernel_subsys
);
70 error
= sysfs_create_group(&kernel_subsys
.kset
.kobj
,
76 core_initcall(ksysfs_init
);