Blame view

include/linux/debugfs.h 11.2 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
  /*
   *  debugfs.h - a tiny little debug file system
   *
   *  Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
   *  Copyright (C) 2004 IBM Inc.
   *
   *	This program is free software; you can redistribute it and/or
   *	modify it under the terms of the GNU General Public License version
   *	2 as published by the Free Software Foundation.
   *
   *  debugfs is for people to use instead of /proc or /sys.
e1b4fc7ad   Mauro Carvalho Chehab   fs: update locati...
12
   *  See Documentation/filesystems/ for more details.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
14
15
16
17
18
   */
  
  #ifndef _DEBUGFS_H_
  #define _DEBUGFS_H_
  
  #include <linux/fs.h>
1a087c6ad   Alessandro Rubini   debugfs: add tool...
19
  #include <linux/seq_file.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
20

a7a76cefc   Roland Dreier   [PATCH] debugfs: ...
21
  #include <linux/types.h>
49d200dea   Nicolai Stange   debugfs: prevent ...
22
  #include <linux/compiler.h>
a7a76cefc   Roland Dreier   [PATCH] debugfs: ...
23

f30d0a815   Arend van Spriel   fs: debugfs: add ...
24
  struct device;
a7a76cefc   Roland Dreier   [PATCH] debugfs: ...
25
  struct file_operations;
49d200dea   Nicolai Stange   debugfs: prevent ...
26
  struct srcu_struct;
a7a76cefc   Roland Dreier   [PATCH] debugfs: ...
27

dd308bc35   Michael Ellerman   [PATCH] debugfs: ...
28
29
30
31
  struct debugfs_blob_wrapper {
  	void *data;
  	unsigned long size;
  };
1a087c6ad   Alessandro Rubini   debugfs: add tool...
32
33
34
35
36
37
  struct debugfs_reg32 {
  	char *name;
  	unsigned long offset;
  };
  
  struct debugfs_regset32 {
833d6e01b   Felipe Balbi   debugfs: regset32...
38
  	const struct debugfs_reg32 *regs;
1a087c6ad   Alessandro Rubini   debugfs: add tool...
39
40
41
  	int nregs;
  	void __iomem *base;
  };
ae79cdaac   venkatesh.pallipadi@intel.com   x86: Add a arch d...
42
  extern struct dentry *arch_debugfs_dir;
49d200dea   Nicolai Stange   debugfs: prevent ...
43
  extern struct srcu_struct debugfs_srcu;
86f0e0676   Christian Lamparter   debugfs: introduc...
44
45
46
47
48
49
50
  /**
   * debugfs_real_fops - getter for the real file operation
   * @filp: a pointer to a struct file
   *
   * Must only be called under the protection established by
   * debugfs_use_file_start().
   */
e41746b0d   Jakub Kicinski   debugfs: improve ...
51
  static inline const struct file_operations *debugfs_real_fops(const struct file *filp)
86f0e0676   Christian Lamparter   debugfs: introduc...
52
53
54
55
56
57
58
59
  	__must_hold(&debugfs_srcu)
  {
  	/*
  	 * Neither the pointer to the struct file_operations, nor its
  	 * contents ever change -- srcu_dereference() is not needed here.
  	 */
  	return filp->f_path.dentry->d_fsdata;
  }
7f847dd31   Arnd Bergmann   debugfs: improve ...
60
61
62
63
64
65
66
67
68
69
70
71
  #define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt)		\
  static int __fops ## _open(struct inode *inode, struct file *file)	\
  {									\
  	__simple_attr_check_format(__fmt, 0ull);			\
  	return simple_attr_open(inode, file, __get, __set, __fmt);	\
  }									\
  static const struct file_operations __fops = {				\
  	.owner	 = THIS_MODULE,						\
  	.open	 = __fops ## _open,					\
  	.release = simple_attr_release,					\
  	.read	 = debugfs_attr_read,					\
  	.write	 = debugfs_attr_write,					\
895ce6c87   Geliang Tang   debugfs: set no_l...
72
  	.llseek  = no_llseek,						\
7f847dd31   Arnd Bergmann   debugfs: improve ...
73
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
74
  #if defined(CONFIG_DEBUG_FS)
3634634ed   Harvey Harrison   debugfs: fix spar...
75

a7c5437b0   Omar Sandoval   debugfs: add debu...
76
  struct dentry *debugfs_lookup(const char *name, struct dentry *parent);
f4ae40a6a   Al Viro   switch debugfs to...
77
  struct dentry *debugfs_create_file(const char *name, umode_t mode,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
78
  				   struct dentry *parent, void *data,
99ac48f54   Arjan van de Ven   [PATCH] mark f_op...
79
  				   const struct file_operations *fops);
c64688081   Nicolai Stange   debugfs: add supp...
80
81
82
  struct dentry *debugfs_create_file_unsafe(const char *name, umode_t mode,
  				   struct dentry *parent, void *data,
  				   const struct file_operations *fops);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83

e59b4e918   David Howells   debugfs: Provide ...
84
85
86
87
  struct dentry *debugfs_create_file_size(const char *name, umode_t mode,
  					struct dentry *parent, void *data,
  					const struct file_operations *fops,
  					loff_t file_size);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
88
  struct dentry *debugfs_create_dir(const char *name, struct dentry *parent);
66f549639   Peter Oberparleiter   debugfs: implemen...
89
90
  struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
  				      const char *dest);
