Home | History | Annotate | Line # | Download | only in procfs
procfs.h revision 1.1
      1 /*
      2  * Copyright (c) 1993 The Regents of the University of California.
      3  * Copyright (c) 1993 Jan-Simon Pendry
      4  * 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  * From:
     38  *	Id: procfs.h,v 4.1 1993/12/17 10:47:45 jsp Rel
     39  *
     40  *	$Id: procfs.h,v 1.1 1994/01/05 07:51:12 cgd Exp $
     41  */
     42 
     43 /*
     44  * The different types of node in a procfs filesystem
     45  */
     46 typedef enum {
     47 	Proot,		/* the filesystem root */
     48 	Pproc,		/* a process-specific sub-directory */
     49 	Pfile,		/* the executable file */
     50 	Pmem,		/* the process's memory image */
     51 	Pregs,		/* the process's register set */
     52 	Pctl,		/* process control */
     53 	Pstatus,	/* process status */
     54 	Pnote,		/* process notifier */
     55 	Pnotepg		/* process group notifier */
     56 } pfstype;
     57 
     58 /*
     59  * control data for the proc file system.
     60  */
     61 struct pfsnode {
     62 	struct pfsnode	*pfs_next;	/* next on list */
     63 	struct vnode	*pfs_vnode;	/* vnode associated with this pfsnode */
     64 	pfstype		pfs_type;	/* type of procfs node */
     65 	pid_t		pfs_pid;	/* associated process */
     66 	u_short		pfs_mode;	/* mode bits for stat() */
     67 	u_long		pfs_flags;	/* open flags */
     68 	u_long		pfs_fileno;	/* unique file id */
     69 };
     70 
     71 #define PROCFS_NOTELEN	64	/* max length of a note (/proc/$pid/note) */
     72 #define PROCFS_CTLLEN 	8	/* max length of a ctl msg (/proc/$pid/ctl */
     73 
     74 /*
     75  * Kernel stuff follows
     76  */
     77 #ifdef KERNEL
     78 
     79 #ifndef VT_PROCFS
     80 #define VT_PROCFS VT_UFS
     81 #endif
     82 
     83 #define NDEQ(ndp, s, len) \
     84 	 ((ndp)->ni_namelen == (len) && \
     85 	  (bcmp((s), (ndp)->ni_ptr, (len)) == 0))
     86 
     87 /*
     88  * Format of a directory entry in /proc, ...
     89  * This must map onto struct dirent (see <dirent.h>)
     90  */
     91 #define PROCFS_NAMELEN 8
     92 struct pfsdent {
     93 	u_long	d_fileno;
     94 	u_short	d_reclen;
     95 	u_short	d_namlen;
     96 	char	d_name[PROCFS_NAMELEN];
     97 };
     98 #define UIO_MX sizeof(struct pfsdent)
     99 #define PROCFS_FILENO(pid, type) \
    100 	(((type) == Proot) ? \
    101 			2 : \
    102 			((((pid)+1) << 3) + ((int) (type))))
    103 
    104 /*
    105  * Convert between pfsnode vnode
    106  */
    107 #define VTOPFS(vp)	((struct pfsnode *)(vp)->v_data)
    108 #define PFSTOV(pfs)	((pfs)->pfs_vnode)
    109 
    110 typedef struct vfs_namemap vfs_namemap_t;
    111 struct vfs_namemap {
    112 	const char *nm_name;
    113 	int nm_val;
    114 };
    115 
    116 extern int vfs_getuserstr __P((struct uio *, char *, int *));
    117 extern vfs_namemap_t *vfs_findname __P((vfs_namemap_t *, char *, int));
    118 
    119 struct reg;
    120 
    121 #define PFIND(pid) ((pid) ? pfind(pid) : &proc0)
    122 extern int procfs_freevp __P((struct vnode *));
    123 extern int procfs_allocvp __P((struct mount *, struct vnode **, long, pfstype));
    124 extern struct vnode *procfs_findtextvp __P((struct proc *));
    125 extern int procfs_sstep __P((struct proc *));
    126 extern int procfs_read_regs __P((struct proc *, struct reg *));
    127 extern int procfs_write_regs __P((struct proc *, struct reg *));
    128 extern int procfs_donote __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
    129 extern int procfs_doregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
    130 extern int procfs_domem __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
    131 extern int procfs_doctl __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
    132 extern int procfs_dostatus __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
    133 extern int procfs_rw __P((struct vnode *, struct uio *, int, struct ucred *));
    134 
    135 #define PROCFS_LOCKED	0x01
    136 #define PROCFS_WANT	0x02
    137 
    138 extern struct vnodeops procfs_vnodeops;
    139 extern struct vfsops procfs_vfsops;
    140 
    141 /*
    142  * Prototypes for procfs vnode ops
    143  */
    144 int	procfs_badop();	/* varargs */
    145 int	procfs_rw __P((
    146 		struct vnode *vp,
    147 		struct uio *uio,
    148 		int ioflag,
    149 		struct ucred *cred));
    150 int	procfs_lookup __P((
    151 		struct vnode *vp,
    152 		struct nameidata *ndp,
    153 		struct proc *p));
    154 #define procfs_create ((int (*) __P(( \
    155 		struct nameidata *ndp, \
    156 		struct vattr *vap, \
    157 		struct proc *p))) procfs_badop)
    158 #define procfs_mknod ((int (*) __P(( \
    159 		struct nameidata *ndp, \
    160 		struct vattr *vap, \
    161 		struct ucred *cred, \
    162 		struct proc *p))) procfs_badop)
    163 int	procfs_open __P((
    164 		struct vnode *vp,
    165 		int mode,
    166 		struct ucred *cred,
    167 		struct proc *p));
    168 int	procfs_close __P((
    169 		struct vnode *vp,
    170 		int fflag,
    171 		struct ucred *cred,
    172 		struct proc *p));
    173 int	procfs_access __P((
    174 		struct vnode *vp,
    175 		int mode,
    176 		struct ucred *cred,
    177 		struct proc *p));
    178 int	procfs_getattr __P((
    179 		struct vnode *vp,
    180 		struct vattr *vap,
    181 		struct ucred *cred,
    182 		struct proc *p));
    183 int	procfs_setattr __P((
    184 		struct vnode *vp,
    185 		struct vattr *vap,
    186 		struct ucred *cred,
    187 		struct proc *p));
    188 #define	procfs_read procfs_rw
    189 #define	procfs_write procfs_rw
    190 int	procfs_ioctl __P((
    191 		struct vnode *vp,
    192 		int command,
    193 		caddr_t data,
    194 		int fflag,
    195 		struct ucred *cred,
    196 		struct proc *p));
    197 #define procfs_select ((int (*) __P(( \
    198 		struct vnode *vp, \
    199 		int which, \
    200 		int fflags, \
    201 		struct ucred *cred, \
    202 		struct proc *p))) procfs_badop)
    203 #define procfs_mmap ((int (*) __P(( \
    204 		struct vnode *vp, \
    205 		int fflags, \
    206 		struct ucred *cred, \
    207 		struct proc *p))) procfs_badop)
    208 #define procfs_fsync ((int (*) __P(( \
    209 		struct vnode *vp, \
    210 		int fflags, \
    211 		struct ucred *cred, \
    212 		int waitfor, \
    213 		struct proc *p))) procfs_badop)
    214 #define procfs_seek ((int (*) __P(( \
    215 		struct vnode *vp, \
    216 		off_t oldoff, \
    217 		off_t newoff, \
    218 		struct ucred *cred))) procfs_badop)
    219 #define procfs_remove ((int (*) __P(( \
    220 		struct nameidata *ndp, \
    221 		struct proc *p))) procfs_badop)
    222 #define procfs_link ((int (*) __P(( \
    223 		struct vnode *vp, \
    224 		struct nameidata *ndp, \
    225 		struct proc *p))) procfs_badop)
    226 #define procfs_rename ((int (*) __P(( \
    227 		struct nameidata *fndp, \
    228 		struct nameidata *tdnp, \
    229 		struct proc *p))) procfs_badop)
    230 #define procfs_mkdir ((int (*) __P(( \
    231 		struct nameidata *ndp, \
    232 		struct vattr *vap, \
    233 		struct proc *p))) procfs_badop)
    234 #define procfs_rmdir ((int (*) __P(( \
    235 		struct nameidata *ndp, \
    236 		struct proc *p))) procfs_badop)
    237 #define procfs_symlink ((int (*) __P(( \
    238 		struct nameidata *ndp, \
    239 		struct vattr *vap, \
    240 		char *target, \
    241 		struct proc *p))) procfs_badop)
    242 int	procfs_readdir __P((
    243 		struct vnode *vp,
    244 		struct uio *uio,
    245 		struct ucred *cred,
    246 		int *eofflagp,
    247 		u_int *cookies,
    248 		int ncookies));
    249 #define procfs_readlink ((int (*) __P(( \
    250 		struct vnode *vp, \
    251 		struct uio *uio, \
    252 		struct ucred *cred))) procfs_badop)
    253 int	procfs_abortop __P((
    254 		struct nameidata *ndp));
    255 int	procfs_inactive __P((
    256 		struct vnode *vp,
    257 		struct proc *p));
    258 int	procfs_reclaim __P((
    259 		struct vnode *vp));
    260 #define procfs_lock ((int (*) __P(( \
    261 		struct vnode *vp))) nullop)
    262 #define procfs_unlock ((int (*) __P(( \
    263 		struct vnode *vp))) nullop)
    264 int	procfs_bmap __P((
    265 		struct vnode *vp,
    266 		daddr_t bn,
    267 		struct vnode **vpp,
    268 		daddr_t *bnp));
    269 #define	procfs_strategy ((int (*) __P(( \
    270 		struct buf *bp))) procfs_badop)
    271 int	procfs_print __P((
    272 		struct vnode *vp));
    273 #define procfs_islocked ((int (*) __P(( \
    274 		struct vnode *vp))) nullop)
    275 #define procfs_advlock ((int (*) __P(( \
    276 		struct vnode *vp, \
    277 		caddr_t id, \
    278 		int op, \
    279 		struct flock *fl, \
    280 		int flags))) procfs_badop)
    281 
    282 #endif /* KERNEL */
    283