version 1.10, 1997/06/05 07:46:55 |
version 1.11, 1997/07/08 00:33:02 |
|
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
|
#include <unistd.h> |
|
|
#define TEXT -1 |
#define TEXT -1 |
#define CDIR -2 |
#define CDIR -2 |
|
|
DEVS *devs; |
DEVS *devs; |
|
|
struct filestat { |
struct filestat { |
long fsid; |
long fsid; |
long fileid; |
long fileid; |
mode_t mode; |
mode_t mode; |
u_long size; |
u_int64_t size; |
dev_t rdev; |
dev_t rdev; |
}; |
}; |
|
|
#ifdef notdef |
#ifdef notdef |
|
|
* a kvm_read that returns true if everything is read |
* a kvm_read that returns true if everything is read |
*/ |
*/ |
#define KVM_READ(kaddr, paddr, len) \ |
#define KVM_READ(kaddr, paddr, len) \ |
(kvm_read(kd, (u_long)(kaddr), (char *)(paddr), (len)) == (len)) |
(kvm_read(kd, (u_long)(kaddr), (void *)(paddr), (len)) == (len)) |
|
|
kvm_t *kd; |
kvm_t *kd; |
|
|
int ufs_filestat(), ext2fs_filestat(), nfs_filestat(); |
int ufs_filestat __P((struct vnode *, struct filestat *)); |
void dofiles(), getinetproto(), socktrans(); |
int ext2fs_filestat __P((struct vnode *, struct filestat *)); |
void usage(), vtrans(); |
int nfs_filestat __P((struct vnode *, struct filestat *)); |
|
void dofiles __P((struct kinfo_proc *)); |
|
void getinetproto __P((int)); |
|
void socktrans __P((struct socket *, int)); |
|
void usage __P((void)); |
|
void vtrans __P((struct vnode *, int, int)); |
|
int getfname __P((char *)); |
|
|
|
int |
main(argc, argv) |
main(argc, argv) |
int argc; |
int argc; |
char **argv; |
char **argv; |
|
|
dofiles(kp) |
dofiles(kp) |
struct kinfo_proc *kp; |
struct kinfo_proc *kp; |
{ |
{ |
int i, last; |
int i; |
struct file file; |
struct file file; |
struct filedesc0 filed0; |
struct filedesc0 filed0; |
#define filed filed0.fd_fd |
#define filed filed0.fd_fd |
|
|
if (p->p_fd == NULL) |
if (p->p_fd == NULL) |
return; |
return; |
if (!KVM_READ(p->p_fd, &filed0, sizeof (filed0))) { |
if (!KVM_READ(p->p_fd, &filed0, sizeof (filed0))) { |
dprintf(stderr, "can't read filedesc at %x for pid %d\n", |
dprintf(stderr, "can't read filedesc at %p for pid %d\n", |
p->p_fd, Pid); |
p->p_fd, Pid); |
return; |
return; |
} |
} |
if (filed.fd_nfiles < 0 || filed.fd_lastfile >= filed.fd_nfiles || |
if (filed.fd_nfiles < 0 || filed.fd_lastfile >= filed.fd_nfiles || |
filed.fd_freefile > filed.fd_lastfile + 1) { |
filed.fd_freefile > filed.fd_lastfile + 1) { |
dprintf(stderr, "filedesc corrupted at %x for pid %d\n", |
dprintf(stderr, "filedesc corrupted at %p for pid %d\n", |
p->p_fd, Pid); |
p->p_fd, Pid); |
return; |
return; |
} |
} |
|
|
if (!KVM_READ(filed.fd_ofiles, ofiles, |
if (!KVM_READ(filed.fd_ofiles, ofiles, |
(filed.fd_lastfile+1) * FPSIZE)) { |
(filed.fd_lastfile+1) * FPSIZE)) { |
dprintf(stderr, |
dprintf(stderr, |
"can't read file structures at %x for pid %d\n", |
"can't read file structures at %p for pid %d\n", |
filed.fd_ofiles, Pid); |
filed.fd_ofiles, Pid); |
return; |
return; |
} |
} |
|
|
if (ofiles[i] == NULL) |
if (ofiles[i] == NULL) |
continue; |
continue; |
if (!KVM_READ(ofiles[i], &file, sizeof (struct file))) { |
if (!KVM_READ(ofiles[i], &file, sizeof (struct file))) { |
dprintf(stderr, "can't read file %d at %x for pid %d\n", |
dprintf(stderr, "can't read file %d at %p for pid %d\n", |
i, ofiles[i], Pid); |
i, ofiles[i], Pid); |
continue; |
continue; |
} |
} |
|
|
|
|
filename = badtype = NULL; |
filename = badtype = NULL; |
if (!KVM_READ(vp, &vn, sizeof (struct vnode))) { |
if (!KVM_READ(vp, &vn, sizeof (struct vnode))) { |
dprintf(stderr, "can't read vnode at %x for pid %d\n", |
dprintf(stderr, "can't read vnode at %p for pid %d\n", |
vp, Pid); |
vp, Pid); |
return; |
return; |
} |
} |
|
|
(void)sprintf(mode, "%o", fst.mode); |
(void)sprintf(mode, "%o", fst.mode); |
else |
else |
strmode(fst.mode, mode); |
strmode(fst.mode, mode); |
(void)printf(" %6d %10s", fst.fileid, mode); |
(void)printf(" %6ld %10s", fst.fileid, mode); |
switch (vn.v_type) { |
switch (vn.v_type) { |
case VBLK: |
case VBLK: |
case VCHR: { |
case VCHR: { |
|
|
break; |
break; |
} |
} |
default: |
default: |
printf(" %6d", fst.size); |
printf(" %6qd", fst.size); |
} |
} |
rw[0] = '\0'; |
rw[0] = '\0'; |
if (flag & FREAD) |
if (flag & FREAD) |
|
|
struct inode inode; |
struct inode inode; |
|
|
if (!KVM_READ(VTOI(vp), &inode, sizeof (inode))) { |
if (!KVM_READ(VTOI(vp), &inode, sizeof (inode))) { |
dprintf(stderr, "can't read inode at %x for pid %d\n", |
dprintf(stderr, "can't read inode at %p for pid %d\n", |
VTOI(vp), Pid); |
VTOI(vp), Pid); |
return 0; |
return 0; |
} |
} |
fsp->fsid = inode.i_dev & 0xffff; |
fsp->fsid = inode.i_dev & 0xffff; |
fsp->fileid = (long)inode.i_number; |
fsp->fileid = (long)inode.i_number; |
fsp->mode = (mode_t)inode.i_ffs_mode; |
fsp->mode = inode.i_ffs_mode; |
fsp->size = (u_long)inode.i_ffs_size; |
fsp->size = inode.i_ffs_size; |
fsp->rdev = inode.i_ffs_rdev; |
fsp->rdev = inode.i_ffs_rdev; |
|
|
return 1; |
return 1; |
|
|
struct inode inode; |
struct inode inode; |
|
|
if (!KVM_READ(VTOI(vp), &inode, sizeof (inode))) { |
if (!KVM_READ(VTOI(vp), &inode, sizeof (inode))) { |
dprintf(stderr, "can't read inode at %x for pid %d\n", |
dprintf(stderr, "can't read inode at %p for pid %d\n", |
VTOI(vp), Pid); |
VTOI(vp), Pid); |
return 0; |
return 0; |
} |
} |
fsp->fsid = inode.i_dev & 0xffff; |
fsp->fsid = inode.i_dev & 0xffff; |
fsp->fileid = (long)inode.i_number; |
fsp->fileid = (long)inode.i_number; |
fsp->mode = (mode_t)inode.i_e2fs_mode; |
fsp->mode = inode.i_e2fs_mode; |
fsp->size = (u_long)inode.i_e2fs_size; |
fsp->size = inode.i_e2fs_size; |
fsp->rdev = 0; /* XXX */ |
fsp->rdev = 0; /* XXX */ |
|
|
return 1; |
return 1; |
|
|
register mode_t mode; |
register mode_t mode; |
|
|
if (!KVM_READ(VTONFS(vp), &nfsnode, sizeof (nfsnode))) { |
if (!KVM_READ(VTONFS(vp), &nfsnode, sizeof (nfsnode))) { |
dprintf(stderr, "can't read nfsnode at %x for pid %d\n", |
dprintf(stderr, "can't read nfsnode at %p for pid %d\n", |
VTONFS(vp), Pid); |
VTONFS(vp), Pid); |
return 0; |
return 0; |
} |
} |
|
|
if (m == mt->m) |
if (m == mt->m) |
return (mt->mntonname); |
return (mt->mntonname); |
if (!KVM_READ(m, &mount, sizeof(struct mount))) { |
if (!KVM_READ(m, &mount, sizeof(struct mount))) { |
fprintf(stderr, "can't read mount table at %x\n", m); |
fprintf(stderr, "can't read mount table at %p\n", m); |
return (NULL); |
return (NULL); |
} |
} |
if ((mt = malloc(sizeof (struct mtab))) == NULL) { |
if ((mt = malloc(sizeof (struct mtab))) == NULL) { |
|
|
|
|
/* fill in socket */ |
/* fill in socket */ |
if (!KVM_READ(sock, &so, sizeof(struct socket))) { |
if (!KVM_READ(sock, &so, sizeof(struct socket))) { |
dprintf(stderr, "can't read sock at %x\n", sock); |
dprintf(stderr, "can't read sock at %p\n", sock); |
goto bad; |
goto bad; |
} |
} |
|
|
/* fill in protosw entry */ |
/* fill in protosw entry */ |
if (!KVM_READ(so.so_proto, &proto, sizeof(struct protosw))) { |
if (!KVM_READ(so.so_proto, &proto, sizeof(struct protosw))) { |
dprintf(stderr, "can't read protosw at %x", so.so_proto); |
dprintf(stderr, "can't read protosw at %p", so.so_proto); |
goto bad; |
goto bad; |
} |
} |
|
|
/* fill in domain */ |
/* fill in domain */ |
if (!KVM_READ(proto.pr_domain, &dom, sizeof(struct domain))) { |
if (!KVM_READ(proto.pr_domain, &dom, sizeof(struct domain))) { |
dprintf(stderr, "can't read domain at %x\n", proto.pr_domain); |
dprintf(stderr, "can't read domain at %p\n", proto.pr_domain); |
goto bad; |
goto bad; |
} |
} |
|
|
if ((len = kvm_read(kd, (u_long)dom.dom_name, dname, |
if ((len = kvm_read(kd, (u_long)dom.dom_name, dname, |
sizeof(dname) - 1)) < 0) { |
sizeof(dname) - 1)) < 0) { |
dprintf(stderr, "can't read domain name at %x\n", |
dprintf(stderr, "can't read domain name at %p\n", |
dom.dom_name); |
dom.dom_name); |
dname[0] = '\0'; |
dname[0] = '\0'; |
} |
} |
|
|
break; |
break; |
if (kvm_read(kd, (u_long)so.so_pcb, (char *)&inpcb, |
if (kvm_read(kd, (u_long)so.so_pcb, (char *)&inpcb, |
sizeof(struct inpcb)) != sizeof(struct inpcb)) { |
sizeof(struct inpcb)) != sizeof(struct inpcb)) { |
dprintf(stderr, "can't read inpcb at %x\n", |
dprintf(stderr, "can't read inpcb at %p\n", |
so.so_pcb); |
so.so_pcb); |
goto bad; |
goto bad; |
} |
} |
printf(" %lx", (long)inpcb.inp_ppcb); |
printf(" %p", inpcb.inp_ppcb); |
printf(" %s:%d", |
printf(" %s:%d", |
inpcb.inp_laddr.s_addr == INADDR_ANY ? "*" : |
inpcb.inp_laddr.s_addr == INADDR_ANY ? "*" : |
inet_ntoa(inpcb.inp_laddr), |
inet_ntoa(inpcb.inp_laddr), |
|
|
break; |
break; |
if (kvm_read(kd, (u_long)so.so_pcb, (char *)&inpcb, |
if (kvm_read(kd, (u_long)so.so_pcb, (char *)&inpcb, |
sizeof(struct inpcb)) != sizeof(struct inpcb)) { |
sizeof(struct inpcb)) != sizeof(struct inpcb)) { |
dprintf(stderr, "can't read inpcb at %x\n", |
dprintf(stderr, "can't read inpcb at %p\n", |
so.so_pcb); |
so.so_pcb); |
goto bad; |
goto bad; |
} |
} |
|
|
inet_ntoa(inpcb.inp_faddr), |
inet_ntoa(inpcb.inp_faddr), |
ntohs(inpcb.inp_fport)); |
ntohs(inpcb.inp_fport)); |
} else if (so.so_pcb) |
} else if (so.so_pcb) |
printf(" %lx", (long)so.so_pcb); |
printf(" %p", so.so_pcb); |
break; |
break; |
case AF_UNIX: |
case AF_UNIX: |
/* print address of pcb and connected pcb */ |
/* print address of pcb and connected pcb */ |
if (so.so_pcb) { |
if (so.so_pcb) { |
printf(" %lx", (long)so.so_pcb); |
printf(" %p", so.so_pcb); |
if (kvm_read(kd, (u_long)so.so_pcb, (char *)&unpcb, |
if (kvm_read(kd, (u_long)so.so_pcb, (char *)&unpcb, |
sizeof(struct unpcb)) != sizeof(struct unpcb)){ |
sizeof(struct unpcb)) != sizeof(struct unpcb)){ |
dprintf(stderr, "can't read unpcb at %x\n", |
dprintf(stderr, "can't read unpcb at %p\n", |
so.so_pcb); |
so.so_pcb); |
goto bad; |
goto bad; |
} |
} |
|
|
if (!(so.so_state & SS_CANTSENDMORE)) |
if (!(so.so_state & SS_CANTSENDMORE)) |
*cp++ = '>'; |
*cp++ = '>'; |
*cp = '\0'; |
*cp = '\0'; |
printf(" %s %lx", shoconn, |
printf(" %s %p", shoconn, |
(long)unpcb.unp_conn); |
unpcb.unp_conn); |
} |
} |
} |
} |
break; |
break; |
default: |
default: |
/* print protocol number and socket address */ |
/* print protocol number and socket address */ |
printf(" %d %lx", proto.pr_protocol, (long)sock); |
printf(" %d %p", proto.pr_protocol, sock); |
} |
} |
printf("\n"); |
printf("\n"); |
return; |
return; |
|
|
printf(" %s", cp); |
printf(" %s", cp); |
} |
} |
|
|
|
int |
getfname(filename) |
getfname(filename) |
char *filename; |
char *filename; |
{ |
{ |