Blame view

include/linux/sysfs.h 8.7 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
  /*
   * sysfs.h - definitions for the device driver filesystem
   *
   * Copyright (c) 2001,2002 Patrick Mochel
   * Copyright (c) 2004 Silicon Graphics, Inc.
6d66f5cd2   Tejun Heo   sysfs: add copyri...
6
7
   * Copyright (c) 2007 SUSE Linux Products GmbH
   * Copyright (c) 2007 Tejun Heo <teheo@suse.de>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8
9
10
11
12
13
   *
   * Please see Documentation/filesystems/sysfs.txt for more information.
   */
  
  #ifndef _SYSFS_H_
  #define _SYSFS_H_
4a7fb6363   Andrew Morton   add __must_check ...
14
  #include <linux/compiler.h>
5851fadce   Ralf Baechle   [PATCH] Fix build...
15
  #include <linux/errno.h>
bf0acc330   Frank Haverkamp   SYSFS: Fix missin...
16
  #include <linux/list.h>
6992f5334   Eric W. Biederman   sysfs: Use one lo...
17
  #include <linux/lockdep.h>
8488a38f4   David Howells   kobject: Break th...
18
  #include <linux/kobject_ns.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
20
21
22
  #include <asm/atomic.h>
  
  struct kobject;
  struct module;
3ff195b01   Eric W. Biederman   sysfs: Implement ...
23
  enum kobj_ns_type;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24
25
  
  struct attribute {
59f690156   Tejun Heo   sysfs: clean up h...
26
  	const char		*name;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
27
  	mode_t			mode;
6992f5334   Eric W. Biederman   sysfs: Use one lo...
28
29
30
31
  #ifdef CONFIG_DEBUG_LOCK_ALLOC
  	struct lock_class_key	*key;
  	struct lock_class_key	skey;
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32
  };
35960258e   Eric W. Biederman   sysfs: Document s...
33
34
35
36
37
38
39
40
41
42
  /**
   *	sysfs_attr_init - initialize a dynamically allocated sysfs attribute
   *	@attr: struct attribute to initialize
   *
   *	Initialize a dynamically allocated struct attribute so we can
   *	make lockdep happy.  This is a new requirement for attributes
   *	and initially this is only needed when lockdep is enabled.
   *	Lockdep gives a nice error when your attribute is added to
   *	sysfs if you don't have this.
   */
6992f5334   Eric W. Biederman   sysfs: Use one lo...
43
44
45
46
47
48
49
50
51
52
  #ifdef CONFIG_DEBUG_LOCK_ALLOC
  #define sysfs_attr_init(attr)				\
  do {							\
  	static struct lock_class_key __key;		\
  							\
  	(attr)->key = &__key;				\
  } while(0)
  #else
  #define sysfs_attr_init(attr) do {} while(0)
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53
  struct attribute_group {
59f690156   Tejun Heo   sysfs: clean up h...
54
  	const char		*name;
0f4238958   James Bottomley   [SCSI] sysfs: mak...
55
  	mode_t			(*is_visible)(struct kobject *,
d4acd722b   James Bottomley   [SCSI] sysfs: add...
56
  					      struct attribute *, int);
59f690156   Tejun Heo   sysfs: clean up h...
57
  	struct attribute	**attrs;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
58
59
60
61
62
63
64
65
66
67
  };
  
  
  
  /**
   * Use these macros to make defining attributes easier. See include/linux/device.h
   * for examples..
   */
  
  #define __ATTR(_name,_mode,_show,_store) { \
7b595756e   Tejun Heo   sysfs: kill unnec...
68
  	.attr = {.name = __stringify(_name), .mode = _mode },	\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
69
70
71
72
73
  	.show	= _show,					\
  	.store	= _store,					\
  }
  
  #define __ATTR_RO(_name) { \
7b595756e   Tejun Heo   sysfs: kill unnec...
74
75
  	.attr	= { .name = __stringify(_name), .mode = 0444 },	\
  	.show	= _name##_show,					\
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
76
77
78
79
80
  }
  
  #define __ATTR_NULL { .attr = { .name = NULL } }
  
  #define attr_name(_attr) (_attr).attr.name
2c3c8bea6   Chris Wright   sysfs: add struct...
81
  struct file;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
82
83
84
85
86
87
  struct vm_area_struct;
  
  struct bin_attribute {
  	struct attribute	attr;
  	size_t			size;
  	void			*private;
2c3c8bea6   Chris Wright   sysfs: add struct...
88
  	ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *,
91a690295   Zhang Rui   sysfs: add parame...
89
  			char *, loff_t, size_t);
