0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef _CONFIGFS_H_
0020 #define _CONFIGFS_H_
0021
0022 #include <linux/stat.h> /* S_IRUGO */
0023 #include <linux/types.h> /* ssize_t */
0024 #include <linux/list.h> /* struct list_head */
0025 #include <linux/kref.h> /* struct kref */
0026 #include <linux/mutex.h> /* struct mutex */
0027
0028 #define CONFIGFS_ITEM_NAME_LEN 20
0029
0030 struct module;
0031
0032 struct configfs_item_operations;
0033 struct configfs_group_operations;
0034 struct configfs_attribute;
0035 struct configfs_bin_attribute;
0036 struct configfs_subsystem;
0037
0038 struct config_item {
0039 char *ci_name;
0040 char ci_namebuf[CONFIGFS_ITEM_NAME_LEN];
0041 struct kref ci_kref;
0042 struct list_head ci_entry;
0043 struct config_item *ci_parent;
0044 struct config_group *ci_group;
0045 const struct config_item_type *ci_type;
0046 struct dentry *ci_dentry;
0047 };
0048
0049 extern __printf(2, 3)
0050 int config_item_set_name(struct config_item *, const char *, ...);
0051
0052 static inline char *config_item_name(struct config_item * item)
0053 {
0054 return item->ci_name;
0055 }
0056
0057 extern void config_item_init_type_name(struct config_item *item,
0058 const char *name,
0059 const struct config_item_type *type);
0060
0061 extern struct config_item *config_item_get(struct config_item *);
0062 extern struct config_item *config_item_get_unless_zero(struct config_item *);
0063 extern void config_item_put(struct config_item *);
0064
0065 struct config_item_type {
0066 struct module *ct_owner;
0067 struct configfs_item_operations *ct_item_ops;
0068 struct configfs_group_operations *ct_group_ops;
0069 struct configfs_attribute **ct_attrs;
0070 struct configfs_bin_attribute **ct_bin_attrs;
0071 };
0072
0073
0074
0075
0076
0077 struct config_group {
0078 struct config_item cg_item;
0079 struct list_head cg_children;
0080 struct configfs_subsystem *cg_subsys;
0081 struct list_head default_groups;
0082 struct list_head group_entry;
0083 };
0084
0085 extern void config_group_init(struct config_group *group);
0086 extern void config_group_init_type_name(struct config_group *group,
0087 const char *name,
0088 const struct config_item_type *type);
0089
0090 static inline struct config_group *to_config_group(struct config_item *item)
0091 {
0092 return item ? container_of(item,struct config_group,cg_item) : NULL;
0093 }
0094
0095 static inline struct config_group *config_group_get(struct config_group *group)
0096 {
0097 return group ? to_config_group(config_item_get(&group->cg_item)) : NULL;
0098 }
0099
0100 static inline void config_group_put(struct config_group *group)
0101 {
0102 config_item_put(&group->cg_item);
0103 }
0104
0105 extern struct config_item *config_group_find_item(struct config_group *,
0106 const char *);
0107
0108
0109 static inline void configfs_add_default_group(struct config_group *new_group,
0110 struct config_group *group)
0111 {
0112 list_add_tail(&new_group->group_entry, &group->default_groups);
0113 }
0114
0115 struct configfs_attribute {
0116 const char *ca_name;
0117 struct module *ca_owner;
0118 umode_t ca_mode;
0119 ssize_t (*show)(struct config_item *, char *);
0120 ssize_t (*store)(struct config_item *, const char *, size_t);
0121 };
0122
0123 #define CONFIGFS_ATTR(_pfx, _name) \
0124 static struct configfs_attribute _pfx##attr_##_name = { \
0125 .ca_name = __stringify(_name), \
0126 .ca_mode = S_IRUGO | S_IWUSR, \
0127 .ca_owner = THIS_MODULE, \
0128 .show = _pfx##_name##_show, \
0129 .store = _pfx##_name##_store, \
0130 }
0131
0132 #define CONFIGFS_ATTR_RO(_pfx, _name) \
0133 static struct configfs_attribute _pfx##attr_##_name = { \
0134 .ca_name = __stringify(_name), \
0135 .ca_mode = S_IRUGO, \
0136 .ca_owner = THIS_MODULE, \
0137 .show = _pfx##_name##_show, \
0138 }
0139
0140 #define CONFIGFS_ATTR_WO(_pfx, _name) \
0141 static struct configfs_attribute _pfx##attr_##_name = { \
0142 .ca_name = __stringify(_name), \
0143 .ca_mode = S_IWUSR, \
0144 .ca_owner = THIS_MODULE, \
0145 .store = _pfx##_name##_store, \
0146 }
0147
0148 struct file;
0149 struct vm_area_struct;
0150
0151 struct configfs_bin_attribute {
0152 struct configfs_attribute cb_attr;
0153 void *cb_private;
0154 size_t cb_max_size;
0155 ssize_t (*read)(struct config_item *, void *, size_t);
0156 ssize_t (*write)(struct config_item *, const void *, size_t);
0157 };
0158
0159 #define CONFIGFS_BIN_ATTR(_pfx, _name, _priv, _maxsz) \
0160 static struct configfs_bin_attribute _pfx##attr_##_name = { \
0161 .cb_attr = { \
0162 .ca_name = __stringify(_name), \
0163 .ca_mode = S_IRUGO | S_IWUSR, \
0164 .ca_owner = THIS_MODULE, \
0165 }, \
0166 .cb_private = _priv, \
0167 .cb_max_size = _maxsz, \
0168 .read = _pfx##_name##_read, \
0169 .write = _pfx##_name##_write, \
0170 }
0171
0172 #define CONFIGFS_BIN_ATTR_RO(_pfx, _name, _priv, _maxsz) \
0173 static struct configfs_bin_attribute _pfx##attr_##_name = { \
0174 .cb_attr = { \
0175 .ca_name = __stringify(_name), \
0176 .ca_mode = S_IRUGO, \
0177 .ca_owner = THIS_MODULE, \
0178 }, \
0179 .cb_private = _priv, \
0180 .cb_max_size = _maxsz, \
0181 .read = _pfx##_name##_read, \
0182 }
0183
0184 #define CONFIGFS_BIN_ATTR_WO(_pfx, _name, _priv, _maxsz) \
0185 static struct configfs_bin_attribute _pfx##attr_##_name = { \
0186 .cb_attr = { \
0187 .ca_name = __stringify(_name), \
0188 .ca_mode = S_IWUSR, \
0189 .ca_owner = THIS_MODULE, \
0190 }, \
0191 .cb_private = _priv, \
0192 .cb_max_size = _maxsz, \
0193 .write = _pfx##_name##_write, \
0194 }
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210 struct configfs_item_operations {
0211 void (*release)(struct config_item *);
0212 int (*allow_link)(struct config_item *src, struct config_item *target);
0213 void (*drop_link)(struct config_item *src, struct config_item *target);
0214 };
0215
0216 struct configfs_group_operations {
0217 struct config_item *(*make_item)(struct config_group *group, const char *name);
0218 struct config_group *(*make_group)(struct config_group *group, const char *name);
0219 int (*commit_item)(struct config_item *item);
0220 void (*disconnect_notify)(struct config_group *group, struct config_item *item);
0221 void (*drop_item)(struct config_group *group, struct config_item *item);
0222 };
0223
0224 struct configfs_subsystem {
0225 struct config_group su_group;
0226 struct mutex su_mutex;
0227 };
0228
0229 static inline struct configfs_subsystem *to_configfs_subsystem(struct config_group *group)
0230 {
0231 return group ?
0232 container_of(group, struct configfs_subsystem, su_group) :
0233 NULL;
0234 }
0235
0236 int configfs_register_subsystem(struct configfs_subsystem *subsys);
0237 void configfs_unregister_subsystem(struct configfs_subsystem *subsys);
0238
0239 int configfs_register_group(struct config_group *parent_group,
0240 struct config_group *group);
0241 void configfs_unregister_group(struct config_group *group);
0242
0243 void configfs_remove_default_groups(struct config_group *group);
0244
0245 struct config_group *
0246 configfs_register_default_group(struct config_group *parent_group,
0247 const char *name,
0248 const struct config_item_type *item_type);
0249 void configfs_unregister_default_group(struct config_group *group);
0250
0251
0252
0253 int configfs_depend_item(struct configfs_subsystem *subsys,
0254 struct config_item *target);
0255 void configfs_undepend_item(struct config_item *target);
0256
0257
0258
0259
0260
0261
0262
0263
0264 int configfs_depend_item_unlocked(struct configfs_subsystem *caller_subsys,
0265 struct config_item *target);
0266
0267
0268 static inline void configfs_undepend_item_unlocked(struct config_item *target)
0269 {
0270 configfs_undepend_item(target);
0271 }
0272
0273 #endif