Home | History | Annotate | Line # | Download | only in procfs
procfs.h revision 1.47.2.2
      1 /*	$NetBSD: procfs.h,v 1.47.2.2 2004/08/03 10:54:06 skrll Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley by
      8  * Jan-Simon Pendry.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. Neither the name of the University nor the names of its contributors
     19  *    may be used to endorse or promote products derived from this software
     20  *    without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  *
     34  *	@(#)procfs.h	8.9 (Berkeley) 5/14/95
     35  */
     36 
     37 /*
     38  * Copyright (c) 1993 Jan-Simon Pendry
     39  *
     40  * This code is derived from software contributed to Berkeley by
     41  * Jan-Simon Pendry.
     42  *
     43  * Redistribution and use in source and binary forms, with or without
     44  * modification, are permitted provided that the following conditions
     45  * are met:
     46  * 1. Redistributions of source code must retain the above copyright
     47  *    notice, this list of conditions and the following disclaimer.
     48  * 2. Redistributions in binary form must reproduce the above copyright
     49  *    notice, this list of conditions and the following disclaimer in the
     50  *    documentation and/or other materials provided with the distribution.
     51  * 3. All advertising materials mentioning features or use of this software
     52  *    must display the following acknowledgement:
     53  *	This product includes software developed by the University of
     54  *	California, Berkeley and its contributors.
     55  * 4. Neither the name of the University nor the names of its contributors
     56  *    may be used to endorse or promote products derived from this software
     57  *    without specific prior written permission.
     58  *
     59  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69  * SUCH DAMAGE.
     70  *
     71  *	@(#)procfs.h	8.9 (Berkeley) 5/14/95
     72  */
     73 
     74 /* This also pulls in __HAVE_PROCFS_MACHDEP */
     75 #include <sys/ptrace.h>
     76 
     77 #ifdef _KERNEL
     78 /*
     79  * The different types of node in a procfs filesystem
     80  */
     81 typedef enum {
     82 	PFSroot,	/* the filesystem root */
     83 	PFScurproc,	/* symbolic link for curproc */
     84 	PFSself,	/* like curproc, but this is the Linux name */
     85 	PFSproc,	/* a process-specific sub-directory */
     86 	PFSfile,	/* the executable file */
     87 	PFSmem,		/* the process's memory image */
     88 	PFSregs,	/* the process's register set */
     89 	PFSfpregs,	/* the process's FP register set */
     90 	PFSctl,		/* process control */
     91 	PFSstat,	/* process status (if -o linux) */
     92 	PFSstatus,	/* process status */
     93 	PFSnote,	/* process notifier */
     94 	PFSnotepg,	/* process group notifier */
     95 	PFSmap,		/* memory map */
     96 	PFScmdline,	/* process command line args */
     97 	PFSmeminfo,	/* system memory info (if -o linux) */
     98 	PFScpuinfo,	/* CPU info (if -o linux) */
     99 	PFSmaps,	/* memory map, Linux style (if -o linux) */
    100 	PFSfd,		/* a directory containing the processes open fd's */
    101 	PFSuptime,	/* elapsed time since (if -o linux) */
    102 #ifdef __HAVE_PROCFS_MACHDEP
    103 	PROCFS_MACHDEP_NODE_TYPES
    104 #endif
    105 } pfstype;
    106 
    107 /*
    108  * control data for the proc file system.
    109  */
    110 struct pfsnode {
    111 	LIST_ENTRY(pfsnode) pfs_hash;	/* hash chain */
    112 	struct vnode	*pfs_vnode;	/* vnode associated with this pfsnode */
    113 	pfstype		pfs_type;	/* type of procfs node */
    114 	pid_t		pfs_pid;	/* associated process */
    115 	int		pfs_fd;		/* associated fd if not -1 */
    116 	mode_t		pfs_mode;	/* mode bits for stat() */
    117 	u_long		pfs_flags;	/* open flags */
    118 	u_long		pfs_fileno;	/* unique file id */
    119 };
    120 
    121 #define PROCFS_NOTELEN	64	/* max length of a note (/proc/$pid/note) */
    122 #define PROCFS_CTLLEN 	8	/* max length of a ctl msg (/proc/$pid/ctl */
    123 
    124 #endif /* _KERNEL */
    125 
    126 struct procfs_args {
    127 	int version;
    128 	int flags;
    129 };
    130 
    131 #define PROCFS_ARGSVERSION	1
    132 
    133 #define PROCFSMNT_LINUXCOMPAT	0x01
    134 
    135 #define PROCFSMNT_BITS "\177\20" \
    136     "b\00linuxcompat\0"
    137 
    138 /*
    139  * Kernel stuff follows
    140  */
    141 #ifdef _KERNEL
    142 #define CNEQ(cnp, s, len) \
    143 	 ((cnp)->cn_namelen == (len) && \
    144 	  (memcmp((s), (cnp)->cn_nameptr, (len)) == 0))
    145 
    146 #define UIO_MX 32
    147 
    148 #define PROCFS_FILENO(pid, type, fd) \
    149     (((type) < PFSproc) ? ((type) + 2) : \
    150 	(((fd) == -1) ? ((((pid)+1) << 5) + ((int) (type))) : \
    151 	((((pid)+1) << 16) | ((fd) << 5) | ((int) (type)))))
    152 
    153 struct procfsmount {
    154 	void *pmnt_exechook;
    155 	int pmnt_flags;
    156 };
    157 
    158 #define VFSTOPROC(mp)	((struct procfsmount *)(mp)->mnt_data)
    159 
    160 /*
    161  * Convert between pfsnode vnode
    162  */
    163 #define VTOPFS(vp)	((struct pfsnode *)(vp)->v_data)
    164 #define PFSTOV(pfs)	((pfs)->pfs_vnode)
    165 
    166 typedef struct vfs_namemap vfs_namemap_t;
    167 struct vfs_namemap {
    168 	const char *nm_name;
    169 	int nm_val;
    170 };
    171 
    172 int vfs_getuserstr __P((struct uio *, char *, int *));
    173 const vfs_namemap_t *vfs_findname __P((const vfs_namemap_t *, const char *, int));
    174 
    175 #define PFIND(pid) ((pid) ? pfind(pid) : &proc0)
    176 int procfs_freevp __P((struct vnode *));
    177 int procfs_allocvp __P((struct mount *, struct vnode **, pid_t, pfstype, int));
    178 int procfs_donote __P((struct lwp *, struct proc *, struct pfsnode *,
    179     struct uio *));
    180 int procfs_doregs __P((struct lwp *, struct lwp *, struct pfsnode *,
    181     struct uio *));
    182 int procfs_dofpregs __P((struct lwp *, struct lwp *, struct pfsnode *,
    183     struct uio *));
    184 int procfs_domem __P((struct lwp *, struct lwp *, struct pfsnode *,
    185     struct uio *));
    186 int procfs_doctl __P((struct lwp *, struct lwp *, struct pfsnode *,
    187     struct uio *));
    188 int procfs_do_pid_stat __P((struct lwp *, struct lwp *, struct pfsnode *,
    189     struct uio *));
    190 int procfs_dostatus __P((struct lwp *, struct lwp *, struct pfsnode *,
    191     struct uio *));
    192 int procfs_domap __P((struct lwp *, struct proc *, struct pfsnode *,
    193     struct uio *, int));
    194 int procfs_docmdline __P((struct lwp *, struct proc *, struct pfsnode *,
    195     struct uio *));
    196 int procfs_domeminfo __P((struct lwp *, struct proc *, struct pfsnode *,
    197     struct uio *));
    198 int procfs_docpuinfo __P((struct lwp *, struct proc *, struct pfsnode *,
    199     struct uio *));
    200 int procfs_dofd __P((struct lwp *, struct proc *, struct pfsnode *,
    201     struct uio *));
    202 int procfs_douptime __P((struct lwp *, struct proc *, struct pfsnode *,
    203     struct uio *));
    204 
    205 void procfs_revoke_vnodes __P((struct lwp *, void *));
    206 void procfs_hashinit __P((void));
    207 void procfs_hashreinit __P((void));
    208 void procfs_hashdone __P((void));
    209 int procfs_getfp __P((struct pfsnode *, struct proc **, struct file **));
    210 
    211 /* functions to check whether or not files should be displayed */
    212 int procfs_validfile __P((struct lwp *, struct mount *));
    213 int procfs_validfpregs __P((struct lwp *, struct mount *));
    214 int procfs_validregs __P((struct lwp *, struct mount *));
    215 int procfs_validmap __P((struct lwp *, struct mount *));
    216 
    217 int procfs_rw __P((void *));
    218 
    219 int procfs_getcpuinfstr __P((char *, int *));
    220 
    221 #define PROCFS_LOCKED	0x01
    222 #define PROCFS_WANT	0x02
    223 
    224 extern int (**procfs_vnodeop_p) __P((void *));
    225 extern struct vfsops procfs_vfsops;
    226 
    227 int	procfs_root __P((struct mount *, struct vnode **, struct lwp *));
    228 
    229 #ifdef __HAVE_PROCFS_MACHDEP
    230 struct vattr;
    231 
    232 void	procfs_machdep_allocvp(struct vnode *);
    233 int	procfs_machdep_rw(struct lwp *, struct lwp *, struct pfsnode *,
    234 	    struct uio *);
    235 int	procfs_machdep_getattr(struct vnode *, struct vattr *, struct proc *);
    236 #endif
    237 
    238 #ifdef SYSCTL_SETUP_PROTO
    239 SYSCTL_SETUP_PROTO(sysctl_vfs_procfs_setup);
    240 #endif /* SYSCTL_SETUP_PROTO */
    241 #endif /* _KERNEL */
    242