BSD 4_3_Net_2 release
[unix-history] / usr / src / usr.bin / fstat / fstat.c
index fa0e48c..264851d 100644 (file)
@@ -2,19 +2,33 @@
  * Copyright (c) 1988 The Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1988 The Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted provided
- * that: (1) source distributions retain this entire copyright notice and
- * comment, and (2) distributions including binaries display the following
- * acknowledgement:  ``This product includes software developed by the
- * University of California, Berkeley and its contributors'' in the
- * documentation or other materials provided with the distribution and in
- * all advertising materials mentioning features or use of this software.
- * Neither the name of the University nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    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.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
@@ -24,27 +38,32 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)fstat.c    5.25 (Berkeley) 6/29/90";
+static char sccsid[] = "@(#)fstat.c    5.32 (Berkeley) 6/17/91";
 #endif /* not lint */
 
 /*
  *  fstat 
  */
 #endif /* not lint */
 
 /*
  *  fstat 
  */
-#include <machine/pte.h>
-
 #include <sys/param.h>
 #include <sys/param.h>
-#include <sys/user.h>
+#include <sys/time.h>
 #include <sys/proc.h>
 #include <sys/proc.h>
-#include <sys/text.h>
+#include <sys/user.h>
+#ifdef SPPWAIT
+#define NEWVM
+#endif
+#ifndef NEWVM
+#include <machine/pte.h>
+#include <sys/vmmac.h>
+#endif
 #include <sys/stat.h>
 #include <sys/stat.h>
-#include <sys/time.h>
 #include <sys/vnode.h>
 #include <sys/socket.h>
 #include <sys/socketvar.h>
 #include <sys/domain.h>
 #include <sys/protosw.h>
 #include <sys/unpcb.h>
 #include <sys/vnode.h>
 #include <sys/socket.h>
 #include <sys/socketvar.h>
 #include <sys/domain.h>
 #include <sys/protosw.h>
 #include <sys/unpcb.h>
-#include <sys/vmmac.h>
+#include <sys/kinfo.h>
+#include <sys/filedesc.h>
 #define        KERNEL
 #define NFS
 #include <sys/file.h>
 #define        KERNEL
 #define NFS
 #include <sys/file.h>
@@ -62,13 +81,15 @@ static char sccsid[] = "@(#)fstat.c 5.25 (Berkeley) 6/29/90";
 #include <netinet/ip.h>
 #include <netinet/in_pcb.h>
 
 #include <netinet/ip.h>
 #include <netinet/in_pcb.h>
 
+#include <errno.h>
+#include <nlist.h>
 #include <kvm.h>
 #include <kvm.h>
+#include <pwd.h>
+#include <stdio.h>
 #include <paths.h>
 #include <ctype.h>
 #include <paths.h>
 #include <ctype.h>
-#include <nlist.h>
-#include <pwd.h>
+#include <stdlib.h>
 #include <string.h>
 #include <string.h>
-#include <stdio.h>
 
 #define        TEXT    -1
 #define        CDIR    -2
 
 #define        TEXT    -1
 #define        CDIR    -2
@@ -106,30 +127,54 @@ int       vflg;   /* display errors in locating kernel data objects etc... */
 
 #define dprintf        if (vflg) fprintf
 
 
 #define dprintf        if (vflg) fprintf
 
