Home | History | Annotate | Line # | Download | only in procfs
procfs.h revision 1.29.4.1
      1 /*	$NetBSD: procfs.h,v 1.29.4.1 2001/03/30 21:47:21 he Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1993 Jan-Simon Pendry
      5  * Copyright (c) 1993
      6  *	The Regents of the University of California.  All rights reserved.
      7  *
      8  * This code is derived from software contributed to Berkeley by
      9  * Jan-Simon Pendry.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the University of
     22  *	California, Berkeley and its contributors.
     23  * 4. Neither the name of the University nor the names of its contributors
     24  *    may be used to endorse or promote products derived from this software
     25  *    without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     37  * SUCH DAMAGE.
     38  *
     39  *	@(#)procfs.h	8.9 (Berkeley) 5/14/95
     40  */
     41 
     42 /*
     43  * The different types of node in a procfs filesystem
     44  */
     45 typedef enum {
     46 	Proot,		/* the filesystem root */
     47 	Pcurproc,	/* symbolic link for curproc */
     48 	Pself,		/* like curproc, but this is the Linux name */
     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 	Pctl,		/* process control */
     55 	Pstatus,	/* process status */
     56 	Pnote,		/* process notifier */
     57 	Pnotepg,	/* process group notifier */
     58 	Pmap,		/* memory map */
     59 	Pcmdline,	/* process command line args */
     60 	Pmeminfo,	/* system memory info (if -o linux) */
     61 	Pcpuinfo	/* CPU info (if -o linux) */
     62 } pfstype;
     63 
     64 /*
     65  * control data for the proc file system.
     66  */
     67 struct pfsnode {
     68 	LIST_ENTRY(pfsnode) pfs_hash;	/* hash chain */
     69 	struct vnode	*pfs_vnode;	/* vnode associated with this pfsnode */
     70 	pfstype		pfs_type;	/* type of procfs node */
     71 	pid_t		pfs_pid;	/* associated process */
     72 	mode_t		pfs_mode;	/* mode bits for stat() */
     73 	u_long		pfs_flags;	/* open flags */
     74 	u_long		pfs_fileno;	/* unique file id */
     75 };
     76 
     77 #define PROCFS_NOTELEN	64	/* max length of a note (/proc/$pid/note) */
     78 #define PROCFS_CTLLEN 	8	/* max length of a ctl msg (/proc/$pid/ctl */
     79 
     80 struct procfs_args {
     81 	int version;
     82 	int flags;
     83 };
     84 
     85 #define PROCFS_ARGSVERSION	1
     86 
     87 #define PROCFSMNT_LINUXCOMPAT	0x01
     88 
     89 /*
     90  * Kernel stuff follows
     91  */
     92 #ifdef _KERNEL
     93 #define CNEQ(cnp, s, len) \
     94 	 ((cnp)->cn_namelen == (len) && \
     95 	  (memcmp((s), (cnp)->cn_nameptr, (len)) == 0))
     96 
     97 #define UIO_MX 32
     98 
     99 #define PROCFS_FILENO(pid, type) \
    100 	(((type) < Pproc) ? \
    101 			((type) + 2) : \
    102 			((((pid)+1) << 4) + ((int) (type))))
    103 
    104 struct procfsmount {
    105 	void *pmnt_exechook;
    106 	struct mount *pmnt_mp;
    107 	int pmnt_flags;
    108 };
    109 
    110 #define VFSTOPROC(mp)	((struct procfsmount *)(mp)->mnt_data)
    111 #define PROCTOVFS(pp)	((pp)->pmnt_mp)
    112 
    113 /*
    114  * Convert between pfsnode vnode
    115  */
    116 #define VTOPFS(vp)	((struct pfsnode *)(vp)->v_data)
    117 #define PFSTOV(pfs)	((pfs)->pfs_vnode)
    118 
    119 typedef struct vfs_namemap vfs_namemap_t;
    120 struct vfs_namemap {
    121 	const char *nm_name;
    122 	int nm_val;
    123 };
    124 
    125 int vfs_getuserstr __P((struct uio *, char *, int *));
    126 vfs_namemap_t *vfs_findname __P((vfs_namemap_t *, char *, int));
    127 
    128 #define PFIND(pid) ((pid) ? pfind(pid) : &proc0)
    129 int procfs_freevp __P((struct vnode *));
    130 int procfs_allocvp __P((struct mount *, struct vnode **, long, pfstype));
    131 struct vnode *procfs_findtextvp __P((struct proc *));
    132 int procfs_donote __P((struct proc *, struct proc *, struct pfsnode *,
    133     struct uio *));
    134 int procfs_doregs __P((struct proc *, struct proc *, struct pfsnode *,
    135     struct uio *));
    136 int procfs_dofpregs __P((struct proc *, struct proc *, struct pfsnode *,
    137     struct uio *));
    138 int procfs_domem __P((struct proc *, struct proc *, struct pfsnode *,
    139     struct uio *));
    140 int procfs_doctl __P((struct proc *, struct proc *, struct pfsnode *,
    141     struct uio *));
    142 int procfs_dostatus __P((struct proc *, struct proc *, struct pfsnode *,
    143     struct uio *));
    144 int procfs_domap __P((struct proc *, struct proc *, struct pfsnode *,
    145     struct uio *));
    146 int procfs_docmdline __P((struct proc *, struct proc *, struct pfsnode *,
    147     struct uio *));
    148 int procfs_domeminfo __P((struct proc *, struct proc *, struct pfsnode *,
    149     struct uio *));
    150 int procfs_docpuinfo __P((struct proc *, struct proc *, struct pfsnode *,
    151     struct uio *));
    152 
    153 int procfs_checkioperm __P((struct proc *, struct proc *));
    154 void procfs_revoke_vnodes __P((struct proc *, void *));
    155 void procfs_hashinit __P((void));
    156 void procfs_hashdone __P((void));
    157 
    158 /* functions to check whether or not files should be displayed */
    159 int procfs_validfile __P((struct proc *, struct mount *));
    160 int procfs_validfpregs __P((struct proc *, struct mount *));
    161 int procfs_validregs __P((struct proc *, struct mount *));
    162 int procfs_validmap __P((struct proc *, struct mount *));
    163 
    164 int procfs_rw __P((void *));
    165 
    166 int procfs_getcpuinfstr __P((char *, int *));
    167 
    168 #define PROCFS_LOCKED	0x01
    169 #define PROCFS_WANT	0x02
    170 
    171 extern int (**procfs_vnodeop_p) __P((void *));
    172 extern struct vfsops procfs_vfsops;
    173 
    174 int	procfs_root __P((struct mount *, struct vnode **));
    175 
    176 #endif /* _KERNEL */
    177