minor rearrangements
[unix-history] / usr / src / usr.sbin / quot / quot.c
index 148f32b..eb1a89a 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)quot.c      4.6 (Berkeley) 83/08/16";
+static char *sccsid = "@(#)quot.c      4.13 (Berkeley) 87/10/22";
 #endif
 
 /*
 #endif
 
 /*
@@ -46,6 +46,7 @@ int   cflg;
 int    vflg;
 int    hflg;
 long   now;
 int    vflg;
 int    hflg;
 long   now;
+long   dev_bsize = 1;
 
 unsigned       ino;
 
 
 unsigned       ino;
 
@@ -85,7 +86,7 @@ main(argc, argv)
        if (argc == 0)
                quotall();
        while (argc-- > 0)
        if (argc == 0)
                quotall();
        while (argc-- > 0)
-               if (check(*argv++) == 0)
+               if (check(*argv++, (char *)NULL) == 0)
                        report();
        exit (0);
 }
                        report();
        exit (0);
 }
@@ -110,15 +111,16 @@ 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, "/dev/r%s", cp + 1);
+               if (check(dev, fs->fs_file) == 0)
                        report();
        }
        endfsent();
 }
 
                        report();
        }
        endfsent();
 }
 
-check(file)
+check(file, fsdir)
        char *file;
        char *file;
+       char *fsdir;
 {
        register int i, j, nfiles;
        register struct du **dp;
 {
        register int i, j, nfiles;
        register struct du **dp;
@@ -142,9 +144,18 @@ 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, SBOFF, (char *)&sblock, SBSIZE);
+       dev_bsize = sblock.fs_fsize / fsbtodb(&sblock, 1);
        if (nflg) {
                if (isdigit(c = getchar()))
                        ungetc(c, stdin);
        if (nflg) {
                if (isdigit(c = getchar()))
                        ungetc(c, stdin);
@@ -155,13 +166,14 @@ check(file)
        for (ino = 0; ino < nfiles; ) {
                iblk = fsbtodb(&sblock, itod(&sblock, ino));
                bread(fd, iblk, (char *)itab, sblock.fs_bsize);
        for (ino = 0; ino < nfiles; ) {
                iblk = fsbtodb(&sblock, itod(&sblock, ino));
                bread(fd, iblk, (char *)itab, sblock.fs_bsize);
-               for (j = 0; j < INOPB(&sblock) && ino < nfiles; j++) {
-                       if (ino++ < ROOTINO)
+               for (j = 0; j < INOPB(&sblock) && ino < nfiles; j++, ino++) {
+                       if (ino < ROOTINO)
                                continue;
                        acct(&itab[j]);
                }
        }
        close(fd);
                                continue;
                        acct(&itab[j]);
                }
        }
        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)
@@ -259,7 +271,7 @@ bread(fd, bno, buf, cnt)
        char *buf;
 {
 
        char *buf;
 {
 
-       lseek(fd, (long)bno * DEV_BSIZE, L_SET);
+       lseek(fd, (long)bno * dev_bsize, L_SET);
        if (read(fd, buf, cnt) != cnt) {
                fprintf(stderr, "quot: read error at block %u\n", bno);
                exit(1);
        if (read(fd, buf, cnt) != cnt) {
                fprintf(stderr, "quot: read error at block %u\n", bno);
                exit(1);
@@ -323,64 +335,42 @@ report()
        }
 }
 
        }
 }
 
+/* rest should be done with nameserver or database */
+
 #include <pwd.h>
 #include <pwd.h>
+#include <grp.h>
 #include <utmp.h>
 
 struct utmp utmp;
 #include <utmp.h>
 
 struct utmp utmp;
-
-#define NUID   2048
 #define        NMAX    (sizeof (utmp.ut_name))
 #define        NMAX    (sizeof (utmp.ut_name))
+#define SCPYN(a, b)    strncpy(a, b, NMAX)
+
+#define NUID   64      /* power of 2 */
+#define UIDMASK        0x3f
 
 
-char   names[NUID][NMAX+1];
+struct ncache {
+       int     uid;
+       char    name[NMAX+1];
+} nc[NUID];
 char   outrangename[NMAX+1];
 int    outrangeuid = -1;
 
 char *
 getname(uid)
 char   outrangename[NMAX+1];
 int    outrangeuid = -1;
 
 char *
 getname(uid)
-       int uid;
 {
        register struct passwd *pw;
 {
        register struct passwd *pw;
-       static init;
        struct passwd *getpwent();
        struct passwd *getpwent();
-
-       if (uid >= 0 && uid < NUID && names[uid][0])
-               return (&names[uid][0]);
-       if (uid >= 0 && uid == outrangeuid)
-               return (outrangename);
-       if (init == 2) {
-               if (uid < NUID)
-                       return (0);
-               setpwent();
-               while (pw = getpwent()) {
-                       if (pw->pw_uid != uid)
-                               continue;
-                       outrangeuid = pw->pw_uid;
-                       strncpy(outrangename, pw->pw_name, NUID);
-                       endpwent();
-                       return (outrangename);
-               }
-               endpwent();
+       extern int _pw_stayopen;
+       register int cp;
+
+       _pw_stayopen = 1;
+       cp = uid & UIDMASK;
+       if (uid >= 0 && nc[cp].uid == uid && nc[cp].name[0])
+               return (nc[cp].name);
+       pw = getpwuid(uid);
+       if (!pw)
                return (0);
                return (0);
-       }
-       if (init == 0)
-               setpwent(), init = 1;
-       while (pw = getpwent()) {
-               if (pw->pw_uid < 0 || pw->pw_uid >= NUID) {
-                       if (pw->pw_uid == uid) {
-                               outrangeuid = pw->pw_uid;
-                               strncpy(outrangename, pw->pw_name, NUID);
-                               return (outrangename);
-                       }
-                       continue;
-               }
-               if (names[pw->pw_uid][0])
-                       continue;
-               strncpy(names[pw->pw_uid], pw->pw_name, NMAX);
-               if (pw->pw_uid == uid) {
-                       return (&names[uid][0]);
-               }
-       }
-       init = 2;
-       endpwent();
-       return (0);
+       nc[cp].uid = uid;
+       SCPYN(nc[cp].name, pw->pw_name);
+       return (nc[cp].name);
 }
 }