-extern int errno;
-off_t lseek();
+struct file **ofiles;  /* buffer of pointers to file structures */
+int maxfiles;
+#define ALLOC_OFILES(d)        \
+       if ((d) > maxfiles) { \
+               free(ofiles); \
+               ofiles = malloc((d) * sizeof(struct file *)); \
+               if (ofiles == NULL) { \
+                       fprintf(stderr, "fstat: %s\n", strerror(errno)); \
+                       exit(1); \
+               } \
+               maxfiles = (d); \
+       }
+
+/*
+ * a kvm_read that returns true if everything is read 
+ */
+#define KVM_READ(kaddr, paddr, len) (kvm_read((kaddr), (paddr), (len)) == (len))
+
+void dofiles(), getinetproto(), socktrans(), nfs_filestat(), ufs_filestat();
+void usage(), vtrans();
 
 main(argc, argv)
        int argc;
        char **argv;
 {
 
 main(argc, argv)
        int argc;
        char **argv;
 {
-       register struct passwd *passwd;
-       int what = KINFO_PROC_ALL, arg = 0;
-       struct passwd *getpwnam(), *getpwuid();
-       struct proc *p;
        extern char *optarg;
        extern int optind;
        extern char *optarg;
        extern int optind;
-       int ch;
-       char *malloc();
-
+       register struct passwd *passwd;
+       struct proc *p;
+       int arg, ch, what;
+       char *namelist = NULL, *memfile = NULL;
 
 
-       while ((ch = getopt(argc, argv, "p:u:fnv")) != EOF)
+       arg = 0;
+       what = KINFO_PROC_ALL;
+       while ((ch = getopt(argc, argv, "fnp:u:vNM")) != EOF)
                switch((char)ch) {
                switch((char)ch) {
+               case 'f':
+                       fsflg = 1;
+                       break;
+               case 'n':
+                       nflg = 1;
+                       break;
                case 'p':
                        if (pflg++)
                                usage();
                        if (!isdigit(*optarg)) {
                case 'p':
                        if (pflg++)
                                usage();
                        if (!isdigit(*optarg)) {
-                               fputs("fstat: -p option requires a process id.\n", stderr);
+                               fprintf(stderr,
+                                   "fstat: -p requires a process id\n");
                                usage();
                        }
                        what = KINFO_PROC_PID;
                                usage();
                        }
                        what = KINFO_PROC_PID;
@@ -146,14 +191,14 @@ main(argc, argv)
                        what = KINFO_PROC_UID;
                        arg = passwd->pw_uid;
                        break;
                        what = KINFO_PROC_UID;
                        arg = passwd->pw_uid;
                        break;
-               case 'f':
-                       fsflg++;
+               case 'v':
+                       vflg = 1;
                        break;
                        break;
-               case 'n':
-                       nflg++;
+               case 'N':
+                       namelist = optarg;
                        break;
                        break;
-               case 'v':
-                       vflg++;
+               case 'M':
+                       memfile = optarg;
                        break;
                case '?':
                default:
                        break;
                case '?':
                default:
@@ -168,6 +213,9 @@ main(argc, argv)
                if (!checkfile) /* file(s) specified, but none accessable */
                        exit(1);
        }
                if (!checkfile) /* file(s) specified, but none accessable */
                        exit(1);
        }
+
+       ALLOC_OFILES(256);      /* reserve space for file pointers */
+
        if (fsflg && !checkfile) {      
                /* -f with no files means use wd */
                if (getfname(".") == 0)
        if (fsflg && !checkfile) {      
                /* -f with no files means use wd */
                if (getfname(".") == 0)
@@ -175,8 +223,7 @@ main(argc, argv)
                checkfile = 1;
        }
 
                checkfile = 1;
        }
 
-       /* modify the following to make work on dead kernels */
-       if (kvm_openfiles(NULL, NULL, NULL) == -1) {
+       if (kvm_openfiles(namelist, memfile, NULL) == -1) {
                fprintf(stderr, "fstat: %s\n", kvm_geterr());
                exit(1);
        }
                fprintf(stderr, "fstat: %s\n", kvm_geterr());
                exit(1);
        }
@@ -191,11 +238,13 @@ main(argc, argv)
                exit(1);
        }
        if (nflg)
                exit(1);
        }
        if (nflg)
-fputs("USER     CMD        PID   FD  DEV    INUM       MODE SZ|DV", stdout);
+               printf("%s",
+"USER     CMD          PID   FD  DEV    INUM       MODE SZ|DV");
        else
        else
-fputs("USER     CMD        PID   FD MOUNT      INUM MODE         SZ|DV", stdout);
+               printf("%s",
+"USER     CMD          PID   FD MOUNT      INUM MODE         SZ|DV");
        if (checkfile && fsflg == 0)
        if (checkfile && fsflg == 0)
