BSD 4_4_Lite2 release
[unix-history] / usr / src / sbin / quotacheck / quotacheck.c
index e4af62e..31c94d1 100644 (file)
@@ -1,52 +1,81 @@
 /*
 /*
- * Copyright (c) 1980, 1990 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1990, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * Robert Elz at The University of Melbourne.
  *
  *
  * This code is derived from software contributed to Berkeley by
  * Robert Elz at The University of Melbourne.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not 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 MERCHANTIBILITY 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
-char copyright[] =
-"@(#) Copyright (c) 1980, 1990 Regents of the University of California.\n\
- All rights reserved.\n";
+static char copyright[] =
+"@(#) Copyright (c) 1980, 1990, 1993\n\
      The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)quotacheck.c       5.13 (Berkeley) %G%";
+static char sccsid[] = "@(#)quotacheck.c       8.6 (Berkeley) 4/28/95";
 #endif /* not lint */
 
 /*
  * Fix up / report on disk quotas & usage
  */
 #include <sys/param.h>
 #endif /* not lint */
 
 /*
  * Fix up / report on disk quotas & usage
  */
 #include <sys/param.h>
-#include <ufs/dinode.h>
-#include <ufs/fs.h>
-#include <ufs/quota.h>
+#include <sys/stat.h>
+#include <sys/queue.h>
+
+#include <ufs/ufs/dinode.h>
+#include <ufs/ufs/quota.h>
+#include <ufs/ffs/fs.h>
+
+#include <fcntl.h>
 #include <fstab.h>
 #include <pwd.h>
 #include <grp.h>
 #include <fstab.h>
 #include <pwd.h>
 #include <grp.h>
-#include <stdio.h>
 #include <errno.h>
 #include <errno.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <err.h>
+
+char *qfname = QUOTAFILENAME;
+char *qfextension[] = INITQFNAMES;
+char *quotagroup = QUOTAGROUP;
 
 union {
        struct  fs      sblk;
        char    dummy[MAXBSIZE];
 } un;
 #define        sblock  un.sblk
 
 union {
        struct  fs      sblk;
        char    dummy[MAXBSIZE];
 } un;
 #define        sblock  un.sblk
