]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/debugfs.h
debugfs: prevent access to removed files' private data
[mirror_ubuntu-bionic-kernel.git] / include / linux / debugfs.h
CommitLineData
1da177e4
LT
1/*
2 * debugfs.h - a tiny little debug file system
3 *
4 * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
5 * Copyright (C) 2004 IBM Inc.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version
9 * 2 as published by the Free Software Foundation.
10 *
11 * debugfs is for people to use instead of /proc or /sys.
55dff495 12 * See Documentation/DocBook/filesystems for more details.
1da177e4
LT
13 */
14
15#ifndef _DEBUGFS_H_
16#define _DEBUGFS_H_
17
18#include <linux/fs.h>
1a087c6a 19#include <linux/seq_file.h>
1da177e4 20
a7a76cef 21#include <linux/types.h>
49d200de 22#include <linux/compiler.h>
a7a76cef 23
f30d0a81 24struct device;
a7a76cef 25struct file_operations;
49d200de 26struct srcu_struct;
a7a76cef 27
dd308bc3
ME
28struct debugfs_blob_wrapper {
29 void *data;
30 unsigned long size;
31};
32
1a087c6a
AR
33struct debugfs_reg32 {
34 char *name;
35 unsigned long offset;
36};
37
38struct debugfs_regset32 {
833d6e01 39 const struct debugfs_reg32 *regs;
1a087c6a
AR
40 int nregs;
41 void __iomem *base;
42};
43
ae79cdaa 44extern struct dentry *arch_debugfs_dir;
45
49d200de
NS
46extern struct srcu_struct debugfs_srcu;
47
1da177e4 48#if defined(CONFIG_DEBUG_FS)
3634634e 49
f4ae40a6 50struct dentry *debugfs_create_file(const char *name, umode_t mode,
1da177e4 51 struct dentry *parent, void *data,
99ac48f5 52 const struct file_operations *fops);
1da177e4 53
e59b4e91
DH
54struct dentry *debugfs_create_file_size(const char *name, umode_t mode,
55 struct dentry *parent, void *data,
56 const struct file_operations *fops,
57 loff_t file_size);
58
1da177e4
LT
59struct dentry *debugfs_create_dir(const char *name, struct dentry *parent);
60
66f54963
PO
61struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
62 const char *dest);
63
77b3da6e
AV
64struct dentry *debugfs_create_automount(const char *name,
65 struct dentry *parent,
66 struct vfsmount *(*f)(void *),
67 void *data);
68
1da177e4 69void debugfs_remove(struct dentry *dentry);
9505e637 70void debugfs_remove_recursive(struct dentry *dentry);
1da177e4 71
49d200de
NS
72int debugfs_use_file_start(const struct dentry *dentry, int *srcu_idx)
73 __acquires(&debugfs_srcu);
74
75void debugfs_use_file_finish(int srcu_idx) __releases(&debugfs_srcu);
76
cfc94cdf
JK
77struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
78 struct dentry *new_dir, const char *new_name);
79
f4ae40a6 80struct dentry *debugfs_create_u8(const char *name, umode_t mode,
1da177e4 81 struct dentry *parent, u8 *value);
f4ae40a6 82struct dentry *debugfs_create_u16(const char *name, umode_t mode,
1da177e4 83 struct dentry *parent, u16 *value);
f4ae40a6 84struct dentry *debugfs_create_u32(const char *name, umode_t mode,
1da177e4 85 struct dentry *parent, u32 *value);
f4ae40a6 86struct dentry *debugfs_create_u64(const char *name, umode_t mode,
8447891f 87 struct dentry *parent, u64 *value);
c23fe831
VK
88struct dentry *debugfs_create_ulong(const char *name, umode_t mode,
89 struct dentry *parent, unsigned long *value);
f4ae40a6 90struct dentry *debugfs_create_x8(const char *name, umode_t mode,
2ebefc50 91 struct dentry *parent, u8 *value);
f4ae40a6 92struct dentry *debugfs_create_x16(const char *name, umode_t mode,
2ebefc50 93 struct dentry *parent, u16 *value);
f4ae40a6 94struct dentry *debugfs_create_x32(const char *name, umode_t mode,
2ebefc50 95 struct dentry *parent, u32 *value);
f4ae40a6 96struct dentry *debugfs_create_x64(const char *name, umode_t mode,
15b0beaa 97 struct dentry *parent, u64 *value);
f4ae40a6 98struct dentry *debugfs_create_size_t(const char *name, umode_t mode,
5e078787 99 struct dentry *parent, size_t *value);
3a76e5e0
SJ
100struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
101 struct dentry *parent, atomic_t *value);
f4ae40a6 102struct dentry *debugfs_create_bool(const char *name, umode_t mode,
621a5f7a 103 struct dentry *parent, bool *value);
1da177e4 104
f4ae40a6 105struct dentry *debugfs_create_blob(const char *name, umode_t mode,
dd308bc3
ME
106 struct dentry *parent,
107 struct debugfs_blob_wrapper *blob);
c0f92ba9 108
88187398 109struct dentry *debugfs_create_regset32(const char *name, umode_t mode,
1a087c6a
AR
110 struct dentry *parent,
111 struct debugfs_regset32 *regset);
112
9761536e
JP
113void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
114 int nregs, void __iomem *base, char *prefix);
1a087c6a 115
9fe2a701
SV
116struct dentry *debugfs_create_u32_array(const char *name, umode_t mode,
117 struct dentry *parent,
118 u32 *array, u32 elements);
119
98210b7f
AS
120struct dentry *debugfs_create_devm_seqfile(struct device *dev, const char *name,
121 struct dentry *parent,
122 int (*read_fn)(struct seq_file *s,
123 void *data));
124
c0f92ba9
FW
125bool debugfs_initialized(void);
126
0642ef6f
RF
127ssize_t debugfs_read_file_bool(struct file *file, char __user *user_buf,
128 size_t count, loff_t *ppos);
129
130ssize_t debugfs_write_file_bool(struct file *file, const char __user *user_buf,
131 size_t count, loff_t *ppos);
132
1da177e4 133#else
a7a76cef
RD
134
135#include <linux/err.h>
136
98210b7f 137/*
1da177e4
LT
138 * We do not return NULL from these functions if CONFIG_DEBUG_FS is not enabled
139 * so users have a chance to detect if there was a real error or not. We don't
140 * want to duplicate the design decision mistakes of procfs and devfs again.
141 */
142
f4ae40a6 143static inline struct dentry *debugfs_create_file(const char *name, umode_t mode,
bde11d79
JD
144 struct dentry *parent, void *data,
145 const struct file_operations *fops)
1da177e4
LT
146{
147 return ERR_PTR(-ENODEV);
148}
149
e59b4e91
DH
150static inline struct dentry *debugfs_create_file_size(const char *name, umode_t mode,
151 struct dentry *parent, void *data,
152 const struct file_operations *fops,
153 loff_t file_size)
154{
155 return ERR_PTR(-ENODEV);
156}
157
1da177e4
LT
158static inline struct dentry *debugfs_create_dir(const char *name,
159 struct dentry *parent)
160{
161 return ERR_PTR(-ENODEV);
162}
163
66f54963
PO
164static inline struct dentry *debugfs_create_symlink(const char *name,
165 struct dentry *parent,
166 const char *dest)
167{
168 return ERR_PTR(-ENODEV);
169}
170
94e1dec7
JW
171static inline struct dentry *debugfs_create_automount(const char *name,
172 struct dentry *parent,
173 struct vfsmount *(*f)(void *),
174 void *data)
175{
176 return ERR_PTR(-ENODEV);
177}
178
1da177e4
LT
179static inline void debugfs_remove(struct dentry *dentry)
180{ }
181
9505e637
HS
182static inline void debugfs_remove_recursive(struct dentry *dentry)
183{ }
184
49d200de
NS
185static inline int debugfs_use_file_start(const struct dentry *dentry,
186 int *srcu_idx)
187 __acquires(&debugfs_srcu)
188{
189 return 0;
190}
191
192static inline void debugfs_use_file_finish(int srcu_idx)
193 __releases(&debugfs_srcu)
194{ }
195
cfc94cdf
JK
196static inline struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
197 struct dentry *new_dir, char *new_name)
198{
199 return ERR_PTR(-ENODEV);
200}
201
f4ae40a6 202static inline struct dentry *debugfs_create_u8(const char *name, umode_t mode,
1da177e4
LT
203 struct dentry *parent,
204 u8 *value)
205{
206 return ERR_PTR(-ENODEV);
207}
208
f4ae40a6 209static inline struct dentry *debugfs_create_u16(const char *name, umode_t mode,
1da177e4 210 struct dentry *parent,
7b558637 211 u16 *value)
1da177e4
LT
212{
213 return ERR_PTR(-ENODEV);
214}
215
f4ae40a6 216static inline struct dentry *debugfs_create_u32(const char *name, umode_t mode,
1da177e4 217 struct dentry *parent,
7b558637 218 u32 *value)
1da177e4
LT
219{
220 return ERR_PTR(-ENODEV);
221}
222
f4ae40a6 223static inline struct dentry *debugfs_create_u64(const char *name, umode_t mode,
8447891f
ME
224 struct dentry *parent,
225 u64 *value)
226{
227 return ERR_PTR(-ENODEV);
228}
229
f4ae40a6 230static inline struct dentry *debugfs_create_x8(const char *name, umode_t mode,
2ebefc50
RG
231 struct dentry *parent,
232 u8 *value)
233{
234 return ERR_PTR(-ENODEV);
235}
236
f4ae40a6 237static inline struct dentry *debugfs_create_x16(const char *name, umode_t mode,
2ebefc50
RG
238 struct dentry *parent,
239 u16 *value)
240{
241 return ERR_PTR(-ENODEV);
242}
243
f4ae40a6 244static inline struct dentry *debugfs_create_x32(const char *name, umode_t mode,
2ebefc50
RG
245 struct dentry *parent,
246 u32 *value)
247{
248 return ERR_PTR(-ENODEV);
249}
250
3159269e
JB
251static inline struct dentry *debugfs_create_x64(const char *name, umode_t mode,
252 struct dentry *parent,
253 u64 *value)
254{
255 return ERR_PTR(-ENODEV);
256}
257
f4ae40a6 258static inline struct dentry *debugfs_create_size_t(const char *name, umode_t mode,
8adb711f
IPG
259 struct dentry *parent,
260 size_t *value)
261{
262 return ERR_PTR(-ENODEV);
263}
264
5b880214
WY
265static inline struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
266 struct dentry *parent, atomic_t *value)
267{
268 return ERR_PTR(-ENODEV);
269}
270
f4ae40a6 271static inline struct dentry *debugfs_create_bool(const char *name, umode_t mode,
1da177e4 272 struct dentry *parent,
621a5f7a 273 bool *value)
1da177e4
LT
274{
275 return ERR_PTR(-ENODEV);
276}
277
f4ae40a6 278static inline struct dentry *debugfs_create_blob(const char *name, umode_t mode,
dd308bc3
ME
279 struct dentry *parent,
280 struct debugfs_blob_wrapper *blob)
281{
282 return ERR_PTR(-ENODEV);
283}
284
1a087c6a 285static inline struct dentry *debugfs_create_regset32(const char *name,
88187398 286 umode_t mode, struct dentry *parent,
1a087c6a
AR
287 struct debugfs_regset32 *regset)
288{
289 return ERR_PTR(-ENODEV);
290}
291
9761536e 292static inline void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
5b880214
WY
293 int nregs, void __iomem *base, char *prefix)
294{
5b880214
WY
295}
296
c0f92ba9
FW
297static inline bool debugfs_initialized(void)
298{
299 return false;
300}
301
9fe2a701
SV
302static inline struct dentry *debugfs_create_u32_array(const char *name, umode_t mode,
303 struct dentry *parent,
304 u32 *array, u32 elements)
305{
306 return ERR_PTR(-ENODEV);
307}
308
98210b7f
AS
309static inline struct dentry *debugfs_create_devm_seqfile(struct device *dev,
310 const char *name,
311 struct dentry *parent,
312 int (*read_fn)(struct seq_file *s,
313 void *data))
314{
315 return ERR_PTR(-ENODEV);
316}
317
0642ef6f
RF
318static inline ssize_t debugfs_read_file_bool(struct file *file,
319 char __user *user_buf,
320 size_t count, loff_t *ppos)
321{
322 return -ENODEV;
323}
324
325static inline ssize_t debugfs_write_file_bool(struct file *file,
326 const char __user *user_buf,
327 size_t count, loff_t *ppos)
328{
329 return -ENODEV;
330}
331
1da177e4
LT
332#endif
333
334#endif