-               fputs(" NAME\n", stdout);       
+               printf(" NAME\n");
        else
                putchar('\n');
 
        else
                putchar('\n');
 
@@ -210,19 +259,19 @@ fputs("USER     CMD        PID   FD MOUNT      INUM MODE         SZ|DV", stdout)
 char   *Uname, *Comm;
 int    Pid;
 
 char   *Uname, *Comm;
 int    Pid;
 
-#define PREFIX(i) printf("%-8.8s %-8.8s %5d", Uname, Comm, Pid); \
+#define PREFIX(i) printf("%-8.8s %-10s %5d", Uname, Comm, Pid); \
        switch(i) { \
        case TEXT: \
        switch(i) { \
        case TEXT: \
-               fputs(" text", stdout); \
+               printf(" text"); \
                break; \
        case CDIR: \
                break; \
        case CDIR: \
-               fputs("   wd", stdout); \
+               printf("   wd"); \
                break; \
        case RDIR: \
                break; \
        case RDIR: \
-               fputs(" root", stdout); \
+               printf(" root"); \
                break; \
        case TRACE: \
                break; \
        case TRACE: \
-               fputs("   tr", stdout); \
+               printf("   tr"); \
                break; \
        default: \
                printf(" %4d", i); \
                break; \
        default: \
                printf(" %4d", i); \
@@ -232,40 +281,67 @@ int       Pid;
 /*
  * print open files attributed to this process
  */
 /*
  * print open files attributed to this process
  */
+void
 dofiles(p)
        struct proc *p;
 {
 dofiles(p)
        struct proc *p;
 {
-       int i;
+       int i, last;
        struct file file;
        struct file file;
-       struct user *up = kvm_getu(p);
-       struct vnode *xvptr;
+#ifdef NEWVM
+       struct filedesc0 filed0;
+#define        filed   filed0.fd_fd
+       struct eproc *ep;
+#else
+       struct filedesc filed;
+#endif
+
        extern char *user_from_uid();
        extern char *user_from_uid();
+#ifndef NEWVM
+       struct vnode *xvptr;
+#endif
 
 
+#ifdef NEWVM
+       ep = kvm_geteproc(p);
+       Uname = user_from_uid(ep->e_ucred.cr_uid, 0);
+#else
        Uname = user_from_uid(p->p_uid, 0);
        Uname = user_from_uid(p->p_uid, 0);
+#endif
        Pid = p->p_pid;
        Comm = p->p_comm;
 
        Pid = p->p_pid;
        Comm = p->p_comm;
 
-       if (up == NULL) {
-               dprintf(stderr, "can't read u for pid %d\n", Pid);
+       if (p->p_fd == NULL)
+               return;
+#ifdef NEWVM
+       if (!KVM_READ(p->p_fd, &filed0, sizeof (filed0))) {
+               dprintf(stderr, "can't read filedesc at %x for pid %d\n",
+                       p->p_fd, Pid);
+               return;
+       }
+#else
+       if (!KVM_READ(p->p_fd, &filed, sizeof (filed))) {
+               dprintf(stderr, "can't read filedesc at %x for pid %d\n",
+                       p->p_fd, Pid);
                return;
        }
                return;
        }
+#endif
        /*
         * root directory vnode, if one
         */
        /*
         * root directory vnode, if one
         */
-       if (up->u_rdir)
-               vtrans(up->u_rdir, RDIR);
+       if (filed.fd_rdir)
+               vtrans(filed.fd_rdir, RDIR);
+#ifndef NEWVM
        /*
         * text vnode
         */
        if (p->p_textp && 
        /*
         * text vnode
         */
        if (p->p_textp && 
-           kvm_read(&(p->p_textp->x_vptr), &xvptr,
-           sizeof (struct vnode *)) == sizeof (struct vnode *) &&
+           KVM_READ(&(p->p_textp->x_vptr), &xvptr, sizeof (struct vnode *)) &&
            xvptr != NULL)
                vtrans(xvptr, TEXT);
            xvptr != NULL)
                vtrans(xvptr, TEXT);
+#endif
        /*
         * current working directory vnode
         */
        /*
         * current working directory vnode
         */
-       vtrans(up->u_cdir, CDIR);
+       vtrans(filed.fd_cdir, CDIR);
        /*
         * ktrace vnode, if one
         */
        /*
         * ktrace vnode, if one
         */
@@ -274,13 +350,35 @@ dofiles(p)
        /*
         * open files
         */
        /*
         * open files
         */
-       for (i = 0; i <= up->u_lastfile; i++) {
-               if (up->u_ofile[i] == 0)
+#define FPSIZE (sizeof (struct file *))
+       ALLOC_OFILES(filed.fd_lastfile);
+#ifdef NEWVM
+       if (filed.fd_nfiles > NDFILE) {
+               if (!KVM_READ(filed.fd_ofiles, ofiles,
+                   filed.fd_lastfile * FPSIZE)) {
+                       dprintf(stderr,
+                           "can't read file structures at %x for pid %d\n",
+                           filed.fd_ofiles, Pid);
+                       return;
+               }
+       } else
+               bcopy(filed0.fd_dfiles, ofiles, filed.fd_lastfile * FPSIZE);
+#else
+       bcopy(filed.fd_ofile, ofiles, MIN(filed.fd_lastfile, NDFILE) * FPSIZE);
+       last = filed.fd_lastfile;
+       if ((last > NDFILE) && !KVM_READ(filed.fd_moreofiles, &ofiles[NDFILE],
+           (last - NDFILE) * FPSIZE)) {
+               dprintf(stderr, "can't read rest of files at %x for pid %d\n",
+                       filed.fd_moreofiles, Pid);
+               return;
+       }
+#endif
+       for (i = 0; i <= filed.fd_lastfile; i++) {
+               if (ofiles[i] == NULL)
                        continue;
                        continue;
-               if (kvm_read(up->u_ofile[i], &file, sizeof (struct file)) !=
-                   sizeof (struct file)) {
-                       dprintf(stderr, "can't read file %d for pid %d\n",
-                               i, Pid);
+               if (!KVM_READ(ofiles[i], &file, sizeof (struct file))) {
+                       dprintf(stderr, "can't read file %d at %x for pid %d\n",
+                               i, ofiles[i], Pid);
                        continue;
                }
                if (file.f_type == DTYPE_VNODE)
                        continue;
                }
                if (file.f_type == DTYPE_VNODE)
@@ -295,19 +393,19 @@ dofiles(p)
        }
 }
 
        }
 }
 
+void
 vtrans(vp, i)
        struct vnode *vp;
 vtrans(vp, i)
        struct vnode *vp;
+       int i;
 {
 {
+       extern char *devname();
        struct vnode vn;
        struct filestat fst;
        struct vnode vn;
        struct filestat fst;
-       char *filename = NULL;
-       char *badtype = NULL;
-       char *getmnton();
-       extern char *devname();
        char mode[15];
        char mode[15];
+       char *badtype, *filename, *getmnton();
 
 
-       if (kvm_read((off_t)vp, &vn, sizeof (struct vnode)) != 
-           sizeof (struct vnode)) {
+       filename = badtype = NULL;
+       if (!KVM_READ(vp, &vn, sizeof (struct vnode))) {
                dprintf(stderr, "can't read vnode at %x for pid %d\n",
                        vp, Pid);
                return;
                dprintf(stderr, "can't read vnode at %x for pid %d\n",
                        vp, Pid);
                return;
@@ -385,6 +483,7 @@ vtrans(vp, i)
        putchar('\n');
 }
 
        putchar('\n');
 }
 
+void
 ufs_filestat(vp, fsp)
        struct vnode *vp;
        struct filestat *fsp;
 ufs_filestat(vp, fsp)
        struct vnode *vp;
        struct filestat *fsp;
@@ -398,6 +497,7 @@ ufs_filestat(vp, fsp)
        fsp->rdev = ip->i_rdev;
 }
 
        fsp->rdev = ip->i_rdev;
 }
 
+void
 nfs_filestat(vp, fsp)
        struct vnode *vp;
        struct filestat *fsp;
 nfs_filestat(vp, fsp)
        struct vnode *vp;
        struct filestat *fsp;
@@ -452,13 +552,12 @@ getmnton(m)
        for (mt = mhead; mt != NULL; mt = mt->next)
                if (m == mt->m)
                        return (mt->mntonname);
        for (mt = mhead; mt != NULL; mt = mt->next)
                if (m == mt->m)
                        return (mt->mntonname);
-       if (kvm_read((off_t)m, &mount, sizeof(struct mount)) != 
-           sizeof(struct mount)) {
+       if (!KVM_READ(m, &mount, sizeof(struct mount))) {
                fprintf(stderr, "can't read mount table at %x\n", m);
                return (NULL);
        }
                fprintf(stderr, "can't read mount table at %x\n", m);
                return (NULL);
        }
-       if ((mt = (struct mtab *)malloc(sizeof (struct mtab))) == NULL) {
-               fprintf(stderr, "out of memory\n");
+       if ((mt = malloc(sizeof (struct mtab))) == NULL) {
+               fprintf(stderr, "fstat: %s\n", strerror(errno));
                exit(1);
        }
        mt->m = m;
                exit(1);
        }
        mt->m = m;
@@ -468,8 +567,10 @@ getmnton(m)
        return (mt->mntonname);
 }
 
        return (mt->mntonname);
 }
 