2c3c8bea6   Chris Wright   sysfs: add struct...
90
  	ssize_t (*write)(struct file *,struct kobject *, struct bin_attribute *,
91a690295   Zhang Rui   sysfs: add parame...
91
  			 char *, loff_t, size_t);
2c3c8bea6   Chris Wright   sysfs: add struct...
92
  	int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
93
94
  		    struct vm_area_struct *vma);
  };
35960258e   Eric W. Biederman   sysfs: Document s...
95
96
97
98
99
100
101
102
103
104
  /**
   *	sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
   *	@attr: struct bin_attribute to initialize
   *
   *	Initialize a dynamically allocated struct bin_attribute so we
   *	can make lockdep happy.  This is a new requirement for
   *	attributes and initially this is only needed when lockdep is
   *	enabled.  Lockdep gives a nice error when your attribute is
   *	added to sysfs if you don't have this.
   */
62e877b89   Stephen Rothwell   sysfs: fix for th...
105
  #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)
6992f5334   Eric W. Biederman   sysfs: Use one lo...
106

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
107
108
109
110
  struct sysfs_ops {
  	ssize_t	(*show)(struct kobject *, struct attribute *,char *);
  	ssize_t	(*store)(struct kobject *,struct attribute *,const char *, size_t);
  };
f1282c844   Neil Brown   sysfs: Support sy...
111
  struct sysfs_dirent;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
112
  #ifdef CONFIG_SYSFS
59f690156   Tejun Heo   sysfs: clean up h...
113
114
  int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *),
  			    void *data, struct module *owner);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
115

59f690156   Tejun Heo   sysfs: clean up h...
116
117
118
119
120
  int __must_check sysfs_create_dir(struct kobject *kobj);
  void sysfs_remove_dir(struct kobject *kobj);
  int __must_check sysfs_rename_dir(struct kobject *kobj, const char *new_name);
  int __must_check sysfs_move_dir(struct kobject *kobj,
  				struct kobject *new_parent_kobj);
31e5abe9a   Kay Sievers   [PATCH] sysfs: ad...
121

59f690156   Tejun Heo   sysfs: clean up h...
122
123
  int __must_check sysfs_create_file(struct kobject *kobj,
  				   const struct attribute *attr);
1c205ae18   Andi Kleen   sysfs: Add sysfs_...
124
125
  int __must_check sysfs_create_files(struct kobject *kobj,
  				   const struct attribute **attr);
49c19400f   Jean Delvare   sysfs: sysfs_chmo...
126
127
  int __must_check sysfs_chmod_file(struct kobject *kobj,
  				  const struct attribute *attr, mode_t mode);
59f690156   Tejun Heo   sysfs: clean up h...
128
  void sysfs_remove_file(struct kobject *kobj, const struct attribute *attr);
1c205ae18   Andi Kleen   sysfs: Add sysfs_...
129
  void sysfs_remove_files(struct kobject *kobj, const struct attribute **attr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
130

4a7fb6363   Andrew Morton   add __must_check ...
131
  int __must_check sysfs_create_bin_file(struct kobject *kobj,
66ecb92be   Phil Carmody   Driver core: bin_...
132
133
134
  				       const struct bin_attribute *attr);
  void sysfs_remove_bin_file(struct kobject *kobj,
  			   const struct bin_attribute *attr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
135

59f690156   Tejun Heo   sysfs: clean up h...
136
137
  int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target,
  				   const char *name);
36ce6dad6   Cornelia Huck   driver core: Supp...
138
139
140
  int __must_check sysfs_create_link_nowarn(struct kobject *kobj,
  					  struct kobject *target,
  					  const char *name);
59f690156   Tejun Heo   sysfs: clean up h...
141
  void sysfs_remove_link(struct kobject *kobj, const char *name);
7cb32942d   Eric W. Biederman   sysfs: Implement ...
142
143
  int sysfs_rename_link(struct kobject *kobj, struct kobject *target,
  			const char *old_name, const char *new_name);
746edb7ae   Eric W. Biederman   sysfs: Implement ...
144
145
  void sysfs_delete_link(struct kobject *dir, struct kobject *targ,
  			const char *name);
59f690156   Tejun Heo   sysfs: clean up h...
146
147
  int __must_check sysfs_create_group(struct kobject *kobj,
  				    const struct attribute_group *grp);
0f4238958   James Bottomley   [SCSI] sysfs: mak...
148
149
  int sysfs_update_group(struct kobject *kobj,
  		       const struct attribute_group *grp);
59f690156   Tejun Heo   sysfs: clean up h...
150
151
  void sysfs_remove_group(struct kobject *kobj,
  			const struct attribute_group *grp);
dfa87c824   Alan Stern   sysfs: allow attr...
152
  int sysfs_add_file_to_group(struct kobject *kobj,
59f690156   Tejun Heo   sysfs: clean up h...
153
  			const struct attribute *attr, const char *group);
dfa87c824   Alan Stern   sysfs: allow attr...
154
  void sysfs_remove_file_from_group(struct kobject *kobj,
59f690156   Tejun Heo   sysfs: clean up h...
155
  			const struct attribute *attr, const char *group);
dfa87c824   Alan Stern   sysfs: allow attr...
156

8c0e3998f   Trent Piepho   sysfs: Make dir a...
157
  void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr);
