| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
|  | 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.org | f743ca5 | 2005-11-22 23:36:13 -0800 | [diff] [blame] | 18 | u64 uevent_seqnum; | 
|  | 19 | char uevent_helper[UEVENT_HELPER_PATH_LEN] = "/sbin/hotplug"; | 
|  | 20 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #define KERNEL_ATTR_RO(_name) \ | 
|  | 22 | static struct subsys_attribute _name##_attr = __ATTR_RO(_name) | 
|  | 23 |  | 
|  | 24 | #define KERNEL_ATTR_RW(_name) \ | 
|  | 25 | static struct subsys_attribute _name##_attr = \ | 
|  | 26 | __ATTR(_name, 0644, _name##_show, _name##_store) | 
|  | 27 |  | 
|  | 28 | #ifdef CONFIG_HOTPLUG | 
| Kay Sievers | 0f76e5a | 2005-11-11 04:58:04 +0100 | [diff] [blame] | 29 | /* current uevent sequence number */ | 
|  | 30 | static ssize_t uevent_seqnum_show(struct subsystem *subsys, char *page) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | { | 
| Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 32 | return sprintf(page, "%llu\n", (unsigned long long)uevent_seqnum); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | } | 
| Kay Sievers | 0f76e5a | 2005-11-11 04:58:04 +0100 | [diff] [blame] | 34 | KERNEL_ATTR_RO(uevent_seqnum); | 
|  | 35 |  | 
|  | 36 | /* uevent helper program, used during early boo */ | 
|  | 37 | static ssize_t uevent_helper_show(struct subsystem *subsys, char *page) | 
|  | 38 | { | 
| Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 39 | return sprintf(page, "%s\n", uevent_helper); | 
| Kay Sievers | 0f76e5a | 2005-11-11 04:58:04 +0100 | [diff] [blame] | 40 | } | 
|  | 41 | static ssize_t uevent_helper_store(struct subsystem *subsys, const char *page, size_t count) | 
|  | 42 | { | 
| Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 43 | if (count+1 > UEVENT_HELPER_PATH_LEN) | 
| Kay Sievers | 0f76e5a | 2005-11-11 04:58:04 +0100 | [diff] [blame] | 44 | return -ENOENT; | 
| Kay Sievers | 312c004 | 2005-11-16 09:00:00 +0100 | [diff] [blame] | 45 | 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 Sievers | 0f76e5a | 2005-11-11 04:58:04 +0100 | [diff] [blame] | 49 | return count; | 
|  | 50 | } | 
|  | 51 | KERNEL_ATTR_RW(uevent_helper); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #endif | 
|  | 53 |  | 
|  | 54 | decl_subsys(kernel, NULL, NULL); | 
|  | 55 | EXPORT_SYMBOL_GPL(kernel_subsys); | 
|  | 56 |  | 
|  | 57 | static struct attribute * kernel_attrs[] = { | 
|  | 58 | #ifdef CONFIG_HOTPLUG | 
| Kay Sievers | 0f76e5a | 2005-11-11 04:58:04 +0100 | [diff] [blame] | 59 | &uevent_seqnum_attr.attr, | 
|  | 60 | &uevent_helper_attr.attr, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | NULL | 
|  | 63 | }; | 
|  | 64 |  | 
|  | 65 | static struct attribute_group kernel_attr_group = { | 
|  | 66 | .attrs = kernel_attrs, | 
|  | 67 | }; | 
|  | 68 |  | 
|  | 69 | static int __init ksysfs_init(void) | 
|  | 70 | { | 
|  | 71 | int error = subsystem_register(&kernel_subsys); | 
|  | 72 | if (!error) | 
|  | 73 | error = sysfs_create_group(&kernel_subsys.kset.kobj, | 
|  | 74 | &kernel_attr_group); | 
|  | 75 |  | 
|  | 76 | return error; | 
|  | 77 | } | 
|  | 78 |  | 
|  | 79 | core_initcall(ksysfs_init); |