Add define for Kirk Smith's USR Courier driver. Change default baud
[unix-history] / usr / src / usr.bin / quota / quota.c
index caab1a3..6cbe513 100644 (file)
@@ -1,6 +1,18 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)quota.c    4.2 (Berkeley, from Melbourne) %G%";
-#endif
+char copyright[] =
+"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif not lint
+
+#ifndef lint
+static char sccsid[] = "@(#)quota.c    5.4 (Berkeley) %G%";
+#endif not lint
 
 /*
  * Disk quota reporting program.
 
 /*
  * Disk quota reporting program.
@@ -9,6 +21,7 @@ static char sccsid[] = "@(#)quota.c    4.2 (Berkeley, from Melbourne) %G%";
 #include <fstab.h>
 #include <ctype.h>
 #include <pwd.h>
 #include <fstab.h>
 #include <ctype.h>
 #include <pwd.h>
+#include <errno.h>
 
 #include <sys/param.h>
 #include <sys/quota.h>
 
 #include <sys/param.h>
 #include <sys/quota.h>
@@ -25,7 +38,12 @@ main(argc, argv)
        char *argv[];
 {
        register char *cp;
        char *argv[];
 {
        register char *cp;
+       extern int errno;
 
 
+       if (quota(Q_SYNC, 0, 0, (caddr_t)0) < 0 && errno == EINVAL) {
+               fprintf(stderr, "There are no quotas on this system\n");
+               exit(0);
+       }
        argc--,argv++;
        while (argc > 0) {
                if (argv[0][0] == '-')
        argc--,argv++;
        while (argc > 0) {
                if (argv[0][0] == '-')
@@ -88,9 +106,14 @@ showquotas(uid, name)
        int uid;
        char *name;
 {
        int uid;
        char *name;
 {
-       register char c, *p;
        register struct fstab *fs;
        register struct fstab *fs;
-       int myuid;
+       register char *msgi, *msgb;
+       register enab = 1;
+       dev_t   fsdev;
+       struct  stat statb;
+       struct  dqblk dqblk;
+       int myuid, fd;
+       char qfilename[MAXPATHLEN + 1], iwarn[8], dwarn[8];
 
        myuid = getuid();
        if (uid != myuid && myuid != 0) {
 
        myuid = getuid();
        if (uid != myuid && myuid != 0) {
@@ -98,33 +121,40 @@ showquotas(uid, name)
                return;
        }
        done = 0;
                return;
        }
        done = 0;
-       setfsent();
+       (void) setfsent();
        while (fs = getfsent()) {
        while (fs = getfsent()) {
-               register char *msgi = (char *)0, *msgb = (char *)0;
-               register enab = 1;
-               dev_t   fsdev;
-               struct  stat statb;
-               struct  dqblk dqblk;
-               char qfilename[MAXPATHLEN + 1], iwarn[8], dwarn[8];
-
                if (stat(fs->fs_spec, &statb) < 0)
                        continue;
                if (stat(fs->fs_spec, &statb) < 0)
                        continue;
+               msgi = msgb = (char *) 0;
                fsdev = statb.st_rdev;
                (void) sprintf(qfilename, "%s/%s", fs->fs_file, qfname);
                if (stat(qfilename, &statb) < 0 || statb.st_dev != fsdev)
                        continue;
                fsdev = statb.st_rdev;
                (void) sprintf(qfilename, "%s/%s", fs->fs_file, qfname);
                if (stat(qfilename, &statb) < 0 || statb.st_dev != fsdev)
                        continue;
-               if (quota(Q_GETDLIM, uid, fsdev, &dqblk) != 0) {
-                       register fd = open(qfilename, FRDONLY);
-
+               if (quota(Q_GETDLIM, uid, fsdev, (caddr_t)&dqblk) != 0) {
+                       fd = open(qfilename, O_RDONLY);
                        if (fd < 0)
                                continue;
                        if (fd < 0)
                                continue;
-                       lseek(fd, (long)(uid * sizeof (dqblk)), FSEEK_ABSOLUTE);
-                       if (read(fd, &dqblk, sizeof dqblk) != sizeof (dqblk)) {
-                               close(fd);
+                       (void) lseek(fd, (off_t)(uid * sizeof (dqblk)), L_SET);
+                       switch (read(fd, (char *)&dqblk, sizeof dqblk)) {
+                       case 0:                 /* EOF */
+                               /*
+                                * Convert implicit 0 quota (EOF)
+                                * into an explicit one (zero'ed dqblk).
+                                */
+                               bzero((caddr_t)&dqblk, sizeof dqblk);
+                               break;
+
+                       case sizeof dqblk:      /* OK */
+                               break;
+
+                       default:                /* ERROR */
+                               fprintf(stderr, "quota: read error in ");
+                               perror(qfilename);
+                               (void) close(fd);
                                continue;
                        }
                                continue;
                        }
-                       close(fd);
-                       if (dqblk.dqb_isoftlimit == 0 &&
+                       (void) close(fd);
+                       if (!vflag && dqblk.dqb_isoftlimit == 0 &&
                            dqblk.dqb_bsoftlimit == 0)
                                continue;
                        enab = 0;
                            dqblk.dqb_bsoftlimit == 0)
                                continue;
                        enab = 0;
@@ -146,11 +176,11 @@ showquotas(uid, name)
                    dqblk.dqb_curblocks >= dqblk.dqb_bsoftlimit)
                        msgb = "Over disc quota on %s";
                if (dqblk.dqb_iwarn < MAX_IQ_WARN)
                    dqblk.dqb_curblocks >= dqblk.dqb_bsoftlimit)
                        msgb = "Over disc quota on %s";
                if (dqblk.dqb_iwarn < MAX_IQ_WARN)
