xref: /freebsd/sys/fs/procfs/procfs.h (revision a220d00e74dd245b4fca59c5eca0c53963686325)
1 /*
2  * Copyright (c) 1993 Jan-Simon Pendry
3  * Copyright (c) 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * Jan-Simon Pendry.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *	This product includes software developed by the University of
20  *	California, Berkeley and its contributors.
21  * 4. Neither the name of the University nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  *	@(#)procfs.h	8.9 (Berkeley) 5/14/95
38  *
39  * From:
40  * $FreeBSD$
41  */
42 
43 /*
44  * The different types of node in a procfs filesystem
45  */
46 typedef enum {
47 	Proot,		/* the filesystem root */
48 	Pcurproc,	/* symbolic link for curproc */
49 	Pproc,		/* a process-specific sub-directory */
50 	Pfile,		/* the executable file */
51 	Pmem,		/* the process's memory image */
52 	Pregs,		/* the process's register set */
53 	Pfpregs,	/* the process's FP register set */
54 	Pdbregs,	/* the process's debug register set */
55 	Pctl,		/* process control */
56 	Pstatus,	/* process status */
57 	Pnote,		/* process notifier */
58 	Pnotepg,	/* process group notifier */
59 	Pmap,		/* memory map */
60 	Ptype,		/* executable type */
61 	Pcmdline,	/* command line */
62 	Prlimit		/* resource limits */
63 } pfstype;
64 
65 /*
66  * control data for the proc file system.
67  */
68 struct pfsnode {
69 	struct pfsnode	*pfs_next;	/* next on list */
70 	struct vnode	*pfs_vnode;	/* vnode associated with this pfsnode */
71 	pfstype		pfs_type;	/* type of procfs node */
72 	pid_t		pfs_pid;	/* associated process */
73 	u_short		pfs_mode;	/* mode bits for stat() */
74 	u_long		pfs_flags;	/* open flags */
75 	u_long		pfs_fileno;	/* unique file id */
76 	pid_t		pfs_lockowner;	/* pfs lock owner */
77 };
78 
79 #define PROCFS_NOTELEN	64	/* max length of a note (/proc/$pid/note) */
80 #define PROCFS_CTLLEN 	8	/* max length of a ctl msg (/proc/$pid/ctl */
81 #define PROCFS_NAMELEN 	8	/* max length of a filename component */
82 
83 /*
84  * Kernel stuff follows
85  */
86 #ifdef _KERNEL
87 #define CNEQ(cnp, s, len) \
88 	 ((cnp)->cn_namelen == (len) && \
89 	  (bcmp((s), (cnp)->cn_nameptr, (len)) == 0))
90 
91 #define PROCFS_FILENO(pid, type) \
92 	(((type) < Pproc) ? \
93 			((type) + 2) : \
94 			((((pid)+1) << 4) + ((int) (type))))
95 
96 /*
97  * Convert between pfsnode vnode
98  */
99 #define VTOPFS(vp)	((struct pfsnode *)(vp)->v_data)
100 #define PFSTOV(pfs)	((pfs)->pfs_vnode)
101 
102 typedef struct vfs_namemap vfs_namemap_t;
103 struct vfs_namemap {
104 	const char *nm_name;
105 	int nm_val;
106 };
107 
108 int vfs_getuserstr __P((struct uio *, char *, int *));
109 vfs_namemap_t *vfs_findname __P((vfs_namemap_t *, char *, int));
110 
111 /* <machine/reg.h> */
112 struct reg;
113 struct fpreg;
114 struct dbreg;
115 
116 #define PFIND(pid) (pfind(pid))
117 
118 void procfs_exit __P((struct proc *));
119 int procfs_freevp __P((struct vnode *));
120 int procfs_allocvp __P((struct mount *, struct vnode **, long, pfstype));
121 int procfs_donote __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
122 int procfs_doregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
123 int procfs_dofpregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
124 int procfs_dodbregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
125 int procfs_domem __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
126 int procfs_doctl __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
127 int procfs_dostatus __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
128 int procfs_domap __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
129 int procfs_dotype __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
130 int procfs_docmdline __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
131 int procfs_dorlimit __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
132 
133 /* functions to check whether or not files should be displayed */
134 int procfs_validfile __P((struct thread *));
135 int procfs_validfpregs __P((struct thread *));
136 int procfs_validregs __P((struct thread *));
137 int procfs_validdbregs __P((struct thread *));
138 int procfs_validmap __P((struct thread *));
139 int procfs_validtype __P((struct thread *));
140 
141 #define PROCFS_LOCKED	0x01
142 #define PROCFS_WANT	0x02
143 
144 extern vop_t **procfs_vnodeop_p;
145 
146 int	procfs_root __P((struct mount *, struct vnode **));
147 int	procfs_rw __P((struct vop_read_args *));
148 #endif /* _KERNEL */
149