93faccbbf   Eric W. Biederman   fs: Better permis...
91
  typedef struct vfsmount *(*debugfs_automount_t)(struct dentry *, void *);
77b3da6e3   Al Viro   new primitive: de...
92
93
  struct dentry *debugfs_create_automount(const char *name,
  					struct dentry *parent,
93faccbbf   Eric W. Biederman   fs: Better permis...
94
  					debugfs_automount_t f,
77b3da6e3   Al Viro   new primitive: de...
95
  					void *data);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
96
  void debugfs_remove(struct dentry *dentry);
9505e6375   Haavard Skinnemoen   debugfs: Implemen...
97
  void debugfs_remove_recursive(struct dentry *dentry);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
98

49d200dea   Nicolai Stange   debugfs: prevent ...
99
100
101
102
  int debugfs_use_file_start(const struct dentry *dentry, int *srcu_idx)
  	__acquires(&debugfs_srcu);
  
  void debugfs_use_file_finish(int srcu_idx) __releases(&debugfs_srcu);
c64688081   Nicolai Stange   debugfs: add supp...
103
104
105
106
  ssize_t debugfs_attr_read(struct file *file, char __user *buf,
  			size_t len, loff_t *ppos);
  ssize_t debugfs_attr_write(struct file *file, const char __user *buf,
  			size_t len, loff_t *ppos);
cfc94cdf8   Jan Kara   debugfs: add rena...
107
108
  struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
                  struct dentry *new_dir, const char *new_name);
f4ae40a6a   Al Viro   switch debugfs to...
109
  struct dentry *debugfs_create_u8(const char *name, umode_t mode,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
110
  				 struct dentry *parent, u8 *value);
f4ae40a6a   Al Viro   switch debugfs to...
111
  struct dentry *debugfs_create_u16(const char *name, umode_t mode,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
112
  				  struct dentry *parent, u16 *value);
f4ae40a6a   Al Viro   switch debugfs to...
113
  struct dentry *debugfs_create_u32(const char *name, umode_t mode,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
114
  				  struct dentry *parent, u32 *value);
f4ae40a6a   Al Viro   switch debugfs to...
115
  struct dentry *debugfs_create_u64(const char *name, umode_t mode,
8447891fe   Michael Ellerman   debugfs: Add debu...
116
  				  struct dentry *parent, u64 *value);
c23fe8313   Viresh Kumar   debugfs: Add debu...
117
118
  struct dentry *debugfs_create_ulong(const char *name, umode_t mode,
  				    struct dentry *parent, unsigned long *value);
f4ae40a6a   Al Viro   switch debugfs to...
119
  struct dentry *debugfs_create_x8(const char *name, umode_t mode,
2ebefc501   Robin Getz   debugfs: helper f...
120
  				 struct dentry *parent, u8 *value);
f4ae40a6a   Al Viro   switch debugfs to...
121
  struct dentry *debugfs_create_x16(const char *name, umode_t mode,
2ebefc501   Robin Getz   debugfs: helper f...
122
  				  struct dentry *parent, u16 *value);
f4ae40a6a   Al Viro   switch debugfs to...
123
  struct dentry *debugfs_create_x32(const char *name, umode_t mode,
2ebefc501   Robin Getz   debugfs: helper f...
124
  				  struct dentry *parent, u32 *value);
f4ae40a6a   Al Viro   switch debugfs to...
125
  struct dentry *debugfs_create_x64(const char *name, umode_t mode,
15b0beaa3   Huang Ying   Add x64 support t...
126
  				  struct dentry *parent, u64 *value);