+void
 socktrans(sock, i)
        struct socket *sock;
 socktrans(sock, i)
        struct socket *sock;
+       int i;
 {
        static char *stypename[] = {
                "unused",       /* 0 */
 {
        static char *stypename[] = {
                "unused",       /* 0 */
@@ -491,41 +592,31 @@ socktrans(sock, i)
        PREFIX(i);
 
        /* fill in socket */
        PREFIX(i);
 
        /* fill in socket */
-       if (kvm_read((off_t)sock, (char *)&so, sizeof(struct socket))
-           != sizeof(struct socket)) {
+       if (!KVM_READ(sock, &so, sizeof(struct socket))) {
                dprintf(stderr, "can't read sock at %x\n", sock);
                goto bad;
        }
 
        /* fill in protosw entry */
                dprintf(stderr, "can't read sock at %x\n", sock);
                goto bad;
        }
 
        /* fill in protosw entry */
-       if (kvm_read((off_t)so.so_proto, (char *)&proto, sizeof(struct protosw))
-           != sizeof(struct protosw)) {
+       if (!KVM_READ(so.so_proto, &proto, sizeof(struct protosw))) {
                dprintf(stderr, "can't read protosw at %x", so.so_proto);
                goto bad;
        }
 
        /* fill in domain */
                dprintf(stderr, "can't read protosw at %x", so.so_proto);
                goto bad;
        }
 
        /* fill in domain */
-       if (kvm_read((off_t)proto.pr_domain, (char *)&dom, sizeof(struct domain))
-           != 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);
                goto bad;
        }
 
                dprintf(stderr, "can't read domain at %x\n", proto.pr_domain);
                goto bad;
        }
 
-       /*
-        * grab domain name
-        * kludge "internet" --> "inet" for brevity
-        */
-       if (dom.dom_family == AF_INET)
-               strcpy(dname, "inet");
-       else {
-               if ((len = kvm_read((off_t)dom.dom_name, dname, sizeof(dname) - 1)) < 0) {
-                       dprintf(stderr, "can't read domain name at %x\n",
-                               dom.dom_name);
-                       dname[0] = '\0';
-               }
-               else
-                       dname[len] = '\0';
+       if ((len =
+           kvm_read(dom.dom_name, dname, sizeof(dname) - 1)) < 0) {
+               dprintf(stderr, "can't read domain name at %x\n",
+                       dom.dom_name);
+               dname[0] = '\0';
        }
        }
+       else
+               dname[len] = '\0';
 
        if ((u_short)so.so_type > STYPEMAX)
                printf("* %s ?%d", dname, so.so_type);
 
        if ((u_short)so.so_type > STYPEMAX)
                printf("* %s ?%d", dname, so.so_type);
@@ -548,10 +639,12 @@ socktrans(sock, i)
                getinetproto(proto.pr_protocol);
                if (proto.pr_protocol == IPPROTO_TCP ) {
                        if (so.so_pcb) {
                getinetproto(proto.pr_protocol);
                if (proto.pr_protocol == IPPROTO_TCP ) {
                        if (so.so_pcb) {
-                               if (kvm_read((off_t)so.so_pcb, (char *)&inpcb, sizeof(struct inpcb))
-                                   != sizeof(struct inpcb)){
+                               if (kvm_read(so.so_pcb, &inpcb,
+                                   sizeof(struct inpcb))
+                                   != sizeof(struct inpcb)) {
                                        dprintf(stderr, 
                                        dprintf(stderr, 
-                                            "can't read inpcb at %x\n", so.so_pcb);
+                                           "can't read inpcb at %x\n",
+                                           so.so_pcb);
                                        goto bad;
                                }
                                printf(" %x", (int)inpcb.inp_ppcb);
                                        goto bad;
                                }
                                printf(" %x", (int)inpcb.inp_ppcb);
@@ -564,10 +657,10 @@ socktrans(sock, i)
                /* print address of pcb and connected pcb */
                if (so.so_pcb) {
                        printf(" %x", (int)so.so_pcb);
                /* print address of pcb and connected pcb */
                if (so.so_pcb) {
                        printf(" %x", (int)so.so_pcb);
-                       if (kvm_read((off_t)so.so_pcb, (char *)&unpcb, sizeof(struct unpcb))
-                           != sizeof(struct unpcb)){
+                       if (kvm_read(so.so_pcb, &unpcb,
+                           sizeof(struct unpcb)) != sizeof(struct unpcb)){
                                dprintf(stderr, "can't read unpcb at %x\n",
                                dprintf(stderr, "can't read unpcb at %x\n",
-                                       so.so_pcb);
+                                   so.so_pcb);
                                goto bad;
                        }
                        if (unpcb.unp_conn) {
                                goto bad;
                        }
                        if (unpcb.unp_conn) {
@@ -599,6 +692,7 @@ bad:
  * getinetproto --
  *     print name of protocol number
  */
  * getinetproto --
  *     print name of protocol number
  */
+void
 getinetproto(number)
        int number;
 {
 getinetproto(number)
        int number;
 {
@@ -635,15 +729,14 @@ getfname(filename)
 {
        struct stat statbuf;
        DEVS *cur;
 {
        struct stat statbuf;
        DEVS *cur;
-       char *malloc();
 
        if (stat(filename, &statbuf)) {
                fprintf(stderr, "fstat: %s: %s\n", strerror(errno),
                    filename);
                return(0);
        }
 
        if (stat(filename, &statbuf)) {
                fprintf(stderr, "fstat: %s: %s\n", strerror(errno),
                    filename);
                return(0);
        }
-       if ((cur = (DEVS *)malloc(sizeof(DEVS))) == NULL) {
-               fprintf(stderr, "fstat: out of space.\n");
+       if ((cur = malloc(sizeof(DEVS))) == NULL) {
+               fprintf(stderr, "fstat: %s\n", strerror(errno));
                exit(1);
        }
        cur->next = devs;
                exit(1);
        }
        cur->next = devs;
@@ -655,9 +748,10 @@ getfname(filename)
        return(1);
 }
 
        return(1);
 }
 
+void
 usage()
 {
        (void)fprintf(stderr,
 usage()
 {
        (void)fprintf(stderr,
          "usage: fstat [-u user] [-p pid] [filename ...]\n");
"usage: fstat [-fnv] [-p pid] [-u user] [-N system] [-M core] [file ...]\n");
        exit(1);
 }
        exit(1);
 }