xref: /linux-6.15/include/linux/proc_fs.h (revision 6da2ec56)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * The proc filesystem constants/structures
4  */
5 #ifndef _LINUX_PROC_FS_H
6 #define _LINUX_PROC_FS_H
7 
8 #include <linux/types.h>
9 #include <linux/fs.h>
10 
11 struct proc_dir_entry;
12 struct seq_file;
13 struct seq_operations;
14 
15 #ifdef CONFIG_PROC_FS
16 
17 extern void proc_root_init(void);
18 extern void proc_flush_task(struct task_struct *);
19 
20 extern struct proc_dir_entry *proc_symlink(const char *,
21 		struct proc_dir_entry *, const char *);
22 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
23 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
24 					      struct proc_dir_entry *, void *);
25 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
26 					      struct proc_dir_entry *);
27 struct proc_dir_entry *proc_create_mount_point(const char *name);
28 
29 struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
30 		struct proc_dir_entry *parent, const struct seq_operations *ops,
31 		unsigned int state_size, void *data);
32 #define proc_create_seq_data(name, mode, parent, ops, data) \
33 	proc_create_seq_private(name, mode, parent, ops, 0, data)
34 #define proc_create_seq(name, mode, parent, ops) \
35 	proc_create_seq_private(name, mode, parent, ops, 0, NULL)
36 struct proc_dir_entry *proc_create_single_data(const char *name, umode_t mode,
37 		struct proc_dir_entry *parent,
38 		int (*show)(struct seq_file *, void *), void *data);
39 #define proc_create_single(name, mode, parent, show) \
40 	proc_create_single_data(name, mode, parent, show, NULL)
41 
42 extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
43 					       struct proc_dir_entry *,
44 					       const struct file_operations *,
45 					       void *);
46 
47 struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct file_operations *proc_fops);
48 extern void proc_set_size(struct proc_dir_entry *, loff_t);
49 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
50 extern void *PDE_DATA(const struct inode *);
51 extern void *proc_get_parent_data(const struct inode *);
52 extern void proc_remove(struct proc_dir_entry *);
53 extern void remove_proc_entry(const char *, struct proc_dir_entry *);
54 extern int remove_proc_subtree(const char *, struct proc_dir_entry *);
55 
56 struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode,
57 		struct proc_dir_entry *parent, const struct seq_operations *ops,
58 		unsigned int state_size, void *data);
59 #define proc_create_net(name, mode, parent, state_size, ops) \
60 	proc_create_net_data(name, mode, parent, state_size, ops, NULL)
61 struct proc_dir_entry *proc_create_net_single(const char *name, umode_t mode,
62 		struct proc_dir_entry *parent,
63 		int (*show)(struct seq_file *, void *), void *data);
64 
65 #else /* CONFIG_PROC_FS */
66 
67 static inline void proc_root_init(void)
68 {
69 }
70 
71 static inline void proc_flush_task(struct task_struct *task)
72 {
73 }
74 
75 static inline struct proc_dir_entry *proc_symlink(const char *name,
76 		struct proc_dir_entry *parent,const char *dest) { return NULL;}
77 static inline struct proc_dir_entry *proc_mkdir(const char *name,
78 	struct proc_dir_entry *parent) {return NULL;}
79 static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; }
80 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
81 	umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
82 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
83 	umode_t mode, struct proc_dir_entry *parent) { return NULL; }
84 #define proc_create_seq_private(name, mode, parent, ops, size, data) ({NULL;})
85 #define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;})
86 #define proc_create_seq(name, mode, parent, ops) ({NULL;})
87 #define proc_create_single(name, mode, parent, show) ({NULL;})
88 #define proc_create_single_data(name, mode, parent, show, data) ({NULL;})
89 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
90 #define proc_create_data(name, mode, parent, proc_fops, data) ({NULL;})
91 
92 static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
93 static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
94 static inline void *PDE_DATA(const struct inode *inode) {BUG(); return NULL;}
95 static inline void *proc_get_parent_data(const struct inode *inode) { BUG(); return NULL; }
96 
97 static inline void proc_remove(struct proc_dir_entry *de) {}
98 #define remove_proc_entry(name, parent) do {} while (0)
99 static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; }
100 
101 #define proc_create_net_data(name, mode, parent, ops, state_size, data) ({NULL;})
102 #define proc_create_net(name, mode, parent, state_size, ops) ({NULL;})
103 #define proc_create_net_single(name, mode, parent, show, data) ({NULL;})
104 
105 #endif /* CONFIG_PROC_FS */
106 
107 struct net;
108 
109 static inline struct proc_dir_entry *proc_net_mkdir(
110 	struct net *net, const char *name, struct proc_dir_entry *parent)
111 {
112 	return proc_mkdir_data(name, 0, parent, net);
113 }
114 
115 struct ns_common;
116 int open_related_ns(struct ns_common *ns,
117 		   struct ns_common *(*get_ns)(struct ns_common *ns));
118 
119 /* get the associated pid namespace for a file in procfs */
120 static inline struct pid_namespace *proc_pid_ns(struct inode *inode)
121 {
122 	return inode->i_sb->s_fs_info;
123 }
124 
125 #endif /* _LINUX_PROC_FS_H */
126