blob: 2112926de8547cc9683f6c61a3431bc7bbd02a78 [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 Viro866ad9a2013-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);
David Howellsa8ca16e2013-04-12 17:27:28 +010070extern void proc_remove(struct proc_dir_entry *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071extern void remove_proc_entry(const char *name, struct proc_dir_entry *parent);
Al Viro8ce584c2013-03-30 20:13:46 -040072extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern struct proc_dir_entry *proc_symlink(const char *,
75 struct proc_dir_entry *, const char *);
76extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
David Howells270b5ac2013-04-12 02:48:30 +010077extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
78 struct proc_dir_entry *, void *);
Al Virod161a132011-07-24 03:36:29 -040079extern struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 struct proc_dir_entry *parent);
81
Al Virod161a132011-07-24 03:36:29 -040082static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
Denis V. Lunev59b74352008-04-29 01:02:00 -070083 struct proc_dir_entry *parent, const struct file_operations *proc_fops)
84{
85 return proc_create_data(name, mode, parent, proc_fops, NULL);
86}
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
David Howells271a15e2013-04-12 00:38:51 +010088extern void proc_set_size(struct proc_dir_entry *, loff_t);
89extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
David Howellsc30480b2013-04-12 18:03:36 +010090extern void *PDE_DATA(const struct inode *);
David Howells4a520d22013-04-12 14:06:01 +010091extern void *proc_get_parent_data(const struct inode *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092#else
93
Pavel Emelyanov60347f62007-10-18 23:40:03 -070094static inline void proc_flush_task(struct task_struct *task)
95{
96}
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Gao feng4fc1a602013-02-19 00:43:10 +000098#define proc_create(name, mode, parent, fops) ({ (void)(mode), NULL; })
99
Denis V. Lunev59b74352008-04-29 01:02:00 -0700100static inline struct proc_dir_entry *proc_create_data(const char *name,
Al Virod161a132011-07-24 03:36:29 -0400101 umode_t mode, struct proc_dir_entry *parent,
Denis V. Lunev59b74352008-04-29 01:02:00 -0700102 const struct file_operations *proc_fops, void *data)
103{
104 return NULL;
105}
David Howellsa8ca16e2013-04-12 17:27:28 +0100106static inline void proc_remove(struct proc_dir_entry *de) {}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107#define remove_proc_entry(name, parent) do {} while (0)
Al Viro8ce584c2013-03-30 20:13:46 -0400108#define remove_proc_subtree(name, parent) do {} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110static inline struct proc_dir_entry *proc_symlink(const char *name,
111 struct proc_dir_entry *parent,const char *dest) {return NULL;}
112static inline struct proc_dir_entry *proc_mkdir(const char *name,
113 struct proc_dir_entry *parent) {return NULL;}
David Howells270b5ac2013-04-12 02:48:30 +0100114static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
115 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
Randy Dunlapf12a20f2011-05-17 15:44:12 -0700116static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
Al Virod161a132011-07-24 03:36:29 -0400117 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
David Howells271a15e2013-04-12 00:38:51 +0100118static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
119static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
David Howellsc30480b2013-04-12 18:03:36 +0100120static inline void *PDE_DATA(const struct inode *inode) {BUG(); return NULL;}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122#endif /* CONFIG_PROC_FS */
123
Eric W. Biederman6b4e3062010-03-07 16:41:34 -0800124
Eric W. Biederman20cdc892006-10-02 02:17:07 -0700125union proc_op {
Cyrill Gorcunov7773fbc2012-01-10 15:11:20 -0800126 int (*proc_get_link)(struct dentry *, struct path *);
Eric W. Biederman20cdc892006-10-02 02:17:07 -0700127 int (*proc_read)(struct task_struct *task, char *page);
Eric W. Biedermanbe614082008-02-08 04:18:30 -0800128 int (*proc_show)(struct seq_file *m,
129 struct pid_namespace *ns, struct pid *pid,
130 struct task_struct *task);
Eric W. Biederman20cdc892006-10-02 02:17:07 -0700131};
132
Al Viro9043476f2008-07-15 08:54:06 -0400133struct ctl_table_header;
134struct ctl_table;
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136struct proc_inode {
Eric W. Biederman13b41b02006-06-26 00:25:56 -0700137 struct pid *pid;
Eric W. Biedermanaed7a6c2006-06-26 00:25:44 -0700138 int fd;
Eric W. Biederman20cdc892006-10-02 02:17:07 -0700139 union proc_op op;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 struct proc_dir_entry *pde;
Al Viro9043476f2008-07-15 08:54:06 -0400141 struct ctl_table_header *sysctl;
142 struct ctl_table *sysctl_entry;
David Howells0bb80f22013-04-12 01:50:06 +0100143 struct proc_ns ns;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 struct inode vfs_inode;
145};
146
David Howells270b5ac2013-04-12 02:48:30 +0100147static inline struct proc_dir_entry *proc_net_mkdir(
148 struct net *net, const char *name, struct proc_dir_entry *parent)
149{
150 return proc_mkdir_data(name, 0, parent, net);
151}
152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#endif /* _LINUX_PROC_FS_H */