1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
4 * configfs.h - definitions for the device driver filesystem
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 021110-1307, USA.
22 * sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel
25 * Copyright (c) 2002-2003 Patrick Mochel
26 * Copyright (c) 2002-2003 Open Source Development Labs
28 * configfs Copyright (C) 2005 Oracle. All rights reserved.
30 * Please read Documentation/filesystems/configfs.txt before using the
31 * configfs interface, ESPECIALLY the parts about reference counts and
40 #include <linux/kernel.h>
41 #include <linux/types.h>
42 #include <linux/list.h>
43 #include <linux/kref.h>
44 #include <linux/mutex.h>
46 #include <asm/atomic.h>
48 #define CONFIGFS_ITEM_NAME_LEN 20
52 struct configfs_item_operations;
53 struct configfs_group_operations;
54 struct configfs_attribute;
55 struct configfs_subsystem;
59 char ci_namebuf[CONFIGFS_ITEM_NAME_LEN];
61 struct list_head ci_entry;
62 struct config_item *ci_parent;
63 struct config_group *ci_group;
64 struct config_item_type *ci_type;
65 struct dentry *ci_dentry;
68 extern int config_item_set_name(struct config_item *, const char *, ...);
70 static inline char *config_item_name(struct config_item * item)
75 extern void config_item_init(struct config_item *);
76 extern void config_item_init_type_name(struct config_item *item,
78 struct config_item_type *type);
80 extern struct config_item * config_item_get(struct config_item *);
81 extern void config_item_put(struct config_item *);
83 struct config_item_type {
84 struct module *ct_owner;
85 struct configfs_item_operations *ct_item_ops;
86 struct configfs_group_operations *ct_group_ops;
87 struct configfs_attribute **ct_attrs;
91 * group - a group of config_items of a specific type, belonging
92 * to a specific subsystem.
95 struct config_item cg_item;
96 struct list_head cg_children;
97 struct configfs_subsystem *cg_subsys;
98 struct config_group **default_groups;
101 extern void config_group_init(struct config_group *group);
102 extern void config_group_init_type_name(struct config_group *group,
104 struct config_item_type *type);
106 static inline struct config_group *to_config_group(struct config_item *item)
108 return item ? container_of(item,struct config_group,cg_item) : NULL;
111 static inline struct config_group *config_group_get(struct config_group *group)
113 return group ? to_config_group(config_item_get(&group->cg_item)) : NULL;
116 static inline void config_group_put(struct config_group *group)
118 config_item_put(&group->cg_item);
121 extern struct config_item *config_group_find_item(struct config_group *,
125 struct configfs_attribute {
127 struct module *ca_owner;
132 * Users often need to create attribute structures for their configurable
133 * attributes, containing a configfs_attribute member and function pointers
134 * for the show() and store() operations on that attribute. They can use
135 * this macro (similar to sysfs' __ATTR) to make defining attributes easier.
137 #define __CONFIGFS_ATTR(_name, _mode, _show, _store) \
140 .ca_name = __stringify(_name), \
142 .ca_owner = THIS_MODULE, \
149 * If allow_link() exists, the item can symlink(2) out to other
150 * items. If the item is a group, it may support mkdir(2).
151 * Groups supply one of make_group() and make_item(). If the
152 * group supports make_group(), one can create group children. If it
153 * supports make_item(), one can create config_item children. If it has
154 * default_groups on group->default_groups, it has automatically created
155 * group children. default_groups may coexist alongsize make_group() or
156 * make_item(), but if the group wishes to have only default_groups
157 * children (disallowing mkdir(2)), it need not provide either function.
158 * If the group has commit(), it supports pending and commited (active)
161 struct configfs_item_operations {
162 void (*release)(struct config_item *);
163 ssize_t (*show_attribute)(struct config_item *, struct configfs_attribute *,char *);
164 ssize_t (*store_attribute)(struct config_item *,struct configfs_attribute *,const char *, size_t);
165 int (*allow_link)(struct config_item *src, struct config_item *target);
166 int (*drop_link)(struct config_item *src, struct config_item *target);
169 struct configfs_group_operations {
170 struct config_item *(*make_item)(struct config_group *group, const char *name);
171 struct config_group *(*make_group)(struct config_group *group, const char *name);
172 int (*commit_item)(struct config_item *item);
173 void (*disconnect_notify)(struct config_group *group, struct config_item *item);
174 void (*drop_item)(struct config_group *group, struct config_item *item);
177 struct configfs_subsystem {
178 struct config_group su_group;
179 struct mutex su_mutex;
182 static inline struct configfs_subsystem *to_configfs_subsystem(struct config_group *group)
185 container_of(group, struct configfs_subsystem, su_group) :
189 int configfs_register_subsystem(struct configfs_subsystem *subsys);
190 void configfs_unregister_subsystem(struct configfs_subsystem *subsys);
192 /* These functions can sleep and can alloc with GFP_KERNEL */
193 /* WARNING: These cannot be called underneath configfs callbacks!! */
194 int configfs_depend_item(struct configfs_subsystem *subsys, struct config_item *target);
195 void configfs_undepend_item(struct configfs_subsystem *subsys, struct config_item *target);
197 #endif /* __KERNEL__ */
199 #endif /* _CONFIGFS_H_ */