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/kernel.h>
39#include <linux/types.h>
40#include <linux/list.h>
41#include <linux/kref.h>
42#include <linux/mutex.h>
43#include <linux/err.h>
44
45#include <linux/atomic.h>
46
47#define CONFIGFS_ITEM_NAME_LEN 20
48
49struct module;
50
51struct configfs_item_operations;
52struct configfs_group_operations;
53struct configfs_attribute;
54struct configfs_subsystem;
55
56struct config_item {
57 char *ci_name;
58 char ci_namebuf[CONFIGFS_ITEM_NAME_LEN];
59 struct kref ci_kref;
60 struct list_head ci_entry;
61 struct config_item *ci_parent;
62 struct config_group *ci_group;
63 struct config_item_type *ci_type;
64 struct dentry *ci_dentry;
65};
66
67extern __printf(2, 3)
68int config_item_set_name(struct config_item *, const char *, ...);
69
70static inline char *config_item_name(struct config_item * item)
71{
72 return item->ci_name;
73}
74
75extern void config_item_init_type_name(struct config_item *item,
76 const char *name,
77 struct config_item_type *type);
78
79extern struct config_item * config_item_get(struct config_item *);
80extern void config_item_put(struct config_item *);
81
82struct config_item_type {
83 struct module *ct_owner;
84 struct configfs_item_operations *ct_item_ops;
85 struct configfs_group_operations *ct_group_ops;
86 struct configfs_attribute **ct_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 config_group **default_groups;
98};
99
100extern void config_group_init(struct config_group *group);
101extern void config_group_init_type_name(struct config_group *group,
102 const char *name,
103 struct config_item_type *type);
104
105static inline struct config_group *to_config_group(struct config_item *item)
106{
107 return item ? container_of(item,struct config_group,cg_item) : NULL;
108}
109
110static inline struct config_group *config_group_get(struct config_group *group)
111{
112 return group ? to_config_group(config_item_get(&group->cg_item)) : NULL;
113}
114
115static inline void config_group_put(struct config_group *group)
116{
117 config_item_put(&group->cg_item);
118}
119
120extern struct config_item *config_group_find_item(struct config_group *,
121 const char *);
122
123
124struct configfs_attribute {
125 const char *ca_name;
126 struct module *ca_owner;
127 umode_t ca_mode;
128};
129
130
131
132
133
134
135
136
137
138#define CONFIGFS_ATTR_STRUCT(_item) \
139struct _item##_attribute { \
140 struct configfs_attribute attr; \
141 ssize_t (*show)(struct _item *, char *); \
142 ssize_t (*store)(struct _item *, const char *, size_t); \
143}
144
145
146
147
148
149
150
151
152
153#define __CONFIGFS_ATTR(_name, _mode, _show, _store) \
154{ \
155 .attr = { \
156 .ca_name = __stringify(_name), \
157 .ca_mode = _mode, \
158 .ca_owner = THIS_MODULE, \
159 }, \
160 .show = _show, \
161 .store = _store, \
162}
163
164#define __CONFIGFS_ATTR_RO(_name, _show) \
165{ \
166 .attr = { \
167 .ca_name = __stringify(_name), \
168 .ca_mode = 0444, \
169 .ca_owner = THIS_MODULE, \
170 }, \
171 .show = _show, \
172}
173
174
175
176
177
178
179
180
181
182#define CONFIGFS_ATTR_OPS(_item) \
183static ssize_t _item##_attr_show(struct config_item *item, \
184 struct configfs_attribute *attr, \
185 char *page) \
186{ \
187 struct _item *_item = to_##_item(item); \
188 struct _item##_attribute *_item##_attr = \
189 container_of(attr, struct _item##_attribute, attr); \
190 ssize_t ret = 0; \
191 \
192 if (_item##_attr->show) \
193 ret = _item##_attr->show(_item, page); \
194 return ret; \
195} \
196static ssize_t _item##_attr_store(struct config_item *item, \
197 struct configfs_attribute *attr, \
198 const char *page, size_t count) \
199{ \
200 struct _item *_item = to_##_item(item); \
201 struct _item##_attribute *_item##_attr = \
202 container_of(attr, struct _item##_attribute, attr); \
203 ssize_t ret = -EINVAL; \
204 \
205 if (_item##_attr->store) \
206 ret = _item##_attr->store(_item, page, count); \
207 return ret; \
208}
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224struct configfs_item_operations {
225 void (*release)(struct config_item *);
226 ssize_t (*show_attribute)(struct config_item *, struct configfs_attribute *,char *);
227 ssize_t (*store_attribute)(struct config_item *,struct configfs_attribute *,const char *, size_t);
228 int (*allow_link)(struct config_item *src, struct config_item *target);
229 int (*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
255
256
257int configfs_depend_item(struct configfs_subsystem *subsys, struct config_item *target);
258void configfs_undepend_item(struct configfs_subsystem *subsys, struct config_item *target);
259
260#endif
261