proc_fs.h 5.68 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds's avatar
Linus Torvalds committed
2 3 4
/*
 * The proc filesystem constants/structures
 */
5 6
#ifndef _LINUX_PROC_FS_H
#define _LINUX_PROC_FS_H
Linus Torvalds's avatar
Linus Torvalds committed
7

8 9
#include <linux/types.h>
#include <linux/fs.h>
Linus Torvalds's avatar
Linus Torvalds committed
10

11
struct proc_dir_entry;
12
struct seq_file;
13
struct seq_operations;
Linus Torvalds's avatar
Linus Torvalds committed
14 15 16

#ifdef CONFIG_PROC_FS

17 18
typedef int (*proc_write_t)(struct file *, char *, size_t);

Linus Torvalds's avatar
Linus Torvalds committed
19
extern void proc_root_init(void);
20
extern void proc_flush_task(struct task_struct *);
Linus Torvalds's avatar
Linus Torvalds committed
21 22 23

extern struct proc_dir_entry *proc_symlink(const char *,
		struct proc_dir_entry *, const char *);
24
extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
25 26
extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
					      struct proc_dir_entry *, void *);
27 28
extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
					      struct proc_dir_entry *);
29
struct proc_dir_entry *proc_create_mount_point(const char *name);
30

31
struct 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 34 35
		unsigned int state_size, void *data);
#define proc_create_seq_data(name, mode, parent, ops, data) \
	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)
38 39 40 41 42
struct proc_dir_entry *proc_create_single_data(const char *name, umode_t mode,
		struct proc_dir_entry *parent,
		int (*show)(struct seq_file *, void *), void *data);
#define proc_create_single(name, mode, parent, show) \
	proc_create_single_data(name, mode, parent, show, NULL)
43 44 45 46 47 48
 
extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
					       struct proc_dir_entry *,
					       const struct file_operations *,
					       void *);

49
struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct file_operations *proc_fops);
50 51
extern void proc_set_size(struct proc_dir_entry *, loff_t);
extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
52
extern void *PDE_DATA(const struct inode *);
53
extern void *proc_get_parent_data(const struct inode *);
54 55 56 57
extern void proc_remove(struct proc_dir_entry *);
extern void remove_proc_entry(const char *, struct proc_dir_entry *);
extern int remove_proc_subtree(const char *, struct proc_dir_entry *);

58 59 60 61 62
struct proc_dir_entry *proc_create_net_data(const char *name, umode_t mode,
		struct proc_dir_entry *parent, const struct seq_operations *ops,
		unsigned int state_size, void *data);
#define proc_create_net(name, mode, parent, state_size, ops) \
	proc_create_net_data(name, mode, parent, state_size, ops, NULL)
63 64 65
struct proc_dir_entry *proc_create_net_single(const char *name, umode_t mode,
		struct proc_dir_entry *parent,
		int (*show)(struct seq_file *, void *), void *data);
66 67 68 69 70 71 72 73 74 75
struct proc_dir_entry *proc_create_net_data_write(const char *name, umode_t mode,
						  struct proc_dir_entry *parent,
						  const struct seq_operations *ops,
						  proc_write_t write,
						  unsigned int state_size, void *data);
struct proc_dir_entry *proc_create_net_single_write(const char *name, umode_t mode,
						    struct proc_dir_entry *parent,
						    int (*show)(struct seq_file *, void *),
						    proc_write_t write,
						    void *data);
76

77
#else /* CONFIG_PROC_FS */
Linus Torvalds's avatar
Linus Torvalds committed
78

79 80 81 82
static inline void proc_root_init(void)
{
}

83 84 85
static inline void proc_flush_task(struct task_struct *task)
{
}
Linus Torvalds's avatar
Linus Torvalds committed
86 87

static inline struct proc_dir_entry *proc_symlink(const char *name,
88
		struct proc_dir_entry *parent,const char *dest) { return NULL;}
Linus Torvalds's avatar
Linus Torvalds committed
89 90
static inline struct proc_dir_entry *proc_mkdir(const char *name,
	struct proc_dir_entry *parent) {return NULL;}
91
static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; }
92 93
static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
	umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
94
static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
Al Viro's avatar
Al Viro committed
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 98
#define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;})
#define proc_create_seq(name, mode, parent, ops) ({NULL;})
99 100
#define proc_create_single(name, mode, parent, show) ({NULL;})
#define proc_create_single_data(name, mode, parent, show, data) ({NULL;})
101 102 103
#define proc_create(name, mode, parent, proc_fops) ({NULL;})
#define proc_create_data(name, mode, parent, proc_fops, data) ({NULL;})

104 105
static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
106
static inline void *PDE_DATA(const struct inode *inode) {BUG(); return NULL;}
107
static inline void *proc_get_parent_data(const struct inode *inode) { BUG(); return NULL; }
Linus Torvalds's avatar
Linus Torvalds committed
108

109 110 111
static inline void proc_remove(struct proc_dir_entry *de) {}
#define remove_proc_entry(name, parent) do {} while (0)
static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) { return 0; }
Al Viro's avatar
Al Viro committed
112

113 114
#define proc_create_net_data(name, mode, parent, ops, state_size, data) ({NULL;})
#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 */
Linus Torvalds's avatar
Linus Torvalds committed
118

119 120
struct net;

121 122 123 124 125 126
static inline struct proc_dir_entry *proc_net_mkdir(
	struct net *net, const char *name, struct proc_dir_entry *parent)
{
	return proc_mkdir_data(name, 0, parent, net);
}

127 128 129 130
struct ns_common;
int open_related_ns(struct ns_common *ns,
		   struct ns_common *(*get_ns)(struct ns_common *ns));

131
/* get the associated pid namespace for a file in procfs */
132
static inline struct pid_namespace *proc_pid_ns(const struct inode *inode)
133 134 135 136
{
	return inode->i_sb->s_fs_info;
}

Linus Torvalds's avatar
Linus Torvalds committed
137
#endif /* _LINUX_PROC_FS_H */