2004-02-22 15:30:11 +03:00
|
|
|
/* $NetBSD: pstat.c,v 1.86 2004/02/22 12:30:11 jdc Exp $ */
|
1996-01-11 09:33:32 +03:00
|
|
|
|
1994-05-14 01:29:29 +04:00
|
|
|
/*-
|
1997-10-17 10:34:19 +04:00
|
|
|
* Copyright (c) 1980, 1991, 1993, 1994
|
1994-05-14 01:29:29 +04:00
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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.
|
2003-08-07 15:25:11 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-14 01:29:29 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
|
|
|
*/
|
|
|
|
|
1997-10-17 16:16:54 +04:00
|
|
|
#include <sys/cdefs.h>
|
1994-05-14 01:29:29 +04:00
|
|
|
#ifndef lint
|
1997-10-17 16:16:54 +04:00
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1980, 1991, 1993, 1994\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n");
|
1994-05-14 01:29:29 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1996-01-11 09:33:32 +03:00
|
|
|
#if 0
|
1997-10-17 10:34:19 +04:00
|
|
|
static char sccsid[] = "@(#)pstat.c 8.16 (Berkeley) 5/9/95";
|
1996-01-11 09:33:32 +03:00
|
|
|
#else
|
2004-02-22 15:30:11 +03:00
|
|
|
__RCSID("$NetBSD: pstat.c,v 1.86 2004/02/22 12:30:11 jdc Exp $");
|
1996-01-11 09:33:32 +03:00
|
|
|
#endif
|
1994-05-14 01:29:29 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/ucred.h>
|
1995-03-28 21:18:59 +04:00
|
|
|
#define _KERNEL
|
1994-05-14 01:29:29 +04:00
|
|
|
#include <sys/file.h>
|
|
|
|
#include <ufs/ufs/inode.h>
|
|
|
|
#define NFS
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#undef NFS
|
1997-10-17 10:34:19 +04:00
|
|
|
#include <sys/uio.h>
|
|
|
|
#include <sys/namei.h>
|
2000-12-13 08:50:33 +03:00
|
|
|
#include <miscfs/genfs/layer.h>
|
1997-10-17 10:34:19 +04:00
|
|
|
#include <miscfs/union/union.h>
|
1995-03-28 21:18:59 +04:00
|
|
|
#undef _KERNEL
|
1994-05-14 01:29:29 +04:00
|
|
|
#include <sys/stat.h>
|
1996-02-21 05:27:57 +03:00
|
|
|
#include <nfs/nfsproto.h>
|
|
|
|
#include <nfs/rpcv2.h>
|
1997-10-17 10:34:19 +04:00
|
|
|
#include <nfs/nfs.h>
|
1994-05-14 01:29:29 +04:00
|
|
|
#include <nfs/nfsnode.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
#include <sys/conf.h>
|
1994-05-16 10:44:00 +04:00
|
|
|
#include <sys/device.h>
|
1994-05-14 01:29:29 +04:00
|
|
|
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <kvm.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <nlist.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
1997-06-12 19:03:43 +04:00
|
|
|
#include "swapctl.h"
|
|
|
|
|
1994-05-14 01:29:29 +04:00
|
|
|
struct nlist nl[] = {
|
1997-06-12 19:03:43 +04:00
|
|
|
#define V_MOUNTLIST 0
|
1994-05-14 01:29:29 +04:00
|
|
|
{ "_mountlist" }, /* address of head of mount list. */
|
1999-11-18 11:27:39 +03:00
|
|
|
#define V_NUMV 1
|
1994-05-14 01:29:29 +04:00
|
|
|
{ "_numvnodes" },
|
1997-06-12 19:03:43 +04:00
|
|
|
#define FNL_NFILE 2
|
1999-11-18 11:27:39 +03:00
|
|
|
{ "_nfiles" },
|
1997-06-12 19:03:43 +04:00
|
|
|
#define FNL_MAXFILE 3
|
1999-11-18 11:27:39 +03:00
|
|
|
{ "_maxfiles" },
|
1997-06-12 19:03:43 +04:00
|
|
|
#define TTY_NTTY 4
|
1999-11-18 11:27:39 +03:00
|
|
|
{ "_tty_count" },
|
1997-06-12 19:03:43 +04:00
|
|
|
#define TTY_TTYLIST 5
|
1999-11-18 11:27:39 +03:00
|
|
|
{ "_ttylist" },
|
1996-05-30 09:45:45 +04:00
|
|
|
#define NLMANDATORY TTY_TTYLIST /* names up to here are mandatory */
|
1994-05-14 01:29:29 +04:00
|
|
|
{ "" }
|
|
|
|
};
|
|
|
|
|
|
|
|
int usenumflag;
|
|
|
|
int totalflag;
|
1995-01-15 10:08:55 +03:00
|
|
|
int kflag;
|
2003-12-20 14:22:25 +03:00
|
|
|
int hflag;
|
1994-05-14 01:29:29 +04:00
|
|
|
char *nlistf = NULL;
|
|
|
|
char *memf = NULL;
|
|
|
|
kvm_t *kd;
|
|
|
|
|
2002-11-06 12:32:26 +03:00
|
|
|
static const struct {
|
2002-02-23 04:06:41 +03:00
|
|
|
u_int m_flag;
|
2002-12-12 01:19:58 +03:00
|
|
|
u_int m_visible;
|
1997-10-17 10:34:19 +04:00
|
|
|
const char *m_name;
|
|
|
|
} mnt_flags[] = {
|
2002-12-12 01:19:58 +03:00
|
|
|
__MNT_FLAGS
|
1997-10-17 10:34:19 +04:00
|
|
|
};
|
|
|
|
|
2002-02-23 04:06:41 +03:00
|
|
|
struct flagbit_desc {
|
|
|
|
u_int fd_flags;
|
|
|
|
char fd_mark;
|
|
|
|
};
|
|
|
|
|
1994-05-14 01:29:29 +04:00
|
|
|
#define SVAR(var) __STRING(var) /* to force expansion */
|
|
|
|
#define KGET(idx, var) \
|
|
|
|
KGET1(idx, &var, sizeof(var), SVAR(var))
|
|
|
|
#define KGET1(idx, p, s, msg) \
|
|
|
|
KGET2(nl[idx].n_value, p, s, msg)
|
2001-02-11 05:44:27 +03:00
|
|
|
#define KGET2(addr, p, s, msg) do { \
|
1994-05-14 01:29:29 +04:00
|
|
|
if (kvm_read(kd, (u_long)(addr), p, s) != s) \
|
2001-02-11 05:44:27 +03:00
|
|
|
warnx("cannot read %s: %s", msg, kvm_geterr(kd)); \
|
|
|
|
} while (/* CONSTCOND */0)
|
|
|
|
#define KGETRET(addr, p, s, msg) do { \
|
1994-05-14 01:29:29 +04:00
|
|
|
if (kvm_read(kd, (u_long)(addr), p, s) != s) { \
|
|
|
|
warnx("cannot read %s: %s", msg, kvm_geterr(kd)); \
|
|
|
|
return (0); \
|
2001-02-11 05:44:27 +03:00
|
|
|
} \
|
|
|
|
} while (/* CONSTCOND */0)
|
1994-05-14 01:29:29 +04:00
|
|
|
|
2002-02-22 07:58:39 +03:00
|
|
|
#if 1 /* This is copied from vmstat/vmstat.c */
|
|
|
|
/*
|
|
|
|
* Print single word. `ovflow' is number of characters didn't fit
|
|
|
|
* on the last word. `fmt' is a format string to print this word.
|
|
|
|
* It must contain asterisk for field width. `width' is a width
|
|
|
|
* occupied by this word. `fixed' is a number of constant chars in
|
|
|
|
* `fmt'. `val' is a value to be printed using format string `fmt'.
|
|
|
|
*/
|
|
|
|
#define PRWORD(ovflw, fmt, width, fixed, val) do { \
|
|
|
|
(ovflw) += printf((fmt), \
|
|
|
|
(width) - (fixed) - (ovflw) > 0 ? \
|
|
|
|
(width) - (fixed) - (ovflw) : 0, \
|
|
|
|
(val)) - (width); \
|
|
|
|
if ((ovflw) < 0) \
|
|
|
|
(ovflw) = 0; \
|
|
|
|
} while (/* CONSTCOND */0)
|
|
|
|
#endif
|
|
|
|
|
1994-05-14 01:29:29 +04:00
|
|
|
void filemode __P((void));
|
2004-02-22 15:30:11 +03:00
|
|
|
int getfiles __P((char **, int *, char **));
|
2002-02-23 04:06:41 +03:00
|
|
|
int getflags __P((const struct flagbit_desc *, char *, u_int));
|
1994-05-14 01:29:29 +04:00
|
|
|
struct mount *
|
|
|
|
getmnt __P((struct mount *));
|
2003-02-11 03:45:02 +03:00
|
|
|
char * kinfo_vnodes __P((int *));
|
2000-12-13 08:50:33 +03:00
|
|
|
void layer_header __P((void));
|
2002-02-22 07:58:39 +03:00
|
|
|
int layer_print __P((struct vnode *, int));
|
2003-02-11 03:45:02 +03:00
|
|
|
char * loadvnodes __P((int *));
|
1997-10-17 16:16:54 +04:00
|
|
|
int main __P((int, char **));
|
1994-05-14 01:29:29 +04:00
|
|
|
void mount_print __P((struct mount *));
|
|
|
|
void nfs_header __P((void));
|
2002-02-22 07:58:39 +03:00
|
|
|
int nfs_print __P((struct vnode *, int));
|
1994-05-14 01:29:29 +04:00
|
|
|
void ttymode __P((void));
|
1996-05-30 09:45:45 +04:00
|
|
|
void ttyprt __P((struct tty *));
|
1994-05-14 01:29:29 +04:00
|
|
|
void ufs_header __P((void));
|
2002-02-22 07:58:39 +03:00
|
|
|
int ufs_print __P((struct vnode *, int));
|
|
|
|
int ext2fs_print __P((struct vnode *, int));
|
1997-10-17 10:34:19 +04:00
|
|
|
void union_header __P((void));
|
2002-02-22 07:58:39 +03:00
|
|
|
int union_print __P((struct vnode *, int));
|
1994-05-14 01:29:29 +04:00
|
|
|
void usage __P((void));
|
|
|
|
void vnode_header __P((void));
|
2002-02-22 07:58:39 +03:00
|
|
|
int vnode_print __P((struct vnode *, struct vnode *));
|
1994-05-14 01:29:29 +04:00
|
|
|
void vnodemode __P((void));
|
|
|
|
|
|
|
|
int
|
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char *argv[];
|
|
|
|
{
|
|
|
|
int ch, i, quit, ret;
|
|
|
|
int fileflag, swapflag, ttyflag, vnodeflag;
|
1999-01-31 13:12:33 +03:00
|
|
|
gid_t egid = getegid();
|
1994-05-14 01:29:29 +04:00
|
|
|
char buf[_POSIX2_LINE_MAX];
|
|
|
|
|
1999-01-31 13:12:33 +03:00
|
|
|
setegid(getgid());
|
1994-05-14 01:29:29 +04:00
|
|
|
fileflag = swapflag = ttyflag = vnodeflag = 0;
|
2003-12-20 16:31:42 +03:00
|
|
|
while ((ch = getopt(argc, argv, "TM:N:fghikmnstv")) != -1)
|
1994-05-14 01:29:29 +04:00
|
|
|
switch (ch) {
|
|
|
|
case 'f':
|
|
|
|
fileflag = 1;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
memf = optarg;
|
|
|
|
break;
|
|
|
|
case 'N':
|
|
|
|
nlistf = optarg;
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
usenumflag = 1;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
swapflag = 1;
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
totalflag = 1;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
ttyflag = 1;
|
|
|
|
break;
|
1995-01-15 10:08:55 +03:00
|
|
|
case 'k':
|
|
|
|
kflag = 1;
|
|
|
|
break;
|
2003-12-20 16:31:42 +03:00
|
|
|
case 'g':
|
|
|
|
kflag = 3; /* 1k ^ 3 */
|
|
|
|
break;
|
2003-12-20 14:22:25 +03:00
|
|
|
case 'h':
|
|
|
|
hflag = 1;
|
|
|
|
break;
|
2003-12-20 16:31:42 +03:00
|
|
|
case 'm':
|
|
|
|
kflag = 2; /* 1k ^ 2 */
|
|
|
|
break;
|
1994-05-14 01:29:29 +04:00
|
|
|
case 'v':
|
|
|
|
case 'i': /* Backward compatibility. */
|
|
|
|
vnodeflag = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
/*
|
1999-01-31 13:12:33 +03:00
|
|
|
* Discard setgid privileges. If not the running kernel, we toss
|
|
|
|
* them away totally so that bad guys can't print interesting stuff
|
|
|
|
* from kernel memory, otherwise switch back to kmem for the
|
|
|
|
* duration of the kvm_openfiles() call.
|
1994-05-14 01:29:29 +04:00
|
|
|
*/
|
|
|
|
if (nlistf != NULL || memf != NULL)
|
|
|
|
(void)setgid(getgid());
|
1999-01-31 13:12:33 +03:00
|
|
|
else
|
|
|
|
(void)setegid(egid);
|
1994-05-14 01:29:29 +04:00
|
|
|
|
|
|
|
if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf)) == 0)
|
|
|
|
errx(1, "kvm_openfiles: %s", buf);
|
1999-01-31 13:12:33 +03:00
|
|
|
|
|
|
|
/* get rid of it now anyway */
|
|
|
|
if (nlistf == NULL && memf == NULL)
|
|
|
|
(void)setgid(getgid());
|
1994-05-14 01:29:29 +04:00
|
|
|
if ((ret = kvm_nlist(kd, nl)) != 0) {
|
|
|
|
if (ret == -1)
|
|
|
|
errx(1, "kvm_nlist: %s", kvm_geterr(kd));
|
|
|
|
for (i = quit = 0; i <= NLMANDATORY; i++)
|
|
|
|
if (!nl[i].n_value) {
|
|
|
|
quit = 1;
|
1996-06-03 22:50:26 +04:00
|
|
|
warnx("undefined symbol: %s", nl[i].n_name);
|
1994-05-14 01:29:29 +04:00
|
|
|
}
|
|
|
|
if (quit)
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!(fileflag | vnodeflag | ttyflag | swapflag | totalflag))
|
|
|
|
usage();
|
|
|
|
if (fileflag || totalflag)
|
|
|
|
filemode();
|
|
|
|
if (vnodeflag || totalflag)
|
|
|
|
vnodemode();
|
|
|
|
if (ttyflag)
|
|
|
|
ttymode();
|
|
|
|
if (swapflag || totalflag)
|
2003-12-20 14:22:25 +03:00
|
|
|
list_swap(0, kflag, 0, totalflag, 1, hflag);
|
2002-02-23 04:06:41 +03:00
|
|
|
exit(0);
|
1994-05-14 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
2001-02-11 06:01:05 +03:00
|
|
|
#define VPTRSZ sizeof(struct vnode *)
|
|
|
|
#define VNODESZ sizeof(struct vnode)
|
2002-02-23 04:06:41 +03:00
|
|
|
#define PTRSTRWIDTH ((int)sizeof(void *) * 2) /* Width of resulting string
|
|
|
|
when pointer is printed
|
|
|
|
in hexadecimal. */
|
1994-05-14 01:29:29 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
vnodemode()
|
|
|
|
{
|
2001-02-11 06:01:05 +03:00
|
|
|
char *e_vnodebase, *endvnode, *evp;
|
1997-10-17 10:34:19 +04:00
|
|
|
struct vnode *vp;
|
|
|
|
struct mount *maddr, *mp;
|
2002-02-22 07:58:39 +03:00
|
|
|
int numvnodes, ovflw;
|
|
|
|
int (*vnode_fsprint)
|
|
|
|
__P((struct vnode *, int)); /* per-fs data printer */
|
1994-05-14 01:29:29 +04:00
|
|
|
|
1997-10-17 16:16:54 +04:00
|
|
|
mp = NULL;
|
2003-02-11 03:45:02 +03:00
|
|
|
e_vnodebase = loadvnodes(&numvnodes);
|
1994-05-14 01:29:29 +04:00
|
|
|
if (totalflag) {
|
|
|
|
(void)printf("%7d vnodes\n", numvnodes);
|
2003-02-11 03:45:02 +03:00
|
|
|
goto out;
|
1994-05-14 01:29:29 +04:00
|
|
|
}
|
2001-02-11 06:01:05 +03:00
|
|
|
endvnode = e_vnodebase + numvnodes * (VPTRSZ + VNODESZ);
|
1994-05-14 01:29:29 +04:00
|
|
|
(void)printf("%d active vnodes\n", numvnodes);
|
|
|
|
|
1999-11-18 11:27:39 +03:00
|
|
|
#define ST mp->mnt_stat
|
1999-11-18 11:34:38 +03:00
|
|
|
#define FSTYPE_IS(mp, name) \
|
|
|
|
(strncmp((mp)->mnt_stat.f_fstypename, (name), MFSNAMELEN) == 0)
|
1994-05-14 01:29:29 +04:00
|
|
|
maddr = NULL;
|
1999-11-18 11:34:38 +03:00
|
|
|
vnode_fsprint = NULL;
|
2001-02-11 06:01:05 +03:00
|
|
|
for (evp = e_vnodebase; evp < endvnode; evp += VPTRSZ + VNODESZ) {
|
|
|
|
vp = (struct vnode *)(evp + VPTRSZ);
|
1994-05-14 01:29:29 +04:00
|
|
|
if (vp->v_mount != maddr) {
|
|
|
|
/*
|
|
|
|
* New filesystem
|
|
|
|
*/
|
|
|
|
if ((mp = getmnt(vp->v_mount)) == NULL)
|
|
|
|
continue;
|
|
|
|
maddr = vp->v_mount;
|
|
|
|
mount_print(mp);
|
|
|
|
vnode_header();
|
1999-11-18 11:34:38 +03:00
|
|
|
if (FSTYPE_IS(mp, MOUNT_FFS) ||
|
|
|
|
FSTYPE_IS(mp, MOUNT_MFS)) {
|
1994-05-14 01:29:29 +04:00
|
|
|
ufs_header();
|
1999-11-18 11:34:38 +03:00
|
|
|
vnode_fsprint = ufs_print;
|
|
|
|
} else if (FSTYPE_IS(mp, MOUNT_NFS)) {
|
1994-05-14 01:29:29 +04:00
|
|
|
nfs_header();
|
1999-11-18 11:34:38 +03:00
|
|
|
vnode_fsprint = nfs_print;
|
|
|
|
} else if (FSTYPE_IS(mp, MOUNT_EXT2FS)) {
|
1997-06-12 11:45:28 +04:00
|
|
|
ufs_header();
|
1999-11-18 11:34:38 +03:00
|
|
|
vnode_fsprint = ext2fs_print;
|
2000-12-13 08:50:33 +03:00
|
|
|
} else if (FSTYPE_IS(mp, MOUNT_NULL) ||
|
|
|
|
FSTYPE_IS(mp, MOUNT_OVERLAY) ||
|
|
|
|
FSTYPE_IS(mp, MOUNT_UMAP)) {
|
|
|
|
layer_header();
|
|
|
|
vnode_fsprint = layer_print;
|
1999-11-18 11:34:38 +03:00
|
|
|
} else if (FSTYPE_IS(mp, MOUNT_UNION)) {
|
1997-10-17 10:34:19 +04:00
|
|
|
union_header();
|
1999-11-18 11:34:38 +03:00
|
|
|
vnode_fsprint = union_print;
|
|
|
|
} else
|
|
|
|
vnode_fsprint = NULL;
|
1994-05-14 01:29:29 +04:00
|
|
|
(void)printf("\n");
|
|
|
|
}
|
2002-02-22 07:58:39 +03:00
|
|
|
ovflw = vnode_print(*(struct vnode **)evp, vp);
|
1999-11-18 11:34:38 +03:00
|
|
|
if (VTOI(vp) != NULL && vnode_fsprint != NULL)
|
2002-02-22 07:58:39 +03:00
|
|
|
(*vnode_fsprint)(vp, ovflw);
|
1994-05-14 01:29:29 +04:00
|
|
|
(void)printf("\n");
|
|
|
|
}
|
2003-02-11 03:45:02 +03:00
|
|
|
|
|
|
|
out:
|
1994-05-14 01:29:29 +04:00
|
|
|
free(e_vnodebase);
|
|
|
|
}
|
|
|
|
|
2002-02-23 04:06:41 +03:00
|
|
|
int
|
|
|
|
getflags(fd, p, flags)
|
|
|
|
const struct flagbit_desc *fd;
|
|
|
|
char *p;
|
|
|
|
u_int flags;
|
|
|
|
{
|
|
|
|
char *q = p;
|
|
|
|
|
|
|
|
if (flags == 0) {
|
|
|
|
*p++ = '-';
|
|
|
|
*p = '\0';
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; fd->fd_flags != 0; fd++)
|
|
|
|
if ((flags & fd->fd_flags) != 0)
|
|
|
|
*p++ = fd->fd_mark;
|
|
|
|
*p = '\0';
|
|
|
|
return (p - q);
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct flagbit_desc vnode_flags[] = {
|
|
|
|
{ VROOT, 'R' },
|
|
|
|
{ VTEXT, 'T' },
|
|
|
|
{ VSYSTEM, 'S' },
|
|
|
|
{ VISTTY, 'I' },
|
|
|
|
{ VEXECMAP, 'E' },
|
|
|
|
{ VXLOCK, 'L' },
|
|
|
|
{ VXWANT, 'W' },
|
|
|
|
{ VBWAIT, 'B' },
|
|
|
|
{ VALIASED, 'A' },
|
|
|
|
{ VDIROP, 'D' },
|
|
|
|
{ VLAYER, 'Y' },
|
|
|
|
{ VONWORKLST, 'O' },
|
|
|
|
{ 0, '\0' },
|
|
|
|
};
|
|
|
|
|
1994-05-14 01:29:29 +04:00
|
|
|
void
|
|
|
|
vnode_header()
|
|
|
|
{
|
1999-11-18 11:27:39 +03:00
|
|
|
|
2002-02-22 07:58:39 +03:00
|
|
|
(void)printf("%-*s TYP VFLAG USE HOLD TAG NPAGE",
|
2002-02-22 08:04:43 +03:00
|
|
|
PTRSTRWIDTH, "ADDR");
|
1994-05-14 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
2002-02-22 07:58:39 +03:00
|
|
|
int
|
1994-05-14 01:29:29 +04:00
|
|
|
vnode_print(avnode, vp)
|
|
|
|
struct vnode *avnode;
|
|
|
|
struct vnode *vp;
|
|
|
|
{
|
2002-02-23 04:06:41 +03:00
|
|
|
char *type, flags[sizeof(vnode_flags) / sizeof(vnode_flags[0])];
|
|
|
|
int ovflw;
|
1994-05-14 01:29:29 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* set type
|
|
|
|
*/
|
1997-10-17 10:34:19 +04:00
|
|
|
switch (vp->v_type) {
|
1994-05-14 01:29:29 +04:00
|
|
|
case VNON:
|
|
|
|
type = "non"; break;
|
|
|
|
case VREG:
|
|
|
|
type = "reg"; break;
|
|
|
|
case VDIR:
|
|
|
|
type = "dir"; break;
|
|
|
|
case VBLK:
|
|
|
|
type = "blk"; break;
|
|
|
|
case VCHR:
|
|
|
|
type = "chr"; break;
|
|
|
|
case VLNK:
|
|
|
|
type = "lnk"; break;
|
|
|
|
case VSOCK:
|
|
|
|
type = "soc"; break;
|
|
|
|
case VFIFO:
|
|
|
|
type = "fif"; break;
|
|
|
|
case VBAD:
|
|
|
|
type = "bad"; break;
|
1999-11-18 11:27:39 +03:00
|
|
|
default:
|
1994-05-14 01:29:29 +04:00
|
|
|
type = "unk"; break;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* gather flags
|
|
|
|
*/
|
2002-02-23 04:06:41 +03:00
|
|
|
(void)getflags(vnode_flags, flags, vp->v_flag);
|
2002-02-22 07:58:39 +03:00
|
|
|
|
|
|
|
ovflw = 0;
|
2002-02-22 08:04:43 +03:00
|
|
|
PRWORD(ovflw, "%*lx", PTRSTRWIDTH, 0, (long)avnode);
|
2002-02-22 07:58:39 +03:00
|
|
|
PRWORD(ovflw, " %*s", 4, 1, type);
|
|
|
|
PRWORD(ovflw, " %*s", 6, 1, flags);
|
|
|
|
PRWORD(ovflw, " %*ld", 5, 1, (long)vp->v_usecount);
|
|
|
|
PRWORD(ovflw, " %*ld", 5, 1, (long)vp->v_holdcnt);
|
|
|
|
PRWORD(ovflw, " %*d", 4, 1, vp->v_tag);
|
|
|
|
PRWORD(ovflw, " %*d", 6, 1, vp->v_uobj.uo_npages);
|
|
|
|
return (ovflw);
|
1994-05-14 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
2002-02-23 04:06:41 +03:00
|
|
|
const struct flagbit_desc ufs_flags[] = {
|
|
|
|
{ IN_ACCESS, 'A' },
|
|
|
|
{ IN_CHANGE, 'C' },
|
|
|
|
{ IN_UPDATE, 'U' },
|
|
|
|
{ IN_MODIFIED, 'M' },
|
|
|
|
{ IN_ACCESSED, 'a' },
|
|
|
|
{ IN_RENAME, 'R' },
|
|
|
|
{ IN_SHLOCK, 'S' },
|
|
|
|
{ IN_EXLOCK, 'E' },
|
|
|
|
{ IN_CLEANING, 'c' },
|
|
|
|
{ IN_ADIROP, 'D' },
|
|
|
|
{ IN_SPACECOUNTED, 's' },
|
|
|
|
{ 0, '\0' },
|
|
|
|
};
|
1997-06-12 11:45:28 +04:00
|
|
|
|
|
|
|
void
|
1999-11-18 11:27:39 +03:00
|
|
|
ufs_header()
|
1997-06-12 11:45:28 +04:00
|
|
|
{
|
1999-11-18 11:27:39 +03:00
|
|
|
|
1997-06-12 11:45:28 +04:00
|
|
|
(void)printf(" FILEID IFLAG RDEV|SZ");
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-02-22 07:58:39 +03:00
|
|
|
ufs_print(vp, ovflw)
|
1997-06-12 11:45:28 +04:00
|
|
|
struct vnode *vp;
|
2002-02-22 07:58:39 +03:00
|
|
|
int ovflw;
|
1997-06-12 11:45:28 +04:00
|
|
|
{
|
|
|
|
struct inode inode, *ip = &inode;
|
2003-04-02 14:39:19 +04:00
|
|
|
union dinode {
|
|
|
|
struct ufs1_dinode dp1;
|
|
|
|
struct ufs2_dinode dp2;
|
|
|
|
} dip;
|
2002-02-23 04:06:41 +03:00
|
|
|
char flags[sizeof(ufs_flags) / sizeof(ufs_flags[0])];
|
|
|
|
char dev[4 + 1 + 7 + 1]; /* 12bit marjor + 20bit minor */
|
|
|
|
char *name;
|
1997-06-12 11:45:28 +04:00
|
|
|
mode_t type;
|
2003-04-02 14:39:19 +04:00
|
|
|
dev_t rdev;
|
1997-06-12 11:45:28 +04:00
|
|
|
|
|
|
|
KGETRET(VTOI(vp), &inode, sizeof(struct inode), "vnode's inode");
|
2003-04-02 14:39:19 +04:00
|
|
|
KGETRET(ip->i_din.ffs1_din, &dip, sizeof (struct ufs1_dinode),
|
|
|
|
"inode's dinode");
|
|
|
|
|
|
|
|
if (ip->i_size == dip.dp1.di_size)
|
|
|
|
rdev = dip.dp1.di_rdev;
|
|
|
|
else {
|
|
|
|
KGETRET(ip->i_din.ffs1_din, &dip, sizeof (struct ufs2_dinode),
|
|
|
|
"inode's UFS2 dinode");
|
|
|
|
rdev = dip.dp2.di_rdev;
|
|
|
|
}
|
2002-02-23 04:06:41 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX need to to locking state.
|
|
|
|
*/
|
|
|
|
|
|
|
|
(void)getflags(ufs_flags, flags, ip->i_flag);
|
2002-02-22 07:58:39 +03:00
|
|
|
PRWORD(ovflw, " %*d", 7, 1, ip->i_number);
|
2002-02-23 04:06:41 +03:00
|
|
|
PRWORD(ovflw, " %*s", 6, 1, flags);
|
2003-04-02 14:39:19 +04:00
|
|
|
type = ip->i_mode & S_IFMT;
|
|
|
|
if (S_ISCHR(ip->i_mode) || S_ISBLK(ip->i_mode)) {
|
1999-11-18 11:27:39 +03:00
|
|
|
if (usenumflag ||
|
2003-04-02 14:39:19 +04:00
|
|
|
(name = devname(rdev, type)) == NULL) {
|
2002-02-23 04:06:41 +03:00
|
|
|
snprintf(dev, sizeof(dev), "%d,%d",
|
2003-04-02 14:39:19 +04:00
|
|
|
major(rdev), minor(rdev));
|
2002-02-23 04:06:41 +03:00
|
|
|
name = dev;
|
2002-02-22 07:58:39 +03:00
|
|
|
}
|
|
|
|
PRWORD(ovflw, " %*s", 8, 1, name);
|
|
|
|
} else
|
2003-04-02 14:39:19 +04:00
|
|
|
PRWORD(ovflw, " %*lld", 8, 1, (long long)ip->i_size);
|
|
|
|
return 0;
|
1997-06-12 11:45:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-02-22 07:58:39 +03:00
|
|
|
ext2fs_print(vp, ovflw)
|
1997-06-12 11:45:28 +04:00
|
|
|
struct vnode *vp;
|
2002-02-22 07:58:39 +03:00
|
|
|
int ovflw;
|
1997-06-12 11:45:28 +04:00
|
|
|
{
|
|
|
|
struct inode inode, *ip = &inode;
|
2002-02-23 04:06:41 +03:00
|
|
|
char flags[sizeof(ufs_flags) / sizeof(ufs_flags[0])];
|
|
|
|
char dev[4 + 1 + 7 + 1]; /* 12bit marjor + 20bit minor */
|
|
|
|
char *name;
|
1997-06-12 11:45:28 +04:00
|
|
|
mode_t type;
|
|
|
|
|
|
|
|
KGETRET(VTOI(vp), &inode, sizeof(struct inode), "vnode's inode");
|
2002-02-23 04:06:41 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX need to to locking state.
|
|
|
|
*/
|
|
|
|
|
|
|
|
(void)getflags(ufs_flags, flags, ip->i_flag);
|
2002-02-22 07:58:39 +03:00
|
|
|
PRWORD(ovflw, " %*d", 7, 1, ip->i_number);
|
2002-02-23 04:06:41 +03:00
|
|
|
PRWORD(ovflw, " %*s", 6, 1, flags);
|
1997-06-12 11:45:28 +04:00
|
|
|
type = ip->i_e2fs_mode & S_IFMT;
|
2002-02-22 07:58:39 +03:00
|
|
|
if (S_ISCHR(ip->i_e2fs_mode) || S_ISBLK(ip->i_e2fs_mode)) {
|
1999-11-18 11:27:39 +03:00
|
|
|
if (usenumflag ||
|
2002-02-22 07:58:39 +03:00
|
|
|
(name = devname(ip->i_e2fs_rdev, type)) == NULL) {
|
2002-02-23 04:06:41 +03:00
|
|
|
snprintf(dev, sizeof(dev), "%d,%d",
|
1999-11-18 11:34:38 +03:00
|
|
|
major(ip->i_e2fs_rdev), minor(ip->i_e2fs_rdev));
|
2002-02-23 04:06:41 +03:00
|
|
|
name = dev;
|
2002-02-22 07:58:39 +03:00
|
|
|
}
|
|
|
|
PRWORD(ovflw, " %*s", 8, 1, name);
|
|
|
|
} else
|
|
|
|
PRWORD(ovflw, " %*u", 8, 1, (u_int)ip->i_e2fs_size);
|
1994-05-14 01:29:29 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2002-02-23 04:06:41 +03:00
|
|
|
const struct flagbit_desc nfs_flags[] = {
|
|
|
|
{ NFLUSHWANT, 'W' },
|
|
|
|
{ NFLUSHINPROG, 'P' },
|
|
|
|
{ NMODIFIED, 'M' },
|
|
|
|
{ NWRITEERR, 'E' },
|
|
|
|
{ NQNFSNONCACHE, 'X' },
|
|
|
|
{ NQNFSWRITE, 'O' },
|
|
|
|
{ NQNFSEVICTED, 'G' },
|
|
|
|
{ NACC, 'A' },
|
|
|
|
{ NUPD, 'U' },
|
|
|
|
{ NCHG, 'C' },
|
|
|
|
{ 0, '\0' },
|
|
|
|
};
|
|
|
|
|
1994-05-14 01:29:29 +04:00
|
|
|
void
|
1999-11-18 11:27:39 +03:00
|
|
|
nfs_header()
|
1994-05-14 01:29:29 +04:00
|
|
|
{
|
1999-11-18 11:27:39 +03:00
|
|
|
|
1994-05-14 01:29:29 +04:00
|
|
|
(void)printf(" FILEID NFLAG RDEV|SZ");
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-02-22 07:58:39 +03:00
|
|
|
nfs_print(vp, ovflw)
|
1994-05-14 01:29:29 +04:00
|
|
|
struct vnode *vp;
|
2002-02-22 07:58:39 +03:00
|
|
|
int ovflw;
|
1994-05-14 01:29:29 +04:00
|
|
|
{
|
|
|
|
struct nfsnode nfsnode, *np = &nfsnode;
|
2002-02-23 04:06:41 +03:00
|
|
|
char flags[sizeof(nfs_flags) / sizeof(nfs_flags[0])];
|
|
|
|
char dev[4 + 1 + 7 + 1]; /* 12bit marjor + 20bit minor */
|
1997-10-20 22:12:56 +04:00
|
|
|
struct vattr va;
|
1994-05-14 01:29:29 +04:00
|
|
|
char *name;
|
|
|
|
mode_t type;
|
|
|
|
|
|
|
|
KGETRET(VTONFS(vp), &nfsnode, sizeof(nfsnode), "vnode's nfsnode");
|
2002-02-23 04:06:41 +03:00
|
|
|
(void)getflags(nfs_flags, flags, np->n_flag);
|
1994-05-14 01:29:29 +04:00
|
|
|
|
1997-10-20 22:12:56 +04:00
|
|
|
KGETRET(np->n_vattr, &va, sizeof(va), "vnode attr");
|
2002-02-22 07:58:39 +03:00
|
|
|
PRWORD(ovflw, " %*ld", 7, 1, (long)va.va_fileid);
|
2002-02-23 04:06:41 +03:00
|
|
|
PRWORD(ovflw, " %*s", 6, 1, flags);
|
2000-12-13 08:34:55 +03:00
|
|
|
switch (va.va_type) {
|
|
|
|
case VCHR:
|
|
|
|
type = S_IFCHR;
|
|
|
|
goto device;
|
|
|
|
|
|
|
|
case VBLK:
|
|
|
|
type = S_IFBLK;
|
|
|
|
device:
|
2002-02-22 07:58:39 +03:00
|
|
|
if (usenumflag || (name = devname(va.va_rdev, type)) == NULL) {
|
2002-02-23 04:06:41 +03:00
|
|
|
(void)snprintf(dev, sizeof(dev), "%d,%d",
|
1997-10-20 22:12:56 +04:00
|
|
|
major(va.va_rdev), minor(va.va_rdev));
|
2002-02-23 04:06:41 +03:00
|
|
|
name = dev;
|
2002-02-22 07:58:39 +03:00
|
|
|
}
|
|
|
|
PRWORD(ovflw, " %*s", 8, 1, name);
|
2000-12-13 08:34:55 +03:00
|
|
|
break;
|
|
|
|
default:
|
2002-02-22 07:58:39 +03:00
|
|
|
PRWORD(ovflw, " %*lld", 8, 1, (long long)np->n_size);
|
2000-12-13 08:34:55 +03:00
|
|
|
break;
|
|
|
|
}
|
1994-05-14 01:29:29 +04:00
|
|
|
return (0);
|
|
|
|
}
|
1997-10-17 10:34:19 +04:00
|
|
|
|
2000-12-13 08:50:33 +03:00
|
|
|
void
|
|
|
|
layer_header()
|
|
|
|
{
|
|
|
|
|
2002-02-22 08:04:43 +03:00
|
|
|
(void)printf(" %*s", PTRSTRWIDTH, "LOWER");
|
2000-12-13 08:50:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-02-22 07:58:39 +03:00
|
|
|
layer_print(vp, ovflw)
|
2000-12-13 08:50:33 +03:00
|
|
|
struct vnode *vp;
|
2002-02-22 07:58:39 +03:00
|
|
|
int ovflw;
|
2000-12-13 08:50:33 +03:00
|
|
|
{
|
|
|
|
struct layer_node lnode, *lp = &lnode;
|
|
|
|
|
|
|
|
KGETRET(VTOLAYER(vp), &lnode, sizeof(lnode), "layer vnode");
|
|
|
|
|
2002-02-22 08:04:43 +03:00
|
|
|
PRWORD(ovflw, " %*lx", PTRSTRWIDTH + 1, 1, (long)lp->layer_lowervp);
|
2000-12-13 08:50:33 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1997-10-17 10:34:19 +04:00
|
|
|
void
|
1999-11-18 11:27:39 +03:00
|
|
|
union_header()
|
1997-10-17 10:34:19 +04:00
|
|
|
{
|
1999-11-18 11:27:39 +03:00
|
|
|
|
2002-02-22 08:04:43 +03:00
|
|
|
(void)printf(" %*s %*s", PTRSTRWIDTH, "UPPER", PTRSTRWIDTH, "LOWER");
|
1997-10-17 10:34:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2002-02-22 07:58:39 +03:00
|
|
|
union_print(vp, ovflw)
|
1997-10-17 10:34:19 +04:00
|
|
|
struct vnode *vp;
|
2002-02-22 07:58:39 +03:00
|
|
|
int ovflw;
|
1997-10-17 10:34:19 +04:00
|
|
|
{
|
|
|
|
struct union_node unode, *up = &unode;
|
|
|
|
|
|
|
|
KGETRET(VTOUNION(vp), &unode, sizeof(unode), "vnode's unode");
|
|
|
|
|
2002-02-22 08:04:43 +03:00
|
|
|
PRWORD(ovflw, " %*lx", PTRSTRWIDTH + 1, 1, (long)up->un_uppervp);
|
|
|
|
PRWORD(ovflw, " %*lx", PTRSTRWIDTH + 1, 1, (long)up->un_lowervp);
|
1997-10-17 10:34:19 +04:00
|
|
|
return (0);
|
|
|
|
}
|
1999-11-18 11:27:39 +03:00
|
|
|
|
1994-05-14 01:29:29 +04:00
|
|
|
/*
|
|
|
|
* Given a pointer to a mount structure in kernel space,
|
|
|
|
* read it in and return a usable pointer to it.
|
|
|
|
*/
|
|
|
|
struct mount *
|
|
|
|
getmnt(maddr)
|
|
|
|
struct mount *maddr;
|
|
|
|
{
|
|
|
|
static struct mtab {
|
|
|
|
struct mtab *next;
|
|
|
|
struct mount *maddr;
|
|
|
|
struct mount mount;
|
|
|
|
} *mhead = NULL;
|
1997-10-17 10:34:19 +04:00
|
|
|
struct mtab *mt;
|
1994-05-14 01:29:29 +04:00
|
|
|
|
|
|
|
for (mt = mhead; mt != NULL; mt = mt->next)
|
|
|
|
if (maddr == mt->maddr)
|
|
|
|
return (&mt->mount);
|
|
|
|
if ((mt = malloc(sizeof(struct mtab))) == NULL)
|
1997-10-17 16:16:54 +04:00
|
|
|
err(1, "malloc");
|
1994-05-14 01:29:29 +04:00
|
|
|
KGETRET(maddr, &mt->mount, sizeof(struct mount), "mount table");
|
|
|
|
mt->maddr = maddr;
|
|
|
|
mt->next = mhead;
|
|
|
|
mhead = mt;
|
|
|
|
return (&mt->mount);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mount_print(mp)
|
|
|
|
struct mount *mp;
|
|
|
|
{
|
1997-10-17 10:34:19 +04:00
|
|
|
int flags;
|
1994-05-14 01:29:29 +04:00
|
|
|
|
1997-10-17 10:34:19 +04:00
|
|
|
(void)printf("*** MOUNT %s %s on %s", ST.f_fstypename,
|
1994-05-14 01:47:55 +04:00
|
|
|
ST.f_mntfromname, ST.f_mntonname);
|
1997-10-17 16:16:54 +04:00
|
|
|
if ((flags = mp->mnt_flag) != 0) {
|
1997-10-17 10:34:19 +04:00
|
|
|
int i;
|
|
|
|
const char *sep = " (";
|
|
|
|
|
2002-12-12 01:19:58 +03:00
|
|
|
for (i = 0; i <= sizeof mnt_flags / sizeof mnt_flags[0]; i++) {
|
1997-10-17 10:34:19 +04:00
|
|
|
if (flags & mnt_flags[i].m_flag) {
|
|
|
|
(void)printf("%s%s", sep, mnt_flags[i].m_name);
|
|
|
|
flags &= ~mnt_flags[i].m_flag;
|
|
|
|
sep = ",";
|
|
|
|
}
|
1999-11-18 11:27:39 +03:00
|
|
|
}
|
|
|
|
if (flags)
|
|
|
|
(void)printf("%sunknown_flags:%x", sep, flags);
|
1994-05-14 01:29:29 +04:00
|
|
|
(void)printf(")");
|
|
|
|
}
|
|
|
|
(void)printf("\n");
|
|
|
|
}
|
|
|
|
|
2003-02-11 03:45:02 +03:00
|
|
|
char *
|
|
|
|
loadvnodes(avnodes)
|
1994-05-14 01:29:29 +04:00
|
|
|
int *avnodes;
|
|
|
|
{
|
|
|
|
int mib[2];
|
|
|
|
size_t copysize;
|
2003-02-11 03:45:02 +03:00
|
|
|
char *vnodebase;
|
1994-05-14 01:29:29 +04:00
|
|
|
|
|
|
|
if (memf != NULL) {
|
|
|
|
/*
|
|
|
|
* do it by hand
|
|
|
|
*/
|
2003-02-11 03:45:02 +03:00
|
|
|
return (kinfo_vnodes(avnodes));
|
1994-05-14 01:29:29 +04:00
|
|
|
}
|
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_VNODE;
|
|
|
|
if (sysctl(mib, 2, NULL, ©size, NULL, 0) == -1)
|
|
|
|
err(1, "sysctl: KERN_VNODE");
|
2003-02-11 03:45:02 +03:00
|
|
|
if ((vnodebase = malloc(copysize)) == NULL)
|
1997-10-17 16:16:54 +04:00
|
|
|
err(1, "malloc");
|
2003-02-11 03:45:02 +03:00
|
|
|
if (sysctl(mib, 2, vnodebase, ©size, NULL, 0) == -1)
|
1994-05-14 01:29:29 +04:00
|
|
|
err(1, "sysctl: KERN_VNODE");
|
2001-02-11 06:01:05 +03:00
|
|
|
if (copysize % (VPTRSZ + VNODESZ))
|
1994-05-14 01:29:29 +04:00
|
|
|
errx(1, "vnode size mismatch");
|
2003-02-11 03:45:02 +03:00
|
|
|
*avnodes = copysize / (VPTRSZ + VNODESZ);
|
|
|
|
|
|
|
|
return (vnodebase);
|
1994-05-14 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* simulate what a running kernel does in in kinfo_vnode
|
|
|
|
*/
|
2003-02-11 03:45:02 +03:00
|
|
|
char *
|
|
|
|
kinfo_vnodes(avnodes)
|
1994-05-14 01:29:29 +04:00
|
|
|
int *avnodes;
|
|
|
|
{
|
|
|
|
struct mntlist mountlist;
|
|
|
|
struct mount *mp, mount;
|
|
|
|
struct vnode *vp, vnode;
|
2001-02-11 06:01:05 +03:00
|
|
|
char *beg, *bp, *ep;
|
|
|
|
int numvnodes;
|
1994-05-14 01:29:29 +04:00
|
|
|
|
|
|
|
KGET(V_NUMV, numvnodes);
|
2001-02-11 06:01:05 +03:00
|
|
|
if ((bp = malloc((numvnodes + 20) * (VPTRSZ + VNODESZ))) == NULL)
|
1997-10-17 16:16:54 +04:00
|
|
|
err(1, "malloc");
|
2001-02-11 06:01:05 +03:00
|
|
|
beg = bp;
|
|
|
|
ep = bp + (numvnodes + 20) * (VPTRSZ + VNODESZ);
|
1994-05-14 01:29:29 +04:00
|
|
|
KGET(V_MOUNTLIST, mountlist);
|
2003-01-20 10:12:12 +03:00
|
|
|
for (mp = mountlist.cqh_first;;
|
1999-11-18 11:27:39 +03:00
|
|
|
mp = mount.mnt_list.cqe_next) {
|
1994-05-14 01:29:29 +04:00
|
|
|
KGET2(mp, &mount, sizeof(mount), "mount entry");
|
|
|
|
for (vp = mount.mnt_vnodelist.lh_first;
|
1996-04-30 04:41:51 +04:00
|
|
|
vp != NULL; vp = vnode.v_mntvnodes.le_next) {
|
1994-05-14 01:29:29 +04:00
|
|
|
KGET2(vp, &vnode, sizeof(vnode), "vnode");
|
2001-02-11 06:01:05 +03:00
|
|
|
if (bp + VPTRSZ + VNODESZ > ep)
|
1994-05-14 01:29:29 +04:00
|
|
|
/* XXX - should realloc */
|
|
|
|
errx(1, "no more room for vnodes");
|
|
|
|
memmove(bp, &vp, VPTRSZ);
|
|
|
|
bp += VPTRSZ;
|
|
|
|
memmove(bp, &vnode, VNODESZ);
|
|
|
|
bp += VNODESZ;
|
|
|
|
}
|
1995-01-18 09:19:49 +03:00
|
|
|
if (mp == mountlist.cqh_last)
|
|
|
|
break;
|
1994-05-14 01:29:29 +04:00
|
|
|
}
|
2001-02-11 06:01:05 +03:00
|
|
|
*avnodes = (bp - beg) / (VPTRSZ + VNODESZ);
|
2003-02-11 03:45:02 +03:00
|
|
|
return (beg);
|
1994-05-14 01:29:29 +04:00
|
|
|
}
|
1999-11-18 11:27:39 +03:00
|
|
|
|
1994-05-14 01:29:29 +04:00
|
|
|
void
|
|
|
|
ttymode()
|
|
|
|
{
|
1997-10-17 16:16:54 +04:00
|
|
|
int ntty;
|
1996-05-30 09:45:45 +04:00
|
|
|
struct ttylist_head tty_head;
|
|
|
|
struct tty *tp, tty;
|
|
|
|
|
|
|
|
KGET(TTY_NTTY, ntty);
|
|
|
|
(void)printf("%d terminal device%s\n", ntty, ntty == 1 ? "" : "s");
|
|
|
|
KGET(TTY_TTYLIST, tty_head);
|
2002-02-24 05:02:59 +03:00
|
|
|
(void)printf(
|
|
|
|
" LINE RAW CAN OUT HWT LWT COL STATE %-*s PGID DISC\n",
|
|
|
|
PTRSTRWIDTH, "SESS");
|
1996-05-30 09:45:45 +04:00
|
|
|
for (tp = tty_head.tqh_first; tp; tp = tty.tty_link.tqe_next) {
|
|
|
|
KGET2(tp, &tty, sizeof tty, "tty struct");
|
|
|
|
ttyprt(&tty);
|
1994-05-16 10:44:00 +04:00
|
|
|
}
|
1994-05-14 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
2002-11-06 12:32:26 +03:00
|
|
|
static const struct flagbit_desc ttystates[] = {
|
1994-05-14 01:29:29 +04:00
|
|
|
{ TS_ISOPEN, 'O'},
|
1998-03-29 16:24:44 +04:00
|
|
|
{ TS_DIALOUT, '>'},
|
1994-05-14 01:29:29 +04:00
|
|
|
{ TS_CARR_ON, 'C'},
|
|
|
|
{ TS_TIMEOUT, 'T'},
|
|
|
|
{ TS_FLUSH, 'F'},
|
|
|
|
{ TS_BUSY, 'B'},
|
|
|
|
{ TS_ASLEEP, 'A'},
|
|
|
|
{ TS_XCLUDE, 'X'},
|
|
|
|
{ TS_TTSTOP, 'S'},
|
|
|
|
{ TS_TBLOCK, 'K'},
|
|
|
|
{ TS_ASYNC, 'Y'},
|
|
|
|
{ TS_BKSL, 'D'},
|
|
|
|
{ TS_ERASE, 'E'},
|
|
|
|
{ TS_LNCH, 'L'},
|
|
|
|
{ TS_TYPEN, 'P'},
|
|
|
|
{ TS_CNTTB, 'N'},
|
2002-02-24 05:02:59 +03:00
|
|
|
{ 0, '\0'},
|
1994-05-14 01:29:29 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
1996-05-30 09:45:45 +04:00
|
|
|
ttyprt(tp)
|
1997-10-17 10:34:19 +04:00
|
|
|
struct tty *tp;
|
1994-05-14 01:29:29 +04:00
|
|
|
{
|
2002-02-23 04:06:41 +03:00
|
|
|
char state[sizeof(ttystates) / sizeof(ttystates[0]) + 1];
|
2002-02-24 05:02:59 +03:00
|
|
|
char dev[2 + 3 + 1 + 5 + 1]; /* 12bit major + 20bit minor */
|
2000-11-03 00:40:37 +03:00
|
|
|
struct linesw t_linesw;
|
2002-02-23 04:06:41 +03:00
|
|
|
char *name, buffer;
|
|
|
|
pid_t pgid;
|
2002-02-24 05:02:59 +03:00
|
|
|
int n, ovflw;
|
1994-05-14 01:29:29 +04:00
|
|
|
|
2002-02-24 05:02:59 +03:00
|
|
|
if (usenumflag || (name = devname(tp->t_dev, S_IFCHR)) == NULL) {
|
|
|
|
(void)snprintf(dev, sizeof(dev), "0x%3x:%x",
|
|
|
|
major(tp->t_dev), minor(tp->t_dev));
|
|
|
|
name = dev;
|
|
|
|
}
|
|
|
|
ovflw = 0;
|
|
|
|
PRWORD(ovflw, "%-*s", 7, 0, name);
|
|
|
|
PRWORD(ovflw, " %*d", 3, 1, tp->t_rawq.c_cc);
|
|
|
|
PRWORD(ovflw, " %*d", 4, 1, tp->t_canq.c_cc);
|
|
|
|
PRWORD(ovflw, " %*d", 4, 1, tp->t_outq.c_cc);
|
|
|
|
PRWORD(ovflw, " %*d", 5, 1, tp->t_hiwat);
|
|
|
|
PRWORD(ovflw, " %*d", 4, 1, tp->t_lowat);
|
|
|
|
PRWORD(ovflw, " %*d", 8, 1, tp->t_column);
|
2002-02-23 04:06:41 +03:00
|
|
|
n = getflags(ttystates, state, tp->t_state);
|
|
|
|
if (tp->t_wopen) {
|
|
|
|
state[n++] = 'W';
|
|
|
|
state[n] = '\0';
|
|
|
|
}
|
2002-02-24 05:02:59 +03:00
|
|
|
PRWORD(ovflw, " %-*s", 7, 1, state);
|
|
|
|
PRWORD(ovflw, " %*lX", PTRSTRWIDTH + 1, 1, (u_long)tp->t_session);
|
1994-05-14 01:29:29 +04:00
|
|
|
pgid = 0;
|
|
|
|
if (tp->t_pgrp != NULL)
|
|
|
|
KGET2(&tp->t_pgrp->pg_id, &pgid, sizeof(pid_t), "pgid");
|
2002-02-24 05:02:59 +03:00
|
|
|
PRWORD(ovflw, " %*d", 6, 1, pgid);
|
2000-11-03 00:40:37 +03:00
|
|
|
KGET2(tp->t_linesw, &t_linesw, sizeof(t_linesw),
|
2002-02-22 07:27:30 +03:00
|
|
|
"line discipline switch table");
|
2000-11-03 00:40:37 +03:00
|
|
|
name = t_linesw.l_name;
|
2002-02-24 05:02:59 +03:00
|
|
|
(void)putchar(' ');
|
2000-11-03 00:40:37 +03:00
|
|
|
for (;;) {
|
|
|
|
KGET2(name, &buffer, sizeof(buffer), "line discipline name");
|
|
|
|
if (buffer == '\0')
|
|
|
|
break;
|
|
|
|
(void)putchar(buffer);
|
|
|
|
name++;
|
1994-05-14 01:29:29 +04:00
|
|
|
}
|
2000-11-03 00:40:37 +03:00
|
|
|
(void)putchar('\n');
|
1994-05-14 01:29:29 +04:00
|
|
|
}
|
|
|
|
|
2002-11-06 12:32:26 +03:00
|
|
|
static const struct flagbit_desc filemode_flags[] = {
|
2002-02-23 04:06:41 +03:00
|
|
|
{ FREAD, 'R' },
|
|
|
|
{ FWRITE, 'W' },
|
|
|
|
{ FAPPEND, 'A' },
|
|
|
|
#ifdef FSHLOCK /* currently gone */
|
|
|
|
{ FSHLOCK, 'S' },
|
|
|
|
{ FEXLOCK, 'X' },
|
|
|
|
#endif
|
|
|
|
{ FASYNC, 'I' },
|
|
|
|
{ 0, '\0' },
|
|
|
|
};
|
|
|
|
|
1994-05-14 01:29:29 +04:00
|
|
|
void
|
|
|
|
filemode()
|
|
|
|
{
|
1997-10-17 10:34:19 +04:00
|
|
|
struct file *fp;
|
1994-05-14 01:29:29 +04:00
|
|
|
struct file *addr;
|
2002-02-23 04:06:41 +03:00
|
|
|
char flags[sizeof(filemode_flags) / sizeof(filemode_flags[0])];
|
2004-02-22 15:30:11 +03:00
|
|
|
char *buf, *offset;
|
2002-02-24 05:02:59 +03:00
|
|
|
int len, maxfile, nfile, ovflw;
|
2002-11-06 12:32:26 +03:00
|
|
|
static const char * const dtypes[] =
|
|
|
|
{ "???", "inode", "socket", "pipe" };
|
1994-05-14 01:29:29 +04:00
|
|
|
|
|
|
|
KGET(FNL_MAXFILE, maxfile);
|
|
|
|
if (totalflag) {
|
|
|
|
KGET(FNL_NFILE, nfile);
|
|
|
|
(void)printf("%3d/%3d files\n", nfile, maxfile);
|
|
|
|
return;
|
|
|
|
}
|
2004-02-22 15:30:11 +03:00
|
|
|
if (getfiles(&buf, &len, &offset) == -1)
|
1994-05-14 01:29:29 +04:00
|
|
|
return;
|
|
|
|
/*
|
|
|
|
* Getfiles returns in malloc'd memory a pointer to the first file
|
|
|
|
* structure, and then an array of file structs (whose addresses are
|
|
|
|
* derivable from the previous entry).
|
|
|
|
*/
|
2004-02-22 15:30:11 +03:00
|
|
|
addr = ((struct filelist *)offset)->lh_first;
|
|
|
|
fp = (struct file *)(offset + sizeof(struct filelist));
|
1994-08-31 07:48:18 +04:00
|
|
|
nfile = (len - sizeof(struct filelist)) / sizeof(struct file);
|
1999-11-18 11:27:39 +03:00
|
|
|
|
1994-05-14 01:29:29 +04:00
|
|
|
(void)printf("%d/%d open files\n", nfile, maxfile);
|
2002-02-24 05:02:59 +03:00
|
|
|
(void)printf("%*s%s%*s TYPE FLG CNT MSG %*s%s%*s OFFSET\n",
|
|
|
|
(PTRSTRWIDTH - 4) / 2, "", " LOC", (PTRSTRWIDTH - 4) / 2, "",
|
|
|
|
(PTRSTRWIDTH - 4) / 2, "", "DATA", (PTRSTRWIDTH - 4) / 2, "");
|
2004-02-22 15:30:11 +03:00
|
|
|
for (; (char *)fp < offset + len; addr = fp->f_list.le_next, fp++) {
|
2002-11-06 12:32:26 +03:00
|
|
|
if ((unsigned)fp->f_type > DTYPE_PIPE)
|
1994-05-14 01:29:29 +04:00
|
|
|
continue;
|
2002-02-24 05:02:59 +03:00
|
|
|
ovflw = 0;
|
2002-02-23 04:06:41 +03:00
|
|
|
(void)getflags(filemode_flags, flags, fp->f_flag);
|
2002-02-24 05:02:59 +03:00
|
|
|
PRWORD(ovflw, "%*lx", PTRSTRWIDTH, 0, (long)addr);
|
|
|
|
PRWORD(ovflw, " %-*s", 9, 1, dtypes[fp->f_type]);
|
|
|
|
PRWORD(ovflw, " %*s", 6, 1, flags);
|
|
|
|
PRWORD(ovflw, " %*d", 5, 1, fp->f_count);
|
|
|
|
PRWORD(ovflw, " %*d", 5, 1, fp->f_msgcount);
|
|
|
|
PRWORD(ovflw, " %*lx", PTRSTRWIDTH + 1, 2, (long)fp->f_data);
|
1994-05-14 01:29:29 +04:00
|
|
|
if (fp->f_offset < 0)
|
2004-02-22 15:30:11 +03:00
|
|
|
PRWORD(ovflw, " %-*lld\n", PTRSTRWIDTH + 1, 2,
|
2002-02-24 05:02:59 +03:00
|
|
|
(long long)fp->f_offset);
|
1994-05-14 01:29:29 +04:00
|
|
|
else
|
2002-02-24 05:02:59 +03:00
|
|
|
PRWORD(ovflw, " %-*lld\n", PTRSTRWIDTH + 1, 2,
|
|
|
|
(long long)fp->f_offset);
|
1994-05-14 01:29:29 +04:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-02-22 15:30:11 +03:00
|
|
|
getfiles(abuf, alen, aoffset)
|
1994-05-14 01:29:29 +04:00
|
|
|
char **abuf;
|
|
|
|
int *alen;
|
2004-02-22 15:30:11 +03:00
|
|
|
char **aoffset;
|
1994-05-14 01:29:29 +04:00
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
int mib[2];
|
|
|
|
char *buf;
|
2004-02-22 15:30:11 +03:00
|
|
|
size_t offset;
|
1994-05-14 01:29:29 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX
|
|
|
|
* Add emulation of KINFO_FILE here.
|
|
|
|
*/
|
|
|
|
if (memf != NULL)
|
2001-07-09 21:30:37 +04:00
|
|
|
errx(1, "files on dead kernel, not implemented");
|
1994-05-14 01:29:29 +04:00
|
|
|
|
|
|
|
mib[0] = CTL_KERN;
|
|
|
|
mib[1] = KERN_FILE;
|
|
|
|
if (sysctl(mib, 2, NULL, &len, NULL, 0) == -1) {
|
|
|
|
warn("sysctl: KERN_FILE");
|
|
|
|
return (-1);
|
|
|
|
}
|
2004-02-22 15:30:11 +03:00
|
|
|
/* We need to align (struct file *) in the buffer. */
|
|
|
|
offset = len % sizeof(off_t);
|
|
|
|
if ((buf = malloc(len + offset)) == NULL)
|
1997-10-17 16:16:54 +04:00
|
|
|
err(1, "malloc");
|
2004-02-22 15:30:11 +03:00
|
|
|
if (sysctl(mib, 2, buf + offset, &len, NULL, 0) == -1) {
|
1994-05-14 01:29:29 +04:00
|
|
|
warn("sysctl: KERN_FILE");
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
*abuf = buf;
|
|
|
|
*alen = len;
|
2004-02-22 15:30:11 +03:00
|
|
|
*aoffset = (buf + offset);
|
1994-05-14 01:29:29 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
usage()
|
|
|
|
{
|
1999-11-18 11:27:39 +03:00
|
|
|
|
1994-05-14 01:29:29 +04:00
|
|
|
(void)fprintf(stderr,
|
2003-12-20 16:31:42 +03:00
|
|
|
"usage: %s [-T|-f|-s|-t|-v] [-ghkmn] [-M core] [-N system]\n",
|
2002-02-22 08:43:20 +03:00
|
|
|
getprogname());
|
1994-05-14 01:29:29 +04:00
|
|
|
exit(1);
|
|
|
|
}
|