kobject-example.c (2d8ad8719591fa803b0d589ed057fa46f49b7155) kobject-example.c (de5109898a8a0cb001abcb6916bef4efa32bf39b)
1/*
2 * Sample kobject implementation
3 *
4 * Copyright (C) 2004-2007 Greg Kroah-Hartman <greg@kroah.com>
5 * Copyright (C) 2007 Novell Inc.
6 *
7 * Released under the GPL version 2 only.
8 *

--- 26 unchanged lines hidden (view full) ---

35
36static ssize_t foo_store(struct kobject *kobj, struct kobj_attribute *attr,
37 const char *buf, size_t count)
38{
39 sscanf(buf, "%du", &foo);
40 return count;
41}
42
1/*
2 * Sample kobject implementation
3 *
4 * Copyright (C) 2004-2007 Greg Kroah-Hartman <greg@kroah.com>
5 * Copyright (C) 2007 Novell Inc.
6 *
7 * Released under the GPL version 2 only.
8 *

--- 26 unchanged lines hidden (view full) ---

35
36static ssize_t foo_store(struct kobject *kobj, struct kobj_attribute *attr,
37 const char *buf, size_t count)
38{
39 sscanf(buf, "%du", &foo);
40 return count;
41}
42
43/* Sysfs attributes cannot be world-writable. */
43static struct kobj_attribute foo_attribute =
44static struct kobj_attribute foo_attribute =
44 __ATTR(foo, 0666, foo_show, foo_store);
45 __ATTR(foo, 0664, foo_show, foo_store);
45
46/*
47 * More complex function where we determine which variable is being accessed by
48 * looking at the attribute for the "baz" and "bar" files.
49 */
50static ssize_t b_show(struct kobject *kobj, struct kobj_attribute *attr,
51 char *buf)
52{

--- 15 unchanged lines hidden (view full) ---

68 if (strcmp(attr->attr.name, "baz") == 0)
69 baz = var;
70 else
71 bar = var;
72 return count;
73}
74
75static struct kobj_attribute baz_attribute =
46
47/*
48 * More complex function where we determine which variable is being accessed by
49 * looking at the attribute for the "baz" and "bar" files.
50 */
51static ssize_t b_show(struct kobject *kobj, struct kobj_attribute *attr,
52 char *buf)
53{

--- 15 unchanged lines hidden (view full) ---

69 if (strcmp(attr->attr.name, "baz") == 0)
70 baz = var;
71 else
72 bar = var;
73 return count;
74}
75
76static struct kobj_attribute baz_attribute =
76 __ATTR(baz, 0666, b_show, b_store);
77 __ATTR(baz, 0664, b_show, b_store);
77static struct kobj_attribute bar_attribute =
78static struct kobj_attribute bar_attribute =
78 __ATTR(bar, 0666, b_show, b_store);
79 __ATTR(bar, 0664, b_show, b_store);
79
80
81/*
82 * Create a group of attributes so that we can create and destroy them all
83 * at once.
84 */
85static struct attribute *attrs[] = {
86 &foo_attribute.attr,

--- 51 unchanged lines hidden ---
80
81
82/*
83 * Create a group of attributes so that we can create and destroy them all
84 * at once.
85 */
86static struct attribute *attrs[] = {
87 &foo_attribute.attr,

--- 51 unchanged lines hidden ---