blob: a0fb1c2f1d8e68a5d9029923292903caeff557e4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_PROC_FS_H
2#define _LINUX_PROC_FS_H
3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004#include <linux/slab.h>
5#include <linux/fs.h>
Steven Rostedt64a07bd2006-03-26 01:36:55 -08006#include <linux/spinlock.h>
Jeff Garzike18fa702006-09-24 11:13:19 -04007#include <linux/magic.h>
Arun Sharma600634972011-07-26 16:09:06 -07008#include <linux/atomic.h>
David Howells0bb80f22013-04-12 01:50:06 +01009#include <linux/proc_ns.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
Eric W. Biederman457c4cb2007-09-12 12:01:34 +020011struct net;
Alexey Dobriyan786d7e12007-07-15 23:39:00 -070012struct completion;
Ben Nizette57d3c642008-06-12 15:21:31 -070013struct mm_struct;
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015/*
16 * The proc filesystem constants/structures
17 */
18
19/*
20 * Offset of the first process in the /proc root directory..
21 */
22#define FIRST_PROCESS_ENTRY 256
23
Matt Mackallf248dcb2008-02-04 22:29:03 -080024/* Worst case buffer size needed for holding an integer. */
25#define PROC_NUMBUF 13
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 * This is not completely implemented yet. The idea is to
29 * create an in-memory tree (like the actual /proc filesystem
30 * tree) of these proc_dir_entries, so that we can dynamically
31 * add new files to /proc.
32 *
33 * The "next" pointer creates a linked list of one /proc directory,
34 * while parent/subdir create the directory structure (every
35 * /proc file has a parent, but "subdir" is NULL for all
36 * non-directory entries).
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 */
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039struct proc_dir_entry {
40 unsigned int low_ino;
Al Virod161a132011-07-24 03:36:29 -040041 umode_t mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 nlink_t nlink;
Eric W. Biedermandcb0f222012-02-09 08:48:21 -080043 kuid_t uid;
44 kgid_t gid;
Maneesh Soni22e6c1b2006-03-26 01:37:29 -080045 loff_t size;
Arjan van de Venc5ef1c42007-02-12 00:55:40 -080046 const struct inode_operations *proc_iops;
47 const struct file_operations *proc_fops;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 struct proc_dir_entry *next, *parent, *subdir;
49 void *data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 atomic_t count; /* use count */
Al Viro05c0ae22013-04-04 16:28:47 -040051 atomic_t in_use; /* number of callers into module in progress; */
Al Viro866ad9a72013-04-03 19:07:30 -040052 /* negative -> it's going away RSN */
Alexey Dobriyan786d7e12007-07-15 23:39:00 -070053 struct completion *pde_unload_completion;
Alexey Dobriyan881adb82008-07-25 01:48:29 -070054 struct list_head pde_openers; /* who did ->open, but not ->release */
David Howells09570f92011-07-27 21:47:03 +030055 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
56 u8 namelen;
57 char name[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070058};
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#ifdef CONFIG_PROC_FS
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062extern void proc_root_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Eric W. Biederman48e64842006-06-26 00:25:48 -070064void proc_flush_task(struct task_struct *task);
Alexey Dobriyan76956502007-05-08 00:25:45 -070065
Al Virod161a132011-07-24 03:36:29 -040066struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
Alexey Dobriyan2d3a4e32008-02-08 04:18:37 -080067 struct proc_dir_entry *parent,
Denis V. Lunev59b74352008-04-29 01:02:00 -070068 const struct file_operations *proc_fops,
69 void *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
Al Viro8ce584c2013-03-30 20:13:46 -040071extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Linus Torvalds1da177e2005-04-16 15:20:36 -070073extern struct proc_dir_entry *proc_symlink(const char *,
74 struct proc_dir_entry *, const char *);
75extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
David Howells270b5ac2013-04-12 02:48:30 +010076extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
77 struct proc_dir_entry *, void *);
Al Virod161a132011-07-24 03:36:29 -040078extern struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 struct proc_dir_entry *parent);
80
Al Virod161a132011-07-24 03:36:29 -040081static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
Denis V. Lunev59b74352008-04-29 01:02:00 -070082 struct proc_dir_entry *parent, const struct file_operations *proc_fops)
83{
84 return proc_create_data(name, mode, parent, proc_fops, NULL);
85}
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
David Howells271a15e2013-04-12 00:38:51 +010087extern void proc_set_size(struct proc_dir_entry *, loff_t);
88extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089#else
90
Pavel Emelyanov60347f62007-10-18 23:40:03 -070091static inline void proc_flush_task(struct task_struct *task)
92{
93}
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Gao feng4fc1a602013-02-19 00:43:10 +000095#define proc_create(name, mode, parent, fops) ({ (void)(mode), NULL; })
96
Denis V. Lunev59b74352008-04-29 01:02:00 -070097static inline struct proc_dir_entry *proc_create_data(const char *name,
Al Virod161a132011-07-24 03:36:29 -040098 umode_t mode, struct proc_dir_entry *parent,
Denis V. Lunev59b74352008-04-29 01:02:00 -070099 const struct file_operations *proc_fops, void *data)
100{
101 return NULL;
102}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103#define remove_proc_entry(name, parent) do {} while (0)
Al Viro8ce584c2013-03-30 20:13:46 -0400104#define remove_proc_subtree(name, parent) do {} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106static inline struct proc_dir_entry *proc_symlink(const char *name,
107 struct proc_dir_entry *parent,const char *dest) {return NULL;}
108static inline struct proc_dir_entry *proc_mkdir(const char *name,
109 struct proc_dir_entry *parent) {return NULL;}
David Howells270b5ac2013-04-12 02:48:30 +0100110static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
111 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
Randy Dunlapf12a20f2011-05-17 15:44:12 -0700112static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
Al Virod161a132011-07-24 03:36:29 -0400113 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
David Howells271a15e2013-04-12 00:38:51 +0100114static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
115static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#endif /* CONFIG_PROC_FS */
118
Eric W. Biederman6b4e3062010-03-07 16:41:34 -0800119
Eric W. Biederman20cdc892006-10-02 02:17:07 -0700120union proc_op {
Cyrill Gorcunov7773fbc2012-01-10 15:11:20 -0800121 int (*proc_get_link)(struct dentry *, struct path *);
Eric W. Biederman20cdc892006-10-02 02:17:07 -0700122 int (*proc_read)(struct task_struct *task, char *page);
Eric W. Biedermanbe614082008-02-08 04:18:30 -0800123 int (*proc_show)(struct seq_file *m,
124 struct pid_namespace *ns, struct pid *pid,
125 struct task_struct *task);
Eric W. Biederman20cdc892006-10-02 02:17:07 -0700126};
127
Al Viro9043476f2008-07-15 08:54:06 -0400128struct ctl_table_header;
129struct ctl_table;
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131struct proc_inode {
Eric W. Biederman13b41b02006-06-26 00:25:56 -0700132 struct pid *pid;
Eric W. Biedermanaed7a6c2006-06-26 00:25:44 -0700133 int fd;
Eric W. Biederman20cdc892006-10-02 02:17:07 -0700134 union proc_op op;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 struct proc_dir_entry *pde;
Al Viro9043476f2008-07-15 08:54:06 -0400136 struct ctl_table_header *sysctl;
137 struct ctl_table *sysctl_entry;
David Howells0bb80f22013-04-12 01:50:06 +0100138 struct proc_ns ns;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 struct inode vfs_inode;
140};
141
142static inline struct proc_inode *PROC_I(const struct inode *inode)
143{
144 return container_of(inode, struct proc_inode, vfs_inode);
145}
146
147static inline struct proc_dir_entry *PDE(const struct inode *inode)
148{
149 return PROC_I(inode)->pde;
150}
151
Al Virod9dda782013-03-31 18:16:14 -0400152static inline void *PDE_DATA(const struct inode *inode)
153{
154 return PROC_I(inode)->pde->data;
155}
156
David Howells270b5ac2013-04-12 02:48:30 +0100157static inline struct proc_dir_entry *proc_net_mkdir(
158 struct net *net, const char *name, struct proc_dir_entry *parent)
159{
160 return proc_mkdir_data(name, 0, parent, net);
161}
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163#endif /* _LINUX_PROC_FS_H */