Annotation of researchv8dc/cmd/pstat/pstat.c, revision 1.1

1.1     ! root        1: static char *sccsid = "@(#)pstat.c     4.9 (Berkeley) 5/7/81";
        !             2: /*
        !             3:  * Print system stuff
        !             4:  */
        !             5: 
        !             6: #define mask(x) (x&0377)
        !             7: #define        clear(x) ((int)x&0x7fffffff)
        !             8: 
        !             9: #include <sys/param.h>
        !            10: #include <sys/dir.h>
        !            11: #include <sys/file.h>
        !            12: #include <sys/user.h>
        !            13: #include <sys/proc.h>
        !            14: #include <sys/text.h>
        !            15: #include <sys/inode.h>
        !            16: #include <sys/map.h>
        !            17: #include <sys/conf.h>
        !            18: #include <sys/vm.h>
        !            19: #include <nlist.h>
        !            20: #include <sys/pte.h>
        !            21: 
        !            22: char   *fcore  = "/dev/kmem";
        !            23: char   *fnlist = "/unix";
        !            24: int    fc;
        !            25: 
        !            26: struct nlist nl[] = {
        !            27: #define        SINODE  0
        !            28:        { "_inode" },
        !            29: #define        STEXT   1
        !            30:        { "_text" },
        !            31: #define        SPROC   2
        !            32:        { "_proc" },
        !            33: #define        SDZ     3
        !            34:        { "_dz_tty" },
        !            35: #define        SNDZ    4
        !            36:        { "_dz_cnt" },
        !            37: #define        SKL     5
        !            38:        { "_cons" },
        !            39: #define        SFIL    6
        !            40:        { "_file" },
        !            41: #define        USRPTMA 7
        !            42:        { "_Usrptmap" },
        !            43: #define        USRPT   8
        !            44:        { "_usrpt" },
        !            45: #define        SNSWAP  9
        !            46:        { "_nswap" },
        !            47: #define        SWAPMAP 10
        !            48:        { "_swapmap" },
        !            49: #define        SDH     11
        !            50:        { "_dh11" },
        !            51: #define        SNDH    12
        !            52:        { "_ndh11" },
        !            53: #define        SGROUP  13
        !            54:        { "_groups" },
        !            55: #define        SCHANS  14
        !            56:        { "_chans" },
        !            57: #define        SSCHANS 15
        !            58:        { "_schans" },
        !            59: #define        SNPROC  16
        !            60:        { "_nproc" },
        !            61: #define        SNTEXT  17
        !            62:        { "_ntext" },
        !            63: #define        SNFILE  18
        !            64:        { "_nfile" },
        !            65: #define        SNINODE 19
        !            66:        { "_ninode" },
        !            67: #define        SNSWAPMAP 20
        !            68:        { "_nswapmap" },
        !            69: #define        STRIMPROF 21
        !            70:        { "_trimprof" },
        !            71:        0,
        !            72: };
        !            73: 
        !            74: int    inof;           /* inode table */
        !            75: int    txtf;           /* text table */
        !            76: int    prcf;           /* proc table */
        !            77: int    ttyf;           /* streams, some day */
        !            78: int    usrf;           /* user struct */
        !            79: long   ubase;
        !            80: int    filf;           /* file table */
        !            81: int    swpf;           /* swap usage */
        !            82: int    totflg;         /* total table usage */
        !            83: int    clkf;           /* clock trims */
        !            84: char   partab[1];
        !            85: struct cdevsw  cdevsw[1];
        !            86: struct bdevsw  bdevsw[1];
        !            87: int    allflg;
        !            88: int    kflg;
        !            89: struct pte *Usrptma;
        !            90: struct pte *usrpt;
        !            91: long   seekmask = 0xffffffff;
        !            92: 
        !            93: main(argc, argv)
        !            94: char **argv;
        !            95: {
        !            96:        register char *argp;
        !            97: 
        !            98:        argc--, argv++;
        !            99:        while (argc > 0 && **argv == '-') {
        !           100:                argp = *argv++;
        !           101:                argp++;
        !           102:                argc--;
        !           103:                while (*argp++)
        !           104:                switch (argp[-1]) {
        !           105: 
        !           106:                case 'T':
        !           107:                        totflg++;
        !           108:                        break;
        !           109: 
        !           110:                case 'a':
        !           111:                        allflg++;
        !           112:                        break;
        !           113: 
        !           114:                case 'i':
        !           115:                        inof++;
        !           116:                        break;
        !           117: 
        !           118:                case 'k':
        !           119:                        kflg++;
        !           120:                        fcore = "/vmcore";
        !           121:                        seekmask = 0x7fffffff;
        !           122:                        break;
        !           123: 
        !           124:                case 'x':
        !           125:                        txtf++;
        !           126:                        break;
        !           127: 
        !           128:                case 'p':
        !           129:                        prcf++;
        !           130:                        break;
        !           131: 
        !           132:                case 't':
        !           133:                        ttyf++;
        !           134:                        break;
        !           135: 
        !           136:                case 'u':
        !           137:                        if (argc == 0)
        !           138:                                break;
        !           139:                        argc--;
        !           140:                        usrf++;
        !           141:                        sscanf( *argv++, "%x", &ubase);
        !           142:                        break;
        !           143: 
        !           144:                case 'f':
        !           145:                        filf++;
        !           146:                        break;
        !           147:                case 's':
        !           148:                        swpf++;
        !           149:                        break;
        !           150:                case 'c':
        !           151:                        clkf++;
        !           152:                        break;
        !           153:                }
        !           154:        }
        !           155:        if (argc>0) {
        !           156:                fcore = argv[0];
        !           157:                seekmask = 0x7fffffff;
        !           158:        }
        !           159:        if ((fc = open(fcore, 0)) < 0) {
        !           160:                printf("Can't find %s\n", fcore);
        !           161:                exit(1);
        !           162:        }
        !           163:        if (argc>1)
        !           164:                fnlist = argv[1];
        !           165:        nlist(fnlist, nl);
        !           166:        if (nl[0].n_type == 0) {
        !           167:                printf("no namelist\n");
        !           168:                exit(1);
        !           169:        }
        !           170:        usrpt = (struct pte *)nl[USRPT].n_value;
        !           171:        Usrptma = (struct pte *)nl[USRPTMA].n_value;
        !           172:        if (filf||totflg)
        !           173:                dofile();
        !           174:        if (inof||totflg)
        !           175:                doinode();
        !           176:        if (prcf||totflg)
        !           177:                doproc();
        !           178:        if (txtf||totflg)
        !           179:                dotext();
        !           180:        if (ttyf)
        !           181:                dotty();
        !           182:        if (usrf)
        !           183:                dousr();
        !           184:        if (swpf||totflg)
        !           185:                doswap();
        !           186:        if (clkf||totflg)
        !           187:                doclk();
        !           188: }
        !           189: 
        !           190: doinode()
        !           191: {
        !           192:        register struct inode *ip;
        !           193:        struct inode *xinode, *ainode;
        !           194:        register int nin;
        !           195:        int ninode;
        !           196: 
        !           197:        nin = 0;
        !           198:        ninode = getw(nl[SNINODE].n_value);
        !           199:        xinode = (struct inode *)calloc(ninode, sizeof (struct inode));
        !           200:        xxseek(fc, (int)(ainode = (struct inode *)getw(nl[SINODE].n_value)), 0);
        !           201:        read(fc, xinode, ninode * sizeof(struct inode));
        !           202:        for (ip = xinode; ip < &xinode[ninode]; ip++)
        !           203:                if (ip->i_count)
        !           204:                        nin++;
        !           205:        printf("%5d/%5d inodes\n", nin, ninode);
        !           206:        if (totflg)
        !           207:                return;
        !           208:        printf("   LOC    FLAGS  CNT DEVICE  INO   MODE  NLN UID   SPTR   SIZE/DEV\n");
        !           209:        for (ip = xinode; ip < &xinode[ninode]; ip++) {
        !           210:                if (ip->i_count == 0)
        !           211:                        continue;
        !           212:                printf("%8.1x ", ainode + (ip - xinode));
        !           213:                putf(ip->i_flag&ILOCK, 'L');
        !           214:                putf(ip->i_flag&IUPD, 'U');
        !           215:                putf(ip->i_flag&IACC, 'A');
        !           216:                putf(ip->i_flag&IMOUNT, 'M');
        !           217:                putf(ip->i_flag&IWANT, 'W');
        !           218:                putf(ip->i_flag&ITEXT, 'T');
        !           219:                printf("%4d", ip->i_count&0377);
        !           220:                printf("%3d,%3d", major(ip->i_dev), minor(ip->i_dev));
        !           221:                printf("%6d", ip->i_number);
        !           222:                printf("%7o", ip->i_mode & 0xffff);
        !           223:                printf("%4d", ip->i_nlink);
        !           224:                printf("%4d", ip->i_uid);
        !           225:                printf("%8x", (int)ip->i_sptr&0xffffff);
        !           226:                if ((ip->i_mode&IFMT)==IFBLK || (ip->i_mode&IFMT)==IFCHR)
        !           227:                        printf("%6d,%3d", major(ip->i_un.i_rdev), minor(ip->i_un.i_rdev));
        !           228:                else
        !           229:                        printf("%10ld", ip->i_size);
        !           230:                printf("\n");
        !           231:        }
        !           232:        free(xinode);
        !           233: }
        !           234: 
        !           235: getw(loc)
        !           236:        off_t loc;
        !           237: {
        !           238:        int word;
        !           239: 
        !           240:        if (kflg)
        !           241:                loc &= 0x7fffffff;
        !           242:        xxseek(fc, loc, 0);
        !           243:        read(fc, &word, sizeof (word));
        !           244:        if (kflg)
        !           245:                word &= 0x7fffffff;
        !           246:        return (word);
        !           247: }
        !           248: 
        !           249: putf(v, n)
        !           250: {
        !           251:        if (v)
        !           252:                printf("%c", n);
        !           253:        else
        !           254:                printf(" ");
        !           255: }
        !           256: 
        !           257: dotext()
        !           258: {
        !           259:        register struct text *xp;
        !           260:        int ntext;
        !           261:        struct text *xtext, *atext;
        !           262:        int ntx;
        !           263: 
        !           264:        ntx = 0;
        !           265:        ntext = getw(nl[SNTEXT].n_value);
        !           266:        xtext = (struct text *)calloc(ntext, sizeof (struct text));
        !           267:        xxseek(fc, (int)(atext = (struct text *)getw(nl[STEXT].n_value)), 0);
        !           268:        read(fc, xtext, ntext * sizeof (struct text));
        !           269:        for (xp = xtext; xp < &xtext[ntext]; xp++)
        !           270:                if (xp->x_iptr!=NULL)
        !           271:                        ntx++;
        !           272:        printf("%5d/%5d active texts\n", ntx, ntext);
        !           273:        if (totflg)
        !           274:                return;
        !           275:        printf("   LOC   FLAGS DADDR      CADDR  RSS SIZE      IPTR  CNT CCNT\n");
        !           276:        for (xp = xtext; xp < &xtext[ntext]; xp++) {
        !           277:                if (xp->x_iptr == NULL)
        !           278:                        continue;
        !           279:                printf("%8.1x", atext + (xp - xtext));
        !           280:                printf(" ");
        !           281:                putf(xp->x_flag&XPAGI, 'P');
        !           282:                putf(xp->x_flag&XTRC, 'T');
        !           283:                putf(xp->x_flag&XWRIT, 'W');
        !           284:                putf(xp->x_flag&XLOAD, 'L');
        !           285:                putf(xp->x_flag&XLOCK, 'K');
        !           286:                putf(xp->x_flag&XWANT, 'w');
        !           287:                printf("%5x", xp->x_daddr[0]);
        !           288:                printf("%11x", xp->x_caddr);
        !           289:                printf("%5d", xp->x_rssize);
        !           290:                printf("%5d", xp->x_size);
        !           291:                printf("%10.1x", xp->x_iptr);
        !           292:                printf("%5d", xp->x_count&0377);
        !           293:                printf("%5d", xp->x_ccount);
        !           294:                printf("\n");
        !           295:        }
        !           296:        free(xtext);
        !           297: }
        !           298: 
        !           299: doproc()
        !           300: {
        !           301:        struct proc *xproc, *aproc;
        !           302:        int nproc;
        !           303:        register struct proc *pp;
        !           304:        register loc, np;
        !           305:        struct pte apte;
        !           306: 
        !           307:        nproc = getw(nl[SNPROC].n_value);
        !           308:        xproc = (struct proc *)calloc(nproc, sizeof (struct proc));
        !           309:        xxseek(fc, (int)(aproc = (struct proc *)getw(nl[SPROC].n_value)), 0);
        !           310:        read(fc, xproc, nproc * sizeof (struct proc));
        !           311:        np = 0;
        !           312:        for (pp=xproc; pp < &xproc[nproc]; pp++)
        !           313:                if (pp->p_stat)
        !           314:                        np++;
        !           315:        printf("%5d/%5d processes\n", np, nproc);
        !           316:        if (totflg)
        !           317:                return;
        !           318:        printf("   LOC    S    F POIP PRI      SIG  UID SLP TIM  CPU  NI   PGRP    PID   PPID    ADDR   RSS SRSS SIZE    WCHAN    LINK   TEXTP CLKT\n");
        !           319:        for (pp=xproc; pp<&xproc[nproc]; pp++) {
        !           320:                if (pp->p_stat==0 && allflg==0)
        !           321:                        continue;
        !           322:                printf("%8x", aproc + (pp - xproc));
        !           323:                printf(" %2d", pp->p_stat);
        !           324:                printf(" %4x", pp->p_flag & 0xffff);
        !           325:                printf(" %4d", pp->p_poip);
        !           326:                printf(" %3d", pp->p_pri);
        !           327:                printf(" %8x", pp->p_sig);
        !           328:                printf(" %4d", pp->p_uid);
        !           329:                printf(" %3d", pp->p_slptime);
        !           330:                printf(" %3d", pp->p_time);
        !           331:                printf(" %4d", pp->p_cpu&0377);
        !           332:                printf(" %3d", pp->p_nice);
        !           333:                printf(" %6d", pp->p_pgrp);
        !           334:                printf(" %6d", pp->p_pid);
        !           335:                printf(" %6d", pp->p_ppid);
        !           336:                if (kflg)
        !           337:                        pp->p_addr = (struct pte *)clear((int)pp->p_addr);
        !           338:                xxseek(fc, (long)(Usrptma+btokmx(pp->p_addr)), 0);
        !           339:                read(fc, &apte, sizeof(apte));
        !           340:                printf(" %8x", ctob(apte.pg_pfnum+1) - sizeof(struct pte) * UPAGES);
        !           341:                printf(" %4x", pp->p_rssize);
        !           342:                printf(" %4x", pp->p_swrss);
        !           343:                printf(" %5x", pp->p_dsize+pp->p_ssize);
        !           344:                printf(" %7x", clear(pp->p_wchan));
        !           345:                printf(" %7x", clear(pp->p_link));
        !           346:                printf(" %7x", clear(pp->p_textp));
        !           347:                printf("    %u", pp->p_clktim);
        !           348:                printf("\n");
        !           349:        }
        !           350: }
        !           351: 
        !           352: dotty()
        !           353: {
        !           354: printf("redo tty stuff for new system\n");
        !           355: /*     struct tty dz_tty[64];
        !           356: /*     int ndz;
        !           357: /*     register struct tty *tp;
        !           358: /*     register char *mesg;
        !           359: /*
        !           360: /*     printf("1 cons\n");
        !           361: /*     if (kflg)
        !           362: /*             nl[SKL].n_value = clear(nl[SKL].n_value);
        !           363: /*     xxseek(fc, (long)nl[SKL].n_value, 0);
        !           364: /*     read(fc, dz_tty, sizeof(dz_tty[0]));
        !           365: /*     mesg = " # RAW CAN OUT   MODE    ADDR   DEL COL  STATE   PGRP DISC\n";
        !           366: /*     printf(mesg);
        !           367: /*     ttyprt(&dz_tty[0], 0);
        !           368: /*     if (nl[SNDZ].n_type == 0)
        !           369: /*             goto dh;
        !           370: /*     if (kflg) {
        !           371: /*             nl[SNDZ].n_value = clear(nl[SNDZ].n_value);
        !           372: /*             nl[SDZ].n_value = clear(nl[SDZ].n_value);
        !           373: /*     }
        !           374: /*     xxseek(fc, (long)nl[SNDZ].n_value, 0);
        !           375: /*     read(fc, &ndz, sizeof(ndz));
        !           376: /*     printf("%d dz lines\n", ndz);
        !           377: /*     xxseek(fc, (long)nl[SDZ].n_value, 0);
        !           378: /*     read(fc, dz_tty, sizeof(dz_tty));
        !           379: /*     for (tp = dz_tty; tp < &dz_tty[ndz]; tp++)
        !           380: /*             ttyprt(tp, tp - dz_tty);
        !           381: /*dh:
        !           382: /*     if (nl[SNDH].n_type == 0)
        !           383: /*             return;
        !           384: /*     if (kflg) {
        !           385: /*             nl[SNDH].n_value = clear(nl[SNDH].n_value);
        !           386: /*             nl[SDH].n_value = clear(nl[SDH].n_value);
        !           387: /*     }
        !           388: /*     xxseek(fc, (long)nl[SNDH].n_value, 0);
        !           389: /*     read(fc, &ndz, sizeof(ndz));
        !           390: /*     printf("%d dh lines\n", ndz);
        !           391: /*     xxseek(fc, (long)nl[SDH].n_value, 0);
        !           392: /*     read(fc, dz_tty, sizeof(dz_tty));
        !           393: /*     for (tp = dz_tty; tp < &dz_tty[ndz]; tp++)
        !           394: /*             ttyprt(tp, tp - dz_tty);
        !           395: /*}
        !           396: /*
        !           397: /*ttyprt(atp, line)
        !           398: /*struct tty *atp;
        !           399: /*{
        !           400: /*     register struct tty *tp;
        !           401: /*
        !           402: /*     printf("%2d", line);
        !           403: /*     tp = atp;
        !           404: /*     switch (tp->t_line) {
        !           405: /*
        !           406: /*     case NETLDISC:
        !           407: /*             if (tp->t_rec)
        !           408: /*                     printf("%4d%4d", 0, tp->t_inbuf);
        !           409: /*             else
        !           410: /*                     printf("%4d%4d", tp->t_inbuf, 0);
        !           411: /*             break;
        !           412: /*
        !           413: /*     default:
        !           414: /*             printf("%4d", tp->t_rawq.c_cc);
        !           415: /*             printf("%4d", tp->t_canq.c_cc);
        !           416: /*     }
        !           417: /*     printf("%4d", tp->t_outq.c_cc);
        !           418: /*     printf("%8.1o", tp->t_flags);
        !           419: /*     printf(" %8.1x", tp->t_addr);
        !           420: /*     printf("%3d", tp->t_delct);
        !           421: /*     printf("%4d ", tp->t_col);
        !           422: /*     putf(tp->t_state&TIMEOUT, 'T');
        !           423: /*     putf(tp->t_state&WOPEN, 'W');
        !           424: /*     putf(tp->t_state&ISOPEN, 'O');
        !           425: /*     putf(tp->t_state&CARR_ON, 'C');
        !           426: /*     putf(tp->t_state&BUSY, 'B');
        !           427: /*     putf(tp->t_state&ASLEEP, 'A');
        !           428: /*     putf(tp->t_state&XCLUDE, 'X');
        !           429: /*
        !           430: /*     putf(tp->t_state&HUPCLS, 'H');
        !           431: /*
        !           432: /*     printf("%6d", tp->t_pgrp);
        !           433: /*     switch (tp->t_line) {
        !           434: /*
        !           435: /*     case NTTYDISC:
        !           436: /*             printf(" ntty");
        !           437: /*             break;
        !           438: /*
        !           439: /*     case NETLDISC:
        !           440: /*             printf(" net");
        !           441: /*             break;
        !           442: /*     }
        !           443: /*     printf("\n");*/
        !           444: }
        !           445: 
        !           446: dousr()
        !           447: {
        !           448:        struct user U;
        !           449:        register i, j, *ip;
        !           450: 
        !           451:        /* This wins only if PAGSIZ > sizeof (struct user) */
        !           452:        xxseek(fc, ubase * NBPG, 0);
        !           453:        read(fc, &U, sizeof(U));
        !           454:        printf("pcb");
        !           455:        ip = (int *)&U.u_pcb;
        !           456:        while (ip < &U.u_arg[0]) {
        !           457:                if ((ip - (int *)&U.u_pcb) % 4 == 0)
        !           458:                        printf("\t");
        !           459:                printf("%x ", *ip++);
        !           460:                if ((ip - (int *)&U.u_pcb) % 4 == 0)
        !           461:                        printf("\n");
        !           462:        }
        !           463:        if ((ip - (int *)&U.u_pcb) % 4 != 0)
        !           464:                printf("\n");
        !           465:        printf("arg\t");
        !           466:        for (i=0; i<5; i++)
        !           467:                printf(" %.1x", U.u_arg[i]);
        !           468:        printf("\n");
        !           469:        for (i=0; i<sizeof(label_t)/sizeof(int); i++) {
        !           470:                if (i%5==0)
        !           471:                        printf("\t");
        !           472:                printf("%9.1x", U.u_ssav[i]);
        !           473:                if (i%5==4)
        !           474:                        printf("\n");
        !           475:        }
        !           476:        if (i%5)
        !           477:                printf("\n");
        !           478:        printf("segflg\t%d\nerror %d\n", U.u_segflg, U.u_error);
        !           479:        printf("uids\t%d,%d,%d,%d\n", U.u_uid,U.u_gid,U.u_ruid,U.u_rgid);
        !           480:        printf("procp\t%.1x\n", U.u_procp);
        !           481:        printf("ap\t%.1x\n", U.u_ap);
        !           482:        printf("r_val?\t%.1x %.1x\n", U.u_r.r_val1, U.u_r.r_val2);
        !           483:        printf("base, count, offset %.1x %.1x %ld\n", U.u_base,
        !           484:                U.u_count, U.u_offset);
        !           485:        printf("cdir rdir %.1x %.1x\n", U.u_cdir, U.u_rdir);
        !           486:        printf("dbuf %.14s\n", U.u_dbuf);
        !           487:        printf("dirp %.1x\n", U.u_dirp);
        !           488:        printf("dent %d %.14s\n", U.u_dent.d_ino, U.u_dent.d_name);
        !           489:        printf("pdir %.1o\n", U.u_pdir);
        !           490:        printf("file\t");
        !           491:        for (i=0; i<10; i++)
        !           492:                printf("%9.1x", U.u_ofile[i]);
        !           493:        printf("\n\t");
        !           494:        for (i=10; i<NOFILE; i++)
        !           495:                printf("%9.1x", U.u_ofile[i]);
        !           496:        printf("\n");
        !           497:        printf("pofile\t");
        !           498:        for (i=0; i<10; i++)
        !           499:                printf("%9.1x", U.u_pofile[i]);
        !           500:        printf("\n\t");
        !           501:        for (i=10; i<NOFILE; i++)
        !           502:                printf("%9.1x", U.u_pofile[i]);
        !           503:        printf("\n");
        !           504:        printf("ssav");
        !           505:        for (i=0; i<sizeof(label_t)/sizeof(int); i++) {
        !           506:                if (i%5==0)
        !           507:                        printf("\t");
        !           508:                printf("%9.1x", U.u_ssav[i]);
        !           509:                if (i%5==4)
        !           510:                        printf("\n");
        !           511:        }
        !           512:        if (i%5)
        !           513:                printf("\n");
        !           514:        printf("sigs\t");
        !           515:        for (i=0; i<NSIG; i++)
        !           516:                printf("%.1x ", U.u_signal[i]);
        !           517:        printf("\n");
        !           518:        printf("ar0\t%.1x\n", U.u_ar0);
        !           519:        printf("prof\t%X %X %X %X\n", U.u_prof.pr_base, U.u_prof.pr_size,
        !           520:            U.u_prof.pr_off, U.u_prof.pr_scale);
        !           521:        printf("\neosys\t%d\n", U.u_eosys);
        !           522:        printf("sep\t%d\n", U.u_sep);
        !           523:        /*
        !           524:        printf("ttyp\t%.1x\n", U.u_ttyp);
        !           525:        printf("ttyd\t%d,%d\n", major(U.u_ttyd), minor(U.u_ttyd));
        !           526:        */
        !           527:        printf("exdata\t");
        !           528:        ip = (int *)&U.u_exdata;
        !           529:        for (i = 0; i < 8; i++)
        !           530:                printf("%.1D ", *ip++);
        !           531:        printf("\n");
        !           532:        printf("comm %.14s\n", U.u_comm);
        !           533:        printf("start\t%D\n", U.u_start);
        !           534:        printf("acflag\t%D\n", U.u_acflag);
        !           535:        printf("fpflag\t%D\n", U.u_fpflag);
        !           536:        printf("cmask\t%D\n", U.u_cmask);
        !           537:        printf("sizes\t%.1x %.1x %.1x\n", U.u_tsize, U.u_dsize, U.u_ssize);
        !           538:        printf("vm\t");
        !           539:        ip = (int *)&U.u_vm;
        !           540:        for (i = 0; i < sizeof(U.u_vm)/sizeof(int); i++)
        !           541:                printf("%D ", ip[i]);
        !           542:        printf("\n");
        !           543:        ip = (int *)&U.u_cvm;
        !           544:        printf("cvm\t");
        !           545:        for (i = 0; i < sizeof(U.u_vm)/sizeof(int); i++)
        !           546:                printf("%D ", ip[i]);
        !           547:        printf("\n");
        !           548: /*
        !           549:        i =  U.u_stack - &U;
        !           550:        while (U[++i] == 0);
        !           551:        i &= ~07;
        !           552:        while (i < 512) {
        !           553:                printf("%x ", 0140000+2*i);
        !           554:                for (j=0; j<8; j++)
        !           555:                        printf("%9x", U[i++]);
        !           556:                printf("\n");
        !           557:        }
        !           558: */
        !           559: }
        !           560: 
        !           561: oatoi(s)
        !           562: char *s;
        !           563: {
        !           564:        register v;
        !           565: 
        !           566:        v = 0;
        !           567:        while (*s)
        !           568:                v = (v<<3) + *s++ - '0';
        !           569:        return(v);
        !           570: }
        !           571: 
        !           572: dofile()
        !           573: {
        !           574:        int nfile;
        !           575:        struct file *xfile, *afile;
        !           576:        register struct file *fp;
        !           577:        register nf;
        !           578:        int loc;
        !           579: 
        !           580:        nf = 0;
        !           581:        nfile = getw(nl[SNFILE].n_value);
        !           582:        xfile = (struct file *)calloc(nfile, sizeof (struct file));
        !           583:        xxseek(fc, (int)(afile = (struct file *)getw(nl[SFIL].n_value)), 0);
        !           584:        read(fc, xfile, nfile * sizeof (struct file));
        !           585:        for (fp=xfile; fp < &xfile[nfile]; fp++)
        !           586:                if (fp->f_count)
        !           587:                        nf++;
        !           588:        printf("%5d/%5d open files\n", nf, nfile);
        !           589:        if (totflg)
        !           590:                return;
        !           591:        printf("   LOC   FLG  CNT   INO    OFFS\n");
        !           592:        for (fp=xfile,loc=nl[SFIL].n_value; fp < &xfile[nfile]; fp++,loc+=sizeof(xfile[0])) {
        !           593:                if (fp->f_count==0)
        !           594:                        continue;
        !           595:                printf("%8x ", loc);
        !           596:                putf(fp->f_flag&FREAD, 'R');
        !           597:                putf(fp->f_flag&FWRITE, 'W');
        !           598:                putf(fp->f_flag&FPIPE, 'P');
        !           599:                printf("%4d", mask(fp->f_count));
        !           600:                printf("%9.1x", fp->f_inode);
        !           601:                printf("  %ld\n", fp->f_offset);
        !           602:        }
        !           603: }
        !           604: 
        !           605: doswap()
        !           606: {
        !           607:        struct proc *proc;
        !           608:        int nproc;
        !           609:        struct text *xtext;
        !           610:        int ntext;
        !           611:        struct map *swapmap;
        !           612:        int nswapmap;
        !           613:        register struct proc *pp;
        !           614:        int nswap, used, tused, free;
        !           615:        register struct mapent *me;
        !           616:        register struct text *xp;
        !           617: 
        !           618:        nproc = getw(nl[SNPROC].n_value);
        !           619:        proc = (struct proc *)calloc(nproc, sizeof (struct proc));
        !           620:        xxseek(fc, getw(nl[SPROC].n_value), 0);
        !           621:        read(fc, proc, nproc * sizeof (struct proc));
        !           622:        nswapmap = getw(nl[SNSWAPMAP].n_value);
        !           623:        swapmap = (struct map *)calloc(nswapmap, sizeof (struct map));
        !           624:        xxseek(fc, getw(nl[SWAPMAP].n_value), 0);
        !           625:        read(fc, swapmap, nswapmap * sizeof (struct map));
        !           626:        nswap = getw(nl[SNSWAP].n_value);
        !           627:        free = 0;
        !           628:        for (me = (struct mapent *)(swapmap+1);
        !           629:            me < (struct mapent *)&swapmap[nswapmap]; me++)
        !           630:                free += me->m_size;
        !           631:        ntext = getw(nl[SNTEXT].n_value);
        !           632:        xtext = (struct text *)calloc(ntext, sizeof (struct text));
        !           633:        xxseek(fc, getw(nl[STEXT].n_value), 0);
        !           634:        read(fc, xtext, ntext * sizeof (struct text));
        !           635:        tused = 0;
        !           636:        for (xp = xtext; xp < &xtext[ntext]; xp++)
        !           637:                if (xp->x_iptr!=NULL)
        !           638:                        tused += xdsize(xp);
        !           639:        used = tused;
        !           640:        for (pp = proc; pp < &proc[nproc]; pp++) {
        !           641:                if (pp->p_stat == 0 || pp->p_stat == SZOMB)
        !           642:                        continue;
        !           643:                if (pp->p_flag & SSYS)
        !           644:                        continue;
        !           645:                used += up(pp->p_dsize) + up(pp->p_ssize);
        !           646:                if ((pp->p_flag&SLOAD) == 0)
        !           647:                        used += vusize(pp);
        !           648:        }
        !           649:        /* a DMMAX/2 block goes to argmap */
        !           650:        if (totflg)
        !           651:                printf("%5d/%5d 00k swap\n", used/2/100, (used+free)/2/100);
        !           652:        printf("%d used (%d text), %d free, %d missing\n",
        !           653:            used/2, tused/2, free/2, (nswap - DMMAX/2 - (used + free))/2);
        !           654: }
        !           655: 
        !           656: doclk()
        !           657: {
        !           658:        register int    i;
        !           659:        unsigned int    trimprof[3];
        !           660: 
        !           661:        if (!nl[STRIMPROF].n_value) {
        !           662:                printf("Clock trim info unavailable.\n");
        !           663:                return;
        !           664:        }
        !           665:        for (i = 0; i < 3; ++i)
        !           666:                trimprof[i] = getw(nl[STRIMPROF].n_value + (i * sizeof trimprof[0]));
        !           667:        printf("%12.12s %12.12s %12.12s\n", "SLOW", "ON TIME", "FAST");
        !           668:        printf("%12d %12d %12d\n", trimprof[0], trimprof[1], trimprof[2]);
        !           669: }
        !           670: 
        !           671: up(size)
        !           672:        register int size;
        !           673: {
        !           674:        register int i, block;
        !           675: 
        !           676:        i = 0;
        !           677:        block = DMMIN;
        !           678:        while (i < size) {
        !           679:                i += block;
        !           680:                if (block < DMMAX)
        !           681:                        block *= 2;
        !           682:        }
        !           683:        return (i);
        !           684: }
        !           685: 
        !           686: vusize(p)
        !           687: struct proc *p;
        !           688: {
        !           689:        register int tsz = p->p_tsize / NPTEPG;
        !           690: 
        !           691:        return (clrnd(UPAGES + clrnd(ctopt(p->p_tsize+p->p_dsize+p->p_ssize+UPAGES)) - tsz));
        !           692: }
        !           693: 
        !           694: xdsize(xp)
        !           695: struct text *xp;
        !           696: {
        !           697: 
        !           698:        if (xp->x_flag & XPAGI)
        !           699:                return (clrnd(xp->x_size + ctopt(xp->x_size)));
        !           700:        return (xp->x_size);
        !           701: }
        !           702: 
        !           703: xxseek(f, l)
        !           704: long l;
        !           705: {
        !           706:        return(lseek(f, l&seekmask, 0));
        !           707: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.