From 41efb2d07524dce3570ccb296a9efc0bd5c05faa Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Fri, 2 Nov 2007 13:47:53 +0100 Subject: [PATCH] --- yaml --- r: 75761 b: refs/heads/master c: 23b5212cc7422f475b82124334b64277b5b43013 h: refs/heads/master i: 75759: a813a7405df628e53df58d2d00a7c3f38c033381 v: v3 --- [refs] | 2 +- trunk/include/linux/kobject.h | 10 ++++++++++ trunk/lib/kobject.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/[refs] b/[refs] index e1380c710478..e095139075f3 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 6dcec2511ff55b4abaca7ad3433011a7c04c2430 +refs/heads/master: 23b5212cc7422f475b82124334b64277b5b43013 diff --git a/trunk/include/linux/kobject.h b/trunk/include/linux/kobject.h index a6dd669cda9d..e694261de90f 100644 --- a/trunk/include/linux/kobject.h +++ b/trunk/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/trunk/lib/kobject.c b/trunk/lib/kobject.c index 67c3d38d48f0..1c343fe4ba63 100644 --- a/trunk/lib/kobject.c +++ b/trunk/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.