blob: 8f7d8f24141abc1a56c3ad23a6f77b9765266cb8 [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);
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
Pavel Emelyanov6f4e6432007-10-18 23:40:11 -070073
Linus Torvalds1da177e2005-04-16 15:20:36 -070074/*
75 * proc_tty.c
76 */
77struct tty_driver;
Joe Millenbach4f73bc42013-01-17 22:44:22 -080078#ifdef CONFIG_TTY
Linus Torvalds1da177e2005-04-16 15:20:36 -070079extern void proc_tty_init(void);
Joe Millenbach4f73bc42013-01-17 22:44:22 -080080#else
81static inline void proc_tty_init(void)
82{ }
83#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070084extern void proc_tty_register_driver(struct tty_driver *driver);
85extern void proc_tty_unregister_driver(struct tty_driver *driver);
86
87/*
88 * proc_devtree.c
89 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070090#ifdef CONFIG_PROC_DEVICETREE
Benjamin Herrenschmidt183d0202005-11-07 14:29:02 +110091struct device_node;
92struct property;
93extern void proc_device_tree_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094extern void proc_device_tree_add_node(struct device_node *, struct proc_dir_entry *);
Benjamin Herrenschmidt183d0202005-11-07 14:29:02 +110095extern void proc_device_tree_add_prop(struct proc_dir_entry *pde, struct property *prop);
Dave C Boutcher898b5392006-01-12 16:07:17 -060096extern void proc_device_tree_remove_prop(struct proc_dir_entry *pde,
97 struct property *prop);
98extern void proc_device_tree_update_prop(struct proc_dir_entry *pde,
99 struct property *newprop,
100 struct property *oldprop);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101#endif /* CONFIG_PROC_DEVICETREE */
102
103extern struct proc_dir_entry *proc_symlink(const char *,
104 struct proc_dir_entry *, const char *);
105extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
Al Virod161a132011-07-24 03:36:29 -0400106extern struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 struct proc_dir_entry *parent);
108
Al Virod161a132011-07-24 03:36:29 -0400109static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
Denis V. Lunev59b74352008-04-29 01:02:00 -0700110 struct proc_dir_entry *parent, const struct file_operations *proc_fops)
111{
112 return proc_create_data(name, mode, parent, proc_fops, NULL);
113}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Denis V. Luneve5d69b92008-01-10 03:51:41 -0800115extern struct proc_dir_entry *proc_net_mkdir(struct net *net, const char *name,
116 struct proc_dir_entry *parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
David Howells271a15e2013-04-12 00:38:51 +0100118extern void proc_set_size(struct proc_dir_entry *, loff_t);
119extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120#else
121
Pavel Emelyanov60347f62007-10-18 23:40:03 -0700122static inline void proc_flush_task(struct task_struct *task)
123{
124}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Gao feng4fc1a602013-02-19 00:43:10 +0000126#define proc_create(name, mode, parent, fops) ({ (void)(mode), NULL; })
127
Denis V. Lunev59b74352008-04-29 01:02:00 -0700128static inline struct proc_dir_entry *proc_create_data(const char *name,
Al Virod161a132011-07-24 03:36:29 -0400129 umode_t mode, struct proc_dir_entry *parent,
Denis V. Lunev59b74352008-04-29 01:02:00 -0700130 const struct file_operations *proc_fops, void *data)
131{
132 return NULL;
133}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#define remove_proc_entry(name, parent) do {} while (0)
Al Viro8ce584c2013-03-30 20:13:46 -0400135#define remove_proc_subtree(name, parent) do {} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137static inline struct proc_dir_entry *proc_symlink(const char *name,
138 struct proc_dir_entry *parent,const char *dest) {return NULL;}
139static inline struct proc_dir_entry *proc_mkdir(const char *name,
140 struct proc_dir_entry *parent) {return NULL;}
Randy Dunlapf12a20f2011-05-17 15:44:12 -0700141static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
Al Virod161a132011-07-24 03:36:29 -0400142 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
David Howells271a15e2013-04-12 00:38:51 +0100143static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {}
144static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146struct tty_driver;
147static inline void proc_tty_register_driver(struct tty_driver *driver) {};
148static inline void proc_tty_unregister_driver(struct tty_driver *driver) {};
149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150#endif /* CONFIG_PROC_FS */
151
Eric W. Biederman6b4e3062010-03-07 16:41:34 -0800152
Eric W. Biederman20cdc892006-10-02 02:17:07 -0700153union proc_op {
Cyrill Gorcunov7773fbc2012-01-10 15:11:20 -0800154 int (*proc_get_link)(struct dentry *, struct path *);
Eric W. Biederman20cdc892006-10-02 02:17:07 -0700155 int (*proc_read)(struct task_struct *task, char *page);
Eric W. Biedermanbe614082008-02-08 04:18:30 -0800156 int (*proc_show)(struct seq_file *m,
157 struct pid_namespace *ns, struct pid *pid,
158 struct task_struct *task);
Eric W. Biederman20cdc892006-10-02 02:17:07 -0700159};
160
Al Viro90434762008-07-15 08:54:06 -0400161struct ctl_table_header;
162struct ctl_table;
163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164struct proc_inode {
Eric W. Biederman13b41b02006-06-26 00:25:56 -0700165 struct pid *pid;
Eric W. Biedermanaed7a6c2006-06-26 00:25:44 -0700166 int fd;
Eric W. Biederman20cdc892006-10-02 02:17:07 -0700167 union proc_op op;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 struct proc_dir_entry *pde;
Al Viro90434762008-07-15 08:54:06 -0400169 struct ctl_table_header *sysctl;
170 struct ctl_table *sysctl_entry;
David Howells0bb80f22013-04-12 01:50:06 +0100171 struct proc_ns ns;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 struct inode vfs_inode;
173};
174
175static inline struct proc_inode *PROC_I(const struct inode *inode)
176{
177 return container_of(inode, struct proc_inode, vfs_inode);
178}
179
180static inline struct proc_dir_entry *PDE(const struct inode *inode)
181{
182 return PROC_I(inode)->pde;
183}
184
Al Virod9dda782013-03-31 18:16:14 -0400185static inline void *PDE_DATA(const struct inode *inode)
186{
187 return PROC_I(inode)->pde->data;
188}
189
Eric W. Biederman457c4cb2007-09-12 12:01:34 +0200190static inline struct net *PDE_NET(struct proc_dir_entry *pde)
191{
192 return pde->parent->data;
193}
194
Cyrill Gorcunov138d22b2012-12-17 16:05:02 -0800195#include <linux/signal.h>
196
197void render_sigset_t(struct seq_file *m, const char *header, sigset_t *set);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198#endif /* _LINUX_PROC_FS_H */