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 <asm/atomic.h>
28 #ifdef CONFIG_DEBUG_LOCK_ALLOC
29 struct lock_class_key *key;
30 struct lock_class_key skey;
35 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
36 * @attr: struct attribute to initialize
38 * Initialize a dynamically allocated struct attribute so we can
39 * make lockdep happy. This is a new requirement for attributes
40 * and initially this is only needed when lockdep is enabled.
41 * Lockdep gives a nice error when your attribute is added to
42 * sysfs if you don't have this.
44 #ifdef CONFIG_DEBUG_LOCK_ALLOC
45 #define sysfs_attr_init(attr) \
47 static struct lock_class_key __key; \
49 (attr)->key = &__key; \
52 #define sysfs_attr_init(attr) do {} while(0)
55 struct attribute_group {
57 mode_t (*is_visible)(struct kobject *,
58 struct attribute *, int);
59 struct attribute **attrs;
65 * Use these macros to make defining attributes easier. See include/linux/device.h
69 #define __ATTR(_name,_mode,_show,_store) { \
70 .attr = {.name = __stringify(_name), .mode = _mode }, \
75 #define __ATTR_RO(_name) { \
76 .attr = { .name = __stringify(_name), .mode = 0444 }, \
77 .show = _name##_show, \
80 #define __ATTR_NULL { .attr = { .name = NULL } }
82 #define attr_name(_attr) (_attr).attr.name
85 struct vm_area_struct;
87 struct bin_attribute {
88 struct attribute attr;
91 ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *,
92 char *, loff_t, size_t);
93 ssize_t (*write)(struct file *,struct kobject *, struct bin_attribute *,
94 char *, loff_t, size_t);
95 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
96 struct vm_area_struct *vma);
100 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
101 * @attr: struct bin_attribute to initialize
103 * Initialize a dynamically allocated struct bin_attribute so we
104 * can make lockdep happy. This is a new requirement for
105 * attributes and initially this is only needed when lockdep is
106 * enabled. Lockdep gives a nice error when your attribute is
107 * added to sysfs if you don't have this.
109 #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)
112 ssize_t (*show)(struct kobject *, struct attribute *,char *);
113 ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
120 int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *),
121 void *data, struct module *owner);
123 int __must_check sysfs_create_dir(struct kobject *kobj);
124 void sysfs_remove_dir(struct kobject *kobj);
125 int __must_check sysfs_rename_dir(struct kobject *kobj, const char *new_name);
126 int __must_check sysfs_move_dir(struct kobject *kobj,
127 struct kobject *new_parent_kobj);
129 int __must_check sysfs_create_file(struct kobject *kobj,
130 const struct attribute *attr);
131 int __must_check sysfs_create_files(struct kobject *kobj,
132 const struct attribute **attr);
133 int __must_check sysfs_chmod_file(struct kobject *kobj,
134 const struct attribute *attr, mode_t mode);
135 void sysfs_remove_file(struct kobject *kobj, const struct attribute *attr);
136 void sysfs_remove_files(struct kobject *kobj, const struct attribute **attr);
138 int __must_check sysfs_create_bin_file(struct kobject *kobj,
139 const struct bin_attribute *attr);
140 void sysfs_remove_bin_file(struct kobject *kobj,
141 const struct bin_attribute *attr);
143 int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,
145 int __must_check sysfs_create_link_nowarn(struct kobject *kobj,
146 struct kobject *target,
148 void sysfs_remove_link(struct kobject *kobj, const char *name);
150 int sysfs_rename_link(struct kobject *kobj, struct kobject *target,
151 const char *old_name, const char *new_name);
153 void sysfs_delete_link(struct kobject *dir, struct kobject *targ,
156 int __must_check sysfs_create_group(struct kobject *kobj,
157 const struct attribute_group *grp);
158 int sysfs_update_group(struct kobject *kobj,
159 const struct attribute_group *grp);
160 void sysfs_remove_group(struct kobject *kobj,
161 const struct attribute_group *grp);
162 int sysfs_add_file_to_group(struct kobject *kobj,
163 const struct attribute *attr, const char *group);
164 void sysfs_remove_file_from_group(struct kobject *kobj,
165 const struct attribute *attr, const char *group);
167 void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr);
168 void sysfs_notify_dirent(struct sysfs_dirent *sd);
169 struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
171 const unsigned char *name);
172 struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd);
173 void sysfs_put(struct sysfs_dirent *sd);
174 void sysfs_printk_last_file(void);
176 /* Called to clear a ns tag when it is no longer valid */
177 void sysfs_exit_ns(enum kobj_ns_type type, const void *tag);
179 int __must_check sysfs_init(void);
181 #else /* CONFIG_SYSFS */
183 static inline int sysfs_schedule_callback(struct kobject *kobj,
184 void (*func)(void *), void *data, struct module *owner)
189 static inline int sysfs_create_dir(struct kobject *kobj)
194 static inline void sysfs_remove_dir(struct kobject *kobj)
198 static inline int sysfs_rename_dir(struct kobject *kobj, const char *new_name)
203 static inline int sysfs_move_dir(struct kobject *kobj,
204 struct kobject *new_parent_kobj)
209 static inline int sysfs_create_file(struct kobject *kobj,
210 const struct attribute *attr)
215 static inline int sysfs_create_files(struct kobject *kobj,
216 const struct attribute **attr)
221 static inline int sysfs_chmod_file(struct kobject *kobj,
222 const struct attribute *attr, mode_t mode)
227 static inline void sysfs_remove_file(struct kobject *kobj,
228 const struct attribute *attr)
232 static inline void sysfs_remove_files(struct kobject *kobj,
233 const struct attribute **attr)
237 static inline int sysfs_create_bin_file(struct kobject *kobj,
238 const struct bin_attribute *attr)
243 static inline void sysfs_remove_bin_file(struct kobject *kobj,
244 const struct bin_attribute *attr)
248 static inline int sysfs_create_link(struct kobject *kobj,
249 struct kobject *target, const char *name)
254 static inline int sysfs_create_link_nowarn(struct kobject *kobj,
255 struct kobject *target,
261 static inline void sysfs_remove_link(struct kobject *kobj, const char *name)
265 static inline int sysfs_rename_link(struct kobject *k, struct kobject *t,
266 const char *old_name, const char *new_name)
271 static inline void sysfs_delete_link(struct kobject *k, struct kobject *t,
276 static inline int sysfs_create_group(struct kobject *kobj,
277 const struct attribute_group *grp)
282 static inline int sysfs_update_group(struct kobject *kobj,
283 const struct attribute_group *grp)
288 static inline void sysfs_remove_group(struct kobject *kobj,
289 const struct attribute_group *grp)
293 static inline int sysfs_add_file_to_group(struct kobject *kobj,
294 const struct attribute *attr, const char *group)
299 static inline void sysfs_remove_file_from_group(struct kobject *kobj,
300 const struct attribute *attr, const char *group)
304 static inline void sysfs_notify(struct kobject *kobj, const char *dir,
308 static inline void sysfs_notify_dirent(struct sysfs_dirent *sd)
312 struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
314 const unsigned char *name)
318 static inline struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd)
322 static inline void sysfs_put(struct sysfs_dirent *sd)
326 static inline void sysfs_exit_ns(int type, const void *tag)
330 static inline int __must_check sysfs_init(void)
335 static inline void sysfs_printk_last_file(void)
339 #endif /* CONFIG_SYSFS */
341 #endif /* _SYSFS_H_ */