fstat.c (9336) | fstat.c (17808) |
---|---|
1/*- 2 * Copyright (c) 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 41 unchanged lines hidden (view full) --- 50#include <sys/socket.h> 51#include <sys/socketvar.h> 52#include <sys/domain.h> 53#include <sys/protosw.h> 54#include <sys/unpcb.h> 55#include <sys/sysctl.h> 56#include <sys/filedesc.h> 57#include <sys/queue.h> | 1/*- 2 * Copyright (c) 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 41 unchanged lines hidden (view full) --- 50#include <sys/socket.h> 51#include <sys/socketvar.h> 52#include <sys/domain.h> 53#include <sys/protosw.h> 54#include <sys/unpcb.h> 55#include <sys/sysctl.h> 56#include <sys/filedesc.h> 57#include <sys/queue.h> |
58#include <sys/pipe.h> |
|
58#define KERNEL 59#include <sys/file.h> 60#include <ufs/ufs/quota.h> 61#include <ufs/ufs/inode.h> 62#undef KERNEL 63#define NFS 64#include <sys/mount.h> 65#include <nfs/nfsproto.h> --- 70 unchanged lines hidden (view full) --- 136/* 137 * a kvm_read that returns true if everything is read 138 */ 139#define KVM_READ(kaddr, paddr, len) \ 140 (kvm_read(kd, (u_long)(kaddr), (char *)(paddr), (len)) == (len)) 141 142kvm_t *kd; 143 | 59#define KERNEL 60#include <sys/file.h> 61#include <ufs/ufs/quota.h> 62#include <ufs/ufs/inode.h> 63#undef KERNEL 64#define NFS 65#include <sys/mount.h> 66#include <nfs/nfsproto.h> --- 70 unchanged lines hidden (view full) --- 137/* 138 * a kvm_read that returns true if everything is read 139 */ 140#define KVM_READ(kaddr, paddr, len) \ 141 (kvm_read(kd, (u_long)(kaddr), (char *)(paddr), (len)) == (len)) 142 143kvm_t *kd; 144 |
144int ufs_filestat(), nfs_filestat(); 145void dofiles(), getinetproto(), socktrans(); 146void usage(), vtrans(); | 145void dofiles __P((struct kinfo_proc *kp)); 146void vtrans __P((struct vnode *vp, int i, int flag)); 147int ufs_filestat __P((struct vnode *vp, struct filestat *fsp)); 148int nfs_filestat __P((struct vnode *vp, struct filestat *fsp)); 149char *getmnton __P((struct mount *m)); 150void pipetrans __P((struct pipe *pi, int i, int flag)); 151void socktrans __P((struct socket *sock, int i)); 152void getinetproto __P((int number)); 153int getfname __P((char *filename)); 154void usage __P((void)); |
147 | 155 |
156 157int |
|
148main(argc, argv) 149 int argc; 150 char **argv; 151{ | 158main(argc, argv) 159 int argc; 160 char **argv; 161{ |
152 extern char *optarg; 153 extern int optind; | |
154 register struct passwd *passwd; 155 struct kinfo_proc *p, *plast; 156 int arg, ch, what; 157 char *memf, *nlistf; 158 int cnt; 159 160 arg = 0; 161 what = KERN_PROC_ALL; --- 131 unchanged lines hidden (view full) --- 293{ 294 int i, last; 295 struct file file; 296 struct filedesc0 filed0; 297#define filed filed0.fd_fd 298 struct proc *p = &kp->kp_proc; 299 struct eproc *ep = &kp->kp_eproc; 300 | 162 register struct passwd *passwd; 163 struct kinfo_proc *p, *plast; 164 int arg, ch, what; 165 char *memf, *nlistf; 166 int cnt; 167 168 arg = 0; 169 what = KERN_PROC_ALL; --- 131 unchanged lines hidden (view full) --- 301{ 302 int i, last; 303 struct file file; 304 struct filedesc0 filed0; 305#define filed filed0.fd_fd 306 struct proc *p = &kp->kp_proc; 307 struct eproc *ep = &kp->kp_eproc; 308 |
301 extern char *user_from_uid(); 302 | |
303 Uname = user_from_uid(ep->e_ucred.cr_uid, 0); 304 Pid = p->p_pid; 305 Comm = p->p_comm; 306 307 if (p->p_fd == NULL) 308 return; 309 if (!KVM_READ(p->p_fd, &filed0, sizeof (filed0))) { 310 dprintf(stderr, "can't read filedesc at %x for pid %d\n", --- 38 unchanged lines hidden (view full) --- 349 continue; 350 } 351 if (file.f_type == DTYPE_VNODE) 352 vtrans((struct vnode *)file.f_data, i, file.f_flag); 353 else if (file.f_type == DTYPE_SOCKET) { 354 if (checkfile == 0) 355 socktrans((struct socket *)file.f_data, i); 356 } | 309 Uname = user_from_uid(ep->e_ucred.cr_uid, 0); 310 Pid = p->p_pid; 311 Comm = p->p_comm; 312 313 if (p->p_fd == NULL) 314 return; 315 if (!KVM_READ(p->p_fd, &filed0, sizeof (filed0))) { 316 dprintf(stderr, "can't read filedesc at %x for pid %d\n", --- 38 unchanged lines hidden (view full) --- 355 continue; 356 } 357 if (file.f_type == DTYPE_VNODE) 358 vtrans((struct vnode *)file.f_data, i, file.f_flag); 359 else if (file.f_type == DTYPE_SOCKET) { 360 if (checkfile == 0) 361 socktrans((struct socket *)file.f_data, i); 362 } |
363#ifdef DTYPE_PIPE 364 else if (file.f_type == DTYPE_PIPE) { 365 if (checkfile == 0) 366 pipetrans((struct pipe *)file.f_data, i, 367 file.f_flag); 368 } 369#endif |
|
357 else { 358 dprintf(stderr, 359 "unknown file type %d for file %d of pid %d\n", 360 file.f_type, i, Pid); 361 } 362 } 363} 364 --- 189 unchanged lines hidden (view full) --- 554 mt->m = m; 555 bcopy(&mount.mnt_stat.f_mntonname[0], &mt->mntonname[0], MNAMELEN); 556 mt->next = mhead; 557 mhead = mt; 558 return (mt->mntonname); 559} 560 561void | 370 else { 371 dprintf(stderr, 372 "unknown file type %d for file %d of pid %d\n", 373 file.f_type, i, Pid); 374 } 375 } 376} 377 --- 189 unchanged lines hidden (view full) --- 567 mt->m = m; 568 bcopy(&mount.mnt_stat.f_mntonname[0], &mt->mntonname[0], MNAMELEN); 569 mt->next = mhead; 570 mhead = mt; 571 return (mt->mntonname); 572} 573 574void |
575pipetrans(pi, i, flag) 576 struct pipe *pi; 577 int i; 578 int flag; 579{ 580 struct pipe pip; 581 char rw[3]; 582 583 PREFIX(i); 584 585 /* fill in socket */ 586 if (!KVM_READ(pi, &pip, sizeof(struct pipe))) { 587 dprintf(stderr, "can't read pipe at %x\n", pi); 588 goto bad; 589 } 590 591 printf("* pipe %8x <-> %8x", (int)pi, (int)pip.pipe_peer); 592 printf(" %6d", (int)pip.pipe_buffer.cnt); 593 rw[0] = '\0'; 594 if (flag & FREAD) 595 strcat(rw, "r"); 596 if (flag & FWRITE) 597 strcat(rw, "w"); 598 printf(" %2s", rw); 599 putchar('\n'); 600 return; 601 602bad: 603 printf("* error\n"); 604} 605 606void |
|
562socktrans(sock, i) 563 struct socket *sock; 564 int i; 565{ 566 static char *stypename[] = { 567 "unused", /* 0 */ 568 "stream", /* 1 */ 569 "dgram", /* 2 */ --- 140 unchanged lines hidden (view full) --- 710 cp ="raw"; break; 711 default: 712 printf(" %d", number); 713 return; 714 } 715 printf(" %s", cp); 716} 717 | 607socktrans(sock, i) 608 struct socket *sock; 609 int i; 610{ 611 static char *stypename[] = { 612 "unused", /* 0 */ 613 "stream", /* 1 */ 614 "dgram", /* 2 */ --- 140 unchanged lines hidden (view full) --- 755 cp ="raw"; break; 756 default: 757 printf(" %d", number); 758 return; 759 } 760 printf(" %s", cp); 761} 762 |
763int |
|
718getfname(filename) 719 char *filename; 720{ 721 struct stat statbuf; 722 DEVS *cur; 723 724 if (stat(filename, &statbuf)) { 725 fprintf(stderr, "fstat: %s: %s\n", filename, strerror(errno)); --- 22 unchanged lines hidden --- | 764getfname(filename) 765 char *filename; 766{ 767 struct stat statbuf; 768 DEVS *cur; 769 770 if (stat(filename, &statbuf)) { 771 fprintf(stderr, "fstat: %s: %s\n", filename, strerror(errno)); --- 22 unchanged lines hidden --- |