file reorg, pathnames.h
[unix-history] / usr / src / usr.sbin / quot / quot.c
index 08a0f14..c172e77 100644 (file)
@@ -1,17 +1,18 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)quot.c      4.10 (Berkeley) 85/05/27";
+static char *sccsid = "@(#)quot.c      4.16 (Berkeley) 89/05/15";
 #endif
 
 /*
  * quot
  */
 
 #endif
 
 /*
  * quot
  */
 
-#include <stdio.h>
-#include <ctype.h>
 #include <sys/param.h>
 #include <sys/inode.h>
 #include <sys/fs.h>
 #include <sys/file.h>
 #include <sys/param.h>
 #include <sys/inode.h>
 #include <sys/fs.h>
 #include <sys/file.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <paths.h>
 
 #define        ISIZ    (MAXBSIZE/sizeof(struct dinode))
 union {
 
 #define        ISIZ    (MAXBSIZE/sizeof(struct dinode))
 union {
@@ -56,52 +57,52 @@ main(argc, argv)
        int argc;
        char *argv[];
 {
        int argc;
        char *argv[];
 {
-       register int n;
-
-       now = time(0);
-       argc--, argv++;
-       while (argc > 0 && argv[0][0] == '-') {
-               register char *cp;
-
-               for (cp = &argv[0][1]; *cp; cp++)
-                       switch (*cp) {
-                       case 'n':
-                               nflg++; break;
-                       case 'f':
-                               fflg++; break;
-                       case 'c':
-                               cflg++; break;
-                       case 'v':
-                               vflg++; break;
-                       case 'h':
-                               hflg++; break;
-                       default:
-                               fprintf(stderr,
-                                   "usage: quot [ -nfcvh ] [ device ... ]\n");
-                               exit(1);
-                       }
-               argc--, argv++;
-       }
-       if (argc == 0)
+       extern char *optarg;
+       extern int optind;
+       int ch;
+       time_t time();
+
+       while ((ch = getopt(argc, argv, "cfhnv")) != EOF)
+               switch((char)ch) {
+               case 'c':
+                       cflg++; break;
+               case 'f':
+                       fflg++; break;
+               case 'h':               /* undocumented */
+                       hflg++; break;
+               case 'n':
+                       nflg++; break;
+               case 'v':               /* undocumented */
+                       vflg++; break;
+               case '?':
+               default:
+                       fputs("usage: quot [-cfn] [filesystem ...]\n", stderr);
+                       exit(1);
+               }
+       argc -= optind;
+       argv += optind;
+
+       (void)time(&now);
+       setpassent(1);
+       if (argc)
+               for (; *argv; ++argv) {
+                       if (check(*argv, (char *)NULL) == 0)
+                               report();
+               }
+       else
                quotall();
                quotall();
-       while (argc-- > 0)
-               if (check(*argv++) == 0)
-                       report();
-       exit (0);
+       exit(0);
 }
 
 }
 
+#include <sys/dir.h>
 #include <fstab.h>
 
 quotall()
 {
        register struct fstab *fs;
        register char *cp;
 #include <fstab.h>
 
 quotall()
 {
        register struct fstab *fs;
        register char *cp;
-       char dev[80], *rindex();
+       char dev[MAXNAMLEN + 10], *rindex();
 
 
-       if (setfsent() == 0) {
-               fprintf(stderr, "quot: no %s file\n", FSTAB);
-               exit(1);
-       }
        while (fs = getfsent()) {
                if (strcmp(fs->fs_type, FSTAB_RO) &&
                    strcmp(fs->fs_type, FSTAB_RW) &&
        while (fs = getfsent()) {
                if (strcmp(fs->fs_type, FSTAB_RO) &&
                    strcmp(fs->fs_type, FSTAB_RW) &&
@@ -110,19 +111,20 @@ quotall()
                cp = rindex(fs->fs_spec, '/');
                if (cp == 0)
                        continue;
                cp = rindex(fs->fs_spec, '/');
                if (cp == 0)
                        continue;
-               sprintf(dev, "/dev/r%s", cp + 1);
-               if (check(dev) == 0)
+               (void)sprintf(dev, "%s/r%s", _PATH_DEV, cp + 1);
+               if (check(dev, fs->fs_file) == 0)
                        report();
        }
                        report();
        }
-       endfsent();
 }
 
 }
 
-check(file)
+check(file, fsdir)
        char *file;
        char *file;
+       char *fsdir;
 {
        register int i, j, nfiles;
        register struct du **dp;
        daddr_t iblk;
 {
        register int i, j, nfiles;
        register struct du **dp;
        daddr_t iblk;
+       long dev_bsize;
        int c, fd;
 
        /*
        int c, fd;
 
        /*
@@ -142,19 +144,28 @@ check(file)
                perror(file);
                return (-1);
        }
                perror(file);
                return (-1);
        }
-       printf("%s:\n", file);
+       printf("%s", file);
+       if (fsdir == NULL) {
+               register struct fstab *fs = getfsspec(file);
+               if (fs != NULL)
+                       fsdir = fs->fs_file;
+       }
+       if (fsdir != NULL && *fsdir != '\0')
+               printf(" (%s)", fsdir);
+       printf(":\n");
        sync();
        sync();
-       bread(fd, SBLOCK, (char *)&sblock, SBSIZE);
+       bread(fd, (long)SBOFF, (char *)&sblock, SBSIZE);
+       dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
        if (nflg) {
                if (isdigit(c = getchar()))
        if (nflg) {
                if (isdigit(c = getchar()))
-                       ungetc(c, stdin);
+                       (void)ungetc(c, stdin);
                else while (c != '\n' && c != EOF)
                        c = getchar();
        }
        nfiles = sblock.fs_ipg * sblock.fs_ncg;
        for (ino = 0; ino < nfiles; ) {
                iblk = fsbtodb(&sblock, itod(&sblock, ino));
                else while (c != '\n' && c != EOF)
                        c = getchar();
        }
        nfiles = sblock.fs_ipg * sblock.fs_ncg;
        for (ino = 0; ino < nfiles; ) {
                iblk = fsbtodb(&sblock, itod(&sblock, ino));
-               bread(fd, iblk, (char *)itab, sblock.fs_bsize);
+               bread(fd, iblk * dev_bsize, (char *)itab, (int)sblock.fs_bsize);
                for (j = 0; j < INOPB(&sblock) && ino < nfiles; j++, ino++) {
                        if (ino < ROOTINO)
                                continue;
                for (j = 0; j < INOPB(&sblock) && ino < nfiles; j++, ino++) {
                        if (ino < ROOTINO)
                                continue;
@@ -162,6 +173,7 @@ check(file)
                }
        }
        close(fd);
                }
        }
        close(fd);
+       return (0);
 }
 
 acct(ip)
 }
 
 acct(ip)
@@ -170,7 +182,7 @@ acct(ip)
        register struct du *dp;
        struct du **hp;
        long blks, frags, size;
        register struct du *dp;
        struct du **hp;
        long blks, frags, size;
-       char n;
+       int n;
        static fino;
 
        if ((ip->di_mode & IFMT) == 0)
        static fino;
 
        if ((ip->di_mode & IFMT) == 0)
@@ -239,9 +251,9 @@ acct(ip)
                        continue;
                }
                if (np = getname(dp->uid))
                        continue;
                }
                if (np = getname(dp->uid))
-                       printf("%.7s    ", np);
+                       printf("%.7s\t", np);
                else
                else
-                       printf("%d      ", ip->di_uid);
+                       printf("%u\t", ip->di_uid);
                while ((n = getchar()) == ' ' || n == '\t')
                        ;
                putchar(n);
                while ((n = getchar()) == ' ' || n == '\t')
                        ;
                putchar(n);
@@ -255,13 +267,14 @@ acct(ip)
 }
 
 bread(fd, bno, buf, cnt)
 }
 
 bread(fd, bno, buf, cnt)
-       unsigned bno;
+       long bno;
        char *buf;
 {
        char *buf;
 {
+       off_t lseek();
 
 
-       lseek(fd, (long)bno * DEV_BSIZE, L_SET);
+       (void)lseek(fd, bno, L_SET);
        if (read(fd, buf, cnt) != cnt) {
        if (read(fd, buf, cnt) != cnt) {
-               fprintf(stderr, "quot: read error at block %u\n", bno);
+               fprintf(stderr, "quot: read error at block %ld\n", bno);
                exit(1);
        }
 }
                exit(1);
        }
 }
@@ -297,9 +310,9 @@ report()
                for (i = 0; i < TSIZE - 1; i++)
                        if (sizes[i]) {
                                t += i*sizes[i];
                for (i = 0; i < TSIZE - 1; i++)
                        if (sizes[i]) {
                                t += i*sizes[i];
-                               printf("%d      %d      %D\n", i, sizes[i], t);
+                               printf("%d\t%d\t%ld\n", i, sizes[i], t);
                        }
                        }
-               printf("%d      %d      %D\n",
+               printf("%d\t%d\t%ld\n",
                    TSIZE - 1, sizes[TSIZE - 1], overflow + t);
                return;
        }
                    TSIZE - 1, sizes[TSIZE - 1], overflow + t);
                return;
        }
@@ -340,18 +353,14 @@ struct ncache {
        int     uid;
        char    name[NMAX+1];
 } nc[NUID];
        int     uid;
        char    name[NMAX+1];
 } nc[NUID];
-char   outrangename[NMAX+1];
-int    outrangeuid = -1;
 
 char *
 getname(uid)
 {
        register struct passwd *pw;
        struct passwd *getpwent();
 
 char *
 getname(uid)
 {
        register struct passwd *pw;
        struct passwd *getpwent();
-       extern int _pw_stayopen;
        register int cp;
 
        register int cp;
 
-       _pw_stayopen = 1;
        cp = uid & UIDMASK;
        if (uid >= 0 && nc[cp].uid == uid && nc[cp].name[0])
                return (nc[cp].name);
        cp = uid & UIDMASK;
        if (uid >= 0 && nc[cp].uid == uid && nc[cp].name[0])
                return (nc[cp].name);