f1282c844   Neil Brown   sysfs: Support sy...
158
159
  void sysfs_notify_dirent(struct sysfs_dirent *sd);
  struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
3ff195b01   Eric W. Biederman   sysfs: Implement ...
160
  				      const void *ns,
f1282c844   Neil Brown   sysfs: Support sy...
161
162
163
  				      const unsigned char *name);
  struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd);
  void sysfs_put(struct sysfs_dirent *sd);
ae87221d3   Andrew Morton   sysfs: crash debu...
164
  void sysfs_printk_last_file(void);
3ff195b01   Eric W. Biederman   sysfs: Implement ...
165

be867b194   Serge E. Hallyn   sysfs: Comment sy...
166
  /* Called to clear a ns tag when it is no longer valid */
3ff195b01   Eric W. Biederman   sysfs: Implement ...
167
  void sysfs_exit_ns(enum kobj_ns_type type, const void *tag);
f1282c844   Neil Brown   sysfs: Support sy...
168
  int __must_check sysfs_init(void);
f20a9ead0   Andrew Morton   sysfs: add proper...
169

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
170
  #else /* CONFIG_SYSFS */
d9a9cdfb0   Alan Stern   [PATCH] sysfs and...
171
  static inline int sysfs_schedule_callback(struct kobject *kobj,
523ded71d   Alan Stern   device_schedule_c...
172
  		void (*func)(void *), void *data, struct module *owner)
d9a9cdfb0   Alan Stern   [PATCH] sysfs and...
173
174
175
  {
  	return -ENOSYS;
  }
59f690156   Tejun Heo   sysfs: clean up h...
176
  static inline int sysfs_create_dir(struct kobject *kobj)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
177
178
179
  {
  	return 0;
  }
59f690156   Tejun Heo   sysfs: clean up h...
180
  static inline void sysfs_remove_dir(struct kobject *kobj)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
181
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
182
  }
59f690156   Tejun Heo   sysfs: clean up h...
183
  static inline int sysfs_rename_dir(struct kobject *kobj, const char *new_name)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
184
  {
0b4a4fea2   Eric W. Biederman   kobject: Cleanup ...
185
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
186
  }
59f690156   Tejun Heo   sysfs: clean up h...
187
188
  static inline int sysfs_move_dir(struct kobject *kobj,
  				 struct kobject *new_parent_kobj)
8a82472f8   Cornelia Huck   driver core: Intr...
189
190
191
  {
  	return 0;
  }
