/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Simon Burge.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
if (w == NULL)
return;
wclear(w);
wrefresh(w);
delwin(w);
ml_init(); /* Clear out mount list */
}
void
labelbufcache(void)
{
int i;
for (i = 0; i <= PAGEINFO_ROWS; i++) {
wmove(wnd, i, 0);
wclrtoeol(wnd);
}
mvwaddstr(wnd, PAGEINFO_ROWS + 1, 0,
"File System Bufs used % kB in use % Bufsize kB % Util %");
wclrtoeol(wnd);
}
void
showbufcache(void)
{
int tbuf, i, lastrow;
double tvalid, tsize;
struct ml_entry *ml;
size_t len;
static int mib[] = { -1, 0 };
if (mib[0] == -1) {
len = __arraycount(mib);
if (sysctlnametomib("vm.bufmem", mib, &len) == -1)
error("can't get \"vm.bufmem\" mib: %s",
strerror(errno));
}
len = sizeof(bufmem);
if (sysctl(mib, 2, &bufmem, &len, NULL, 0) == -1)
error("can't get \"vm.bufmem\": %s", strerror(errno));
ret = NULL;
oldest = 0;
for (i = 0; i < VCACHE_SIZE; i++) {
if (vcache[i].vc_addr == NULL)
break;
vcache[i].vc_age++;
if (vcache[i].vc_age < vcache[oldest].vc_age)
oldest = i;
if (vcache[i].vc_addr == vaddr) {
vcache[i].vc_age = 0;
ret = &vcache[i].vc_node;
}
}
/* Find an entry in the cache? */
if (ret != NULL)
return(ret);
/* Go past the end of the cache? */
if (i >= VCACHE_SIZE)
i = oldest;
/* Read in new vnode and reset age counter. */
if (KREAD(vaddr, &vcache[i].vc_node, sizeof(struct vnode)) == 0)
return NULL;
vcache[i].vc_addr = vaddr;
vcache[i].vc_age = 0;
return(&vcache[i].vc_node);
}
static struct mount *
ml_lookup(struct mount *maddr, int size, int valid)
{
struct ml_entry *ml;
for (ml = LIST_FIRST(&mount_list); ml != NULL;
ml = LIST_NEXT(ml, ml_entries))
if (ml->ml_addr == maddr) {
ml->ml_count++;
ml->ml_size += size;
ml->ml_valid += valid;
if (ml->ml_addr == NULL)
return(NULL);
else
return(&ml->ml_mount);
}