xref: /freebsd/sys/fs/procfs/procfs.h (revision df8bae1de4b67ccf57f4afebd4e2bf258c38910d)
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  *
37df8bae1dSRodney W. Grimes  *	@(#)procfs.h	8.6 (Berkeley) 2/3/94
38df8bae1dSRodney W. Grimes  *
39df8bae1dSRodney W. Grimes  * From:
40df8bae1dSRodney W. Grimes  *	$Id: procfs.h,v 3.2 1993/12/15 09:40:17 jsp Exp $
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 */
48df8bae1dSRodney W. Grimes 	Pproc,		/* a process-specific sub-directory */
49df8bae1dSRodney W. Grimes 	Pfile,		/* the executable file */
50df8bae1dSRodney W. Grimes 	Pmem,		/* the process's memory image */
51df8bae1dSRodney W. Grimes 	Pregs,		/* the process's register set */
52df8bae1dSRodney W. Grimes 	Pfpregs,	/* the process's FP register set */
53df8bae1dSRodney W. Grimes 	Pctl,		/* process control */
54df8bae1dSRodney W. Grimes 	Pstatus,	/* process status */
55df8bae1dSRodney W. Grimes 	Pnote,		/* process notifier */
56df8bae1dSRodney W. Grimes 	Pnotepg		/* process group notifier */
57df8bae1dSRodney W. Grimes } pfstype;
58df8bae1dSRodney W. Grimes 
59df8bae1dSRodney W. Grimes /*
60df8bae1dSRodney W. Grimes  * control data for the proc file system.
61df8bae1dSRodney W. Grimes  */
62df8bae1dSRodney W. Grimes struct pfsnode {
63df8bae1dSRodney W. Grimes 	struct pfsnode	*pfs_next;	/* next on list */
64df8bae1dSRodney W. Grimes 	struct vnode	*pfs_vnode;	/* vnode associated with this pfsnode */
65df8bae1dSRodney W. Grimes 	pfstype		pfs_type;	/* type of procfs node */
66df8bae1dSRodney W. Grimes 	pid_t		pfs_pid;	/* associated process */
67df8bae1dSRodney W. Grimes 	u_short		pfs_mode;	/* mode bits for stat() */
68df8bae1dSRodney W. Grimes 	u_long		pfs_flags;	/* open flags */
69df8bae1dSRodney W. Grimes 	u_long		pfs_fileno;	/* unique file id */
70df8bae1dSRodney W. Grimes };
71df8bae1dSRodney W. Grimes 
72df8bae1dSRodney W. Grimes #define PROCFS_NOTELEN	64	/* max length of a note (/proc/$pid/note) */
73df8bae1dSRodney W. Grimes #define PROCFS_CTLLEN 	8	/* max length of a ctl msg (/proc/$pid/ctl */
74df8bae1dSRodney W. Grimes 
75df8bae1dSRodney W. Grimes /*
76df8bae1dSRodney W. Grimes  * Kernel stuff follows
77df8bae1dSRodney W. Grimes  */
78df8bae1dSRodney W. Grimes #ifdef KERNEL
79df8bae1dSRodney W. Grimes #define CNEQ(cnp, s, len) \
80df8bae1dSRodney W. Grimes 	 ((cnp)->cn_namelen == (len) && \
81df8bae1dSRodney W. Grimes 	  (bcmp((s), (cnp)->cn_nameptr, (len)) == 0))
82df8bae1dSRodney W. Grimes 
83df8bae1dSRodney W. Grimes /*
84df8bae1dSRodney W. Grimes  * Format of a directory entry in /proc, ...
85df8bae1dSRodney W. Grimes  * This must map onto struct dirent (see <dirent.h>)
86df8bae1dSRodney W. Grimes  */
87df8bae1dSRodney W. Grimes #define PROCFS_NAMELEN 8
88df8bae1dSRodney W. Grimes struct pfsdent {
89df8bae1dSRodney W. Grimes 	u_long	d_fileno;
90df8bae1dSRodney W. Grimes 	u_short	d_reclen;
91df8bae1dSRodney W. Grimes 	u_char	d_type;
92df8bae1dSRodney W. Grimes 	u_char	d_namlen;
93df8bae1dSRodney W. Grimes 	char	d_name[PROCFS_NAMELEN];
94df8bae1dSRodney W. Grimes };
95df8bae1dSRodney W. Grimes #define UIO_MX sizeof(struct pfsdent)
96df8bae1dSRodney W. Grimes #define PROCFS_FILENO(pid, type) \
97df8bae1dSRodney W. Grimes 	(((type) == Proot) ? \
98df8bae1dSRodney W. Grimes 			2 : \
99df8bae1dSRodney W. Grimes 			((((pid)+1) << 3) + ((int) (type))))
100df8bae1dSRodney W. Grimes 
101df8bae1dSRodney W. Grimes /*
102df8bae1dSRodney W. Grimes  * Convert between pfsnode vnode
103df8bae1dSRodney W. Grimes  */
104df8bae1dSRodney W. Grimes #define VTOPFS(vp)	((struct pfsnode *)(vp)->v_data)
105df8bae1dSRodney W. Grimes #define PFSTOV(pfs)	((pfs)->pfs_vnode)
106df8bae1dSRodney W. Grimes 
107df8bae1dSRodney W. Grimes typedef struct vfs_namemap vfs_namemap_t;
108df8bae1dSRodney W. Grimes struct vfs_namemap {
109df8bae1dSRodney W. Grimes 	const char *nm_name;
110df8bae1dSRodney W. Grimes 	int nm_val;
111df8bae1dSRodney W. Grimes };
112df8bae1dSRodney W. Grimes 
113df8bae1dSRodney W. Grimes extern int vfs_getuserstr __P((struct uio *, char *, int *));
114df8bae1dSRodney W. Grimes extern vfs_namemap_t *vfs_findname __P((vfs_namemap_t *, char *, int));
115df8bae1dSRodney W. Grimes 
116df8bae1dSRodney W. Grimes /* <machine/reg.h> */
117df8bae1dSRodney W. Grimes struct reg;
118df8bae1dSRodney W. Grimes struct fpreg;
119df8bae1dSRodney W. Grimes 
120df8bae1dSRodney W. Grimes #define PFIND(pid) ((pid) ? pfind(pid) : &proc0)
121df8bae1dSRodney W. Grimes extern int procfs_freevp __P((struct vnode *));
122df8bae1dSRodney W. Grimes extern int procfs_allocvp __P((struct mount *, struct vnode **, long, pfstype));
123df8bae1dSRodney W. Grimes extern struct vnode *procfs_findtextvp __P((struct proc *));
124df8bae1dSRodney W. Grimes extern int procfs_sstep __P((struct proc *));
125df8bae1dSRodney W. Grimes extern void procfs_fix_sstep __P((struct proc *));
126df8bae1dSRodney W. Grimes extern int procfs_read_regs __P((struct proc *, struct reg *));
127df8bae1dSRodney W. Grimes extern int procfs_write_regs __P((struct proc *, struct reg *));
128df8bae1dSRodney W. Grimes extern int procfs_read_fpregs __P((struct proc *, struct fpreg *));
129df8bae1dSRodney W. Grimes extern int procfs_write_fpregs __P((struct proc *, struct fpreg *));
130df8bae1dSRodney W. Grimes extern int procfs_donote __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
131df8bae1dSRodney W. Grimes extern int procfs_doregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
132df8bae1dSRodney W. Grimes extern int procfs_dofpregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
133df8bae1dSRodney W. Grimes extern int procfs_domem __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
134df8bae1dSRodney W. Grimes extern int procfs_doctl __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
135df8bae1dSRodney W. Grimes extern int procfs_dostatus __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
136df8bae1dSRodney W. Grimes 
137df8bae1dSRodney W. Grimes #define PROCFS_LOCKED	0x01
138df8bae1dSRodney W. Grimes #define PROCFS_WANT	0x02
139df8bae1dSRodney W. Grimes 
140df8bae1dSRodney W. Grimes extern int (**procfs_vnodeop_p)();
141df8bae1dSRodney W. Grimes extern struct vfsops procfs_vfsops;
142df8bae1dSRodney W. Grimes 
143df8bae1dSRodney W. Grimes /*
144df8bae1dSRodney W. Grimes  * Prototypes for procfs vnode ops
145df8bae1dSRodney W. Grimes  */
146df8bae1dSRodney W. Grimes int	procfs_badop();	/* varargs */
147df8bae1dSRodney W. Grimes int	procfs_rw __P((struct vop_read_args *));
148df8bae1dSRodney W. Grimes int	procfs_lookup __P((struct vop_lookup_args *));
149df8bae1dSRodney W. Grimes #define procfs_create ((int (*) __P((struct vop_create_args *))) procfs_badop)
150df8bae1dSRodney W. Grimes #define procfs_mknod ((int (*) __P((struct vop_mknod_args *))) procfs_badop)
151df8bae1dSRodney W. Grimes int	procfs_open __P((struct vop_open_args *));
152df8bae1dSRodney W. Grimes int	procfs_close __P((struct vop_close_args *));
153df8bae1dSRodney W. Grimes int	procfs_access __P((struct vop_access_args *));
154df8bae1dSRodney W. Grimes int	procfs_getattr __P((struct vop_getattr_args *));
155df8bae1dSRodney W. Grimes int	procfs_setattr __P((struct vop_setattr_args *));
156df8bae1dSRodney W. Grimes #define	procfs_read procfs_rw
157df8bae1dSRodney W. Grimes #define	procfs_write procfs_rw
158df8bae1dSRodney W. Grimes int	procfs_ioctl __P((struct vop_ioctl_args *));
159df8bae1dSRodney W. Grimes #define procfs_select ((int (*) __P((struct vop_select_args *))) procfs_badop)
160df8bae1dSRodney W. Grimes #define procfs_mmap ((int (*) __P((struct vop_mmap_args *))) procfs_badop)
161df8bae1dSRodney W. Grimes #define procfs_fsync ((int (*) __P((struct vop_fsync_args *))) procfs_badop)
162df8bae1dSRodney W. Grimes #define procfs_seek ((int (*) __P((struct vop_seek_args *))) procfs_badop)
163df8bae1dSRodney W. Grimes #define procfs_remove ((int (*) __P((struct vop_remove_args *))) procfs_badop)
164df8bae1dSRodney W. Grimes #define procfs_link ((int (*) __P((struct vop_link_args *))) procfs_badop)
165df8bae1dSRodney W. Grimes #define procfs_rename ((int (*) __P((struct vop_rename_args *))) procfs_badop)
166df8bae1dSRodney W. Grimes #define procfs_mkdir ((int (*) __P((struct vop_mkdir_args *))) procfs_badop)
167df8bae1dSRodney W. Grimes #define procfs_rmdir ((int (*) __P((struct vop_rmdir_args *))) procfs_badop)
168df8bae1dSRodney W. Grimes #define procfs_symlink ((int (*) __P((struct vop_symlink_args *))) procfs_badop)
169df8bae1dSRodney W. Grimes int	procfs_readdir __P((struct vop_readdir_args *));
170df8bae1dSRodney W. Grimes #define procfs_readlink ((int (*) __P((struct vop_readlink_args *))) procfs_badop)
171df8bae1dSRodney W. Grimes int	procfs_abortop __P((struct vop_abortop_args *));
172df8bae1dSRodney W. Grimes int	procfs_inactive __P((struct vop_inactive_args *));
173df8bae1dSRodney W. Grimes int	procfs_reclaim __P((struct vop_reclaim_args *));
174df8bae1dSRodney W. Grimes #define procfs_lock ((int (*) __P((struct vop_lock_args *))) nullop)
175df8bae1dSRodney W. Grimes #define procfs_unlock ((int (*) __P((struct vop_unlock_args *))) nullop)
176df8bae1dSRodney W. Grimes int	procfs_bmap __P((struct vop_bmap_args *));
177df8bae1dSRodney W. Grimes #define	procfs_strategy ((int (*) __P((struct vop_strategy_args *))) procfs_badop)
178df8bae1dSRodney W. Grimes int	procfs_print __P((struct vop_print_args *));
179df8bae1dSRodney W. Grimes #define procfs_islocked ((int (*) __P((struct vop_islocked_args *))) nullop)
180df8bae1dSRodney W. Grimes #define procfs_advlock ((int (*) __P((struct vop_advlock_args *))) procfs_badop)
181df8bae1dSRodney W. Grimes #define procfs_blkatoff ((int (*) __P((struct vop_blkatoff_args *))) procfs_badop)
182df8bae1dSRodney W. Grimes #define procfs_valloc ((int (*) __P((struct vop_valloc_args *))) procfs_badop)
183df8bae1dSRodney W. Grimes #define procfs_vfree ((int (*) __P((struct vop_vfree_args *))) nullop)
184df8bae1dSRodney W. Grimes #define procfs_truncate ((int (*) __P((struct vop_truncate_args *))) procfs_badop)
185df8bae1dSRodney W. Grimes #define procfs_update ((int (*) __P((struct vop_update_args *))) nullop)
186df8bae1dSRodney W. Grimes #endif /* KERNEL */
187