f4ae40a6a   Al Viro   switch debugfs to...
127
  struct dentry *debugfs_create_size_t(const char *name, umode_t mode,
5e0787878   Inaky Perez-Gonzalez   debugfs: add help...
128
  				     struct dentry *parent, size_t *value);
3a76e5e09   Seth Jennings   debugfs: add get/...
129
130
  struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
  				     struct dentry *parent, atomic_t *value);
f4ae40a6a   Al Viro   switch debugfs to...
131
  struct dentry *debugfs_create_bool(const char *name, umode_t mode,
621a5f7ad   Viresh Kumar   debugfs: Pass boo...
132
  				  struct dentry *parent, bool *value);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
133

f4ae40a6a   Al Viro   switch debugfs to...
134
  struct dentry *debugfs_create_blob(const char *name, umode_t mode,
dd308bc35   Michael Ellerman   [PATCH] debugfs: ...
135
136
  				  struct dentry *parent,
  				  struct debugfs_blob_wrapper *blob);
c0f92ba99   Frederic Weisbecker   debugfs: function...
137

88187398c   Al Viro   debugfs-related m...
138
  struct dentry *debugfs_create_regset32(const char *name, umode_t mode,
1a087c6ad   Alessandro Rubini   debugfs: add tool...
139
140
  				     struct dentry *parent,
  				     struct debugfs_regset32 *regset);
9761536e1   Joe Perches   debugfs: Have deb...
141
142
  void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
  			  int nregs, void __iomem *base, char *prefix);
1a087c6ad   Alessandro Rubini   debugfs: add tool...
143

9fe2a7015   Srivatsa Vaddagiri   debugfs: Add supp...
144
145
146
  struct dentry *debugfs_create_u32_array(const char *name, umode_t mode,
  					struct dentry *parent,
  					u32 *array, u32 elements);
98210b7f7   Arend van Spriel   debugfs: add help...
147
148
149
150
  struct dentry *debugfs_create_devm_seqfile(struct device *dev, const char *name,
  					   struct dentry *parent,
  					   int (*read_fn)(struct seq_file *s,
  							  void *data));
c0f92ba99   Frederic Weisbecker   debugfs: function...
151
  bool debugfs_initialized(void);
0642ef6f2   Richard Fitzgerald   debugfs: Export b...
152
153
154
155
156
  ssize_t debugfs_read_file_bool(struct file *file, char __user *user_buf,
  			       size_t count, loff_t *ppos);
  
  ssize_t debugfs_write_file_bool(struct file *file, const char __user *user_buf,
  				size_t count, loff_t *ppos);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
157
  #else
a7a76cefc   Roland Dreier   [PATCH] debugfs: ...
158
159
  
  #include <linux/err.h>
98210b7f7   Arend van Spriel   debugfs: add help...
160
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
161
162
163
164
   * We do not return NULL from these functions if CONFIG_DEBUG_FS is not enabled
   * so users have a chance to detect if there was a real error or not.  We don't
   * want to duplicate the design decision mistakes of procfs and devfs again.
   */
a7c5437b0   Omar Sandoval   debugfs: add debu...
165
166
167
168
169
  static inline struct dentry *debugfs_lookup(const char *name,
  					    struct dentry *parent)
  {
  	return ERR_PTR(-ENODEV);
  }
f4ae40a6a   Al Viro   switch debugfs to...
170
  static inline struct dentry *debugfs_create_file(const char *name, umode_t mode,
bde11d794   Jean Delvare   [PATCH] Fix OCFS2...
171
172
  					struct dentry *parent, void *data,
  					const struct file_operations *fops)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
173
174
175
  {
  	return ERR_PTR(-ENODEV);
  }
c2a737eb2   Viresh Kumar   debugfs: Add dumm...
176
177
178
179
180
181
182
  static inline struct dentry *debugfs_create_file_unsafe(const char *name,
  					umode_t mode, struct dentry *parent,
  					void *data,
  					const struct file_operations *fops)
  {
  	return ERR_PTR(-ENODEV);
  }
