fstat.c revision 58125
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 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35static const char copyright[] = 36"@(#) Copyright (c) 1988, 1993\n\ 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 $"; 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> 54#include <sys/socket.h> 55#include <sys/socketvar.h> 56#include <sys/domain.h> 57#include <sys/protosw.h> 58#include <sys/un.h> 59#include <sys/unpcb.h> 60#include <sys/sysctl.h> 61#include <sys/filedesc.h> 62#include <sys/queue.h> 63#include <sys/pipe.h> 64#include <sys/conf.h> 65#define _KERNEL 66#include <sys/file.h> 67#include <ufs/ufs/quota.h> 68#include <ufs/ufs/inode.h> 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 <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> 85#include <fcntl.h> 86#include <kvm.h> 87#include <limits.h> 88#include <nlist.h> 89#include <paths.h> 90#include <pwd.h> 91#include <stdio.h> 92#include <stdlib.h> 93#include <string.h> 94#include <unistd.h> 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 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... */ 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)); 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)); 143void usage __P((void)); 144 145 146int 147main(argc, argv) 148 int argc; 149 char **argv; 150{ 151 register struct passwd *passwd; 152 struct kinfo_proc *p, *plast; 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; 161 while ((ch = getopt(argc, argv, "fnp: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; 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"); 180 usage(); 181 } 182 what = KERN_PROC_PID; 183 arg = atoi(optarg); 184 break; 185 case 'u': 186 if (uflg++) 187 usage(); 188 if (!(passwd = getpwnam(optarg))) 189 errx(1, "%s: unknown uid", optarg); 190 what = KERN_PROC_UID; 191 arg = passwd->pw_uid; 192 break; 193 case 'v': 194 vflg = 1; 195 break; 196 case '?': 197 default: 198 usage(); 199 } 200 201 if (*(argv += optind)) { 202 for (; *argv; ++argv) { 203 if (getfname(*argv)) 204 checkfile = 1; 205 } 206 if (!checkfile) /* file(s) specified, but none accessable */ 207 exit(1); 208 } 209 210 ALLOC_OFILES(256); /* reserve space for file pointers */ 211 212 if (fsflg && !checkfile) { 213 /* -f with no files means use wd */ 214 if (getfname(".") == 0) 215 exit(1); 216 checkfile = 1; 217 } 218 219 /* 220 * Discard setgid privileges if not the running kernel so that bad 221 * guys can't print interesting stuff from kernel memory. 222 */ 223 if (nlistf != NULL || memf != NULL) 224 setgid(getgid()); 225 226 if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf)) == NULL) 227 errx(1, "%s", buf); 228#ifdef notdef 229 if (kvm_nlist(kd, nl) != 0) 230 errx(1, "no namelist: %s", kvm_geterr(kd)); 231#endif 232 if ((p = kvm_getprocs(kd, what, arg, &cnt)) == NULL) 233 errx(1, "%s", kvm_geterr(kd)); 234 if (nflg) 235 printf("%s", 236"USER CMD PID FD DEV INUM MODE SZ|DV R/W"); 237 else 238 printf("%s", 239"USER CMD PID FD MOUNT INUM MODE SZ|DV R/W"); 240 if (checkfile && fsflg == 0) 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); 249 } 250 exit(0); 251} 252 253char *Uname, *Comm; 254int Pid; 255 256#define PREFIX(i) printf("%-8.8s %-10s %5d", Uname, Comm, Pid); \ 257 switch(i) { \ 258 case TEXT: \ 259 printf(" text"); \ 260 break; \ 261 case CDIR: \ 262 printf(" wd"); \ 263 break; \ 264 case RDIR: \ 265 printf(" root"); \ 266 break; \ 267 case TRACE: \ 268 printf(" tr"); \ 269 break; \ 270 default: \ 271 printf(" %4d", i); \ 272 break; \ 273 } 274 275/* 276 * print open files attributed to this process 277 */ 278void 279dofiles(kp) 280 struct kinfo_proc *kp; 281{ 282 int i; 283 struct file file; 284 struct filedesc0 filed0; 285#define filed filed0.fd_fd 286 struct proc *p = &kp->kp_proc; 287 struct eproc *ep = &kp->kp_eproc; 288 289 Uname = user_from_uid(ep->e_ucred.cr_uid, 0); 290 Pid = p->p_pid; 291 Comm = p->p_comm; 292 293 if (p->p_fd == NULL) 294 return; 295 if (!KVM_READ(p->p_fd, &filed0, sizeof (filed0))) { 296 dprintf(stderr, "can't read filedesc at %p for pid %d\n", 297 (void *)p->p_fd, Pid); 298 return; 299 } 300 /* 301 * root directory vnode, if one 302 */ 303 if (filed.fd_rdir) 304 vtrans(filed.fd_rdir, RDIR, FREAD); 305 /* 306 * current working directory vnode 307 */ 308 vtrans(filed.fd_cdir, CDIR, FREAD); 309 /* 310 * ktrace vnode, if one 311 */ 312 if (p->p_tracep) 313 vtrans(p->p_tracep, TRACE, FREAD|FWRITE); 314 /* 315 * text vnode, if one 316 */ 317 if (p->p_textvp) 318 vtrans(p->p_textvp, TEXT, FREAD); 319 /* 320 * open files 321 */ 322#define FPSIZE (sizeof (struct file *)) 323 ALLOC_OFILES(filed.fd_lastfile+1); 324 if (filed.fd_nfiles > NDFILE) { 325 if (!KVM_READ(filed.fd_ofiles, ofiles, 326 (filed.fd_lastfile+1) * FPSIZE)) { 327 dprintf(stderr, 328 "can't read file structures at %p for pid %d\n", 329 (void *)filed.fd_ofiles, Pid); 330 return; 331 } 332 } else 333 bcopy(filed0.fd_dfiles, ofiles, (filed.fd_lastfile+1) * FPSIZE); 334 for (i = 0; i <= filed.fd_lastfile; i++) { 335 if (ofiles[i] == NULL) 336 continue; 337 if (!KVM_READ(ofiles[i], &file, sizeof (struct file))) { 338 dprintf(stderr, "can't read file %d at %p for pid %d\n", 339 i, (void *)ofiles[i], Pid); 340 continue; 341 } 342 if (file.f_type == DTYPE_VNODE) 343 vtrans((struct vnode *)file.f_data, i, file.f_flag); 344 else if (file.f_type == DTYPE_SOCKET) { 345 if (checkfile == 0) 346 socktrans((struct socket *)file.f_data, i); 347 } 348#ifdef DTYPE_PIPE 349 else if (file.f_type == DTYPE_PIPE) { 350 if (checkfile == 0) 351 pipetrans((struct pipe *)file.f_data, i, 352 file.f_flag); 353 } 354#endif 355 else { 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 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]; 372 char *badtype = NULL, *filename, *getmnton(); 373 374 filename = badtype = NULL; 375 if (!KVM_READ(vp, &vn, sizeof (struct vnode))) { 376 dprintf(stderr, "can't read vnode at %p for pid %d\n", 377 (void *)vp, Pid); 378 return; 379 } 380 if (vn.v_type == VNON || vn.v_tag == VT_NON) 381 badtype = "none"; 382 else if (vn.v_type == VBAD) 383 badtype = "bad"; 384 else 385 switch (vn.v_tag) { 386 case VT_UFS: 387 if (!ufs_filestat(&vn, &fst)) 388 badtype = "error"; 389 break; 390 case VT_MFS: 391 if (!ufs_filestat(&vn, &fst)) 392 badtype = "error"; 393 break; 394 case VT_NFS: 395 if (!nfs_filestat(&vn, &fst)) 396 badtype = "error"; 397 break; 398 399 case VT_MSDOSFS: 400 if (!msdosfs_filestat(&vn, &fst)) 401 badtype = "error"; 402 break; 403 404 case VT_ISOFS: 405 if (!isofs_filestat(&vn, &fst)) 406 badtype = "error"; 407 break; 408 409 default: { 410 static char unknown[10]; 411 sprintf(badtype = unknown, "?(%x)", vn.v_tag); 412 break;; 413 } 414 } 415 if (checkfile) { 416 int fsmatch = 0; 417 register DEVS *d; 418 419 if (badtype) 420 return; 421 for (d = devs; d != NULL; d = d->next) 422 if (d->fsid == fst.fsid) { 423 fsmatch = 1; 424 if (d->ino == fst.fileid) { 425 filename = d->name; 426 break; 427 } 428 } 429 if (fsmatch == 0 || (filename == NULL && fsflg == 0)) 430 return; 431 } 432 PREFIX(i); 433 if (badtype) { 434 (void)printf(" - - %10s -\n", badtype); 435 return; 436 } 437 if (nflg) 438 (void)printf(" %2d,%-2d", major(fst.fsid), minor(fst.fsid)); 439 else 440 (void)printf(" %-8s", getmnton(vn.v_mount)); 441 if (nflg) 442 (void)sprintf(mode, "%o", fst.mode); 443 else 444 strmode(fst.mode, mode); 445 (void)printf(" %6ld %10s", fst.fileid, mode); 446 switch (vn.v_type) { 447 case VBLK: 448 case VCHR: { 449 char *name; 450 451 if (nflg || ((name = devname(fst.rdev, vn.v_type == VCHR ? 452 S_IFCHR : S_IFBLK)) == NULL)) 453 printf(" %2d,%-2d", major(fst.rdev), minor(fst.rdev)); 454 else 455 printf(" %6s", name); 456 break; 457 } 458 default: 459 printf(" %6lu", fst.size); 460 } 461 rw[0] = '\0'; 462 if (flag & FREAD) 463 strcat(rw, "r"); 464 if (flag & FWRITE) 465 strcat(rw, "w"); 466 printf(" %2s", rw); 467 if (filename && !fsflg) 468 printf(" %s", filename); 469 putchar('\n'); 470} 471 472int 473ufs_filestat(vp, fsp) 474 struct vnode *vp; 475 struct filestat *fsp; 476{ 477 struct inode inode; 478 479 if (!KVM_READ(VTOI(vp), &inode, sizeof (inode))) { 480 dprintf(stderr, "can't read inode at %p for pid %d\n", 481 (void *)VTOI(vp), Pid); 482 return 0; 483 } 484 /* 485 * The st_dev from stat(2) is a udev_t. These kernel structures 486 * contain dev_t structures. We need to convert to udev to make 487 * comparisons 488 */ 489 fsp->fsid = dev2udev(inode.i_dev) & 0xffff; 490 fsp->fileid = (long)inode.i_number; 491 fsp->mode = (mode_t)inode.i_mode; 492 fsp->size = (u_long)inode.i_size; 493 fsp->rdev = inode.i_rdev; 494 495 return 1; 496} 497 498int 499nfs_filestat(vp, fsp) 500 struct vnode *vp; 501 struct filestat *fsp; 502{ 503 struct nfsnode nfsnode; 504 register mode_t mode; 505 506 if (!KVM_READ(VTONFS(vp), &nfsnode, sizeof (nfsnode))) { 507 dprintf(stderr, "can't read nfsnode at %p for pid %d\n", 508 (void *)VTONFS(vp), Pid); 509 return 0; 510 } 511 fsp->fsid = nfsnode.n_vattr.va_fsid; 512 fsp->fileid = nfsnode.n_vattr.va_fileid; 513 fsp->size = nfsnode.n_size; 514 fsp->rdev = nfsnode.n_vattr.va_rdev; 515 mode = (mode_t)nfsnode.n_vattr.va_mode; 516 switch (vp->v_type) { 517 case VREG: 518 mode |= S_IFREG; 519 break; 520 case VDIR: 521 mode |= S_IFDIR; 522 break; 523 case VBLK: 524 mode |= S_IFBLK; 525 break; 526 case VCHR: 527 mode |= S_IFCHR; 528 break; 529 case VLNK: 530 mode |= S_IFLNK; 531 break; 532 case VSOCK: 533 mode |= S_IFSOCK; 534 break; 535 case VFIFO: 536 mode |= S_IFIFO; 537 break; 538 case VNON: 539 case VBAD: 540 return 0; 541 }; 542 fsp->mode = mode; 543 544 return 1; 545} 546 547 548char * 549getmnton(m) 550 struct mount *m; 551{ 552 static struct mount mount; 553 static struct mtab { 554 struct mtab *next; 555 struct mount *m; 556 char mntonname[MNAMELEN]; 557 } *mhead = NULL; 558 register struct mtab *mt; 559 560 for (mt = mhead; mt != NULL; mt = mt->next) 561 if (m == mt->m) 562 return (mt->mntonname); 563 if (!KVM_READ(m, &mount, sizeof(struct mount))) { 564 warnx("can't read mount table at %p", (void *)m); 565 return (NULL); 566 } 567 if ((mt = malloc(sizeof (struct mtab))) == NULL) 568 err(1, NULL); 569 mt->m = m; 570 bcopy(&mount.mnt_stat.f_mntonname[0], &mt->mntonname[0], MNAMELEN); 571 mt->next = mhead; 572 mhead = mt; 573 return (mt->mntonname); 574} 575 576void 577pipetrans(pi, i, flag) 578 struct pipe *pi; 579 int i; 580 int flag; 581{ 582 struct pipe pip; 583 char rw[3]; 584 585 PREFIX(i); 586 587 /* fill in socket */ 588 if (!KVM_READ(pi, &pip, sizeof(struct pipe))) { 589 dprintf(stderr, "can't read pipe at %p\n", (void *)pi); 590 goto bad; 591 } 592 593 printf("* pipe %8x <-> %8x", (int)pi, (int)pip.pipe_peer); 594 printf(" %6d", (int)pip.pipe_buffer.cnt); 595 rw[0] = '\0'; 596 if (flag & FREAD) 597 strcat(rw, "r"); 598 if (flag & FWRITE) 599 strcat(rw, "w"); 600 printf(" %2s", rw); 601 putchar('\n'); 602 return; 603 604bad: 605 printf("* error\n"); 606} 607 608void 609socktrans(sock, i) 610 struct socket *sock; 611 int i; 612{ 613 static char *stypename[] = { 614 "unused", /* 0 */ 615 "stream", /* 1 */ 616 "dgram", /* 2 */ 617 "raw", /* 3 */ 618 "rdm", /* 4 */ 619 "seqpak" /* 5 */ 620 }; 621#define STYPEMAX 5 622 struct socket so; 623 struct protosw proto; 624 struct domain dom; 625 struct inpcb inpcb; 626 struct unpcb unpcb; 627 int len; 628 char dname[32], *strcpy(); 629 630 PREFIX(i); 631 632 /* fill in socket */ 633 if (!KVM_READ(sock, &so, sizeof(struct socket))) { 634 dprintf(stderr, "can't read sock at %p\n", (void *)sock); 635 goto bad; 636 } 637 638 /* fill in protosw entry */ 639 if (!KVM_READ(so.so_proto, &proto, sizeof(struct protosw))) { 640 dprintf(stderr, "can't read protosw at %p", 641 (void *)so.so_proto); 642 goto bad; 643 } 644 645 /* fill in domain */ 646 if (!KVM_READ(proto.pr_domain, &dom, sizeof(struct domain))) { 647 dprintf(stderr, "can't read domain at %p\n", 648 (void *)proto.pr_domain); 649 goto bad; 650 } 651 652 if ((len = kvm_read(kd, (u_long)dom.dom_name, dname, 653 sizeof(dname) - 1)) < 0) { 654 dprintf(stderr, "can't read domain name at %p\n", 655 (void *)dom.dom_name); 656 dname[0] = '\0'; 657 } 658 else 659 dname[len] = '\0'; 660 661 if ((u_short)so.so_type > STYPEMAX) 662 printf("* %s ?%d", dname, so.so_type); 663 else 664 printf("* %s %s", dname, stypename[so.so_type]); 665 666 /* 667 * protocol specific formatting 668 * 669 * Try to find interesting things to print. For tcp, the interesting 670 * thing is the address of the tcpcb, for udp and others, just the 671 * inpcb (socket pcb). For unix domain, its the address of the socket 672 * pcb and the address of the connected pcb (if connected). Otherwise 673 * just print the protocol number and address of the socket itself. 674 * The idea is not to duplicate netstat, but to make available enough 675 * information for further analysis. 676 */ 677 switch(dom.dom_family) { 678 case AF_INET: 679 case AF_INET6: 680 getinetproto(proto.pr_protocol); 681 if (proto.pr_protocol == IPPROTO_TCP ) { 682 if (so.so_pcb) { 683 if (kvm_read(kd, (u_long)so.so_pcb, 684 (char *)&inpcb, sizeof(struct inpcb)) 685 != sizeof(struct inpcb)) { 686 dprintf(stderr, 687 "can't read inpcb at %p\n", 688 (void *)so.so_pcb); 689 goto bad; 690 } 691 printf(" %x", (int)inpcb.inp_ppcb); 692 } 693 } 694 else if (so.so_pcb) 695 printf(" %x", (int)so.so_pcb); 696 break; 697 case AF_UNIX: 698 /* print address of pcb and connected pcb */ 699 if (so.so_pcb) { 700 printf(" %x", (int)so.so_pcb); 701 if (kvm_read(kd, (u_long)so.so_pcb, (char *)&unpcb, 702 sizeof(struct unpcb)) != sizeof(struct unpcb)){ 703 dprintf(stderr, "can't read unpcb at %p\n", 704 (void *)so.so_pcb); 705 goto bad; 706 } 707 if (unpcb.unp_conn) { 708 char shoconn[4], *cp; 709 710 cp = shoconn; 711 if (!(so.so_state & SS_CANTRCVMORE)) 712 *cp++ = '<'; 713 *cp++ = '-'; 714 if (!(so.so_state & SS_CANTSENDMORE)) 715 *cp++ = '>'; 716 *cp = '\0'; 717 printf(" %s %x", shoconn, 718 (int)unpcb.unp_conn); 719 } 720 } 721 break; 722 default: 723 /* print protocol number and socket address */ 724 printf(" %d %x", proto.pr_protocol, (int)sock); 725 } 726 printf("\n"); 727 return; 728bad: 729 printf("* error\n"); 730} 731 732 733/* 734 * Read the specinfo structure in the kernel (as pointed to by a dev_t) 735 * in order to work out the associated udev_t 736 */ 737udev_t 738dev2udev(dev) 739 dev_t dev; 740{ 741 struct specinfo si; 742 743 if (KVM_READ(dev, &si, sizeof si)) { 744 return si.si_udev; 745 } else { 746 dprintf(stderr, "can't convert dev_t %p to a udev_t\n", 747 (void *)dev); 748 return -1; 749 } 750} 751 752/* 753 * getinetproto -- 754 * print name of protocol number 755 */ 756void 757getinetproto(number) 758 int number; 759{ 760 static int isopen; 761 register struct protoent *pe; 762 763 if (!isopen) 764 setprotoent(++isopen); 765 if ((pe = getprotobynumber(number)) != NULL) 766 printf(" %s", pe->p_name); 767 else 768 printf(" %d", number); 769} 770 771int 772getfname(filename) 773 char *filename; 774{ 775 struct stat statbuf; 776 DEVS *cur; 777 778 if (stat(filename, &statbuf)) { 779 warn("%s", filename); 780 return(0); 781 } 782 if ((cur = malloc(sizeof(DEVS))) == NULL) 783 err(1, NULL); 784 cur->next = devs; 785 devs = cur; 786 787 cur->ino = statbuf.st_ino; 788 cur->fsid = statbuf.st_dev & 0xffff; 789 cur->name = filename; 790 return(1); 791} 792 793void 794usage() 795{ 796 (void)fprintf(stderr, 797 "usage: fstat [-fnv] [-p pid] [-u user] [-N system] [-M core] [file ...]\n"); 798 exit(1); 799} 800