]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - kernel/ksysfs.c
[PATCH] Char: stallion, implement fail paths
[mirror_ubuntu-bionic-kernel.git] / kernel / ksysfs.c
CommitLineData
1da177e4
LT
1/*
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
1da177e4
LT
11#include <linux/kobject.h>
12#include <linux/string.h>
13#include <linux/sysfs.h>
14#include <linux/module.h>
15#include <linux/init.h>
c330dda9 16#include <linux/kexec.h>
1da177e4
LT
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
f125b561 25#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
0f76e5ac
KS
26/* current uevent sequence number */
27static ssize_t uevent_seqnum_show(struct subsystem *subsys, char *page)
1da177e4 28{
312c004d 29 return sprintf(page, "%llu\n", (unsigned long long)uevent_seqnum);
1da177e4 30}
0f76e5ac
KS
31KERNEL_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{
312c004d 36 return sprintf(page, "%s\n", uevent_helper);
0f76e5ac
KS
37}
38static ssize_t uevent_helper_store(struct subsystem *subsys, const char *page, size_t count)
39{
312c004d 40 if (count+1 > UEVENT_HELPER_PATH_LEN)
0f76e5ac 41 return -ENOENT;
312c004d
KS
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';
0f76e5ac
KS
46 return count;
47}
48KERNEL_ATTR_RW(uevent_helper);
1da177e4
LT
49#endif
50
c330dda9
JM
51#ifdef CONFIG_KEXEC
52static ssize_t kexec_loaded_show(struct subsystem *subsys, char *page)
53{
54 return sprintf(page, "%d\n", !!kexec_image);
55}
56KERNEL_ATTR_RO(kexec_loaded);
57
58static ssize_t kexec_crash_loaded_show(struct subsystem *subsys, char *page)
59{
60 return sprintf(page, "%d\n", !!kexec_crash_image);
61}
62KERNEL_ATTR_RO(kexec_crash_loaded);
63#endif /* CONFIG_KEXEC */
64
1da177e4
LT
65decl_subsys(kernel, NULL, NULL);
66EXPORT_SYMBOL_GPL(kernel_subsys);
67
68static struct attribute * kernel_attrs[] = {
f125b561 69#if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
0f76e5ac
KS
70 &uevent_seqnum_attr.attr,
71 &uevent_helper_attr.attr,
c330dda9
JM
72#endif
73#ifdef CONFIG_KEXEC
74 &kexec_loaded_attr.attr,
75 &kexec_crash_loaded_attr.attr,
1da177e4
LT
76#endif
77 NULL
78};
79
80static struct attribute_group kernel_attr_group = {
81 .attrs = kernel_attrs,
82};
83
84static int __init ksysfs_init(void)
85{
86 int error = subsystem_register(&kernel_subsys);
87 if (!error)
88 error = sysfs_create_group(&kernel_subsys.kset.kobj,
89 &kernel_attr_group);
90
91 return error;
92}
93
94core_initcall(ksysfs_init);