]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - lib/libprocstat/libprocstat.h
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / lib / libprocstat / libprocstat.h
1 /*-
2  * Copyright (c) 2009 Stanislav Sedov <stas@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28
29 #ifndef _LIBPROCSTAT_H_
30 #define _LIBPROCSTAT_H_
31
32 /*
33  * Vnode types.
34  */
35 #define PS_FST_VTYPE_VNON       1
36 #define PS_FST_VTYPE_VREG       2
37 #define PS_FST_VTYPE_VDIR       3
38 #define PS_FST_VTYPE_VBLK       4
39 #define PS_FST_VTYPE_VCHR       5
40 #define PS_FST_VTYPE_VLNK       6
41 #define PS_FST_VTYPE_VSOCK      7
42 #define PS_FST_VTYPE_VFIFO      8
43 #define PS_FST_VTYPE_VBAD       9
44 #define PS_FST_VTYPE_UNKNOWN    255
45
46 /*
47  * Descriptor types.
48  */
49 #define PS_FST_TYPE_VNODE       1
50 #define PS_FST_TYPE_FIFO        2
51 #define PS_FST_TYPE_SOCKET      3
52 #define PS_FST_TYPE_PIPE        4
53 #define PS_FST_TYPE_PTS         5
54 #define PS_FST_TYPE_KQUEUE      6
55 #define PS_FST_TYPE_CRYPTO      7
56 #define PS_FST_TYPE_MQUEUE      8
57 #define PS_FST_TYPE_SHM         9
58 #define PS_FST_TYPE_SEM         10
59 #define PS_FST_TYPE_UNKNOWN     11
60 #define PS_FST_TYPE_NONE        12
61
62 /*
63  * Special descriptor numbers.
64  */
65 #define PS_FST_UFLAG_RDIR       0x0001
66 #define PS_FST_UFLAG_CDIR       0x0002
67 #define PS_FST_UFLAG_JAIL       0x0004
68 #define PS_FST_UFLAG_TRACE      0x0008
69 #define PS_FST_UFLAG_TEXT       0x0010
70 #define PS_FST_UFLAG_MMAP       0x0020
71 #define PS_FST_UFLAG_CTTY       0x0040
72
73 /*
74  * Descriptor flags.
75  */
76 #define PS_FST_FFLAG_READ       0x0001
77 #define PS_FST_FFLAG_WRITE      0x0002
78 #define PS_FST_FFLAG_NONBLOCK   0x0004
79 #define PS_FST_FFLAG_APPEND     0x0008
80 #define PS_FST_FFLAG_SHLOCK     0x0010
81 #define PS_FST_FFLAG_EXLOCK     0x0020
82 #define PS_FST_FFLAG_ASYNC      0x0040
83 #define PS_FST_FFLAG_SYNC       0x0080
84 #define PS_FST_FFLAG_NOFOLLOW   0x0100
85 #define PS_FST_FFLAG_CREAT      0x0200
86 #define PS_FST_FFLAG_TRUNC      0x0400
87 #define PS_FST_FFLAG_EXCL       0x0800
88 #define PS_FST_FFLAG_DIRECT     0x1000
89 #define PS_FST_FFLAG_EXEC       0x2000
90 #define PS_FST_FFLAG_HASLOCK    0x4000
91 #define PS_FST_FFLAG_CAPABILITY 0x8000
92
93 struct procstat;
94 struct filestat {
95         int     fs_type;        /* Descriptor type. */
96         int     fs_flags;       /* filestat specific flags. */
97         int     fs_fflags;      /* Descriptor access flags. */
98         int     fs_uflags;      /* How this file is used. */
99         int     fs_fd;          /* File descriptor number. */
100         int     fs_ref_count;   /* Reference count. */
101         off_t   fs_offset;      /* Seek location. */
102         void    *fs_typedep;    /* Type dependent data. */
103         char    *fs_path;
104         STAILQ_ENTRY(filestat)  next;
105         cap_rights_t    fs_cap_rights;  /* Capability rights, if flag set. */
106 };
107 struct vnstat {
108         uint64_t        vn_fileid;
109         uint64_t        vn_size;
110         char            *vn_mntdir;
111         uint32_t        vn_dev;
112         uint32_t        vn_fsid;
113         int             vn_type;
114         uint16_t        vn_mode;
115         char            vn_devname[SPECNAMELEN + 1];
116 };
117 struct ptsstat {
118         uint32_t        dev;
119         char            devname[SPECNAMELEN + 1];
120 };
121 struct pipestat {
122         size_t          buffer_cnt;
123         uint64_t        addr;
124         uint64_t        peer;
125 };
126 struct sockstat {
127         uint64_t        inp_ppcb;
128         uint64_t        so_addr;
129         uint64_t        so_pcb;
130         uint64_t        unp_conn;
131         int             dom_family;
132         int             proto;
133         int             so_rcv_sb_state;
134         int             so_snd_sb_state;
135         struct sockaddr_storage sa_local;       /* Socket address. */
136         struct sockaddr_storage sa_peer;        /* Peer address. */
137         int             type;
138         char            dname[32];
139 };
140
141 STAILQ_HEAD(filestat_list, filestat);
142
143 void    procstat_close(struct procstat *procstat);
144 void    procstat_freeprocs(struct procstat *procstat, struct kinfo_proc *p);
145 void    procstat_freefiles(struct procstat *procstat,
146     struct filestat_list *head);
147 struct filestat_list    *procstat_getfiles(struct procstat *procstat,
148     struct kinfo_proc *kp, int mmapped);
149 struct kinfo_proc       *procstat_getprocs(struct procstat *procstat,
150     int what, int arg, unsigned int *count);
151 int     procstat_get_pipe_info(struct procstat *procstat, struct filestat *fst,
152     struct pipestat *pipe, char *errbuf);
153 int     procstat_get_pts_info(struct procstat *procstat, struct filestat *fst,
154     struct ptsstat *pts, char *errbuf);
155 int     procstat_get_socket_info(struct procstat *procstat, struct filestat *fst,
156     struct sockstat *sock, char *errbuf);
157 int     procstat_get_vnode_info(struct procstat *procstat, struct filestat *fst,
158     struct vnstat *vn, char *errbuf);
159 struct procstat *procstat_open_sysctl(void);
160 struct procstat *procstat_open_kvm(const char *nlistf, const char *memf);
161
162 #endif  /* !_LIBPROCSTAT_H_ */