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