diff options
-rw-r--r-- | include/linux/kobject.h | 10 | ||||
-rw-r--r-- | lib/kobject.c | 29 |
2 files changed, 39 insertions, 0 deletions
diff --git a/include/linux/kobject.h b/include/linux/kobject.h index a6dd669cda9d..e694261de90f 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h | |||
@@ -126,6 +126,16 @@ struct kset_uevent_ops { | |||
126 | struct kobj_uevent_env *env); | 126 | struct kobj_uevent_env *env); |
127 | }; | 127 | }; |
128 | 128 | ||
129 | struct kobj_attribute { | ||
130 | struct attribute attr; | ||
131 | ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr, | ||
132 | char *buf); | ||
133 | ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr, | ||
134 | const char *buf, size_t count); | ||
135 | }; | ||
136 | |||
137 | extern struct sysfs_ops kobj_sysfs_ops; | ||
138 | |||
129 | /** | 139 | /** |
130 | * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem. | 140 | * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem. |
131 | * | 141 | * |
diff --git a/lib/kobject.c b/lib/kobject.c index 67c3d38d48f0..1c343fe4ba63 100644 --- a/lib/kobject.c +++ b/lib/kobject.c | |||
@@ -697,6 +697,35 @@ void kset_init(struct kset * k) | |||
697 | spin_lock_init(&k->list_lock); | 697 | spin_lock_init(&k->list_lock); |
698 | } | 698 | } |
699 | 699 | ||
700 | /* default kobject attribute operations */ | ||
701 | static ssize_t kobj_attr_show(struct kobject *kobj, struct attribute *attr, | ||
702 | char *buf) | ||
703 | { | ||
704 | struct kobj_attribute *kattr; | ||
705 | ssize_t ret = -EIO; | ||
706 | |||
707 | kattr = container_of(attr, struct kobj_attribute, attr); | ||
708 | if (kattr->show) | ||
709 | ret = kattr->show(kobj, kattr, buf); | ||
710 | return ret; | ||
711 | } | ||
712 | |||
713 | static ssize_t kobj_attr_store(struct kobject *kobj, struct attribute *attr, | ||
714 | const char *buf, size_t count) | ||
715 | { | ||
716 | struct kobj_attribute *kattr; | ||
717 | ssize_t ret = -EIO; | ||
718 | |||
719 | kattr = container_of(attr, struct kobj_attribute, attr); | ||
720 | if (kattr->store) | ||
721 | ret = kattr->store(kobj, kattr, buf, count); | ||
722 | return ret; | ||
723 | } | ||
724 | |||
725 | struct sysfs_ops kobj_sysfs_ops = { | ||
726 | .show = kobj_attr_show, | ||
727 | .store = kobj_attr_store, | ||
728 | }; | ||
700 | 729 | ||
701 | /** | 730 | /** |
702 | * kset_add - add a kset object to the hierarchy. | 731 | * kset_add - add a kset object to the hierarchy. |