1*65791Smckusick /*-
2*65791Smckusick  * Copyright (c) 1982, 1986, 1989, 1993
3*65791Smckusick  *	The Regents of the University of California.  All rights reserved.
4*65791Smckusick  * (c) UNIX System Laboratories, Inc.
5*65791Smckusick  * All or some portions of this file are derived from material licensed
6*65791Smckusick  * to the University of California by American Telephone and Telegraph
7*65791Smckusick  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8*65791Smckusick  * the permission of UNIX System Laboratories, Inc.
949676Smckusick  *
1049676Smckusick  * %sccs.include.redist.c%
1149676Smckusick  *
12*65791Smckusick  *	from: @(#)kern_acct.c	8.1 (Berkeley) 6/14/93
1349676Smckusick  */
1449676Smckusick 
15*65791Smckusick #include <sys/param.h>
16*65791Smckusick #include <sys/proc.h>
17*65791Smckusick #include <sys/mount.h>
18*65791Smckusick #include <sys/vnode.h>
19*65791Smckusick #include <sys/file.h>
20*65791Smckusick #include <sys/syslog.h>
21*65791Smckusick #include <sys/kernel.h>
2249676Smckusick 
23*65791Smckusick struct acct_args {
24*65791Smckusick 	char	*fname;
25*65791Smckusick };
26*65791Smckusick acct(a1, a2, a3)
27*65791Smckusick 	struct proc *a1;
28*65791Smckusick 	struct acct_args *a2;
29*65791Smckusick 	int *a3;
30*65791Smckusick {
31*65791Smckusick 	/*
32*65791Smckusick 	 * Body deleted.
33*65791Smckusick 	 */
34*65791Smckusick 	return (ENOSYS);
35*65791Smckusick }
3649676Smckusick 
37*65791Smckusick acct_process(a1)
38*65791Smckusick 	struct proc *a1;
3949676Smckusick {
4049676Smckusick 
4149676Smckusick 	/*
4249676Smckusick 	 * Body deleted.
4349676Smckusick 	 */
44*65791Smckusick 	return;
4549676Smckusick }
4649676Smckusick 
4749676Smckusick /*
4849676Smckusick  * Periodically check the file system to see if accounting
4949676Smckusick  * should be turned on or off.
5049676Smckusick  */
51*65791Smckusick 
52*65791Smckusick /*
53*65791Smckusick  * Values associated with enabling and disabling accounting
54*65791Smckusick  */
55*65791Smckusick int	acctsuspend = 2;	/* stop accounting when < 2% free space left */
56*65791Smckusick int	acctresume = 4;		/* resume when free space risen to > 4% */
57*65791Smckusick int	acctchkfreq = 15;	/* frequency (in seconds) to check space */
58*65791Smckusick 
59*65791Smckusick /*
60*65791Smckusick  * SHOULD REPLACE THIS WITH A DRIVER THAT CAN BE READ TO SIMPLIFY.
61*65791Smckusick  */
62*65791Smckusick struct	vnode *acctp;
63*65791Smckusick struct	vnode *savacctp;
64*65791Smckusick 
65*65791Smckusick /* ARGSUSED */
66*65791Smckusick void
67*65791Smckusick acctwatch(a)
68*65791Smckusick 	void *a;
6949676Smckusick {
7049676Smckusick 	struct statfs sb;
7149676Smckusick 
7249676Smckusick 	if (savacctp) {
7349676Smckusick 		(void)VFS_STATFS(savacctp->v_mount, &sb, (struct proc *)0);
7449676Smckusick 		if (sb.f_bavail > acctresume * sb.f_blocks / 100) {
7549676Smckusick 			acctp = savacctp;
7649676Smckusick 			savacctp = NULL;
7749676Smckusick 			log(LOG_NOTICE, "Accounting resumed\n");
78*65791Smckusick 		}
79*65791Smckusick 	} else {
80*65791Smckusick 		if (acctp == NULL)
8149676Smckusick 			return;
82*65791Smckusick 		(void)VFS_STATFS(acctp->v_mount, &sb, (struct proc *)0);
83*65791Smckusick 		if (sb.f_bavail <= acctsuspend * sb.f_blocks / 100) {
84*65791Smckusick 			savacctp = acctp;
85*65791Smckusick 			acctp = NULL;
86*65791Smckusick 			log(LOG_NOTICE, "Accounting suspended\n");
8749676Smckusick 		}
8849676Smckusick 	}
89*65791Smckusick 	timeout(acctwatch, NULL, acctchkfreq * hz);
9049676Smckusick }
91