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 a6dd669cda9..e694261de90 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h @@ -126,6 +126,16 @@ struct kset_uevent_ops { struct kobj_uevent_env *env); }; +struct kobj_attribute { + struct attribute attr; + ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr, + char *buf); + ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr, + const char *buf, size_t count); +}; + +extern struct sysfs_ops kobj_sysfs_ops; + /** * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem. * diff --git a/lib/kobject.c b/lib/kobject.c index 67c3d38d48f..1c343fe4ba6 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -697,6 +697,35 @@ void kset_init(struct kset * k) spin_lock_init(&k->list_lock); } +/* default kobject attribute operations */ +static ssize_t kobj_attr_show(struct kobject *kobj, struct attribute *attr, + char *buf) +{ + struct kobj_attribute *kattr; + ssize_t ret = -EIO; + + kattr = container_of(attr, struct kobj_attribute, attr); + if (kattr->show) + ret = kattr->show(kobj, kattr, buf); + return ret; +} + +static ssize_t kobj_attr_store(struct kobject *kobj, struct attribute *attr, + const char *buf, size_t count) +{ + struct kobj_attribute *kattr; + ssize_t ret = -EIO; + + kattr = container_of(attr, struct kobj_attribute, attr); + if (kattr->store) + ret = kattr->store(kobj, kattr, buf, count); + return ret; +} + +struct sysfs_ops kobj_sysfs_ops = { + .show = kobj_attr_show, + .store = kobj_attr_store, +}; /** * kset_add - add a kset object to the hierarchy. |