libprocstat.h revision 240080
1221807Sstas/*-
2221807Sstas * Copyright (c) 2009 Stanislav Sedov <stas@FreeBSD.org>
3221807Sstas * All rights reserved.
4221807Sstas *
5221807Sstas * Redistribution and use in source and binary forms, with or without
6221807Sstas * modification, are permitted provided that the following conditions
7221807Sstas * are met:
8221807Sstas * 1. Redistributions of source code must retain the above copyright
9221807Sstas *    notice, this list of conditions and the following disclaimer.
10221807Sstas * 2. Redistributions in binary form must reproduce the above copyright
11221807Sstas *    notice, this list of conditions and the following disclaimer in the
12221807Sstas *    documentation and/or other materials provided with the distribution.
13221807Sstas *
14221807Sstas * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
15221807Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16221807Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17221807Sstas * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18221807Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19221807Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20221807Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21221807Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22221807Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23221807Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24221807Sstas * SUCH DAMAGE.
25221807Sstas *
26221807Sstas * $FreeBSD: head/lib/libprocstat/libprocstat.h 240080 2012-09-04 05:51:50Z trociny $
27221807Sstas */
28221807Sstas
29221807Sstas#ifndef _LIBPROCSTAT_H_
30221807Sstas#define	_LIBPROCSTAT_H_
31221807Sstas
32221807Sstas/*
33221807Sstas * Vnode types.
34221807Sstas */
35221807Sstas#define	PS_FST_VTYPE_VNON	1
36221807Sstas#define	PS_FST_VTYPE_VREG	2
37221807Sstas#define	PS_FST_VTYPE_VDIR	3
38221807Sstas#define	PS_FST_VTYPE_VBLK	4
39221807Sstas#define	PS_FST_VTYPE_VCHR	5
40221807Sstas#define	PS_FST_VTYPE_VLNK	6
41221807Sstas#define	PS_FST_VTYPE_VSOCK	7
42221807Sstas#define	PS_FST_VTYPE_VFIFO	8
43221807Sstas#define	PS_FST_VTYPE_VBAD	9
44221807Sstas#define	PS_FST_VTYPE_UNKNOWN	255
45221807Sstas
46221807Sstas/*
47221807Sstas * Descriptor types.
48221807Sstas */
49221807Sstas#define	PS_FST_TYPE_VNODE	1
50221807Sstas#define	PS_FST_TYPE_FIFO	2
51221807Sstas#define	PS_FST_TYPE_SOCKET	3
52221807Sstas#define	PS_FST_TYPE_PIPE	4
53221807Sstas#define	PS_FST_TYPE_PTS		5
54221807Sstas#define	PS_FST_TYPE_KQUEUE	6
55221807Sstas#define	PS_FST_TYPE_CRYPTO	7
56221807Sstas#define	PS_FST_TYPE_MQUEUE	8
57221807Sstas#define	PS_FST_TYPE_SHM		9
58221807Sstas#define	PS_FST_TYPE_SEM		10
59221807Sstas#define	PS_FST_TYPE_UNKNOWN	11
60221807Sstas#define	PS_FST_TYPE_NONE	12
61221807Sstas
62221807Sstas/*
63221807Sstas * Special descriptor numbers.
64221807Sstas */
65221807Sstas#define	PS_FST_UFLAG_RDIR	0x0001
66221807Sstas#define	PS_FST_UFLAG_CDIR	0x0002
67221807Sstas#define	PS_FST_UFLAG_JAIL	0x0004
68221807Sstas#define	PS_FST_UFLAG_TRACE	0x0008
69221807Sstas#define	PS_FST_UFLAG_TEXT	0x0010
70221807Sstas#define	PS_FST_UFLAG_MMAP	0x0020
71221807Sstas#define	PS_FST_UFLAG_CTTY	0x0040
72221807Sstas
73221807Sstas/*
74221807Sstas * Descriptor flags.
75221807Sstas */
76221807Sstas#define PS_FST_FFLAG_READ	0x0001
77221807Sstas#define PS_FST_FFLAG_WRITE	0x0002
78221807Sstas#define	PS_FST_FFLAG_NONBLOCK	0x0004
79221807Sstas#define	PS_FST_FFLAG_APPEND	0x0008
80221807Sstas#define	PS_FST_FFLAG_SHLOCK	0x0010
81221807Sstas#define	PS_FST_FFLAG_EXLOCK	0x0020
82221807Sstas#define	PS_FST_FFLAG_ASYNC	0x0040
83221807Sstas#define	PS_FST_FFLAG_SYNC	0x0080
84221807Sstas#define	PS_FST_FFLAG_NOFOLLOW	0x0100
85221807Sstas#define	PS_FST_FFLAG_CREAT	0x0200
86221807Sstas#define	PS_FST_FFLAG_TRUNC	0x0400
87221807Sstas#define	PS_FST_FFLAG_EXCL	0x0800
88221807Sstas#define	PS_FST_FFLAG_DIRECT	0x1000
89221807Sstas#define	PS_FST_FFLAG_EXEC	0x2000
90221807Sstas#define	PS_FST_FFLAG_HASLOCK	0x4000
91224859Srwatson#define	PS_FST_FFLAG_CAPABILITY	0x8000
92221807Sstas
93221807Sstasstruct procstat;
94221807Sstasstruct filestat {
95221807Sstas	int	fs_type;	/* Descriptor type. */
96221807Sstas	int	fs_flags;	/* filestat specific flags. */
97221807Sstas	int	fs_fflags;	/* Descriptor access flags. */
98221807Sstas	int	fs_uflags;	/* How this file is used. */
99221807Sstas	int	fs_fd;		/* File descriptor number. */
100221807Sstas	int	fs_ref_count;	/* Reference count. */
101221807Sstas	off_t	fs_offset;	/* Seek location. */
102221807Sstas	void	*fs_typedep;	/* Type dependent data. */
103221807Sstas	char	*fs_path;
104221807Sstas	STAILQ_ENTRY(filestat)	next;
105224859Srwatson	cap_rights_t	fs_cap_rights;	/* Capability rights, if flag set. */
106221807Sstas};
107221807Sstasstruct vnstat {
108221807Sstas	uint64_t	vn_fileid;
109221807Sstas	uint64_t	vn_size;
110221807Sstas	char		*vn_mntdir;
111221807Sstas	uint32_t	vn_dev;
112221807Sstas	uint32_t	vn_fsid;
113221807Sstas	int		vn_type;
114221807Sstas	uint16_t	vn_mode;
115221807Sstas	char		vn_devname[SPECNAMELEN + 1];
116221807Sstas};
117221807Sstasstruct ptsstat {
118221807Sstas	uint32_t	dev;
119221807Sstas	char		devname[SPECNAMELEN + 1];
120221807Sstas};
121221807Sstasstruct pipestat {
122221807Sstas	size_t		buffer_cnt;
123221807Sstas	uint64_t	addr;
124221807Sstas	uint64_t	peer;
125221807Sstas};
126233760Sjhbstruct shmstat {
127233760Sjhb	uint64_t	size;
128233760Sjhb	uint16_t	mode;
129233760Sjhb};
130221807Sstasstruct sockstat {
131221807Sstas	uint64_t	inp_ppcb;
132221807Sstas	uint64_t	so_addr;
133221807Sstas	uint64_t	so_pcb;
134221807Sstas	uint64_t	unp_conn;
135221807Sstas	int		dom_family;
136221807Sstas	int		proto;
137221807Sstas	int		so_rcv_sb_state;
138221807Sstas	int		so_snd_sb_state;
139221807Sstas	struct sockaddr_storage	sa_local;	/* Socket address. */
140221807Sstas	struct sockaddr_storage	sa_peer;	/* Peer address. */
141221807Sstas	int		type;
142221807Sstas	char		dname[32];
143221807Sstas};
144221807Sstas
145221807SstasSTAILQ_HEAD(filestat_list, filestat);
146221807Sstas
147240080Strociny__BEGIN_DECLS
148221807Sstasvoid	procstat_close(struct procstat *procstat);
149221807Sstasvoid	procstat_freeprocs(struct procstat *procstat, struct kinfo_proc *p);
150221807Sstasvoid	procstat_freefiles(struct procstat *procstat,
151221807Sstas    struct filestat_list *head);
152221807Sstasstruct filestat_list	*procstat_getfiles(struct procstat *procstat,
153221807Sstas    struct kinfo_proc *kp, int mmapped);
154221807Sstasstruct kinfo_proc	*procstat_getprocs(struct procstat *procstat,
155221807Sstas    int what, int arg, unsigned int *count);
156221807Sstasint	procstat_get_pipe_info(struct procstat *procstat, struct filestat *fst,
157221807Sstas    struct pipestat *pipe, char *errbuf);
158221807Sstasint	procstat_get_pts_info(struct procstat *procstat, struct filestat *fst,
159221807Sstas    struct ptsstat *pts, char *errbuf);
160233760Sjhbint	procstat_get_shm_info(struct procstat *procstat, struct filestat *fst,
161233760Sjhb    struct shmstat *shm, char *errbuf);
162221807Sstasint	procstat_get_socket_info(struct procstat *procstat, struct filestat *fst,
163221807Sstas    struct sockstat *sock, char *errbuf);
164221807Sstasint	procstat_get_vnode_info(struct procstat *procstat, struct filestat *fst,
165221807Sstas    struct vnstat *vn, char *errbuf);
166221807Sstasstruct procstat	*procstat_open_sysctl(void);
167221807Sstasstruct procstat	*procstat_open_kvm(const char *nlistf, const char *memf);
168240080Strociny__END_DECLS
169221807Sstas
170221807Sstas#endif	/* !_LIBPROCSTAT_H_ */
171