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