Merge branch 'radix-tree' of git://git.kernel.org/pub/scm/linux/kernel/git/dgc/xfsdev
[deliverable/linux.git] / include / linux / sysfs.h
CommitLineData
1da177e4
LT
1/*
2 * sysfs.h - definitions for the device driver filesystem
3 *
4 * Copyright (c) 2001,2002 Patrick Mochel
5 * Copyright (c) 2004 Silicon Graphics, Inc.
6d66f5cd
TH
6 * Copyright (c) 2007 SUSE Linux Products GmbH
7 * Copyright (c) 2007 Tejun Heo <teheo@suse.de>
1da177e4
LT
8 *
9 * Please see Documentation/filesystems/sysfs.txt for more information.
10 */
11
12#ifndef _SYSFS_H_
13#define _SYSFS_H_
14
4a7fb636 15#include <linux/compiler.h>
5851fadc 16#include <linux/errno.h>
bf0acc33 17#include <linux/list.h>
6992f533 18#include <linux/lockdep.h>
1da177e4
LT
19#include <asm/atomic.h>
20
21struct kobject;
22struct module;
3ff195b0 23enum kobj_ns_type;
1da177e4
LT
24
25struct attribute {
59f69015 26 const char *name;
1da177e4 27 mode_t mode;
6992f533
EB
28#ifdef CONFIG_DEBUG_LOCK_ALLOC
29 struct lock_class_key *key;
30 struct lock_class_key skey;
31#endif
1da177e4
LT
32};
33
35960258
EB
34/**
35 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
36 * @attr: struct attribute to initialize
37 *
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.
43 */
6992f533
EB
44#ifdef CONFIG_DEBUG_LOCK_ALLOC
45#define sysfs_attr_init(attr) \
46do { \
47 static struct lock_class_key __key; \
48 \
49 (attr)->key = &__key; \
50} while(0)
51#else
52#define sysfs_attr_init(attr) do {} while(0)
53#endif
54
1da177e4 55struct attribute_group {
59f69015 56 const char *name;
0f423895 57 mode_t (*is_visible)(struct kobject *,
d4acd722 58 struct attribute *, int);
59f69015 59 struct attribute **attrs;
1da177e4
LT
60};
61
62
63
64/**
65 * Use these macros to make defining attributes easier. See include/linux/device.h
66 * for examples..
67 */
68
69#define __ATTR(_name,_mode,_show,_store) { \
7b595756 70 .attr = {.name = __stringify(_name), .mode = _mode }, \
1da177e4
LT
71 .show = _show, \
72 .store = _store, \
73}
74
75#define __ATTR_RO(_name) { \
7b595756
TH
76 .attr = { .name = __stringify(_name), .mode = 0444 }, \
77 .show = _name##_show, \
1da177e4
LT
78}
79
80#define __ATTR_NULL { .attr = { .name = NULL } }
81
82#define attr_name(_attr) (_attr).attr.name
83
2c3c8bea 84struct file;
1da177e4
LT
85struct vm_area_struct;
86
87struct bin_attribute {
88 struct attribute attr;
89 size_t size;
90 void *private;
2c3c8bea 91 ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *,
91a69029 92 char *, loff_t, size_t);
2c3c8bea 93 ssize_t (*write)(struct file *,struct kobject *, struct bin_attribute *,
91a69029 94 char *, loff_t, size_t);
2c3c8bea 95 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
1da177e4
LT
96 struct vm_area_struct *vma);
97};
98
35960258
EB
99/**
100 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
101 * @attr: struct bin_attribute to initialize
102 *
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.
108 */
62e877b8 109#define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)
6992f533 110
1da177e4
LT
111struct sysfs_ops {
112 ssize_t (*show)(struct kobject *, struct attribute *,char *);
113 ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
114};
115
f1282c84
NB
116struct sysfs_dirent;
117
1da177e4
LT
118#ifdef CONFIG_SYSFS
119
59f69015
TH
120int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *),
121 void *data, struct module *owner);
1da177e4 122
59f69015
TH
123int __must_check sysfs_create_dir(struct kobject *kobj);
124void sysfs_remove_dir(struct kobject *kobj);
125int __must_check sysfs_rename_dir(struct kobject *kobj, const char *new_name);
126int __must_check sysfs_move_dir(struct kobject *kobj,
127 struct kobject *new_parent_kobj);
31e5abe9 128
59f69015
TH
129int __must_check sysfs_create_file(struct kobject *kobj,
130 const struct attribute *attr);
1c205ae1
AK
131int __must_check sysfs_create_files(struct kobject *kobj,
132 const struct attribute **attr);
49c19400
JD
133int __must_check sysfs_chmod_file(struct kobject *kobj,
134 const struct attribute *attr, mode_t mode);
59f69015 135void sysfs_remove_file(struct kobject *kobj, const struct attribute *attr);
1c205ae1 136void sysfs_remove_files(struct kobject *kobj, const struct attribute **attr);
1da177e4 137
4a7fb636 138int __must_check sysfs_create_bin_file(struct kobject *kobj,
66ecb92b
PC
139 const struct bin_attribute *attr);
140void sysfs_remove_bin_file(struct kobject *kobj,
141 const struct bin_attribute *attr);
1da177e4 142
59f69015
TH
143int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,
144 const char *name);
36ce6dad
CH
145int __must_check sysfs_create_link_nowarn(struct kobject *kobj,
146 struct kobject *target,
147 const char *name);
59f69015
TH
148void sysfs_remove_link(struct kobject *kobj, const char *name);
149
7cb32942
EB
150int sysfs_rename_link(struct kobject *kobj, struct kobject *target,
151 const char *old_name, const char *new_name);
152
746edb7a
EB
153void sysfs_delete_link(struct kobject *dir, struct kobject *targ,
154 const char *name);
155
59f69015
TH
156int __must_check sysfs_create_group(struct kobject *kobj,
157 const struct attribute_group *grp);
0f423895
JB
158int sysfs_update_group(struct kobject *kobj,
159 const struct attribute_group *grp);
59f69015
TH
160void sysfs_remove_group(struct kobject *kobj,
161 const struct attribute_group *grp);
dfa87c82 162int sysfs_add_file_to_group(struct kobject *kobj,
59f69015 163 const struct attribute *attr, const char *group);
dfa87c82 164void sysfs_remove_file_from_group(struct kobject *kobj,
59f69015 165 const struct attribute *attr, const char *group);
dfa87c82 166
8c0e3998 167void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr);
f1282c84
NB
168void sysfs_notify_dirent(struct sysfs_dirent *sd);
169struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
3ff195b0 170 const void *ns,
f1282c84
NB
171 const unsigned char *name);
172struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd);
173void sysfs_put(struct sysfs_dirent *sd);
ae87221d 174void sysfs_printk_last_file(void);
3ff195b0 175
be867b19 176/* Called to clear a ns tag when it is no longer valid */
3ff195b0
EB
177void sysfs_exit_ns(enum kobj_ns_type type, const void *tag);
178
f1282c84 179int __must_check sysfs_init(void);
f20a9ead 180
1da177e4
LT
181#else /* CONFIG_SYSFS */
182
d9a9cdfb 183static inline int sysfs_schedule_callback(struct kobject *kobj,
523ded71 184 void (*func)(void *), void *data, struct module *owner)
d9a9cdfb
AS
185{
186 return -ENOSYS;
187}
188
59f69015 189static inline int sysfs_create_dir(struct kobject *kobj)
1da177e4
LT
190{
191 return 0;
192}
193
59f69015 194static inline void sysfs_remove_dir(struct kobject *kobj)
1da177e4 195{
1da177e4
LT
196}
197
59f69015 198static inline int sysfs_rename_dir(struct kobject *kobj, const char *new_name)
1da177e4 199{
0b4a4fea 200 return 0;
1da177e4
LT
201}
202
59f69015
TH
203static inline int sysfs_move_dir(struct kobject *kobj,
204 struct kobject *new_parent_kobj)
8a82472f
CH
205{
206 return 0;
207}
208
59f69015
TH
209static inline int sysfs_create_file(struct kobject *kobj,
210 const struct attribute *attr)
1da177e4
LT
211{
212 return 0;
213}
214
1c205ae1
AK
215static inline int sysfs_create_files(struct kobject *kobj,
216 const struct attribute **attr)
217{
218 return 0;
219}
220
59f69015 221static inline int sysfs_chmod_file(struct kobject *kobj,
49c19400 222 const struct attribute *attr, mode_t mode)
31e5abe9
KS
223{
224 return 0;
225}
1da177e4 226
59f69015
TH
227static inline void sysfs_remove_file(struct kobject *kobj,
228 const struct attribute *attr)
1da177e4 229{
1da177e4
LT
230}
231
1c205ae1
AK
232static inline void sysfs_remove_files(struct kobject *kobj,
233 const struct attribute **attr)
234{
235}
236
59f69015 237static inline int sysfs_create_bin_file(struct kobject *kobj,
66ecb92b 238 const struct bin_attribute *attr)
1da177e4
LT
239{
240 return 0;
241}
242
3612e06b 243static inline void sysfs_remove_bin_file(struct kobject *kobj,
66ecb92b 244 const struct bin_attribute *attr)
1da177e4 245{
1da177e4
LT
246}
247
59f69015
TH
248static inline int sysfs_create_link(struct kobject *kobj,
249 struct kobject *target, const char *name)
1da177e4
LT
250{
251 return 0;
252}
253
36ce6dad
CH
254static inline int sysfs_create_link_nowarn(struct kobject *kobj,
255 struct kobject *target,
256 const char *name)
257{
258 return 0;
259}
260
59f69015 261static inline void sysfs_remove_link(struct kobject *kobj, const char *name)
1da177e4 262{
1da177e4
LT
263}
264
7cb32942
EB
265static inline int sysfs_rename_link(struct kobject *k, struct kobject *t,
266 const char *old_name, const char *new_name)
267{
268 return 0;
269}
270
746edb7a
EB
271static inline void sysfs_delete_link(struct kobject *k, struct kobject *t,
272 const char *name)
273{
274}
275
59f69015
TH
276static inline int sysfs_create_group(struct kobject *kobj,
277 const struct attribute_group *grp)
1da177e4
LT
278{
279 return 0;
280}
281
1cbfb7a5
RD
282static inline int sysfs_update_group(struct kobject *kobj,
283 const struct attribute_group *grp)
284{
285 return 0;
286}
287
59f69015
TH
288static inline void sysfs_remove_group(struct kobject *kobj,
289 const struct attribute_group *grp)
1da177e4 290{
1da177e4
LT
291}
292
dfa87c82
AS
293static inline int sysfs_add_file_to_group(struct kobject *kobj,
294 const struct attribute *attr, const char *group)
295{
296 return 0;
297}
298
299static inline void sysfs_remove_file_from_group(struct kobject *kobj,
d701d8a3 300 const struct attribute *attr, const char *group)
dfa87c82 301{
dfa87c82
AS
302}
303
8c0e3998
TP
304static inline void sysfs_notify(struct kobject *kobj, const char *dir,
305 const char *attr)
4508a7a7
N
306{
307}
f1282c84
NB
308static inline void sysfs_notify_dirent(struct sysfs_dirent *sd)
309{
310}
311static inline
312struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
3ff195b0 313 const void *ns,
f1282c84
NB
314 const unsigned char *name)
315{
316 return NULL;
317}
318static inline struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd)
319{
320 return NULL;
321}
322static inline void sysfs_put(struct sysfs_dirent *sd)
323{
324}
4508a7a7 325
27eabc7c 326static inline void sysfs_exit_ns(int type, const void *tag)
3ff195b0
EB
327{
328}
329
f20a9ead
AM
330static inline int __must_check sysfs_init(void)
331{
332 return 0;
333}
334
ae87221d
AM
335static inline void sysfs_printk_last_file(void)
336{
337}
338
1da177e4
LT
339#endif /* CONFIG_SYSFS */
340
341#endif /* _SYSFS_H_ */
This page took 0.926624 seconds and 5 git commands to generate.