xref: /linux/fs/debugfs/internal.h (revision 2c1ed907520c50326b8f604907a8478b27881a2e)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  *  internal.h - declarations internal to debugfs
4  *
5  *  Copyright (C) 2016 Nicolai Stange <nicstange@gmail.com>
6  */
7 
8 #ifndef _DEBUGFS_INTERNAL_H_
9 #define _DEBUGFS_INTERNAL_H_
10 #include <linux/list.h>
11 
12 struct file_operations;
13 
14 struct debugfs_inode_info {
15 	struct inode vfs_inode;
16 	union {
17 		const void *raw;
18 		const struct file_operations *real_fops;
19 		const struct debugfs_short_fops *short_fops;
20 		debugfs_automount_t automount;
21 	};
22 	const void *aux;
23 };
24 
DEBUGFS_I(struct inode * inode)25 static inline struct debugfs_inode_info *DEBUGFS_I(struct inode *inode)
26 {
27 	return container_of(inode, struct debugfs_inode_info, vfs_inode);
28 }
29 
30 /* declared over in file.c */
31 extern const struct file_operations debugfs_noop_file_operations;
32 extern const struct file_operations debugfs_open_proxy_file_operations;
33 extern const struct file_operations debugfs_full_proxy_file_operations;
34 extern const struct file_operations debugfs_full_short_proxy_file_operations;
35 
36 struct debugfs_fsdata {
37 	const struct file_operations *real_fops;
38 	const struct debugfs_short_fops *short_fops;
39 	struct {
40 		refcount_t active_users;
41 		struct completion active_users_drained;
42 
43 		/* protect cancellations */
44 		struct mutex cancellations_mtx;
45 		struct list_head cancellations;
46 		unsigned int methods;
47 	};
48 };
49 
50 enum {
51 	HAS_READ = 1,
52 	HAS_WRITE = 2,
53 	HAS_LSEEK = 4,
54 	HAS_POLL = 8,
55 	HAS_IOCTL = 16
56 };
57 
58 #define DEBUGFS_ALLOW_API	BIT(0)
59 #define DEBUGFS_ALLOW_MOUNT	BIT(1)
60 
61 #ifdef CONFIG_DEBUG_FS_ALLOW_ALL
62 #define DEFAULT_DEBUGFS_ALLOW_BITS (DEBUGFS_ALLOW_MOUNT | DEBUGFS_ALLOW_API)
63 #endif
64 #ifdef CONFIG_DEBUG_FS_DISALLOW_MOUNT
65 #define DEFAULT_DEBUGFS_ALLOW_BITS (DEBUGFS_ALLOW_API)
66 #endif
67 #ifdef CONFIG_DEBUG_FS_ALLOW_NONE
68 #define DEFAULT_DEBUGFS_ALLOW_BITS (0)
69 #endif
70 
71 #endif /* _DEBUGFS_INTERNAL_H_ */
72