e59b4e918   David Howells   debugfs: Provide ...
183
184
185
186
187
188
189
  static inline struct dentry *debugfs_create_file_size(const char *name, umode_t mode,
  					struct dentry *parent, void *data,
  					const struct file_operations *fops,
  					loff_t file_size)
  {
  	return ERR_PTR(-ENODEV);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
190
191
192
193
194
  static inline struct dentry *debugfs_create_dir(const char *name,
  						struct dentry *parent)
  {
  	return ERR_PTR(-ENODEV);
  }
66f549639   Peter Oberparleiter   debugfs: implemen...
195
196
197
198
199
200
  static inline struct dentry *debugfs_create_symlink(const char *name,
  						    struct dentry *parent,
  						    const char *dest)
  {
  	return ERR_PTR(-ENODEV);
  }
94e1dec7a   Jiaxing Wang   debugfs: Add stub...
201
202
203
204
205
206
207
  static inline struct dentry *debugfs_create_automount(const char *name,
  					struct dentry *parent,
  					struct vfsmount *(*f)(void *),
  					void *data)
  {
  	return ERR_PTR(-ENODEV);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
208
209
  static inline void debugfs_remove(struct dentry *dentry)
  { }
9505e6375   Haavard Skinnemoen   debugfs: Implemen...
210
211
  static inline void debugfs_remove_recursive(struct dentry *dentry)
  { }
49d200dea   Nicolai Stange   debugfs: prevent ...
212
213
214
215
216
217
218
219
220
221
  static inline int debugfs_use_file_start(const struct dentry *dentry,
  					int *srcu_idx)
  	__acquires(&debugfs_srcu)
  {
  	return 0;
  }
  
  static inline void debugfs_use_file_finish(int srcu_idx)
  	__releases(&debugfs_srcu)
  { }
7f847dd31   Arnd Bergmann   debugfs: improve ...
222
223
224
225
226
227
228
229
230
231
232
233
  static inline ssize_t debugfs_attr_read(struct file *file, char __user *buf,
  					size_t len, loff_t *ppos)
  {
  	return -ENODEV;
  }
  
  static inline ssize_t debugfs_attr_write(struct file *file,
  					const char __user *buf,
  					size_t len, loff_t *ppos)
  {
  	return -ENODEV;
  }
c64688081   Nicolai Stange   debugfs: add supp...
234

cfc94cdf8   Jan Kara   debugfs: add rena...
235
236
237
238
239
  static inline struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
                  struct dentry *new_dir, char *new_name)
  {
  	return ERR_PTR(-ENODEV);
  }
f4ae40a6a   Al Viro   switch debugfs to...
240
  static inline struct dentry *debugfs_create_u8(const char *name, umode_t mode,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
241
242
243
244
245
  					       struct dentry *parent,
  					       u8 *value)
  {
  	return ERR_PTR(-ENODEV);
  }
f4ae40a6a   Al Viro   switch debugfs to...
246
  static inline struct dentry *debugfs_create_u16(const char *name, umode_t mode,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
247
  						struct dentry *parent,
7b558637b   Michal Ostrowski   [PATCH] debugfs: ...
248
  						u16 *value)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
249
250
251
  {
  	return ERR_PTR(-ENODEV);
  }
f4ae40a6a   Al Viro   switch debugfs to...
252
  static inline struct dentry *debugfs_create_u32(const char *name, umode_t mode,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
253
  						struct dentry *parent,
7b558637b   Michal Ostrowski   [PATCH] debugfs: ...
254
  						u32 *value)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
255
256
257
  {
  	return ERR_PTR(-ENODEV);
  }
f4ae40a6a   Al Viro   switch debugfs to...
258
  static inline struct dentry *debugfs_create_u64(const char *name, umode_t mode,
8447891fe   Michael Ellerman   debugfs: Add debu...
259
260
261
262
263
  						struct dentry *parent,
  						u64 *value)
  {
  	return ERR_PTR(-ENODEV);
  }
c2a737eb2   Viresh Kumar   debugfs: Add dumm...
264
265
266
267
268
269
270
  static inline struct dentry *debugfs_create_ulong(const char *name,
  						umode_t mode,
  						struct dentry *parent,
  						unsigned long *value)
  {
  	return ERR_PTR(-ENODEV);
  }
f4ae40a6a   Al Viro   switch debugfs to...
271
  static inline struct dentry *debugfs_create_x8(const char *name, umode_t mode,
2ebefc501   Robin Getz   debugfs: helper f...
272
273
274
275
276
  					       struct dentry *parent,
  					       u8 *value)
  {
  	return ERR_PTR(-ENODEV);
  }
f4ae40a6a   Al Viro   switch debugfs to...
277
  static inline struct dentry *debugfs_create_x16(const char *name, umode_t mode,
2ebefc501   Robin Getz   debugfs: helper f...
278
279
280
281
282
  						struct dentry *parent,
  						u16 *value)
  {
  	return ERR_PTR(-ENODEV);
  }
f4ae40a6a   Al Viro   switch debugfs to...
283
  static inline struct dentry *debugfs_create_x32(const char *name, umode_t mode,
2ebefc501   Robin Getz   debugfs: helper f...
284
285
286
287
288
  						struct dentry *parent,
  						u32 *value)
  {
  	return ERR_PTR(-ENODEV);
  }
3159269ef   Johannes Berg   debugfs: provide ...
289
290
291
292
293
294
  static inline struct dentry *debugfs_create_x64(const char *name, umode_t mode,
  						struct dentry *parent,
  						u64 *value)
  {
  	return ERR_PTR(-ENODEV);
  }
f4ae40a6a   Al Viro   switch debugfs to...
295
  static inline struct dentry *debugfs_create_size_t(const char *name, umode_t mode,
8adb711f3   Inaky Perez-Gonzalez   debugfs: introduc...
296
297
298
299
300
  				     struct dentry *parent,
  				     size_t *value)
  {
  	return ERR_PTR(-ENODEV);
  }
5b8802143   Weijie Yang   fs/debugfs: add d...
301
302
303
304
305
  static inline struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
  				     struct dentry *parent, atomic_t *value)
  {
  	return ERR_PTR(-ENODEV);
  }