59f690156   Tejun Heo   sysfs: clean up h...
192
193
  static inline int sysfs_create_file(struct kobject *kobj,
  				    const struct attribute *attr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
194
195
196
  {
  	return 0;
  }
1c205ae18   Andi Kleen   sysfs: Add sysfs_...
197
198
199
200
201
  static inline int sysfs_create_files(struct kobject *kobj,
  				    const struct attribute **attr)
  {
  	return 0;
  }
59f690156   Tejun Heo   sysfs: clean up h...
202
  static inline int sysfs_chmod_file(struct kobject *kobj,
49c19400f   Jean Delvare   sysfs: sysfs_chmo...
203
  				   const struct attribute *attr, mode_t mode)
31e5abe9a   Kay Sievers   [PATCH] sysfs: ad...
204
205
206
  {
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
207

59f690156   Tejun Heo   sysfs: clean up h...
208
209
  static inline void sysfs_remove_file(struct kobject *kobj,
  				     const struct attribute *attr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
210
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
211
  }
1c205ae18   Andi Kleen   sysfs: Add sysfs_...
212
213
214
215
  static inline void sysfs_remove_files(struct kobject *kobj,
  				     const struct attribute **attr)
  {
  }
59f690156   Tejun Heo   sysfs: clean up h...
216
  static inline int sysfs_create_bin_file(struct kobject *kobj,
66ecb92be   Phil Carmody   Driver core: bin_...
217
  					const struct bin_attribute *attr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
218
219
220
  {
  	return 0;
  }
3612e06b2   David Rientjes   sysfs: small head...
221
  static inline void sysfs_remove_bin_file(struct kobject *kobj,
66ecb92be   Phil Carmody   Driver core: bin_...
222
  					 const struct bin_attribute *attr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
223
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
224
  }
59f690156   Tejun Heo   sysfs: clean up h...
225
226
  static inline int sysfs_create_link(struct kobject *kobj,
  				    struct kobject *target, const char *name)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
227
228
229
  {
  	return 0;
  }
36ce6dad6   Cornelia Huck   driver core: Supp...
230
231
232
233
234
235
  static inline int sysfs_create_link_nowarn(struct kobject *kobj,
  					   struct kobject *target,
  					   const char *name)
  {
  	return 0;
  }
59f690156   Tejun Heo   sysfs: clean up h...
236
  static inline void sysfs_remove_link(struct kobject *kobj, const char *name)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
237
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
238
  }
7cb32942d   Eric W. Biederman   sysfs: Implement ...
239
240
241
242
243
  static inline int sysfs_rename_link(struct kobject *k, struct kobject *t,
  				    const char *old_name, const char *new_name)
  {
  	return 0;
  }
746edb7ae   Eric W. Biederman   sysfs: Implement ...
244
245
246
247
  static inline void sysfs_delete_link(struct kobject *k, struct kobject *t,
  				     const char *name)
  {
  }
59f690156   Tejun Heo   sysfs: clean up h...
248
249
  static inline int sysfs_create_group(struct kobject *kobj,
  				     const struct attribute_group *grp)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
250
251
252
  {
  	return 0;
  }
1cbfb7a5a   Randy Dunlap   sysfs: sysfs_upda...
253
254
255
256
257
  static inline int sysfs_update_group(struct kobject *kobj,
  				const struct attribute_group *grp)
  {
  	return 0;
  }
59f690156   Tejun Heo   sysfs: clean up h...
258
259
  static inline void sysfs_remove_group(struct kobject *kobj,
  				      const struct attribute_group *grp)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
260
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
261
  }
dfa87c824   Alan Stern   sysfs: allow attr...
262
263
264
265
266
267
268
  static inline int sysfs_add_file_to_group(struct kobject *kobj,
  		const struct attribute *attr, const char *group)
  {
  	return 0;
  }
  
  static inline void sysfs_remove_file_from_group(struct kobject *kobj,
d701d8a3b   Ralf Baechle   [PATCH] Fix sysfs...
269
  		const struct attribute *attr, const char *group)
dfa87c824   Alan Stern   sysfs: allow attr...
270
  {
dfa87c824   Alan Stern   sysfs: allow attr...
271
  }
8c0e3998f   Trent Piepho   sysfs: Make dir a...
272
273
  static inline void sysfs_notify(struct kobject *kobj, const char *dir,
  				const char *attr)
4508a7a73   NeilBrown   [PATCH] sysfs: Al...
274
275
  {
  }
f1282c844   Neil Brown   sysfs: Support sy...
276
277
278
279
280
  static inline void sysfs_notify_dirent(struct sysfs_dirent *sd)
  {
  }
  static inline
  struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
3ff195b01   Eric W. Biederman   sysfs: Implement ...
281
  				      const void *ns,
f1282c844   Neil Brown   sysfs: Support sy...
282
283
284
285
286
287
288
289
290
291
292
  				      const unsigned char *name)
  {
  	return NULL;
  }
  static inline struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd)
  {
  	return NULL;
  }
  static inline void sysfs_put(struct sysfs_dirent *sd)
  {
  }
4508a7a73   NeilBrown   [PATCH] sysfs: Al...
293

27eabc7cb   Eric W. Biederman   sysfs: Don't use ...
294
  static inline void sysfs_exit_ns(int type, const void *tag)
3ff195b01   Eric W. Biederman   sysfs: Implement ...
295
296
  {
  }
f20a9ead0   Andrew Morton   sysfs: add proper...
297
298
299
300
  static inline int __must_check sysfs_init(void)
  {
  	return 0;
  }
ae87221d3   Andrew Morton   sysfs: crash debu...
301
302
303
  static inline void sysfs_printk_last_file(void)
  {
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
304
305
306
  #endif /* CONFIG_SYSFS */
  
  #endif /* _SYSFS_H_ */