blob: 3d4a96eb0e9b66ed614f12ecd9131925df87ad83 [file] [log] [blame]
Joel Becker7063fbf2005-12-15 14:29:43 -08001/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * configfs.h - definitions for the device driver filesystem
5 *
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.
10 *
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.
15 *
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.
20 *
21 * Based on sysfs:
22 * sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel
23 *
24 * Based on kobject.h:
25 * Copyright (c) 2002-2003 Patrick Mochel
26 * Copyright (c) 2002-2003 Open Source Development Labs
27 *
28 * configfs Copyright (C) 2005 Oracle. All rights reserved.
29 *
30 * Please read Documentation/filesystems/configfs.txt before using the
31 * configfs interface, ESPECIALLY the parts about reference counts and
32 * item destructors.
33 */
34
35#ifndef _CONFIGFS_H_
36#define _CONFIGFS_H_
37
38#ifdef __KERNEL__
39
40#include <linux/types.h>
41#include <linux/list.h>
42#include <linux/kref.h>
43
44#include <asm/atomic.h>
45#include <asm/semaphore.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 int config_item_set_name(struct config_item *, const char *, ...);
68
69static inline char *config_item_name(struct config_item * item)
70{
71 return item->ci_name;
72}
73
74extern void config_item_init(struct config_item *);
75extern void config_item_init_type_name(struct config_item *item,
76 const char *name,
77 struct config_item_type *type);
Joel Becker7063fbf2005-12-15 14:29:43 -080078
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 * group - a group of config_items of a specific type, belonging
92 * to a specific subsystem.
93 */
94
95struct config_group {
96 struct config_item cg_item;
97 struct list_head cg_children;
98 struct configfs_subsystem *cg_subsys;
99 struct config_group **default_groups;
100};
101
102
103extern void config_group_init(struct config_group *group);
104extern void config_group_init_type_name(struct config_group *group,
105 const char *name,
106 struct config_item_type *type);
107
108
109static inline struct config_group *to_config_group(struct config_item *item)
110{
111 return item ? container_of(item,struct config_group,cg_item) : NULL;
112}
113
114static inline struct config_group *config_group_get(struct config_group *group)
115{
116 return group ? to_config_group(config_item_get(&group->cg_item)) : NULL;
117}
118
119static inline void config_group_put(struct config_group *group)
120{
121 config_item_put(&group->cg_item);
122}
123
124extern struct config_item *config_group_find_obj(struct config_group *, const char *);
125
126
127struct configfs_attribute {
Joel Becker3d0f89b2006-01-25 13:31:07 -0800128 const char *ca_name;
Joel Becker7063fbf2005-12-15 14:29:43 -0800129 struct module *ca_owner;
130 mode_t ca_mode;
131};
132
133
134/*
135 * If allow_link() exists, the item can symlink(2) out to other
136 * items. If the item is a group, it may support mkdir(2).
137 * Groups supply one of make_group() and make_item(). If the
138 * group supports make_group(), one can create group children. If it
139 * supports make_item(), one can create config_item children. If it has
140 * default_groups on group->default_groups, it has automatically created
141 * group children. default_groups may coexist alongsize make_group() or
142 * make_item(), but if the group wishes to have only default_groups
143 * children (disallowing mkdir(2)), it need not provide either function.
144 * If the group has commit(), it supports pending and commited (active)
145 * items.
146 */
147struct configfs_item_operations {
148 void (*release)(struct config_item *);
149 ssize_t (*show_attribute)(struct config_item *, struct configfs_attribute *,char *);
150 ssize_t (*store_attribute)(struct config_item *,struct configfs_attribute *,const char *, size_t);
151 int (*allow_link)(struct config_item *src, struct config_item *target);
152 int (*drop_link)(struct config_item *src, struct config_item *target);
153};
154
155struct configfs_group_operations {
156 struct config_item *(*make_item)(struct config_group *group, const char *name);
157 struct config_group *(*make_group)(struct config_group *group, const char *name);
158 int (*commit_item)(struct config_item *item);
159 void (*drop_item)(struct config_group *group, struct config_item *item);
160};
161
Joel Becker7063fbf2005-12-15 14:29:43 -0800162struct configfs_subsystem {
163 struct config_group su_group;
164 struct semaphore su_sem;
165};
166
167static inline struct configfs_subsystem *to_configfs_subsystem(struct config_group *group)
168{
169 return group ?
170 container_of(group, struct configfs_subsystem, su_group) :
171 NULL;
172}
173
174int configfs_register_subsystem(struct configfs_subsystem *subsys);
175void configfs_unregister_subsystem(struct configfs_subsystem *subsys);
176
177#endif /* __KERNEL__ */
178
179#endif /* _CONFIGFS_H_ */