f4ae40a6a   Al Viro   switch debugfs to...
306
  static inline struct dentry *debugfs_create_bool(const char *name, umode_t mode,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
307
  						 struct dentry *parent,
621a5f7ad   Viresh Kumar   debugfs: Pass boo...
308
  						 bool *value)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
309
310
311
  {
  	return ERR_PTR(-ENODEV);
  }
f4ae40a6a   Al Viro   switch debugfs to...
312
  static inline struct dentry *debugfs_create_blob(const char *name, umode_t mode,
dd308bc35   Michael Ellerman   [PATCH] debugfs: ...
313
314
315
316
317
  				  struct dentry *parent,
  				  struct debugfs_blob_wrapper *blob)
  {
  	return ERR_PTR(-ENODEV);
  }
1a087c6ad   Alessandro Rubini   debugfs: add tool...
318
  static inline struct dentry *debugfs_create_regset32(const char *name,
88187398c   Al Viro   debugfs-related m...
319
  				   umode_t mode, struct dentry *parent,
1a087c6ad   Alessandro Rubini   debugfs: add tool...
320
321
322
323
  				   struct debugfs_regset32 *regset)
  {
  	return ERR_PTR(-ENODEV);
  }
9761536e1   Joe Perches   debugfs: Have deb...
324
  static inline void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
5b8802143   Weijie Yang   fs/debugfs: add d...
325
326
  			 int nregs, void __iomem *base, char *prefix)
  {
5b8802143   Weijie Yang   fs/debugfs: add d...
327
  }
c0f92ba99   Frederic Weisbecker   debugfs: function...
328
329
330
331
  static inline bool debugfs_initialized(void)
  {
  	return false;
  }
9fe2a7015   Srivatsa Vaddagiri   debugfs: Add supp...
332
333
334
335
336
337
  static inline struct dentry *debugfs_create_u32_array(const char *name, umode_t mode,
  					struct dentry *parent,
  					u32 *array, u32 elements)
  {
  	return ERR_PTR(-ENODEV);
  }
98210b7f7   Arend van Spriel   debugfs: add help...
338
339
340
341
342
343
344
345
  static inline struct dentry *debugfs_create_devm_seqfile(struct device *dev,
  							 const char *name,
  							 struct dentry *parent,
  					   int (*read_fn)(struct seq_file *s,
  							  void *data))
  {
  	return ERR_PTR(-ENODEV);
  }
0642ef6f2   Richard Fitzgerald   debugfs: Export b...
346
347
348
349
350
351
352
353
354
355
356
357
358
  static inline ssize_t debugfs_read_file_bool(struct file *file,
  					     char __user *user_buf,
  					     size_t count, loff_t *ppos)
  {
  	return -ENODEV;
  }
  
  static inline ssize_t debugfs_write_file_bool(struct file *file,
  					      const char __user *user_buf,
  					      size_t count, loff_t *ppos)
  {
  	return -ENODEV;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
359
360
361
  #endif
  
  #endif