fstat.c (58125) | fstat.c (59029) |
---|---|
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 --- 28 unchanged lines hidden (view full) --- 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; 43#endif 44static const char rcsid[] = | 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 --- 28 unchanged lines hidden (view full) --- 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)fstat.c 8.3 (Berkeley) 5/2/95"; 43#endif 44static const char rcsid[] = |
45 "$FreeBSD: head/usr.bin/fstat/fstat.c 58125 2000-03-16 02:02:34Z green $"; | 45 "$FreeBSD: head/usr.bin/fstat/fstat.c 59029 2000-04-05 05:45:40Z green $"; |
46#endif /* not lint */ 47 48#include <sys/param.h> 49#include <sys/time.h> 50#include <sys/proc.h> 51#include <sys/user.h> 52#include <sys/stat.h> 53#include <sys/vnode.h> --- 15 unchanged lines hidden (view full) --- 69#undef _KERNEL 70#include <sys/mount.h> 71#include <nfs/nfsproto.h> 72#include <nfs/rpcv2.h> 73#include <nfs/nfs.h> 74#include <nfs/nfsnode.h> 75 76 | 46#endif /* not lint */ 47 48#include <sys/param.h> 49#include <sys/time.h> 50#include <sys/proc.h> 51#include <sys/user.h> 52#include <sys/stat.h> 53#include <sys/vnode.h> --- 15 unchanged lines hidden (view full) --- 69#undef _KERNEL 70#include <sys/mount.h> 71#include <nfs/nfsproto.h> 72#include <nfs/rpcv2.h> 73#include <nfs/nfs.h> 74#include <nfs/nfsnode.h> 75 76 |
77#include <vm/vm.h> 78#include <vm/vm_map.h> 79#include <vm/vm_object.h> 80 |
|
77#include <net/route.h> 78#include <netinet/in.h> 79#include <netinet/in_systm.h> 80#include <netinet/ip.h> 81#include <netinet/in_pcb.h> 82 83#include <ctype.h> 84#include <err.h> --- 10 unchanged lines hidden (view full) --- 95#include <netdb.h> 96 97#include "fstat.h" 98 99#define TEXT -1 100#define CDIR -2 101#define RDIR -3 102#define TRACE -4 | 81#include <net/route.h> 82#include <netinet/in.h> 83#include <netinet/in_systm.h> 84#include <netinet/ip.h> 85#include <netinet/in_pcb.h> 86 87#include <ctype.h> 88#include <err.h> --- 10 unchanged lines hidden (view full) --- 99#include <netdb.h> 100 101#include "fstat.h" 102 103#define TEXT -1 104#define CDIR -2 105#define RDIR -3 106#define TRACE -4 |
107#define MMAP -5 |
|
103 104DEVS *devs; 105 106#ifdef notdef 107struct nlist nl[] = { 108 { "" }, 109}; 110#endif 111 112int fsflg, /* show files on same filesystem as file(s) argument */ 113 pflg, /* show files open by a particular pid */ 114 uflg; /* show files open by a particular (effective) user */ 115int checkfile; /* true if restricting to particular files or filesystems */ 116int nflg; /* (numerical) display f.s. and rdev as dev_t */ 117int vflg; /* display errors in locating kernel data objects etc... */ | 108 109DEVS *devs; 110 111#ifdef notdef 112struct nlist nl[] = { 113 { "" }, 114}; 115#endif 116 117int fsflg, /* show files on same filesystem as file(s) argument */ 118 pflg, /* show files open by a particular pid */ 119 uflg; /* show files open by a particular (effective) user */ 120int checkfile; /* true if restricting to particular files or filesystems */ 121int nflg; /* (numerical) display f.s. and rdev as dev_t */ 122int vflg; /* display errors in locating kernel data objects etc... */ |
123int mflg; /* include memory-mapped files */ |
|
118 119 120struct file **ofiles; /* buffer of pointers to file structures */ 121int maxfiles; 122#define ALLOC_OFILES(d) \ 123 if ((d) > maxfiles) { \ 124 free(ofiles); \ 125 ofiles = malloc((d) * sizeof(struct file *)); \ 126 if (ofiles == NULL) { \ 127 err(1, NULL); \ 128 } \ 129 maxfiles = (d); \ 130 } 131 132kvm_t *kd; 133 134void dofiles __P((struct kinfo_proc *kp)); | 124 125 126struct file **ofiles; /* buffer of pointers to file structures */ 127int maxfiles; 128#define ALLOC_OFILES(d) \ 129 if ((d) > maxfiles) { \ 130 free(ofiles); \ 131 ofiles = malloc((d) * sizeof(struct file *)); \ 132 if (ofiles == NULL) { \ 133 err(1, NULL); \ 134 } \ 135 maxfiles = (d); \ 136 } 137 138kvm_t *kd; 139 140void dofiles __P((struct kinfo_proc *kp)); |
141void dommap __P((struct kinfo_proc *kp)); |
|
135void vtrans __P((struct vnode *vp, int i, int flag)); 136int ufs_filestat __P((struct vnode *vp, struct filestat *fsp)); 137int nfs_filestat __P((struct vnode *vp, struct filestat *fsp)); 138char *getmnton __P((struct mount *m)); 139void pipetrans __P((struct pipe *pi, int i, int flag)); 140void socktrans __P((struct socket *sock, int i)); 141void getinetproto __P((int number)); 142int getfname __P((char *filename)); --- 10 unchanged lines hidden (view full) --- 153 int arg, ch, what; 154 char *memf, *nlistf; 155 char buf[_POSIX2_LINE_MAX]; 156 int cnt; 157 158 arg = 0; 159 what = KERN_PROC_ALL; 160 nlistf = memf = NULL; | 142void vtrans __P((struct vnode *vp, int i, int flag)); 143int ufs_filestat __P((struct vnode *vp, struct filestat *fsp)); 144int nfs_filestat __P((struct vnode *vp, struct filestat *fsp)); 145char *getmnton __P((struct mount *m)); 146void pipetrans __P((struct pipe *pi, int i, int flag)); 147void socktrans __P((struct socket *sock, int i)); 148void getinetproto __P((int number)); 149int getfname __P((char *filename)); --- 10 unchanged lines hidden (view full) --- 160 int arg, ch, what; 161 char *memf, *nlistf; 162 char buf[_POSIX2_LINE_MAX]; 163 int cnt; 164 165 arg = 0; 166 what = KERN_PROC_ALL; 167 nlistf = memf = NULL; |
161 while ((ch = getopt(argc, argv, "fnp:u:vN:M:")) != -1) | 168 while ((ch = getopt(argc, argv, "fmnp:u:vN:M:")) != -1) |
162 switch((char)ch) { 163 case 'f': 164 fsflg = 1; 165 break; 166 case 'M': 167 memf = optarg; 168 break; 169 case 'N': 170 nlistf = optarg; 171 break; | 169 switch((char)ch) { 170 case 'f': 171 fsflg = 1; 172 break; 173 case 'M': 174 memf = optarg; 175 break; 176 case 'N': 177 nlistf = optarg; 178 break; |
179 case 'm': 180 mflg = 1; 181 break; |
|
172 case 'n': 173 nflg = 1; 174 break; 175 case 'p': 176 if (pflg++) 177 usage(); 178 if (!isdigit(*optarg)) { 179 warnx("-p requires a process id"); --- 61 unchanged lines hidden (view full) --- 241 printf(" NAME\n"); 242 else 243 putchar('\n'); 244 245 for (plast = &p[cnt]; p < plast; ++p) { 246 if (p->kp_proc.p_stat == SZOMB) 247 continue; 248 dofiles(p); | 182 case 'n': 183 nflg = 1; 184 break; 185 case 'p': 186 if (pflg++) 187 usage(); 188 if (!isdigit(*optarg)) { 189 warnx("-p requires a process id"); --- 61 unchanged lines hidden (view full) --- 251 printf(" NAME\n"); 252 else 253 putchar('\n'); 254 255 for (plast = &p[cnt]; p < plast; ++p) { 256 if (p->kp_proc.p_stat == SZOMB) 257 continue; 258 dofiles(p); |
259 if (mflg) 260 dommap(p); |
|
249 } 250 exit(0); 251} 252 253char *Uname, *Comm; 254int Pid; 255 256#define PREFIX(i) printf("%-8.8s %-10s %5d", Uname, Comm, Pid); \ --- 5 unchanged lines hidden (view full) --- 262 printf(" wd"); \ 263 break; \ 264 case RDIR: \ 265 printf(" root"); \ 266 break; \ 267 case TRACE: \ 268 printf(" tr"); \ 269 break; \ | 261 } 262 exit(0); 263} 264 265char *Uname, *Comm; 266int Pid; 267 268#define PREFIX(i) printf("%-8.8s %-10s %5d", Uname, Comm, Pid); \ --- 5 unchanged lines hidden (view full) --- 274 printf(" wd"); \ 275 break; \ 276 case RDIR: \ 277 printf(" root"); \ 278 break; \ 279 case TRACE: \ 280 printf(" tr"); \ 281 break; \ |
282 case MMAP: \ 283 printf(" mmap"); \ 284 break; \ |
|
270 default: \ 271 printf(" %4d", i); \ 272 break; \ 273 } 274 275/* 276 * print open files attributed to this process 277 */ --- 78 unchanged lines hidden (view full) --- 356 dprintf(stderr, 357 "unknown file type %d for file %d of pid %d\n", 358 file.f_type, i, Pid); 359 } 360 } 361} 362 363void | 285 default: \ 286 printf(" %4d", i); \ 287 break; \ 288 } 289 290/* 291 * print open files attributed to this process 292 */ --- 78 unchanged lines hidden (view full) --- 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 378void |
379dommap(kp) 380 struct kinfo_proc *kp; 381{ 382 struct proc *p = &kp->kp_proc; 383 struct vmspace vmspace; 384 vm_map_t map; 385 struct vm_map_entry entry; 386 vm_map_entry_t entryp; 387 struct vm_object object; 388 vm_object_t objp; 389 int prot, fflags; 390 391 if (!KVM_READ(p->p_vmspace, &vmspace, sizeof(vmspace))) { 392 dprintf(stderr, "can't read vmspace at %p for pid %d\n", 393 (void *)p->p_vmspace, Pid); 394 return; 395 } 396 397 map = &vmspace.vm_map; 398 399 for (entryp = map->header.next; entryp != &p->p_vmspace->vm_map.header; 400 entryp = entry.next) { 401 if (!KVM_READ(entryp, &entry, sizeof(entry))) { 402 dprintf(stderr, 403 "can't read vm_map_entry at %p for pid %d\n", 404 (void *)entryp, Pid); 405 return; 406 } 407 408 if (entry.eflags & MAP_ENTRY_IS_SUB_MAP) 409 continue; 410 411 if ((objp = entry.object.vm_object) == NULL) 412 continue; 413 414 for (; objp; objp = object.backing_object) { 415 if (!KVM_READ(objp, &object, sizeof(object))) { 416 dprintf(stderr, 417 "can't read vm_object at %p for pid %d\n", 418 (void *)objp, Pid); 419 return; 420 } 421 } 422 423 prot = entry.protection; 424 fflags = (prot & VM_PROT_READ ? FREAD : 0) | 425 (prot & VM_PROT_WRITE ? FWRITE : 0); 426 427 switch (object.type) { 428 case OBJT_VNODE: 429 vtrans((struct vnode *)object.handle, MMAP, fflags); 430 break; 431 default: 432 break; 433 } 434 } 435} 436 437void |
|
364vtrans(vp, i, flag) 365 struct vnode *vp; 366 int i; 367 int flag; 368{ 369 struct vnode vn; 370 struct filestat fst; 371 char rw[3], mode[15]; --- 417 unchanged lines hidden (view full) --- 789 cur->name = filename; 790 return(1); 791} 792 793void 794usage() 795{ 796 (void)fprintf(stderr, | 438vtrans(vp, i, flag) 439 struct vnode *vp; 440 int i; 441 int flag; 442{ 443 struct vnode vn; 444 struct filestat fst; 445 char rw[3], mode[15]; --- 417 unchanged lines hidden (view full) --- 863 cur->name = filename; 864 return(1); 865} 866 867void 868usage() 869{ 870 (void)fprintf(stderr, |
797 "usage: fstat [-fnv] [-p pid] [-u user] [-N system] [-M core] [file ...]\n"); | 871 "usage: fstat [-fmnv] [-p pid] [-u user] [-N system] [-M core] [file ...]\n"); |
798 exit(1); 799} | 872 exit(1); 873} |