blob: 626fc65c433640c5d6c6302949c9a3028c84a6de [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * The proc filesystem constants/structures
4 */
David Howells59d80532013-04-11 13:34:43 +01005#ifndef _LINUX_PROC_FS_H
6#define _LINUX_PROC_FS_H
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
David Howells59d80532013-04-11 13:34:43 +01008#include <linux/types.h>
9#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
David Howells59d80532013-04-11 13:34:43 +010011struct proc_dir_entry;
Christoph Hellwig3f3942a2018-05-15 15:57:23 +020012struct seq_file;
Christoph Hellwigfddda2b2018-04-13 19:44:18 +020013struct seq_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#ifdef CONFIG_PROC_FS
16
David Howells564def72018-05-18 11:46:15 +010017typedef int (*proc_write_t)(struct file *, char *, size_t);
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019extern void proc_root_init(void);
David Howells59d80532013-04-11 13:34:43 +010020extern void proc_flush_task(struct task_struct *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022extern struct proc_dir_entry *proc_symlink(const char *,
23 struct proc_dir_entry *, const char *);
David Howells59d80532013-04-11 13:34:43 +010024extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
David Howells270b5ac2013-04-12 02:48:30 +010025extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
26 struct proc_dir_entry *, void *);
David Howells59d80532013-04-11 13:34:43 +010027extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
28 struct proc_dir_entry *);
Seth Forsheef97df702016-11-14 11:12:56 +000029struct proc_dir_entry *proc_create_mount_point(const char *name);
Christoph Hellwigfddda2b2018-04-13 19:44:18 +020030
Christoph Hellwig44414d82018-04-24 17:05:17 +020031struct proc_dir_entry *proc_create_seq_private(const char *name, umode_t mode,
Christoph Hellwigfddda2b2018-04-13 19:44:18 +020032 struct proc_dir_entry *parent, const struct seq_operations *ops,
Christoph Hellwig44414d82018-04-24 17:05:17 +020033 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)
Christoph Hellwigfddda2b2018-04-13 19:44:18 +020036#define proc_create_seq(name, mode, parent, ops) \
Christoph Hellwig44414d82018-04-24 17:05:17 +020037 proc_create_seq_private(name, mode, parent, ops, 0, NULL)
Christoph Hellwig3f3942a2018-05-15 15:57:23 +020038struct 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)
David Howells59d80532013-04-11 13:34:43 +010043
44extern struct proc_dir_entry *proc_create_data(const char *, umode_t,
45 struct proc_dir_entry *,
46 const struct file_operations *,
47 void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Alexey Dobriyan855d9762017-09-08 16:13:38 -070049struct proc_dir_entry *proc_create(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct file_operations *proc_fops);
David Howells271a15e2013-04-12 00:38:51 +010050extern void proc_set_size(struct proc_dir_entry *, loff_t);
51extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
David Howellsc30480b2013-04-12 18:03:36 +010052extern void *PDE_DATA(const struct inode *);
David Howells4a520d22013-04-12 14:06:01 +010053extern void *proc_get_parent_data(const struct inode *);
David Howells59d80532013-04-11 13:34:43 +010054extern 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
Christoph Hellwigc3506372018-04-10 19:42:55 +020058struct 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)
Christoph Hellwig3617d942018-04-13 20:38:35 +020063struct 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);
David Howells564def72018-05-18 11:46:15 +010066struct 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);
Christoph Hellwigc3506372018-04-10 19:42:55 +020076
David Howells59d80532013-04-11 13:34:43 +010077#else /* CONFIG_PROC_FS */
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Andrew Morton647f0102014-06-04 16:12:20 -070079static inline void proc_root_init(void)
80{
81}
82
Pavel Emelyanov60347f62007-10-18 23:40:03 -070083static inline void proc_flush_task(struct task_struct *task)
84{
85}
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
Linus Torvalds1da177e2005-04-16 15:20:36 -070087static inline struct proc_dir_entry *proc_symlink(const char *name,
David Howells59d80532013-04-11 13:34:43 +010088 struct proc_dir_entry *parent,const char *dest) { return NULL;}
Linus Torvalds1da177e2005-04-16 15:20:36 -070089static inline struct proc_dir_entry *proc_mkdir(const char *name,
90 struct proc_dir_entry *parent) {return NULL;}
Seth Forsheef97df702016-11-14 11:12:56 +000091static inline struct proc_dir_entry *proc_create_mount_point(const char *name) { return NULL; }
David Howells270b5ac2013-04-12 02:48:30 +010092static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
93 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
Randy Dunlapf12a20f2011-05-17 15:44:12 -070094static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
Al Virod161a132011-07-24 03:36:29 -040095 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
Christoph Hellwig3f3942a2018-05-15 15:57:23 +020096#define proc_create_seq_private(name, mode, parent, ops, size, data) ({NULL;})
Christoph Hellwigfddda2b2018-04-13 19:44:18 +020097#define proc_create_seq_data(name, mode, parent, ops, data) ({NULL;})
98#define proc_create_seq(name, mode, parent, ops) ({NULL;})
Christoph Hellwig3f3942a2018-05-15 15:57:23 +020099#define proc_create_single(name, mode, parent, show) ({NULL;})
100#define proc_create_single_data(name, mode, parent, show, data) ({NULL;})
David Howells59d80532013-04-11 13:34:43 +0100101#define proc_create(name, mode, parent, proc_fops) ({NULL;})
102#define proc_create_data(name, mode, parent, proc_fops, data) ({NULL;})
103
David Howells271a15e2013-04-12 00:38:51 +0100104static 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) {}
David Howellsc30480b2013-04-12 18:03:36 +0100106static inline void *PDE_DATA(const struct inode *inode) {BUG(); return NULL;}
David Howells59d80532013-04-11 13:34:43 +0100107static 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; }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Christoph Hellwigc3506372018-04-10 19:42:55 +0200113#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;})
Christoph Hellwig3617d942018-04-13 20:38:35 +0200115#define proc_create_net_single(name, mode, parent, show, data) ({NULL;})
Christoph Hellwigc3506372018-04-10 19:42:55 +0200116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#endif /* CONFIG_PROC_FS */
118
Jeff Laytonf7790022014-09-12 16:40:20 -0400119struct net;
120
David Howells270b5ac2013-04-12 02:48:30 +0100121static 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
Andrey Vaginc62cce22016-10-24 18:29:13 -0700127struct ns_common;
128int open_related_ns(struct ns_common *ns,
129 struct ns_common *(*get_ns)(struct ns_common *ns));
130
Christoph Hellwig76f668b2018-05-16 07:19:01 +0200131/* 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#endif /* _LINUX_PROC_FS_H */