install correct aliases file
[unix-history] / usr / src / usr.sbin / repquota / repquota.c
index ee99a33..5de9e09 100644 (file)
@@ -1,11 +1,35 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * 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.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)repquota.c 4.3 (Berkeley, from Melbourne) %G%";
-#endif
+static char sccsid[] = "@(#)repquota.c 5.6 (Berkeley) %G%";
+#endif /* not lint */
 
 /*
  * Quota report
  */
 #include <stdio.h>
 
 /*
  * Quota report
  */
 #include <stdio.h>
+#include <errno.h>
 #include <sys/param.h>
 #include <sys/quota.h>
 #include <sys/stat.h>
 #include <sys/param.h>
 #include <sys/quota.h>
 #include <sys/stat.h>
@@ -32,7 +56,6 @@ int   vflag;          /* verbose */
 int    aflag;          /* all file systems */
 
 char *qfname = "quotas";
 int    aflag;          /* all file systems */
 
 char *qfname = "quotas";
-char quotafile[MAXPATHLEN + 1];
 struct dqblk zerodqblk;
 
 main(argc, argv)
 struct dqblk zerodqblk;
 
 main(argc, argv)
@@ -80,7 +103,7 @@ again:
                      oneof(fs->fs_spec, argv, argc)))
                        continue;
                (void) sprintf(quotafile, "%s/%s", fs->fs_file, qfname);
                      oneof(fs->fs_spec, argv, argc)))
                        continue;
                (void) sprintf(quotafile, "%s/%s", fs->fs_file, qfname);
-               errs += repquota(fs->fs_spec, quotafile);
+               errs += repquota(fs->fs_spec, fs->fs_file, quotafile);
        }
        endfsent();
        for (i = 0; i < argc; i++)
        }
        endfsent();
        for (i = 0; i < argc; i++)
@@ -90,8 +113,9 @@ again:
        exit(errs);
 }
 
        exit(errs);
 }
 
-repquota(fsdev, qffile)
+repquota(fsdev, fsfile, qffile)
        char *fsdev;
        char *fsdev;
+       char *fsfile;
        char *qffile;
 {
        register struct fileusage *fup;
        char *qffile;
 {
        register struct fileusage *fup;
@@ -99,9 +123,11 @@ repquota(fsdev, qffile)
        u_short uid;
        struct dqblk dqbuf;
        struct stat statb;
        u_short uid;
        struct dqblk dqbuf;
        struct stat statb;
+       static int warned = 0;
+       extern int errno;
 
        if (vflag)
 
        if (vflag)
-               fprintf(stdout, "*** Quota report for %s\n", fsdev);
+               fprintf(stdout, "*** Quota report for %s (%s)\n", fsdev, fsfile);
        qf = fopen(qffile, "r");
        if (qf == NULL) {
                perror(qffile);
        qf = fopen(qffile, "r");
        if (qf == NULL) {
                perror(qffile);
@@ -109,16 +135,23 @@ repquota(fsdev, qffile)
        }
        if (fstat(fileno(qf), &statb) < 0) {
                perror(qffile);
        }
        if (fstat(fileno(qf), &statb) < 0) {
                perror(qffile);
+               fclose(qf);
                return (1);
        }
                return (1);
        }
-       quota(Q_SYNC, 0, statb.st_dev, 0);
+       if (quota(Q_SYNC, 0, statb.st_dev, 0) < 0 &&
+           errno == EINVAL && !warned && vflag) {
+               warned++;
+               fprintf(stdout,
+                   "*** Warning: Quotas are not compiled into this kernel\n");
+       }
        for (uid = 0; ; uid++) {
                fread(&dqbuf, sizeof(struct dqblk), 1, qf);
                if (feof(qf))
                        break;
        for (uid = 0; ; uid++) {
                fread(&dqbuf, sizeof(struct dqblk), 1, qf);
                if (feof(qf))
                        break;
-               if (dqbuf.dqb_curinodes == 0 && dqbuf.dqb_curblocks == 0)
-                       continue;
                fup = lookup(uid);
                fup = lookup(uid);
+               if ((fup == 0 || fup->fu_name[0] == 0) &&
+                   dqbuf.dqb_curinodes == 0 && dqbuf.dqb_curblocks == 0)
+                       continue;
                if (fup == 0)
                        fup = adduid(uid);
                fup->fu_dqblk = dqbuf;
                if (fup == 0)
                        fup = adduid(uid);
                fup->fu_dqblk = dqbuf;
@@ -143,9 +176,9 @@ repquota(fsdev, qffile)
                        fup->fu_dqblk.dqb_isoftlimit &&
                            fup->fu_dqblk.dqb_curinodes >=
                            fup->fu_dqblk.dqb_isoftlimit ? '+' : '-',
                        fup->fu_dqblk.dqb_isoftlimit &&
                            fup->fu_dqblk.dqb_curinodes >=
                            fup->fu_dqblk.dqb_isoftlimit ? '+' : '-',
-                       fup->fu_dqblk.dqb_curblocks / btodb(1024),
-                       fup->fu_dqblk.dqb_bsoftlimit / btodb(1024),
-                       fup->fu_dqblk.dqb_bhardlimit / btodb(1024),
+                       dbtob(fup->fu_dqblk.dqb_curblocks) / 1024,
+                       dbtob(fup->fu_dqblk.dqb_bsoftlimit) / 1024,
+                       dbtob(fup->fu_dqblk.dqb_bhardlimit) / 1024,
                        fup->fu_dqblk.dqb_bwarn,
                        fup->fu_dqblk.dqb_curinodes,
                        fup->fu_dqblk.dqb_isoftlimit,
                        fup->fu_dqblk.dqb_bwarn,
                        fup->fu_dqblk.dqb_curinodes,
                        fup->fu_dqblk.dqb_isoftlimit,
@@ -153,6 +186,7 @@ repquota(fsdev, qffile)
                        fup->fu_dqblk.dqb_iwarn);
                fup->fu_dqblk = zerodqblk;
        }
                        fup->fu_dqblk.dqb_iwarn);
                fup->fu_dqblk = zerodqblk;
        }
+       fclose(qf);
        return (0);
 }
 
        return (0);
 }
 
@@ -187,6 +221,7 @@ adduid(uid)
        u_short uid;
 {
        struct fileusage *fup, **fhp;
        u_short uid;
 {
        struct fileusage *fup, **fhp;
+       extern char *calloc();
 
        fup = lookup(uid);
        if (fup != 0)
 
        fup = lookup(uid);
        if (fup != 0)