-long dev_bsize = 1;
+long dev_bsize;
 long maxino;
 
 struct quotaname {
 long maxino;
 
 struct quotaname {
@@ -67,9 +96,6 @@ struct fileusage {
 };
 #define FUHASH 1024    /* must be power of two */
 struct fileusage *fuhead[MAXQUOTAS][FUHASH];
 };
 #define FUHASH 1024    /* must be power of two */
 struct fileusage *fuhead[MAXQUOTAS][FUHASH];
-struct fileusage *lookup();
-struct fileusage *addid();
-struct dinode *getnextinode();
 
 int    aflag;                  /* all file systems */
 int    gflag;                  /* check group quotas */
 
 int    aflag;                  /* all file systems */
 int    gflag;                  /* check group quotas */
@@ -78,20 +104,38 @@ int        vflag;                  /* verbose */
 int    fi;                     /* open disk file descriptor */
 u_long highid[MAXQUOTAS];      /* highest addid()'ed identifier per type */
 
 int    fi;                     /* open disk file descriptor */
 u_long highid[MAXQUOTAS];      /* highest addid()'ed identifier per type */
 
+struct fileusage *
+        addid __P((u_long, int, char *));
+char   *blockcheck __P((char *));
+void    bread __P((daddr_t, char *, long));
+int     chkquota __P((char *, char *, struct quotaname *));
+void    freeinodebuf __P((void));
+struct dinode *
+        getnextinode __P((ino_t));
+int     getquotagid __P((void));
+int     hasquota __P((struct fstab *, int, char **));
+struct fileusage *
+        lookup __P((u_long, int));
+void   *needchk __P((struct fstab *));
+int     oneof __P((char *, char*[], int));
+void    resetinodebuf __P((void));
+int     update __P((char *, char *, int));
+void    usage __P((void));
+
+int
 main(argc, argv)
        int argc;
 main(argc, argv)
        int argc;
-       char **argv;
+       char *argv[];
 {
        register struct fstab *fs;
        register struct passwd *pw;
        register struct group *gr;
 {
        register struct fstab *fs;
        register struct passwd *pw;
        register struct group *gr;
-       int i, argnum, maxrun, errs = 0;
-       long auxdata, done = 0;
-       char ch, *name, *blockcheck();
-       int needchk(), chkquota();
-       extern char *optarg;
-       extern int optind;
+       struct quotaname *auxdata;
+       int i, argnum, maxrun, errs;
+       long done = 0;
+       char ch, *name;
 
 
+       errs = maxrun = 0;
        while ((ch = getopt(argc, argv, "aguvl:")) != EOF) {
                switch(ch) {
                case 'a':
        while ((ch = getopt(argc, argv, "aguvl:")) != EOF) {
                switch(ch) {
                case 'a':
@@ -135,11 +179,8 @@ main(argc, argv)
        }
        if (aflag)
                exit(checkfstab(1, maxrun, needchk, chkquota));
        }
        if (aflag)
                exit(checkfstab(1, maxrun, needchk, chkquota));
-       if (setfsent() == 0) {
-               fprintf(stderr, "Can't open ");
-               perror(FSTAB);
-               exit(8);
-       }
+       if (setfsent() == 0)
+               err(1, "%s: can't open", FSTAB);
        while ((fs = getfsent()) != NULL) {
                if (((argnum = oneof(fs->fs_file, argv, argc)) >= 0 ||
                    (argnum = oneof(fs->fs_spec, argv, argc)) >= 0) &&
        while ((fs = getfsent()) != NULL) {
                if (((argnum = oneof(fs->fs_file, argv, argc)) >= 0 ||
                    (argnum = oneof(fs->fs_spec, argv, argc)) >= 0) &&
@@ -157,15 +198,16 @@ main(argc, argv)
        exit(errs);
 }
 
        exit(errs);
 }
 
+void
 usage()
 {
 usage()
 {
-
-       fprintf(stderr, "Usage:\n\t%s\n\t%s\n",
-               "quotacheck [-g] [-u] [-v] -a",
-               "quotacheck [-g] [-u] [-v] filesys ...");
+       (void)fprintf(stderr, "usage:\t%s\n\t%s\n",
+               "quotacheck -a [-guv]",
+               "quotacheck [-guv] filesys ...");
        exit(1);
 }
 
        exit(1);
 }
 
+void *
 needchk(fs)
        register struct fstab *fs;
 {
 needchk(fs)
        register struct fstab *fs;
 {
@@ -174,11 +216,9 @@ needchk(fs)
 
        if (strcmp(fs->fs_vfstype, "ufs") ||
            strcmp(fs->fs_type, FSTAB_RW))
 
        if (strcmp(fs->fs_vfstype, "ufs") ||
            strcmp(fs->fs_type, FSTAB_RW))
-               return (0);
-       if ((qnp = (struct quotaname *)malloc(sizeof *qnp)) == 0) {
-               fprintf(stderr, "out of memory for quota structures\n");
-               exit(1);
-       }
+               return (NULL);
+       if ((qnp = malloc(sizeof(*qnp))) == NULL)
+               err(1, "%s", strerror(errno));
        qnp->flags = 0;
        if (gflag && hasquota(fs, GRPQUOTA, &qfnp)) {
                strcpy(qnp->grpqfname, qfnp);
        qnp->flags = 0;
        if (gflag && hasquota(fs, GRPQUOTA, &qfnp)) {
                strcpy(qnp->grpqfname, qfnp);
@@ -189,14 +229,15 @@ needchk(fs)
                qnp->flags |= HASUSR;
        }
        if (qnp->flags)
                qnp->flags |= HASUSR;
        }
        if (qnp->flags)
-               return ((int)qnp);
-       free((char *)qnp);
-       return (0);
+               return (qnp);
+       free(qnp);
+       return (NULL);
 }
 
 /*
  * Scan the specified filesystem to check quota(s) present on it.
  */
 }
 
 /*
  * Scan the specified filesystem to check quota(s) present on it.
  */
+int
 chkquota(fsname, mntpt, qnp)
        char *fsname, *mntpt;
        register struct quotaname *qnp;
 chkquota(fsname, mntpt, qnp)
        char *fsname, *mntpt;
        register struct quotaname *qnp;
@@ -206,20 +247,21 @@ chkquota(fsname, mntpt, qnp)
        int cg, i, mode, errs = 0;
        ino_t ino;
 
        int cg, i, mode, errs = 0;
        ino_t ino;
 
-       if ((fi = open(fsname, 0)) < 0) {
+       if ((fi = open(fsname, O_RDONLY, 0)) < 0) {
                perror(fsname);
                return (1);
        }
        if (vflag) {
                perror(fsname);
                return (1);
        }
        if (vflag) {
-               fprintf(stdout, "*** Checking ");
+               (void)printf("*** Checking ");
                if (qnp->flags & HASUSR)
                if (qnp->flags & HASUSR)
-                       fprintf(stdout, "%s%s", qfextension[USRQUOTA],
+                       (void)printf("%s%s", qfextension[USRQUOTA],
                            (qnp->flags & HASGRP) ? " and " : "");
                if (qnp->flags & HASGRP)
                            (qnp->flags & HASGRP) ? " and " : "");
                if (qnp->flags & HASGRP)
-                       fprintf(stdout, "%s", qfextension[GRPQUOTA]);
-               fprintf(stdout, " quotas for %s (%s)\n", fsname, mntpt);
+                       (void)printf("%s", qfextension[GRPQUOTA]);
+               (void)printf(" quotas for %s (%s)\n", fsname, mntpt);
        }
        sync();
        }
        sync();
+       dev_bsize = 1;
        bread(SBOFF, (char *)&sblock, (long)SBSIZE);
        dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
        maxino = sblock.fs_ncg * sblock.fs_ipg;
        bread(SBOFF, (char *)&sblock, (long)SBSIZE);
        dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
        maxino = sblock.fs_ncg * sblock.fs_ipg;
@@ -262,6 +304,7 @@ chkquota(fsname, mntpt, qnp)
 /*
  * Update a specified quota file.
  */
 /*
  * Update a specified quota file.
  */
+int
 update(fsname, quotafile, type)
        char *fsname, *quotafile;
        register int type;
 update(fsname, quotafile, type)
        char *fsname, *quotafile;
        register int type;
@@ -270,33 +313,35 @@ update(fsname, quotafile, type)
        register FILE *qfi, *qfo;
        register u_long id, lastid;
        struct dqblk dqbuf;
        register FILE *qfi, *qfo;
        register u_long id, lastid;
        struct dqblk dqbuf;
-       extern int errno;
        static int warned = 0;
        static struct dqblk zerodqbuf;
        static struct fileusage zerofileusage;
 
        if ((qfo = fopen(quotafile, "r+")) == NULL) {
        static int warned = 0;
        static struct dqblk zerodqbuf;
        static struct fileusage zerofileusage;
 
        if ((qfo = fopen(quotafile, "r+")) == NULL) {
-               if (errno != ENOENT) {
-                       perror(quotafile);
-                       return (1);
-               }
-               if ((qfo = fopen(quotafile, "w+")) == NULL) {
-                       perror(quotafile);
+               if (errno == ENOENT)
+                       qfo = fopen(quotafile, "w+");
+               if (qfo) {
+                       (void) fprintf(stderr,
+                           "quotacheck: creating quota file %s\n", quotafile);
+#define        MODE    (S_IRUSR|S_IWUSR|S_IRGRP)
+                       (void) fchown(fileno(qfo), getuid(), getquotagid());
+                       (void) fchmod(fileno(qfo), MODE);
+               } else {
+                       (void) fprintf(stderr,
+                           "quotacheck: %s: %s\n", quotafile, strerror(errno));
                        return (1);
                }
                        return (1);
                }
-               fprintf(stderr, "Creating quota file %s\n", quotafile);
-               (void) fchown(fileno(qfo), getuid(), getquotagid());
-               (void) fchmod(fileno(qfo), 0640);
        }
        if ((qfi = fopen(quotafile, "r")) == NULL) {
        }
        if ((qfi = fopen(quotafile, "r")) == NULL) {
-               perror(quotafile);
-               fclose(qfo);
+               (void) fprintf(stderr,
+                   "quotacheck: %s: %s\n", quotafile, strerror(errno));
+               (void) fclose(qfo);
                return (1);
        }
        if (quotactl(fsname, QCMD(Q_SYNC, type), (u_long)0, (caddr_t)0) < 0 &&
            errno == EOPNOTSUPP && !warned && vflag) {
                warned++;
                return (1);
        }
        if (quotactl(fsname, QCMD(Q_SYNC, type), (u_long)0, (caddr_t)0) < 0 &&
            errno == EOPNOTSUPP && !warned && vflag) {
                warned++;
-               fprintf(stdout, "*** Warning: %s\n",
+               (void)printf("*** Warning: %s\n",
                    "Quotas are not compiled into this kernel");
        }
        for (lastid = highid[type], id = 0; id <= lastid; id++) {
                    "Quotas are not compiled into this kernel");
        }
        for (lastid = highid[type], id = 0; id <= lastid; id++) {
@@ -316,12 +361,12 @@ update(fsname, quotafile, type)
                                printf("%s: ", fsname);
                        printf("%-8s fixed:", fup->fu_name);
                        if (dqbuf.dqb_curinodes != fup->fu_curinodes)
                                printf("%s: ", fsname);
                        printf("%-8s fixed:", fup->fu_name);
                        if (dqbuf.dqb_curinodes != fup->fu_curinodes)
-                               fprintf(stdout, "\tinodes %d -> %d",
+                               (void)printf("\tinodes %d -> %d",
                                        dqbuf.dqb_curinodes, fup->fu_curinodes);
                        if (dqbuf.dqb_curblocks != fup->fu_curblocks)
                                        dqbuf.dqb_curinodes, fup->fu_curinodes);
                        if (dqbuf.dqb_curblocks != fup->fu_curblocks)
-                               fprintf(stdout, "\tblocks %d -> %d",
+                               (void)printf("\tblocks %d -> %d",
                                        dqbuf.dqb_curblocks, fup->fu_curblocks);
                                        dqbuf.dqb_curblocks, fup->fu_curblocks);
-                       fprintf(stdout, "\n");
+                       (void)printf("\n");
                }
                /*
                 * Reset time limit if have a soft limit and were
                }
                /*
                 * Reset time limit if have a soft limit and were
@@ -354,6 +399,7 @@ update(fsname, quotafile, type)
 /*
  * Check to see if target appears in list of size cnt.
  */
 /*
  * Check to see if target appears in list of size cnt.
  */
+int
 oneof(target, list, cnt)
        register char *target, *list[];
        int cnt;
 oneof(target, list, cnt)
        register char *target, *list[];
        int cnt;
@@ -369,6 +415,7 @@ oneof(target, list, cnt)
 /*
  * Determine the group identifier for quota files.
  */
 /*
  * Determine the group identifier for quota files.
  */
+int
 getquotagid()
 {
        struct group *gr;
 getquotagid()
 {
        struct group *gr;
@@ -381,24 +428,27 @@ getquotagid()
 /*
  * Check to see if a particular quota is to be enabled.
  */
 /*
  * Check to see if a particular quota is to be enabled.
  */
+int
 hasquota(fs, type, qfnamep)
        register struct fstab *fs;
        int type;
        char **qfnamep;
 {
        register char *opt;
 hasquota(fs, type, qfnamep)
        register struct fstab *fs;
        int type;
        char **qfnamep;
 {
        register char *opt;
-       char *cp, *index(), *strtok();
+       char *cp;
        static char initname, usrname[100], grpname[100];
        static char buf[BUFSIZ];
 
        if (!initname) {
        static char initname, usrname[100], grpname[100];
        static char buf[BUFSIZ];
 
        if (!initname) {
-               sprintf(usrname, "%s%s", qfextension[USRQUOTA], qfname);
-               sprintf(grpname, "%s%s", qfextension[GRPQUOTA], qfname);
+               (void)snprintf(usrname, sizeof(usrname),
+                   "%s%s", qfextension[USRQUOTA], qfname);
+               (void)snprintf(grpname, sizeof(grpname),
+                   "%s%s", qfextension[GRPQUOTA], qfname);
                initname = 1;
        }
        strcpy(buf, fs->fs_mntops);
        for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) {
                initname = 1;
        }
        strcpy(buf, fs->fs_mntops);
        for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) {
-               if (cp = index(opt, '='))
+               if (cp = strchr(opt, '='))
                        *cp++ = '\0';
                if (type == USRQUOTA && strcmp(opt, usrname) == 0)
                        break;
                        *cp++ = '\0';
                if (type == USRQUOTA && strcmp(opt, usrname) == 0)
                        break;
@@ -407,12 +457,13 @@ hasquota(fs, type, qfnamep)
        }
        if (!opt)
                return (0);
        }
        if (!opt)
                return (0);
-       if (cp) {
+       if (cp)
                *qfnamep = cp;
                *qfnamep = cp;
-               return (1);
+       else {
+               (void)snprintf(buf, sizeof(buf),
+                   "%s/%s.%s", fs->fs_file, qfname, qfextension[type]);
+               *qfnamep = buf;
        }
        }
-       (void) sprintf(buf, "%s/%s.%s", fs->fs_file, qfname, qfextension[type]);
-       *qfnamep = buf;
        return (1);
 }
 
        return (1);
 }
 
@@ -431,7 +482,7 @@ lookup(id, type)
        for (fup = fuhead[type][id & (FUHASH-1)]; fup != 0; fup = fup->fu_next)
                if (fup->fu_id == id)
                        return (fup);
        for (fup = fuhead[type][id & (FUHASH-1)]; fup != 0; fup = fup->fu_next)
                if (fup->fu_id == id)
                        return (fup);
-       return ((struct fileusage *)0);
+       return (NULL);
 }
 
 /*
 }
 
 /*
@@ -445,7 +496,6 @@ addid(id, type, name)
 {
        struct fileusage *fup, **fhp;
        int len;
 {
        struct fileusage *fup, **fhp;
        int len;
-       extern char *calloc();
 
        if (fup = lookup(id, type))
                return (fup);
 
        if (fup = lookup(id, type))
                return (fup);
@@ -453,21 +503,18 @@ addid(id, type, name)
                len = strlen(name);
        else
                len = 10;
                len = strlen(name);
        else
                len = 10;
-       if ((fup = (struct fileusage *)calloc(1, sizeof(*fup) + len)) == NULL) {
-               fprintf(stderr, "out of memory for fileusage structures\n");
-               exit(1);
-       }
+       if ((fup = calloc(1, sizeof(*fup) + len)) == NULL)
+               err(1, "%s", strerror(errno));
        fhp = &fuhead[type][id & (FUHASH - 1)];
        fup->fu_next = *fhp;
        *fhp = fup;
        fup->fu_id = id;
        if (id > highid[type])
                highid[type] = id;
        fhp = &fuhead[type][id & (FUHASH - 1)];
        fup->fu_next = *fhp;
        *fhp = fup;
        fup->fu_id = id;
        if (id > highid[type])
                highid[type] = id;
-       if (name) {
-               bcopy(name, fup->fu_name, len + 1);
-       } else {
-               sprintf(fup->fu_name, "%u", id);
-       }
+       if (name)
+               memmove(fup->fu_name, name, len + 1);
+       else
+               (void)sprintf(fup->fu_name, "%u", id);
        return (fup);
 }
 
        return (fup);
 }
 
@@ -488,13 +535,11 @@ getnextinode(inumber)
        daddr_t dblk;
        static struct dinode *dp;
 
        daddr_t dblk;
        static struct dinode *dp;
 
-       if (inumber != nextino++ || inumber > maxino) {
-               fprintf(stderr, "bad inode number %d to nextinode\n", inumber);
-               exit(1);
-       }
+       if (inumber != nextino++ || inumber > maxino)
+               err(1, "bad inode number %d to nextinode", inumber);
        if (inumber >= lastinum) {
                readcnt++;
        if (inumber >= lastinum) {
                readcnt++;
-               dblk = fsbtodb(&sblock, itod(&sblock, lastinum));
+               dblk = fsbtodb(&sblock, ino_to_fsba(&sblock, lastinum));
                if (readcnt % readpercg == 0) {
                        size = partialsize;
                        lastinum += partialcnt;
                if (readcnt % readpercg == 0) {
                        size = partialsize;
                        lastinum += partialcnt;
@@ -511,6 +556,7 @@ getnextinode(inumber)
 /*
  * Prepare to scan a set of inodes.
  */
 /*
  * Prepare to scan a set of inodes.
  */
+void
 resetinodebuf()
 {
 
 resetinodebuf()
 {
 
@@ -529,10 +575,8 @@ resetinodebuf()
                partialsize = inobufsize;
        }
        if (inodebuf == NULL &&
                partialsize = inobufsize;
        }
        if (inodebuf == NULL &&
-          (inodebuf = (struct dinode *)malloc((unsigned)inobufsize)) == NULL) {
-               fprintf(stderr, "Cannot allocate space for inode buffer\n");
-               exit(1);
-       }
+          (inodebuf = malloc((u_int)inobufsize)) == NULL)
+               err(1, "%s", strerror(errno));
        while (nextino < ROOTINO)
                getnextinode(nextino);
 }
        while (nextino < ROOTINO)
                getnextinode(nextino);
 }
@@ -540,30 +584,26 @@ resetinodebuf()
 /*
  * Free up data structures used to scan inodes.
  */
 /*
  * Free up data structures used to scan inodes.
  */
+void
 freeinodebuf()
 {
 
        if (inodebuf != NULL)
 freeinodebuf()
 {
 
        if (inodebuf != NULL)
-               free((char *)inodebuf);
+               free(inodebuf);
        inodebuf = NULL;
 }
 
 /*
  * Read specified disk blocks.
  */
        inodebuf = NULL;
 }
 
 /*
  * Read specified disk blocks.
  */
+void
 bread(bno, buf, cnt)
        daddr_t bno;
        char *buf;
        long cnt;
 {
 
 bread(bno, buf, cnt)
        daddr_t bno;
        char *buf;
        long cnt;
 {
 
-       if (lseek(fi, bno * dev_bsize, 0) < 0) {
-               perror("lseek");
-               exit(1);
-       }
-
-       if (read(fi, buf, cnt) != cnt) {
-               perror("read");
-               exit(1);
-       }
+       if (lseek(fi, (off_t)bno * dev_bsize, SEEK_SET) < 0 ||
+           read(fi, buf, cnt) != cnt)
+               err(1, "block %ld", bno);
 }
 }