BSD 4_4_Lite2 release
[unix-history] / usr / src / sbin / quotacheck / quotacheck.c
index 6e4e48e..31c94d1 100644 (file)
@@ -1,21 +1,47 @@
 /*
 /*
- * 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.
  *
- * %sccs.include.redist.c%
+ * 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.19 (Berkeley) %G%";
+static char sccsid[] = "@(#)quotacheck.c       8.6 (Berkeley) 4/28/95";
 #endif /* not lint */
 
 /*
 #endif /* not lint */
 
 /*
@@ -23,6 +49,7 @@ static char sccsid[] = "@(#)quotacheck.c      5.19 (Berkeley) %G%";
  */
 #include <sys/param.h>
 #include <sys/stat.h>
  */
 #include <sys/param.h>
 #include <sys/stat.h>
+#include <sys/queue.h>
 
 #include <ufs/ufs/dinode.h>
 #include <ufs/ufs/quota.h>
 
 #include <ufs/ufs/dinode.h>
 #include <ufs/ufs/quota.h>
@@ -37,6 +64,7 @@ static char sccsid[] = "@(#)quotacheck.c      5.19 (Berkeley) %G%";
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <err.h>
 
 char *qfname = QUOTAFILENAME;
 char *qfextension[] = INITQFNAMES;
 
 char *qfname = QUOTAFILENAME;
 char *qfextension[] = INITQFNAMES;
@@ -47,7 +75,7 @@ union {
        char    dummy[MAXBSIZE];
 } un;
 #define        sblock  un.sblk
        char    dummy[MAXBSIZE];
 } un;
 #define        sblock  un.sblk
-long dev_bsize = 1;
+long dev_bsize;
 long maxino;
 
 struct quotaname {
 long maxino;
 
 struct quotaname {
@@ -81,7 +109,6 @@ struct fileusage *
 char   *blockcheck __P((char *));
 void    bread __P((daddr_t, char *, long));
 int     chkquota __P((char *, char *, struct quotaname *));
 char   *blockcheck __P((char *));
 void    bread __P((daddr_t, char *, long));
 int     chkquota __P((char *, char *, struct quotaname *));
-void    err __P((const char *, ...));
 void    freeinodebuf __P((void));
 struct dinode *
         getnextinode __P((ino_t));
 void    freeinodebuf __P((void));
 struct dinode *
         getnextinode __P((ino_t));
@@ -104,10 +131,11 @@ main(argc, argv)
        register struct passwd *pw;
        register struct group *gr;
        struct quotaname *auxdata;
        register struct passwd *pw;
        register struct group *gr;
        struct quotaname *auxdata;
-       int i, argnum, maxrun, errs = 0;
+       int i, argnum, maxrun, errs;
        long done = 0;
        char ch, *name;
 
        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':
@@ -152,7 +180,7 @@ main(argc, argv)
        if (aflag)
                exit(checkfstab(1, maxrun, needchk, chkquota));
        if (setfsent() == 0)
        if (aflag)
                exit(checkfstab(1, maxrun, needchk, chkquota));
        if (setfsent() == 0)
-               err("%s: can't open", FSTAB);
+               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) &&
@@ -190,7 +218,7 @@ needchk(fs)
            strcmp(fs->fs_type, FSTAB_RW))
                return (NULL);
        if ((qnp = malloc(sizeof(*qnp))) == NULL)
            strcmp(fs->fs_type, FSTAB_RW))
                return (NULL);
        if ((qnp = malloc(sizeof(*qnp))) == NULL)
-               err("%s", strerror(errno));
+               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);
@@ -233,6 +261,7 @@ chkquota(fsname, mntpt, qnp)
                (void)printf(" quotas for %s (%s)\n", fsname, mntpt);
        }
        sync();
                (void)printf(" quotas for %s (%s)\n", fsname, mntpt);
        }
        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;
@@ -419,7 +448,7 @@ hasquota(fs, type, qfnamep)
        }
        strcpy(buf, fs->fs_mntops);
        for (opt = strtok(buf, ","); opt; opt = strtok(NULL, ",")) {
        }
        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;
@@ -475,7 +504,7 @@ addid(id, type, name)
        else
                len = 10;
        if ((fup = calloc(1, sizeof(*fup) + len)) == NULL)
        else
                len = 10;
        if ((fup = calloc(1, sizeof(*fup) + len)) == NULL)
-               err("%s", strerror(errno));
+               err(1, "%s", strerror(errno));
        fhp = &fuhead[type][id & (FUHASH - 1)];
        fup->fu_next = *fhp;
        *fhp = fup;
        fhp = &fuhead[type][id & (FUHASH - 1)];
        fup->fu_next = *fhp;
        *fhp = fup;
@@ -483,7 +512,7 @@ addid(id, type, name)
        if (id > highid[type])
                highid[type] = id;
        if (name)
        if (id > highid[type])
                highid[type] = id;
        if (name)
-               bcopy(name, fup->fu_name, len + 1);
+               memmove(fup->fu_name, name, len + 1);
        else
                (void)sprintf(fup->fu_name, "%u", id);
        return (fup);
        else
                (void)sprintf(fup->fu_name, "%u", id);
        return (fup);
@@ -507,10 +536,10 @@ getnextinode(inumber)
        static struct dinode *dp;
 
        if (inumber != nextino++ || inumber > maxino)
        static struct dinode *dp;
 
        if (inumber != nextino++ || inumber > maxino)
-               err("bad inode number %d to nextinode", inumber);
+               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;
@@ -547,7 +576,7 @@ resetinodebuf()
        }
        if (inodebuf == NULL &&
           (inodebuf = malloc((u_int)inobufsize)) == NULL)
        }
        if (inodebuf == NULL &&
           (inodebuf = malloc((u_int)inobufsize)) == NULL)
-               err("%s", strerror(errno));
+               err(1, "%s", strerror(errno));
        while (nextino < ROOTINO)
                getnextinode(nextino);
 }
        while (nextino < ROOTINO)
                getnextinode(nextino);
 }
@@ -576,34 +605,5 @@ bread(bno, buf, cnt)
 
        if (lseek(fi, (off_t)bno * dev_bsize, SEEK_SET) < 0 ||
            read(fi, buf, cnt) != cnt)
 
        if (lseek(fi, (off_t)bno * dev_bsize, SEEK_SET) < 0 ||
            read(fi, buf, cnt) != cnt)
-               err("block %ld", bno);
-}
-
-#if __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-void
-#if __STDC__
-err(const char *fmt, ...)
-#else
-err(fmt, va_alist)
-       char *fmt;
-        va_dcl
-#endif
-{
-       va_list ap;
-#if __STDC__
-       va_start(ap, fmt);
-#else
-       va_start(ap);
-#endif
-       (void)fprintf(stderr, "quotacheck: ");
-       (void)vfprintf(stderr, fmt, ap);
-       va_end(ap);
-       (void)fprintf(stderr, "\n");
-       exit(1);
-       /* NOTREACHED */
+               err(1, "block %ld", bno);
 }
 }