Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 28290
b: refs/heads/master
c: 670dd90
h: refs/heads/master
v: v3
  • Loading branch information
Shaohua Li authored and Greg Kroah-Hartman committed Jun 21, 2006
1 parent 4890709 commit ad18b7c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1740757e8f94c6899705eb6f5434de9404992778
refs/heads/master: 670dd90d81f60ef429cbba54ad235e9207f4d444
51 changes: 50 additions & 1 deletion trunk/drivers/base/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,59 @@ void sysdev_remove_file(struct sys_device * s, struct sysdev_attribute * a)
EXPORT_SYMBOL_GPL(sysdev_create_file);
EXPORT_SYMBOL_GPL(sysdev_remove_file);

#define to_sysdev_class(k) container_of(k, struct sysdev_class, kset.kobj)
#define to_sysdev_class_attr(a) container_of(a, \
struct sysdev_class_attribute, attr)

static ssize_t sysdev_class_show(struct kobject *kobj, struct attribute *attr,
char *buffer)
{
struct sysdev_class * class = to_sysdev_class(kobj);
struct sysdev_class_attribute *class_attr = to_sysdev_class_attr(attr);

if (class_attr->show)
return class_attr->show(class, buffer);
return -EIO;
}

static ssize_t sysdev_class_store(struct kobject *kobj, struct attribute *attr,
const char *buffer, size_t count)
{
struct sysdev_class * class = to_sysdev_class(kobj);
struct sysdev_class_attribute * class_attr = to_sysdev_class_attr(attr);

if (class_attr->store)
return class_attr->store(class, buffer, count);
return -EIO;
}

static struct sysfs_ops sysfs_class_ops = {
.show = sysdev_class_show,
.store = sysdev_class_store,
};

static struct kobj_type ktype_sysdev_class = {
.sysfs_ops = &sysfs_class_ops,
};

int sysdev_class_create_file(struct sysdev_class *c,
struct sysdev_class_attribute *a)
{
return sysfs_create_file(&c->kset.kobj, &a->attr);
}
EXPORT_SYMBOL_GPL(sysdev_class_create_file);

void sysdev_class_remove_file(struct sysdev_class *c,
struct sysdev_class_attribute *a)
{
sysfs_remove_file(&c->kset.kobj, &a->attr);
}
EXPORT_SYMBOL_GPL(sysdev_class_remove_file);

/*
* declare system_subsys
*/
static decl_subsys(system, &ktype_sysdev, NULL);
static decl_subsys(system, &ktype_sysdev_class, NULL);

int sysdev_class_register(struct sysdev_class * cls)
{
Expand Down
18 changes: 17 additions & 1 deletion trunk/include/linux/sysdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,27 @@ struct sysdev_class {
struct kset kset;
};

struct sysdev_class_attribute {
struct attribute attr;
ssize_t (*show)(struct sysdev_class *, char *);
ssize_t (*store)(struct sysdev_class *, const char *, size_t);
};

#define SYSDEV_CLASS_ATTR(_name,_mode,_show,_store) \
struct sysdev_class_attribute attr_##_name = { \
.attr = {.name = __stringify(_name), .mode = _mode }, \
.show = _show, \
.store = _store, \
};


extern int sysdev_class_register(struct sysdev_class *);
extern void sysdev_class_unregister(struct sysdev_class *);


extern int sysdev_class_create_file(struct sysdev_class *,
struct sysdev_class_attribute *);
extern void sysdev_class_remove_file(struct sysdev_class *,
struct sysdev_class_attribute *);
/**
* Auxillary system device drivers.
*/
Expand Down

0 comments on commit ad18b7c

Please sign in to comment.