Merge to Fedora kernel-2.6.7-1.492
[linux-2.6.git] / include / linux / sysfs.h
1 /*
2  * sysfs.h - definitions for the device driver filesystem
3  *
4  * Copyright (c) 2001,2002 Patrick Mochel
5  *
6  * Please see Documentation/filesystems/sysfs.txt for more information.
7  */
8
9 #ifndef _SYSFS_H_
10 #define _SYSFS_H_
11
12 struct kobject;
13 struct module;
14
15 struct attribute {
16         char                    * name;
17         struct module           * owner;
18         mode_t                  mode;
19 };
20
21 struct attribute_group {
22         char                    * name;
23         struct attribute        ** attrs;
24 };
25
26
27
28 /**
29  * Use these macros to make defining attributes easier. See include/linux/device.h
30  * for examples..
31  */
32
33 #define __ATTR(_name,_mode,_show,_store) { \
34         .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE },     \
35         .show   = _show,                                        \
36         .store  = _store,                                       \
37 }
38
39 #define __ATTR_RO(_name) { \
40         .attr   = { .name = __stringify(_name), .mode = 0444, .owner = THIS_MODULE },   \
41         .show   = _name##_show, \
42 }
43
44 #define __ATTR_NULL { .attr = { .name = NULL } }
45
46 #define attr_name(_attr) (_attr).attr.name
47
48 struct bin_attribute {
49         struct attribute        attr;
50         size_t                  size;
51         ssize_t (*read)(struct kobject *, char *, loff_t, size_t);
52         ssize_t (*write)(struct kobject *, char *, loff_t, size_t);
53 };
54
55 struct sysfs_ops {
56         ssize_t (*show)(struct kobject *, struct attribute *,char *);
57         ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
58 };
59
60 #ifdef CONFIG_SYSFS
61
62 extern int
63 sysfs_create_dir(struct kobject *);
64
65 extern void
66 sysfs_remove_dir(struct kobject *);
67
68 extern int
69 sysfs_rename_dir(struct kobject *, const char *new_name);
70
71 extern int
72 sysfs_create_file(struct kobject *, const struct attribute *);
73
74 extern int
75 sysfs_update_file(struct kobject *, const struct attribute *);
76
77 extern void
78 sysfs_remove_file(struct kobject *, const struct attribute *);
79
80 extern int 
81 sysfs_create_link(struct kobject * kobj, struct kobject * target, char * name);
82
83 extern void
84 sysfs_remove_link(struct kobject *, char * name);
85
86 int sysfs_create_bin_file(struct kobject * kobj, struct bin_attribute * attr);
87 int sysfs_remove_bin_file(struct kobject * kobj, struct bin_attribute * attr);
88
89 int sysfs_create_group(struct kobject *, const struct attribute_group *);
90 void sysfs_remove_group(struct kobject *, const struct attribute_group *);
91
92 #else /* CONFIG_SYSFS */
93
94 static inline int sysfs_create_dir(struct kobject * k)
95 {
96         return 0;
97 }
98
99 static inline void sysfs_remove_dir(struct kobject * k)
100 {
101         ;
102 }
103
104 static inline int sysfs_rename_dir(struct kobject * k, const char *new_name)
105 {
106         return 0;
107 }
108
109 static inline int sysfs_create_file(struct kobject * k, const struct attribute * a)
110 {
111         return 0;
112 }
113
114 static inline int sysfs_update_file(struct kobject * k, const struct attribute * a)
115 {
116         return 0;
117 }
118
119 static inline void sysfs_remove_file(struct kobject * k, const struct attribute * a)
120 {
121         ;
122 }
123
124 static inline int sysfs_create_link(struct kobject * k, struct kobject * t, char * n)
125 {
126         return 0;
127 }
128
129 static inline void sysfs_remove_link(struct kobject * k, char * name)
130 {
131         ;
132 }
133
134
135 static inline int sysfs_create_bin_file(struct kobject * k, struct bin_attribute * a)
136 {
137         return 0;
138 }
139
140 static inline int sysfs_remove_bin_file(struct kobject * k, struct bin_attribute * a)
141 {
142         return 0;
143 }
144
145 static inline int sysfs_create_group(struct kobject * k, const struct attribute_group *g)
146 {
147         return 0;
148 }
149
150 static inline void sysfs_remove_group(struct kobject * k, const struct attribute_group * g)
151 {
152         ;
153 }
154
155 #endif /* CONFIG_SYSFS */
156
157 #endif /* _SYSFS_H_ */