dm: factor out max_io_len_target_boundary
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / linux / sysfs.h
blob3c92121ba9afb3f75700e540e24c52f3aae8b974
1 /*
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.
12 #ifndef _SYSFS_H_
13 #define _SYSFS_H_
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>
21 struct kobject;
22 struct module;
23 enum kobj_ns_type;
25 struct attribute {
26 const char *name;
27 mode_t mode;
28 #ifdef CONFIG_DEBUG_LOCK_ALLOC
29 struct lock_class_key *key;
30 struct lock_class_key skey;
31 #endif
34 /**
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) \
46 do { \
47 static struct lock_class_key __key; \
49 (attr)->key = &__key; \
50 } while(0)
51 #else
52 #define sysfs_attr_init(attr) do {} while(0)
53 #endif
55 struct attribute_group {
56 const char *name;
57 mode_t (*is_visible)(struct kobject *,
58 struct attribute *, int);
59 struct attribute **attrs;
64 /**
65 * Use these macros to make defining attributes easier. See include/linux/device.h
66 * for examples..
69 #define __ATTR(_name,_mode,_show,_store) { \
70 .attr = {.name = __stringify(_name), .mode = _mode }, \
71 .show = _show, \
72 .store = _store, \
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
84 struct file;
85 struct vm_area_struct;
87 struct bin_attribute {
88 struct attribute attr;
89 size_t size;
90 void *private;
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);
99 /**
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)
111 struct sysfs_ops {
112 ssize_t (*show)(struct kobject *, struct attribute *,char *);
113 ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
116 struct sysfs_dirent;
118 #ifdef CONFIG_SYSFS
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,
144 const char *name);
145 int __must_check sysfs_create_link_nowarn(struct kobject *kobj,
146 struct kobject *target,
147 const char *name);
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,
154 const char *name);
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,
170 const void *ns,
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)
186 return -ENOSYS;
189 static inline int sysfs_create_dir(struct kobject *kobj)
191 return 0;
194 static inline void sysfs_remove_dir(struct kobject *kobj)
198 static inline int sysfs_rename_dir(struct kobject *kobj, const char *new_name)
200 return 0;
203 static inline int sysfs_move_dir(struct kobject *kobj,
204 struct kobject *new_parent_kobj)
206 return 0;
209 static inline int sysfs_create_file(struct kobject *kobj,
210 const struct attribute *attr)
212 return 0;
215 static inline int sysfs_create_files(struct kobject *kobj,
216 const struct attribute **attr)
218 return 0;
221 static inline int sysfs_chmod_file(struct kobject *kobj,
222 const struct attribute *attr, mode_t mode)
224 return 0;
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)
240 return 0;
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)
251 return 0;
254 static inline int sysfs_create_link_nowarn(struct kobject *kobj,
255 struct kobject *target,
256 const char *name)
258 return 0;
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)
268 return 0;
271 static inline void sysfs_delete_link(struct kobject *k, struct kobject *t,
272 const char *name)
276 static inline int sysfs_create_group(struct kobject *kobj,
277 const struct attribute_group *grp)
279 return 0;
282 static inline int sysfs_update_group(struct kobject *kobj,
283 const struct attribute_group *grp)
285 return 0;
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)
296 return 0;
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,
305 const char *attr)
308 static inline void sysfs_notify_dirent(struct sysfs_dirent *sd)
311 static inline
312 struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
313 const void *ns,
314 const unsigned char *name)
316 return NULL;
318 static inline struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd)
320 return NULL;
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)
332 return 0;
335 static inline void sysfs_printk_last_file(void)
339 #endif /* CONFIG_SYSFS */
341 #endif /* _SYSFS_H_ */