1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35#ifndef _CONFIGFS_H_
36#define _CONFIGFS_H_
37
38#include <linux/stat.h>
39#include <linux/types.h>
40#include <linux/list.h>
41#include <linux/kref.h>
42#include <linux/mutex.h>
43
44#define CONFIGFS_ITEM_NAME_LEN 20
45
46struct module;
47
48struct configfs_item_operations;
49struct configfs_group_operations;
50struct configfs_attribute;
51struct configfs_bin_attribute;
52struct configfs_subsystem;
53
54struct config_item {
55 char *ci_name;
56 char ci_namebuf[CONFIGFS_ITEM_NAME_LEN];
57 struct kref ci_kref;
58 struct list_head ci_entry;
59 struct config_item *ci_parent;
60 struct config_group *ci_group;
61 const struct config_item_type *ci_type;
62 struct dentry *ci_dentry;
63};
64
65extern __printf(2, 3)
66int config_item_set_name(struct config_item *, const char *, ...);
67
68static inline char *config_item_name(struct config_item * item)
69{
70 return item->ci_name;
71}
72
73extern void config_item_init_type_name(struct config_item *item,
74 const char *name,
75 const struct config_item_type *type);
76
77extern struct config_item *config_item_get(struct config_item *);
78extern struct config_item *config_item_get_unless_zero(struct config_item *);
79extern void config_item_put(struct config_item *);
80
81struct config_item_type {
82 struct module *ct_owner;
83 struct configfs_item_operations *ct_item_ops;
84 struct configfs_group_operations *ct_group_ops;
85 struct configfs_attribute **ct_attrs;
86 struct configfs_bin_attribute **ct_bin_attrs;
87};
88
89
90
91
92
93struct config_group {
94 struct config_item cg_item;
95 struct list_head cg_children;
96 struct configfs_subsystem *cg_subsys;
97 struct list_head default_groups;
98 struct list_head group_entry;
99};
100
101extern void config_group_init(struct config_group *group);
102extern void config_group_init_type_name(struct config_group *group,
103 const char *name,
104 const struct config_item_type *type);
105
106static inline struct config_group *to_config_group(struct config_item *item)
107{
108 return item ? container_of(item,struct config_group,cg_item) : NULL;
109}
110
111static inline struct config_group *config_group_get(struct config_group *group)
112{
113 return group ? to_config_group(config_item_get(&group->cg_item)) : NULL;
114}
115
116static inline void config_group_put(struct config_group *group)
117{
118 config_item_put(&group->cg_item);
119}
120
121extern struct config_item *config_group_find_item(struct config_group *,
122 const char *);
123
124
125static inline void configfs_add_default_group(struct config_group *new_group,
126 struct config_group *group)
127{
128 list_add_tail(&new_group->group_entry, &group->default_groups);
129}
130
131struct configfs_attribute {
132 const char *ca_name;
133 struct module *ca_owner;
134 umode_t ca_mode;
135 ssize_t (*show)(struct config_item *, char *);
136 ssize_t (*store)(struct config_item *, const char *, size_t);
137};
138
139#define CONFIGFS_ATTR(_pfx, _name) \
140static struct configfs_attribute _pfx##attr_##_name = { \
141 .ca_name = __stringify(_name), \
142 .ca_mode = S_IRUGO | S_IWUSR, \
143 .ca_owner = THIS_MODULE, \
144 .show = _pfx##_name##_show, \
145 .store = _pfx##_name##_store, \
146}
147
148#define CONFIGFS_ATTR_RO(_pfx, _name) \
149static struct configfs_attribute _pfx##attr_##_name = { \
150 .ca_name = __stringify(_name), \
151 .ca_mode = S_IRUGO, \
152 .ca_owner = THIS_MODULE, \
153 .show = _pfx##_name##_show, \
154}
155
156#define CONFIGFS_ATTR_WO(_pfx, _name) \
157static struct configfs_attribute _pfx##attr_##_name = { \
158 .ca_name = __stringify(_name), \
159 .ca_mode = S_IWUSR, \
160 .ca_owner = THIS_MODULE, \
161 .store = _pfx##_name##_store, \
162}
163
164struct file;
165struct vm_area_struct;
166
167struct configfs_bin_attribute {
168 struct configfs_attribute cb_attr;
169 void *cb_private;
170 size_t cb_max_size;
171 ssize_t (*read)(struct config_item *, void *, size_t);
172 ssize_t (*write)(struct config_item *, const void *, size_t);
173};
174
175#define CONFIGFS_BIN_ATTR(_pfx, _name, _priv, _maxsz) \
176static struct configfs_bin_attribute _pfx##attr_##_name = { \
177 .cb_attr = { \
178 .ca_name = __stringify(_name), \
179 .ca_mode = S_IRUGO | S_IWUSR, \
180 .ca_owner = THIS_MODULE, \
181 }, \
182 .cb_private = _priv, \
183 .cb_max_size = _maxsz, \
184 .read = _pfx##_name##_read, \
185 .write = _pfx##_name##_write, \
186}
187
188#define CONFIGFS_BIN_ATTR_RO(_pfx, _name, _priv, _maxsz) \
189static struct configfs_bin_attribute _pfx##attr_##_name = { \
190 .cb_attr = { \
191 .ca_name = __stringify(_name), \
192 .ca_mode = S_IRUGO, \
193 .ca_owner = THIS_MODULE, \
194 }, \
195 .cb_private = _priv, \
196 .cb_max_size = _maxsz, \
197 .read = _pfx##_name##_read, \
198}
199
200#define CONFIGFS_BIN_ATTR_WO(_pfx, _name, _priv, _maxsz) \
201static struct configfs_bin_attribute _pfx##attr_##_name = { \
202 .cb_attr = { \
203 .ca_name = __stringify(_name), \
204 .ca_mode = S_IWUSR, \
205 .ca_owner = THIS_MODULE, \
206 }, \
207 .cb_private = _priv, \
208 .cb_max_size = _maxsz, \
209 .write = _pfx##_name##_write, \
210}
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226struct configfs_item_operations {
227 void (*release)(struct config_item *);
228 int (*allow_link)(struct config_item *src, struct config_item *target);
229 void (*drop_link)(struct config_item *src, struct config_item *target);
230};
231
232struct configfs_group_operations {
233 struct config_item *(*make_item)(struct config_group *group, const char *name);
234 struct config_group *(*make_group)(struct config_group *group, const char *name);
235 int (*commit_item)(struct config_item *item);
236 void (*disconnect_notify)(struct config_group *group, struct config_item *item);
237 void (*drop_item)(struct config_group *group, struct config_item *item);
238};
239
240struct configfs_subsystem {
241 struct config_group su_group;
242 struct mutex su_mutex;
243};
244
245static inline struct configfs_subsystem *to_configfs_subsystem(struct config_group *group)
246{
247 return group ?
248 container_of(group, struct configfs_subsystem, su_group) :
249 NULL;
250}
251
252int configfs_register_subsystem(struct configfs_subsystem *subsys);
253void configfs_unregister_subsystem(struct configfs_subsystem *subsys);
254
255int configfs_register_group(struct config_group *parent_group,
256 struct config_group *group);
257void configfs_unregister_group(struct config_group *group);
258
259void configfs_remove_default_groups(struct config_group *group);
260
261struct config_group *
262configfs_register_default_group(struct config_group *parent_group,
263 const char *name,
264 const struct config_item_type *item_type);
265void configfs_unregister_default_group(struct config_group *group);
266
267
268
269int configfs_depend_item(struct configfs_subsystem *subsys,
270 struct config_item *target);
271void configfs_undepend_item(struct config_item *target);
272
273
274
275
276
277
278
279
280int configfs_depend_item_unlocked(struct configfs_subsystem *caller_subsys,
281 struct config_item *target);
282
283
284static inline void configfs_undepend_item_unlocked(struct config_item *target)
285{
286 configfs_undepend_item(target);
287}
288
289#endif
290