1/*-
2 * SPDX-License-Identifier: BSD-4-Clause
3 *
4 * Copyright (c) 1994 Christopher G. Demetriou
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 *    must display the following acknowledgement:
17 *      This product includes software developed by Christopher G. Demetriou.
18 * 4. The name of the author may not be used to endorse or promote products
19 *    derived from this software without specific prior written permission
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * $FreeBSD: stable/11/usr.sbin/sa/extern.h 330449 2018-03-05 07:26:05Z eadler $
33 */
34
35#include <sys/types.h>
36#include <sys/param.h>
37#include <db.h>
38
39/* structures */
40
41/* All times are stored in 1e-6s units. */
42
43struct cmdinfo {
44	char		ci_comm[MAXCOMLEN+2];	/* command name (+ '*') */
45	uid_t		ci_uid;			/* user id */
46	u_quad_t	ci_calls;		/* number of calls */
47	double		ci_etime;		/* elapsed time */
48	double		ci_utime;		/* user time */
49	double		ci_stime;		/* system time */
50	double		ci_mem;			/* memory use */
51	double		ci_io;			/* number of disk i/o ops */
52	u_int		ci_flags;		/* flags; see below */
53};
54#define	CI_UNPRINTABLE	0x0001			/* unprintable chars in name */
55
56struct userinfo {
57	uid_t		ui_uid;			/* user id; for consistency */
58	u_quad_t	ui_calls;		/* number of invocations */
59	double		ui_utime;		/* user time */
60	double		ui_stime;		/* system time */
61	double		ui_mem;			/* memory use */
62	double		ui_io;			/* number of disk i/o ops */
63};
64
65/* typedefs */
66
67typedef	int (*cmpf_t)(const DBT *, const DBT *);
68
69/* external functions in db.c */
70int db_copy_in(DB **mdb, const char *dbname, const char *name,
71    BTREEINFO *bti, int (*v1_to_v2)(DBT *key, DBT *data));
72int db_copy_out(DB *mdb, const char *dbname, const char *name,
73    BTREEINFO *bti);
74void db_destroy(DB *db, const char *uname);
75
76/* external functions in pdb.c */
77int	pacct_init(void);
78void	pacct_destroy(void);
79int	pacct_add(const struct cmdinfo *);
80int	pacct_update(void);
81void	pacct_print(void);
82
83/* external functions in readrec.c */
84int	readrec_forward(FILE *f, struct acctv2 *av2);
85
86/* external functions in usrdb.c */
87int	usracct_init(void);
88void	usracct_destroy(void);
89int	usracct_add(const struct cmdinfo *);
90int	usracct_update(void);
91void	usracct_print(void);
92
93/* variables */
94
95extern int	aflag, bflag, cflag, dflag, Dflag, fflag, iflag, jflag, kflag;
96extern int	Kflag, lflag, mflag, qflag, rflag, sflag, tflag, uflag, vflag;
97extern u_quad_t	cutoff;
98extern cmpf_t	sa_cmp;
99extern const char *pdb_file, *usrdb_file;
100
101/* some #defines to help with db's stupidity */
102
103#define	DB_CLOSE(db) \
104	((*(db)->close)(db))
105#define	DB_GET(db, key, data, flags) \
106	((*(db)->get)((db), (key), (data), (flags)))
107#define	DB_PUT(db, key, data, flags) \
108	((*(db)->put)((db), (key), (data), (flags)))
109#define	DB_SYNC(db, flags) \
110	((*(db)->sync)((db), (flags)))
111#define	DB_SEQ(db, key, data, flags) \
112	((*(db)->seq)((db), (key), (data), (flags)))
113