1df8bae1dSRodney W. Grimes /* 2df8bae1dSRodney W. Grimes * Copyright (c) 1993 Jan-Simon Pendry 3df8bae1dSRodney W. Grimes * Copyright (c) 1993 4df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 5df8bae1dSRodney W. Grimes * 6df8bae1dSRodney W. Grimes * This code is derived from software contributed to Berkeley by 7df8bae1dSRodney W. Grimes * Jan-Simon Pendry. 8df8bae1dSRodney W. Grimes * 9df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 10df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 11df8bae1dSRodney W. Grimes * are met: 12df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 13df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 14df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 15df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 16df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 17df8bae1dSRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 18df8bae1dSRodney W. Grimes * must display the following acknowledgement: 19df8bae1dSRodney W. Grimes * This product includes software developed by the University of 20df8bae1dSRodney W. Grimes * California, Berkeley and its contributors. 21df8bae1dSRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 22df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 23df8bae1dSRodney W. Grimes * without specific prior written permission. 24df8bae1dSRodney W. Grimes * 25df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 26df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 30df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 31df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 32df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 35df8bae1dSRodney W. Grimes * SUCH DAMAGE. 36df8bae1dSRodney W. Grimes * 37996c772fSJohn Dyson * @(#)procfs.h 8.9 (Berkeley) 5/14/95 38df8bae1dSRodney W. Grimes * 39996c772fSJohn Dyson * From: 401130b656SJordan K. Hubbard * $FreeBSD$ 41df8bae1dSRodney W. Grimes */ 42df8bae1dSRodney W. Grimes 43df8bae1dSRodney W. Grimes /* 44df8bae1dSRodney W. Grimes * The different types of node in a procfs filesystem 45df8bae1dSRodney W. Grimes */ 46df8bae1dSRodney W. Grimes typedef enum { 47df8bae1dSRodney W. Grimes Proot, /* the filesystem root */ 48996c772fSJohn Dyson Pcurproc, /* symbolic link for curproc */ 49df8bae1dSRodney W. Grimes Pproc, /* a process-specific sub-directory */ 50df8bae1dSRodney W. Grimes Pfile, /* the executable file */ 51df8bae1dSRodney W. Grimes Pmem, /* the process's memory image */ 52df8bae1dSRodney W. Grimes Pregs, /* the process's register set */ 53df8bae1dSRodney W. Grimes Pfpregs, /* the process's FP register set */ 54df8bae1dSRodney W. Grimes Pctl, /* process control */ 55df8bae1dSRodney W. Grimes Pstatus, /* process status */ 56df8bae1dSRodney W. Grimes Pnote, /* process notifier */ 579353aaddSJohn Dyson Pnotepg, /* process group notifier */ 586ead3eddSJohn Dyson Pmap, /* memory map */ 596ead3eddSJohn Dyson Ptype /* executable type */ 60df8bae1dSRodney W. Grimes } pfstype; 61df8bae1dSRodney W. Grimes 62df8bae1dSRodney W. Grimes /* 63df8bae1dSRodney W. Grimes * control data for the proc file system. 64df8bae1dSRodney W. Grimes */ 65df8bae1dSRodney W. Grimes struct pfsnode { 66df8bae1dSRodney W. Grimes struct pfsnode *pfs_next; /* next on list */ 67df8bae1dSRodney W. Grimes struct vnode *pfs_vnode; /* vnode associated with this pfsnode */ 68df8bae1dSRodney W. Grimes pfstype pfs_type; /* type of procfs node */ 69df8bae1dSRodney W. Grimes pid_t pfs_pid; /* associated process */ 70df8bae1dSRodney W. Grimes u_short pfs_mode; /* mode bits for stat() */ 71df8bae1dSRodney W. Grimes u_long pfs_flags; /* open flags */ 72df8bae1dSRodney W. Grimes u_long pfs_fileno; /* unique file id */ 73688bbd5bSJohn Dyson pid_t pfs_lockowner; /* pfs lock owner */ 74df8bae1dSRodney W. Grimes }; 75df8bae1dSRodney W. Grimes 76df8bae1dSRodney W. Grimes #define PROCFS_NOTELEN 64 /* max length of a note (/proc/$pid/note) */ 77df8bae1dSRodney W. Grimes #define PROCFS_CTLLEN 8 /* max length of a ctl msg (/proc/$pid/ctl */ 78df8bae1dSRodney W. Grimes 79df8bae1dSRodney W. Grimes /* 80df8bae1dSRodney W. Grimes * Kernel stuff follows 81df8bae1dSRodney W. Grimes */ 82df8bae1dSRodney W. Grimes #ifdef KERNEL 83df8bae1dSRodney W. Grimes #define CNEQ(cnp, s, len) \ 84df8bae1dSRodney W. Grimes ((cnp)->cn_namelen == (len) && \ 85df8bae1dSRodney W. Grimes (bcmp((s), (cnp)->cn_nameptr, (len)) == 0)) 86df8bae1dSRodney W. Grimes 87f62e09f2SDavid Greenman #define KMEM_GROUP 2 88df8bae1dSRodney W. Grimes /* 89df8bae1dSRodney W. Grimes * Format of a directory entry in /proc, ... 90df8bae1dSRodney W. Grimes * This must map onto struct dirent (see <dirent.h>) 91df8bae1dSRodney W. Grimes */ 92df8bae1dSRodney W. Grimes #define PROCFS_NAMELEN 8 93df8bae1dSRodney W. Grimes struct pfsdent { 94df8bae1dSRodney W. Grimes u_long d_fileno; 95df8bae1dSRodney W. Grimes u_short d_reclen; 96df8bae1dSRodney W. Grimes u_char d_type; 97df8bae1dSRodney W. Grimes u_char d_namlen; 98df8bae1dSRodney W. Grimes char d_name[PROCFS_NAMELEN]; 99df8bae1dSRodney W. Grimes }; 100df8bae1dSRodney W. Grimes #define UIO_MX sizeof(struct pfsdent) 101df8bae1dSRodney W. Grimes #define PROCFS_FILENO(pid, type) \ 102996c772fSJohn Dyson (((type) < Pproc) ? \ 103996c772fSJohn Dyson ((type) + 2) : \ 104996c772fSJohn Dyson ((((pid)+1) << 4) + ((int) (type)))) 105df8bae1dSRodney W. Grimes 106df8bae1dSRodney W. Grimes /* 107df8bae1dSRodney W. Grimes * Convert between pfsnode vnode 108df8bae1dSRodney W. Grimes */ 109df8bae1dSRodney W. Grimes #define VTOPFS(vp) ((struct pfsnode *)(vp)->v_data) 110df8bae1dSRodney W. Grimes #define PFSTOV(pfs) ((pfs)->pfs_vnode) 111df8bae1dSRodney W. Grimes 112df8bae1dSRodney W. Grimes typedef struct vfs_namemap vfs_namemap_t; 113df8bae1dSRodney W. Grimes struct vfs_namemap { 114df8bae1dSRodney W. Grimes const char *nm_name; 115df8bae1dSRodney W. Grimes int nm_val; 116df8bae1dSRodney W. Grimes }; 117df8bae1dSRodney W. Grimes 118996c772fSJohn Dyson int vfs_getuserstr __P((struct uio *, char *, int *)); 119996c772fSJohn Dyson vfs_namemap_t *vfs_findname __P((vfs_namemap_t *, char *, int)); 120df8bae1dSRodney W. Grimes 121df8bae1dSRodney W. Grimes /* <machine/reg.h> */ 122df8bae1dSRodney W. Grimes struct reg; 123df8bae1dSRodney W. Grimes struct fpreg; 124df8bae1dSRodney W. Grimes 125df8bae1dSRodney W. Grimes #define PFIND(pid) ((pid) ? pfind(pid) : &proc0) 126996c772fSJohn Dyson int procfs_freevp __P((struct vnode *)); 127996c772fSJohn Dyson int procfs_allocvp __P((struct mount *, struct vnode **, long, pfstype)); 128996c772fSJohn Dyson struct vnode *procfs_findtextvp __P((struct proc *)); 129996c772fSJohn Dyson int procfs_sstep __P((struct proc *)); 130996c772fSJohn Dyson void procfs_fix_sstep __P((struct proc *)); 131996c772fSJohn Dyson int procfs_read_regs __P((struct proc *, struct reg *)); 132996c772fSJohn Dyson int procfs_write_regs __P((struct proc *, struct reg *)); 133996c772fSJohn Dyson int procfs_read_fpregs __P((struct proc *, struct fpreg *)); 134996c772fSJohn Dyson int procfs_write_fpregs __P((struct proc *, struct fpreg *)); 135996c772fSJohn Dyson int procfs_donote __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio)); 136996c772fSJohn Dyson int procfs_doregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio)); 137996c772fSJohn Dyson int procfs_dofpregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio)); 138996c772fSJohn Dyson int procfs_domem __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio)); 139996c772fSJohn Dyson int procfs_doctl __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio)); 140996c772fSJohn Dyson int procfs_dostatus __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio)); 141996c772fSJohn Dyson int procfs_domap __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio)); 142996c772fSJohn Dyson int procfs_dotype __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio)); 143df8bae1dSRodney W. Grimes 144996c772fSJohn Dyson /* functions to check whether or not files should be displayed */ 1450cc75213SPeter Wemm int procfs_validfile __P((struct proc *)); 1460cc75213SPeter Wemm int procfs_validfpregs __P((struct proc *)); 1470cc75213SPeter Wemm int procfs_validregs __P((struct proc *)); 1486ead3eddSJohn Dyson int procfs_validmap __P((struct proc *)); 1496ead3eddSJohn Dyson int procfs_validtype __P((struct proc *)); 1500cc75213SPeter Wemm 151df8bae1dSRodney W. Grimes #define PROCFS_LOCKED 0x01 152df8bae1dSRodney W. Grimes #define PROCFS_WANT 0x02 153df8bae1dSRodney W. Grimes 154f57e6547SBruce Evans extern vop_t **procfs_vnodeop_p; 155df8bae1dSRodney W. Grimes extern struct vfsops procfs_vfsops; 156df8bae1dSRodney W. Grimes 157b5e8ce9fSBruce Evans int procfs_root __P((struct mount *, struct vnode **)); 158df8bae1dSRodney W. Grimes int procfs_rw __P((struct vop_read_args *)); 159df8bae1dSRodney W. Grimes #endif /* KERNEL */ 160