-                       sprintf(iwarn, "%d", dqblk.dqb_iwarn);
+                       (void) sprintf(iwarn, "%d", dqblk.dqb_iwarn);
                else
                        iwarn[0] = '\0';
                if (dqblk.dqb_bwarn < MAX_DQ_WARN)
                else
                        iwarn[0] = '\0';
                if (dqblk.dqb_bwarn < MAX_DQ_WARN)
-                       sprintf(dwarn, "%d", dqblk.dqb_bwarn);
+                       (void) sprintf(dwarn, "%d", dqblk.dqb_bwarn);
                else
                        dwarn[0] = '\0';
                if (qflag) {
                else
                        dwarn[0] = '\0';
                if (qflag) {
@@ -164,29 +194,29 @@ showquotas(uid, name)
                }
                if (vflag || dqblk.dqb_curblocks || dqblk.dqb_curinodes) {
                        heading(uid, name);
                }
                if (vflag || dqblk.dqb_curblocks || dqblk.dqb_curinodes) {
                        heading(uid, name);
-                       printf("%8s%8d%c%7d%8d%8s%8d%c%7d%8d%8s\n"
+                       printf("%10s%8d%c%7d%8d%8s%8d%c%7d%8d%8s\n"
                                , fs->fs_file
                                , fs->fs_file
-                               , (dqblk.dqb_curblocks / (1024/DEV_BSIZE)) 
+                               , dbtob(dqblk.dqb_curblocks) / 1024
                                , (msgb == (char *)0) ? ' ' : '*'
                                , (msgb == (char *)0) ? ' ' : '*'
-                               , (dqblk.dqb_bsoftlimit / (1024/DEV_BSIZE)) 
-                               , ((dqblk.dqb_bhardlimit-1) / (1024/DEV_BSIZE)) 
+                               , dbtob(dqblk.dqb_bsoftlimit) / 1024
+                               , dbtob(dqblk.dqb_bhardlimit) / 1024
                                , dwarn
                                , dqblk.dqb_curinodes
                                , (msgi == (char *)0) ? ' ' : '*'
                                , dqblk.dqb_isoftlimit
                                , dwarn
                                , dqblk.dqb_curinodes
                                , (msgi == (char *)0) ? ' ' : '*'
                                , dqblk.dqb_isoftlimit
-                               , dqblk.dqb_ihardlimit-1
+                               , dqblk.dqb_ihardlimit
                                , iwarn
                        );
                }
        }
                                , iwarn
                        );
                }
        }
-       endfsent();
+       (void) endfsent();
        if (!done && !qflag) {
                if (morethanone)
        if (!done && !qflag) {
                if (morethanone)
-                       putchar('\n');
+                       (void) putchar('\n');
                xprintf("Disc quotas for %s (uid %d):", name, uid);
                xprintf("none.");
        }
                xprintf("Disc quotas for %s (uid %d):", name, uid);
                xprintf("none.");
        }
-       xprintf(0);
+       xprintf((char *)0);
 }
 
 heading(uid, name)
 }
 
 heading(uid, name)
@@ -196,18 +226,18 @@ heading(uid, name)
 
        if (done++)
                return;
 
        if (done++)
                return;
-       xprintf(0);
+       xprintf((char *)0);
        if (qflag) {
                if (!morethanone)
                        return;
                xprintf("User %s (uid %d):", name, uid);
        if (qflag) {
                if (!morethanone)
                        return;
                xprintf("User %s (uid %d):", name, uid);
-               xprintf(0);
+               xprintf((char *)0);
                return;
        }
                return;
        }
-       putchar('\n');
+       (void) putchar('\n');
        xprintf("Disc quotas for %s (uid %d):", name, uid);
        xprintf("Disc quotas for %s (uid %d):", name, uid);
-       xprintf(0);
-       printf("%8s%8s %7s%8s%8s%8s %7s%8s%8s\n"
+       xprintf((char *)0);
+       printf("%10s%8s %7s%8s%8s%8s %7s%8s%8s\n"
                , "Filsys"
                , "current"
                , "quota"
                , "Filsys"
                , "current"
                , "quota"
@@ -220,6 +250,7 @@ heading(uid, name)
        );
 }
 
        );
 }
 
+/*VARARGS1*/
 xprintf(fmt, arg1, arg2, arg3, arg4, arg5, arg6)
        char *fmt;
 {
 xprintf(fmt, arg1, arg2, arg3, arg4, arg5, arg6)
        char *fmt;
 {
@@ -227,17 +258,17 @@ xprintf(fmt, arg1, arg2, arg3, arg4, arg5, arg6)
        static int column;
 
        if (fmt == 0 && column || column >= 40) {
        static int column;
 
        if (fmt == 0 && column || column >= 40) {
-               putchar('\n');
+               (void) putchar('\n');
                column = 0;
        }
        if (fmt == 0)
                return;
                column = 0;
        }
        if (fmt == 0)
                return;
-       sprintf(buf, fmt, arg1, arg2, arg3, arg4, arg5, arg6);
+       (void) sprintf(buf, fmt, arg1, arg2, arg3, arg4, arg5, arg6);
        if (column != 0 && strlen(buf) < 39)
                while (column++ < 40)
        if (column != 0 && strlen(buf) < 39)
                while (column++ < 40)
-                       putchar(' ');
+                       (void) putchar(' ');
        else if (column) {
        else if (column) {
-               putchar('\n');
+               (void) putchar('\n');
                column = 0;
        }
        printf("%s", buf);
                column = 0;
        }
        printf("%s", buf);