2 * sysfs.h - definitions for the device driver filesystem
4 * Copyright (c) 2001,2002 Patrick Mochel
5 * Copyright (c) 2004 Silicon Graphics, Inc.
6 * Copyright (c) 2007 SUSE Linux Products GmbH
7 * Copyright (c) 2007 Tejun Heo <teheo@suse.de>
9 * Please see Documentation/filesystems/sysfs.txt for more information.
15 #include <linux/compiler.h>
16 #include <linux/errno.h>
17 #include <linux/list.h>
18 #include <linux/lockdep.h>
19 #include <linux/kobject_ns.h>
20 #include <linux/atomic.h>
29 #ifdef CONFIG_DEBUG_LOCK_ALLOC
30 bool ignore_lockdep:1;
31 struct lock_class_key *key;
32 struct lock_class_key skey;
37 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
38 * @attr: struct attribute to initialize
40 * Initialize a dynamically allocated struct attribute so we can
41 * make lockdep happy. This is a new requirement for attributes
42 * and initially this is only needed when lockdep is enabled.
43 * Lockdep gives a nice error when your attribute is added to
44 * sysfs if you don't have this.
46 #ifdef CONFIG_DEBUG_LOCK_ALLOC
47 #define sysfs_attr_init(attr) \
49 static struct lock_class_key __key; \
51 (attr)->key = &__key; \
54 #define sysfs_attr_init(attr) do {} while(0)
57 struct attribute_group {
59 umode_t (*is_visible)(struct kobject *,
60 struct attribute *, int);
61 struct attribute **attrs;
67 * Use these macros to make defining attributes easier. See include/linux/device.h
71 #define __ATTR(_name,_mode,_show,_store) { \
72 .attr = {.name = __stringify(_name), .mode = _mode }, \
77 #define __ATTR_RO(_name) { \
78 .attr = { .name = __stringify(_name), .mode = 0444 }, \
79 .show = _name##_show, \
82 #define __ATTR_RW(_name) __ATTR(_name, 0644, _name##_show, _name##_store)
84 #define __ATTR_NULL { .attr = { .name = NULL } }
86 #ifdef CONFIG_DEBUG_LOCK_ALLOC
87 #define __ATTR_IGNORE_LOCKDEP(_name, _mode, _show, _store) { \
88 .attr = {.name = __stringify(_name), .mode = _mode, \
89 .ignore_lockdep = true }, \
94 #define __ATTR_IGNORE_LOCKDEP __ATTR
97 #define attr_name(_attr) (_attr).attr.name
100 struct vm_area_struct;
102 struct bin_attribute {
103 struct attribute attr;
106 ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *,
107 char *, loff_t, size_t);
108 ssize_t (*write)(struct file *,struct kobject *, struct bin_attribute *,
109 char *, loff_t, size_t);
110 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
111 struct vm_area_struct *vma);
115 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
116 * @attr: struct bin_attribute to initialize
118 * Initialize a dynamically allocated struct bin_attribute so we
119 * can make lockdep happy. This is a new requirement for
120 * attributes and initially this is only needed when lockdep is
121 * enabled. Lockdep gives a nice error when your attribute is
122 * added to sysfs if you don't have this.
124 #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)
127 ssize_t (*show)(struct kobject *, struct attribute *,char *);
128 ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
129 const void *(*namespace)(struct kobject *, const struct attribute *);
136 int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *),
137 void *data, struct module *owner);
139 int __must_check sysfs_create_dir(struct kobject *kobj);
140 void sysfs_remove_dir(struct kobject *kobj);
141 int __must_check sysfs_rename_dir(struct kobject *kobj, const char *new_name);
142 int __must_check sysfs_move_dir(struct kobject *kobj,
143 struct kobject *new_parent_kobj);
145 int __must_check sysfs_create_file(struct kobject *kobj,
146 const struct attribute *attr);
147 int __must_check sysfs_create_files(struct kobject *kobj,
148 const struct attribute **attr);
149 int __must_check sysfs_chmod_file(struct kobject *kobj,
150 const struct attribute *attr, umode_t mode);
151 void sysfs_remove_file(struct kobject *kobj, const struct attribute *attr);
152 void sysfs_remove_files(struct kobject *kobj, const struct attribute **attr);
154 int __must_check sysfs_create_bin_file(struct kobject *kobj,
155 const struct bin_attribute *attr);
156 void sysfs_remove_bin_file(struct kobject *kobj,
157 const struct bin_attribute *attr);
159 int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,
161 int __must_check sysfs_create_link_nowarn(struct kobject *kobj,
162 struct kobject *target,
164 void sysfs_remove_link(struct kobject *kobj, const char *name);
166 int sysfs_rename_link(struct kobject *kobj, struct kobject *target,
167 const char *old_name, const char *new_name);
169 void sysfs_delete_link(struct kobject *dir, struct kobject *targ,
172 int __must_check sysfs_create_group(struct kobject *kobj,
173 const struct attribute_group *grp);
174 int sysfs_update_group(struct kobject *kobj,
175 const struct attribute_group *grp);
176 void sysfs_remove_group(struct kobject *kobj,
177 const struct attribute_group *grp);
178 int sysfs_add_file_to_group(struct kobject *kobj,
179 const struct attribute *attr, const char *group);
180 void sysfs_remove_file_from_group(struct kobject *kobj,
181 const struct attribute *attr, const char *group);
182 int sysfs_merge_group(struct kobject *kobj,
183 const struct attribute_group *grp);
184 void sysfs_unmerge_group(struct kobject *kobj,
185 const struct attribute_group *grp);
186 int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name,
187 struct kobject *target, const char *link_name);
188 void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
189 const char *link_name);
191 void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr);
192 void sysfs_notify_dirent(struct sysfs_dirent *sd);
193 struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
195 const unsigned char *name);
196 struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd);
197 void sysfs_put(struct sysfs_dirent *sd);
199 int __must_check sysfs_init(void);
201 #else /* CONFIG_SYSFS */
203 static inline int sysfs_schedule_callback(struct kobject *kobj,
204 void (*func)(void *), void *data, struct module *owner)
209 static inline int sysfs_create_dir(struct kobject *kobj)
214 static inline void sysfs_remove_dir(struct kobject *kobj)
218 static inline int sysfs_rename_dir(struct kobject *kobj, const char *new_name)
223 static inline int sysfs_move_dir(struct kobject *kobj,
224 struct kobject *new_parent_kobj)
229 static inline int sysfs_create_file(struct kobject *kobj,
230 const struct attribute *attr)
235 static inline int sysfs_create_files(struct kobject *kobj,
236 const struct attribute **attr)
241 static inline int sysfs_chmod_file(struct kobject *kobj,
242 const struct attribute *attr, umode_t mode)
247 static inline void sysfs_remove_file(struct kobject *kobj,
248 const struct attribute *attr)
252 static inline void sysfs_remove_files(struct kobject *kobj,
253 const struct attribute **attr)
257 static inline int sysfs_create_bin_file(struct kobject *kobj,
258 const struct bin_attribute *attr)
263 static inline void sysfs_remove_bin_file(struct kobject *kobj,
264 const struct bin_attribute *attr)
268 static inline int sysfs_create_link(struct kobject *kobj,
269 struct kobject *target, const char *name)
274 static inline int sysfs_create_link_nowarn(struct kobject *kobj,
275 struct kobject *target,
281 static inline void sysfs_remove_link(struct kobject *kobj, const char *name)
285 static inline int sysfs_rename_link(struct kobject *k, struct kobject *t,
286 const char *old_name, const char *new_name)
291 static inline void sysfs_delete_link(struct kobject *k, struct kobject *t,
296 static inline int sysfs_create_group(struct kobject *kobj,
297 const struct attribute_group *grp)
302 static inline int sysfs_update_group(struct kobject *kobj,
303 const struct attribute_group *grp)
308 static inline void sysfs_remove_group(struct kobject *kobj,
309 const struct attribute_group *grp)
313 static inline int sysfs_add_file_to_group(struct kobject *kobj,
314 const struct attribute *attr, const char *group)
319 static inline void sysfs_remove_file_from_group(struct kobject *kobj,
320 const struct attribute *attr, const char *group)
324 static inline int sysfs_merge_group(struct kobject *kobj,
325 const struct attribute_group *grp)
330 static inline void sysfs_unmerge_group(struct kobject *kobj,
331 const struct attribute_group *grp)
335 static inline int sysfs_add_link_to_group(struct kobject *kobj,
336 const char *group_name, struct kobject *target,
337 const char *link_name)
342 static inline void sysfs_remove_link_from_group(struct kobject *kobj,
343 const char *group_name, const char *link_name)
347 static inline void sysfs_notify(struct kobject *kobj, const char *dir,
351 static inline void sysfs_notify_dirent(struct sysfs_dirent *sd)
355 struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
357 const unsigned char *name)
361 static inline struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd)
365 static inline void sysfs_put(struct sysfs_dirent *sd)
369 static inline int __must_check sysfs_init(void)
374 #endif /* CONFIG_SYSFS */
376 #endif /* _SYSFS_H_ */