1: /*
   2:  * Copyright (c) 1980 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #if !defined(lint) && defined(DOSCCS)
   8: char copyright[] =
   9: "@(#) Copyright (c) 1980 Regents of the University of California.\n\
  10:  All rights reserved.\n";
  11: 
  12: static char sccsid[] = "@(#)pstat.c	5.8.6 (2.11BSD) 1999/9/13";
  13: #endif
  14: 
  15: /*
  16:  * Print system stuff
  17:  */
  18: 
  19: #include <sys/param.h>
  20: #define KERNEL
  21: #include <sys/localopts.h>
  22: #include <sys/file.h>
  23: #include <sys/user.h>
  24: #undef  KERNEL
  25: #include <sys/proc.h>
  26: #include <sys/text.h>
  27: #include <sys/inode.h>
  28: #include <sys/map.h>
  29: #include <sys/ioctl.h>
  30: #include <sys/tty.h>
  31: #include <sys/conf.h>
  32: #include <sys/vm.h>
  33: #include <nlist.h>
  34: #include <stdio.h>
  35: 
  36: char    *fcore  = "/dev/kmem";
  37: char    *fmem   = "/dev/mem";
  38: char    *fnlist = "/vmunix";
  39: int fc, fm;
  40: 
  41: struct nlist nl[] = {
  42: #define SINODE  0
  43:     { "_inode" },
  44: #define STEXT   1
  45:     { "_text" },
  46: #define SPROC   2
  47:     { "_proc" },
  48: #define SDZ 3
  49:     { "_dz_tty" },
  50: #define SNDZ    4
  51:     { "_dz_cnt" },
  52: #define SKL 5
  53:     { "_cons" },
  54: #define SFIL    6
  55:     { "_file" },
  56: #define SNSWAP  7
  57:     { "_nswap" },
  58: #define SNKL    8
  59:     { "_nkl11" },
  60: #define SWAPMAP 9
  61:     { "_swapmap" },
  62: #define SDH 10
  63:     { "_dh11" },
  64: #define SNDH    11
  65:     { "_ndh11" },
  66: #define SNPROC  12
  67:     { "_nproc" },
  68: #define SNTEXT  13
  69:     { "_ntext" },
  70: #define SNFILE  14
  71:     { "_nfile" },
  72: #define SNINODE 15
  73:     { "_ninode" },
  74: #define SPTY    16
  75:     { "_pt_tty" },
  76: #define SNPTY   17
  77:     { "_npty" },
  78: #define SDHU    18
  79:     { "_dhu_tty" },
  80: #define SNDHU   19
  81:     { "_ndhu" },
  82: #define SDHV    20
  83:     { "_dhv_tty" },
  84: #define SNDHV   21
  85:     { "_ndhv" },
  86:     { "" }
  87: };
  88: 
  89: int inof;
  90: int txtf;
  91: int prcf;
  92: int ttyf;
  93: int usrf;
  94: long    ubase;
  95: int filf;
  96: int swpf;
  97: int totflg;
  98: int allflg;
  99: int kflg;
 100: u_short getw();
 101: 
 102: main(argc, argv)
 103: char **argv;
 104: {
 105:     register char *argp;
 106:     int allflags;
 107: 
 108:     argc--, argv++;
 109:     while (argc > 0 && **argv == '-') {
 110:         argp = *argv++;
 111:         argp++;
 112:         argc--;
 113:         while (*argp++)
 114:         switch (argp[-1]) {
 115: 
 116:         case 'T':
 117:             totflg++;
 118:             break;
 119: 
 120:         case 'a':
 121:             allflg++;
 122:             break;
 123: 
 124:         case 'i':
 125:             inof++;
 126:             break;
 127: 
 128:         case 'k':
 129:             kflg++;
 130:             fcore = fmem = "/core";
 131:             break;
 132: 
 133:         case 'x':
 134:             txtf++;
 135:             break;
 136: 
 137:         case 'p':
 138:             prcf++;
 139:             break;
 140: 
 141:         case 't':
 142:             ttyf++;
 143:             break;
 144: 
 145:         case 'u':
 146:             if (argc == 0)
 147:                 break;
 148:             argc--;
 149:             usrf++;
 150:             sscanf( *argv++, "%lo", &ubase);
 151:             break;
 152: 
 153:         case 'f':
 154:             filf++;
 155:             break;
 156:         case 's':
 157:             swpf++;
 158:             break;
 159:         default:
 160:             usage();
 161:             exit(1);
 162:         }
 163:     }
 164:     if (argc>1) {
 165:         fcore = fmem = argv[1];
 166:         kflg++;
 167:     }
 168:     if ((fc = open(fcore, 0)) < 0) {
 169:         printf("Can't find %s\n", fcore);
 170:         exit(1);
 171:     }
 172:     if ((fm = open(fmem, 0)) < 0) {
 173:         printf("Can't find %s\n", fmem);
 174:         exit(1);
 175:     }
 176:     if (argc>0)
 177:         fnlist = argv[0];
 178:     nlist(fnlist, nl);
 179:     if (nl[0].n_type == 0) {
 180:         printf("no namelist, n_type: %d n_value: %o n_name: %s\n", nl[0].n_type, nl[0].n_value, nl[0].n_name);
 181:         exit(1);
 182:     }
 183:     allflags = filf | totflg | inof | prcf | txtf | ttyf | usrf | swpf;
 184:     if (allflags == 0) {
 185:         printf("pstat: one or more of -[aixptfsu] is required\n");
 186:         exit(1);
 187:     }
 188:     if (filf||totflg)
 189:         dofile();
 190:     if (inof||totflg)
 191:         doinode();
 192:     if (prcf||totflg)
 193:         doproc();
 194:     if (txtf||totflg)
 195:         dotext();
 196:     if (ttyf)
 197:         dotty();
 198:     if (usrf)
 199:         dousr();
 200:     if (swpf||totflg)
 201:         doswap();
 202: }
 203: 
 204: usage()
 205: {
 206: 
 207:     printf("usage: pstat -[aixptfs] [-u [ubase]] [system] [core]\n");
 208: }
 209: 
 210: doinode()
 211: {
 212:     register struct inode *ip;
 213:     struct inode *xinode;
 214:     register int nin;
 215:     u_int ninode, ainode;
 216: 
 217:     nin = 0;
 218:     ninode = getw((off_t)nl[SNINODE].n_value);
 219:     xinode = (struct inode *)calloc(ninode, sizeof (struct inode));
 220:     ainode = nl[SINODE].n_value;
 221:     if (ninode < 0 || ninode > 10000) {
 222:         fprintf(stderr, "number of inodes is preposterous (%d)\n",
 223:             ninode);
 224:         return;
 225:     }
 226:     if (xinode == NULL) {
 227:         fprintf(stderr, "can't allocate memory for inode table\n");
 228:         return;
 229:     }
 230:     lseek(fc, (off_t)ainode, 0);
 231:     read(fc, xinode, ninode * sizeof(struct inode));
 232:     for (ip = xinode; ip < &xinode[ninode]; ip++)
 233:         if (ip->i_count)
 234:             nin++;
 235:     if (totflg) {
 236:         printf("%3d/%3d inodes\n", nin, ninode);
 237:         return;
 238:     }
 239:     printf("%d/%d active inodes\n", nin, ninode);
 240: printf("   LOC      FLAGS      CNT  DEVICE  RDC WRC  INO   MODE  NLK  UID  SIZE/DEV FS\n");
 241:     for (ip = xinode; ip < &xinode[ninode]; ip++) {
 242:         if (ip->i_count == 0)
 243:             continue;
 244:         printf("%7.1o ", ainode + (ip - xinode)*sizeof (*ip));
 245:         putf((long)ip->i_flag&ILOCKED, 'L');
 246:         putf((long)ip->i_flag&IUPD, 'U');
 247:         putf((long)ip->i_flag&IACC, 'A');
 248:         putf((long)ip->i_flag&IMOUNT, 'M');
 249:         putf((long)ip->i_flag&IWANT, 'W');
 250:         putf((long)ip->i_flag&ITEXT, 'T');
 251:         putf((long)ip->i_flag&ICHG, 'C');
 252:         putf((long)ip->i_flag&ISHLOCK, 'S');
 253:         putf((long)ip->i_flag&IEXLOCK, 'E');
 254:         putf((long)ip->i_flag&ILWAIT, 'Z');
 255:         putf((long)ip->i_flag&IPIPE, 'P');
 256:         putf((long)ip->i_flag&IMOD, 'm');
 257:         putf((long)ip->i_flag&IRENAME, 'r');
 258:         putf((long)ip->i_flag&IXMOD, 'x');
 259:         printf("%4d", ip->i_count);
 260:         printf("%4d,%3d", major(ip->i_dev), minor(ip->i_dev));
 261:         printf("%4d", ip->i_flag&IPIPE ? 0 : ip->i_shlockc);
 262:         printf("%4d", ip->i_flag&IPIPE ? 0 : ip->i_exlockc);
 263:         printf("%6u ", ip->i_number);
 264:         printf("%7.1o", ip->i_mode);
 265:         printf("%4d", ip->i_nlink);
 266:         printf("%5u", ip->i_uid);
 267:         if ((ip->i_mode&IFMT)==IFBLK || (ip->i_mode&IFMT)==IFCHR)
 268:             printf("%6d,%3d", major(ip->i_rdev), minor(ip->i_rdev));
 269:         else
 270:             printf("%10ld", ip->i_size);
 271:         printf(" %2d", ip->i_fs);
 272:         printf("\n");
 273:     }
 274:     free(xinode);
 275: }
 276: 
 277: u_short
 278: getw(loc)
 279:     off_t loc;
 280: {
 281:     u_short word;
 282: 
 283:     lseek(fc, loc, 0);
 284:     read(fc, &word, sizeof (word));
 285:     return (word);
 286: }
 287: 
 288: putf(v, n)
 289:     long    v;
 290:     char    n;
 291: {
 292:     if (v)
 293:         printf("%c", n);
 294:     else
 295:         printf(" ");
 296: }
 297: 
 298: dotext()
 299: {
 300:     register struct text *xp;
 301:     int ntext;
 302:     struct text *xtext;
 303:     u_int ntx, ntxca, atext;
 304: 
 305:     ntx = ntxca = 0;
 306:     ntext = getw((off_t)nl[SNTEXT].n_value);
 307:     xtext = (struct text *)calloc(ntext, sizeof (struct text));
 308:     atext = nl[STEXT].n_value;
 309:     if (ntext < 0 || ntext > 10000) {
 310:         fprintf(stderr, "number of texts is preposterous (%d)\n",
 311:             ntext);
 312:         return;
 313:     }
 314:     if (xtext == NULL) {
 315:         fprintf(stderr, "can't allocate memory for text table\n");
 316:         return;
 317:     }
 318:     lseek(fc, (off_t)atext, 0);
 319:     read(fc, xtext, ntext * sizeof (struct text));
 320:     for (xp = xtext; xp < &xtext[ntext]; xp++) {
 321:         if (xp->x_iptr != NULL)
 322:             ntxca++;
 323:         if (xp->x_count != 0)
 324:             ntx++;
 325:     }
 326:     if (totflg) {
 327:         printf("%3d/%3d texts active, %3d used\n", ntx, ntext, ntxca);
 328:         return;
 329:     }
 330:     printf("%d/%d active texts, %d used\n", ntx, ntext, ntxca);
 331:     printf("\
 332:    LOC   FLAGS   DADDR   CADDR    SIZE   IPTR   CNT CCNT   FORW     BACK\n");
 333:     for (xp = xtext; xp < &xtext[ntext]; xp++) {
 334:         if (xp->x_iptr == NULL)
 335:             continue;
 336:         printf("%7.1o ", atext + (xp - xtext)*sizeof (*xp));
 337:         putf((long)xp->x_flag&XPAGI, 'P');
 338:         putf((long)xp->x_flag&XTRC, 'T');
 339:         putf((long)xp->x_flag&XWRIT, 'W');
 340:         putf((long)xp->x_flag&XLOAD, 'L');
 341:         putf((long)xp->x_flag&XLOCK, 'K');
 342:         putf((long)xp->x_flag&XWANT, 'w');
 343:         putf((long)xp->x_flag&XUNUSED, 'u');
 344:         printf("%7.1o ", xp->x_daddr);
 345:         printf("%7.1o ", xp->x_caddr);
 346:         printf("%7.1o ", xp->x_size);
 347:         printf("%7.1o", xp->x_iptr);
 348:         printf("%4u ", xp->x_count);
 349:         printf("%4u ", xp->x_ccount);
 350:         printf("%7.1o ", xp->x_forw);
 351:         printf("%7.1o\n", xp->x_back);
 352:     }
 353:     free(xtext);
 354: }
 355: 
 356: doproc()
 357: {
 358:     struct proc *xproc;
 359:     u_int nproc, aproc;
 360:     register struct proc *pp;
 361:     register loc, np;
 362: 
 363:     nproc = getw((off_t)nl[SNPROC].n_value);
 364:     xproc = (struct proc *)calloc(nproc, sizeof (struct proc));
 365:     aproc = nl[SPROC].n_value;
 366:     if (nproc < 0 || nproc > 10000) {
 367:         fprintf(stderr, "number of procs is preposterous (%d)\n",
 368:             nproc);
 369:         return;
 370:     }
 371:     if (xproc == NULL) {
 372:         fprintf(stderr, "can't allocate memory for proc table\n");
 373:         return;
 374:     }
 375:     lseek(fc, (off_t)aproc, 0);
 376:     read(fc, xproc, nproc * sizeof (struct proc));
 377:     np = 0;
 378:     for (pp=xproc; pp < &xproc[nproc]; pp++)
 379:         if (pp->p_stat)
 380:             np++;
 381:     if (totflg) {
 382:         printf("%3d/%3d processes\n", np, nproc);
 383:         return;
 384:     }
 385:     printf("%d/%d processes\n", np, nproc);
 386: printf("   LOC   S       F PRI      SIG   UID SLP TIM  CPU  NI   PGRP    PID   PPID    ADDR   SADDR   DADDR    SIZE   WCHAN    LINK   TEXTP SIGM\n");
 387:     for (pp=xproc; pp<&xproc[nproc]; pp++) {
 388:         if (pp->p_stat==0 && allflg==0)
 389:             continue;
 390:         printf("%7.1o", aproc + (pp - xproc)*sizeof (*pp));
 391:         printf(" %2d", pp->p_stat);
 392:         printf(" %7.1x", pp->p_flag);
 393:         printf(" %3d", pp->p_pri);
 394:         printf(" %8.1lx", pp->p_sig);
 395:         printf(" %5u", pp->p_uid);
 396:         printf(" %3d", pp->p_slptime);
 397:         printf(" %3d", pp->p_time);
 398:         printf(" %4d", pp->p_cpu&0377);
 399:         printf(" %3d", pp->p_nice);
 400:         printf(" %6d", pp->p_pgrp);
 401:         printf(" %6d", pp->p_pid);
 402:         printf(" %6d", pp->p_ppid);
 403:         printf(" %7.1o", pp->p_addr);
 404:         printf(" %7.1o", pp->p_saddr);
 405:         printf(" %7.1o", pp->p_daddr);
 406:         printf(" %7.1o", pp->p_dsize+pp->p_ssize);
 407:         printf(" %7.1o", pp->p_wchan);
 408:         printf(" %7.1o", pp->p_link);
 409:         printf(" %7.1o", pp->p_textp);
 410:         printf(" %8.1lx", pp->p_sigmask);
 411:         printf("\n");
 412:     }
 413:     free(xproc);
 414: }
 415: 
 416: static char mesg[] =
 417: " # RAW CAN OUT         MODE    ADDR  DEL  COL      STATE       PGRP DISC\n";
 418: static int ttyspace = 64;
 419: static struct tty *tty;
 420: 
 421: dotty()
 422: {
 423:     extern char *malloc();
 424: 
 425:     if ((tty = (struct tty *)malloc(ttyspace * sizeof(*tty))) == 0) {
 426:         printf("pstat: out of memory\n");
 427:         return;
 428:     }
 429:     dottytype("kl", SKL, SNKL);
 430:     if (nl[SNDZ].n_type != 0)
 431:         dottytype("dz", SDZ, SNDZ);
 432:     if (nl[SNDH].n_type != 0)
 433:         dottytype("dh", SDH, SNDH);
 434:     if (nl[SNDHU].n_type != 0)
 435:         dottytype("dhu", SDHU, SNDHU);
 436:     if (nl[SNDHV].n_type != 0)
 437:         dottytype("dhv", SDHV, SNDHV);
 438:     if (nl[SNPTY].n_type != 0)
 439:         dottytype("pty", SPTY, SNPTY);
 440: }
 441: 
 442: dottytype(name, type, number)
 443: char *name;
 444: {
 445:     int ntty;
 446:     register struct tty *tp;
 447:     extern char *realloc();
 448: 
 449:     lseek(fc, (long)nl[number].n_value, 0);
 450:     read(fc, &ntty, sizeof(ntty));
 451:     printf("%d %s lines\n", ntty, name);
 452:     if (ntty > ttyspace) {
 453:         ttyspace = ntty;
 454:         if ((tty = (struct tty *)realloc(tty, ttyspace * sizeof(*tty))) == 0) {
 455:             printf("pstat: out of memory\n");
 456:             return;
 457:         }
 458:     }
 459:     lseek(fc, (long)nl[type].n_value, 0);
 460:     read(fc, tty, ntty * sizeof(struct tty));
 461:     printf(mesg);
 462:     for (tp = tty; tp < &tty[ntty]; tp++)
 463:         ttyprt(tp, tp - tty);
 464: }
 465: 
 466: ttyprt(atp, line)
 467: struct tty *atp;
 468: {
 469:     register struct tty *tp;
 470: 
 471:     printf("%2d", line);
 472:     tp = atp;
 473: 
 474:     printf("%4d%4d", tp->t_rawq.c_cc, tp->t_canq.c_cc);
 475:     printf("%4d %12.1lo %7.1o %4d %4d ", tp->t_outq.c_cc, tp->t_flags,
 476:         tp->t_addr, tp->t_delct, tp->t_col);
 477:     putf(tp->t_state&TS_TIMEOUT, 'T');
 478:     putf(tp->t_state&TS_WOPEN, 'W');
 479:     putf(tp->t_state&TS_ISOPEN, 'O');
 480:     putf(tp->t_state&TS_FLUSH, 'F');
 481:     putf(tp->t_state&TS_CARR_ON, 'C');
 482:     putf(tp->t_state&TS_BUSY, 'B');
 483:     putf(tp->t_state&TS_ASLEEP, 'A');
 484:     putf(tp->t_state&TS_XCLUDE, 'X');
 485:     putf(tp->t_state&TS_TTSTOP, 'S');
 486:     putf(tp->t_state&TS_HUPCLS, 'H');
 487:     putf(tp->t_state&TS_TBLOCK, 'b');
 488:     putf(tp->t_state&TS_RCOLL, 'r');
 489:     putf(tp->t_state&TS_WCOLL, 'w');
 490:     putf(tp->t_state&TS_ASYNC, 'a');
 491:     printf("%6d", tp->t_pgrp);
 492:     switch (tp->t_line) {
 493: 
 494:     case OTTYDISC:
 495:         printf("\n");
 496:         break;
 497: 
 498:     case NTTYDISC:
 499:         printf(" ntty\n");
 500:         break;
 501: 
 502:     case NETLDISC:
 503:         printf(" berknet\n");
 504:         break;
 505: 
 506:     case TABLDISC:
 507:         printf(" tab\n");
 508:         break;
 509: 
 510:     case SLIPDISC:
 511:         printf(" slip\n");
 512:         break;
 513: 
 514:     default:
 515:         printf(" %d\n", tp->t_line);
 516:     }
 517: }
 518: 
 519: dousr()
 520: {
 521:     struct user U;
 522:     long    *ip;
 523:     register i, j;
 524: 
 525:     lseek(fm, ubase << 6, 0);
 526:     read(fm, &U, sizeof(U));
 527:     printf("pcb\t%.1o\n", U.u_pcb.pcb_sigc);
 528:     printf("fps\t%.1o %g %g %g %g %g %g\n", U.u_fps.u_fpsr,
 529:         U.u_fps.u_fpregs[0], U.u_fps.u_fpregs[1], U.u_fps.u_fpregs[2],
 530:         U.u_fps.u_fpregs[3], U.u_fps.u_fpregs[4], U.u_fps.u_fpregs[5]);
 531:     printf("fpsaved\t%d\n", U.u_fpsaved);
 532:     printf("fperr\t%.1o %.1o\n", U.u_fperr.f_fec, U.u_fperr.f_fea);
 533:     printf("procp\t%.1o\n", U.u_procp);
 534:     printf("ar0\t%.1o\n", U.u_ar0);
 535:     printf("comm\t%s\n", U.u_comm);
 536:     printf("arg\t%.1o %.1o %.1o %.1o %.1o %.1o\n", U.u_arg[0], U.u_arg[1],
 537:         U.u_arg[2], U.u_arg[3], U.u_arg[4], U.u_arg[5]);
 538:     printf("ap\t%.1o\n", U.u_ap);
 539:     printf("qsave\t");
 540:     for (i = 0; i < sizeof (label_t) / sizeof (int); i++)
 541:         printf("%.1o ", U.u_qsave.val[i]);
 542:     printf("\n");
 543:     printf("r_val1\t%.1o\n", U.u_r.r_val1);
 544:     printf("r_val2\t%.1o\n", U.u_r.r_val2);
 545:     printf("error\t%d\n", U.u_error);
 546:     printf("uids\t%d,%d,%d,%d,%d\n", U.u_uid, U.u_svuid, U.u_ruid,
 547:         U.u_svgid, U.u_rgid);
 548:     printf("groups");
 549:     for (i = 0; (i < NGROUPS) && (U.u_groups[i] != NOGROUP); i++)
 550:         {
 551:         if  (i%8 == 0) printf("\t");
 552:         printf("%u ", U.u_groups[i]);
 553:         if  (i%8 == 7) printf("\n");
 554:         }
 555:     if  (i%8) printf("\n");
 556:     printf("tsize\t%.1o\n", U.u_tsize);
 557:     printf("dsize\t%.1o\n", U.u_dsize);
 558:     printf("ssize\t%.1o\n", U.u_ssize);
 559:     printf("ssave\t");
 560:     for (i = 0; i < sizeof (label_t) / sizeof (int); i++)
 561:         printf("%.1o ", U.u_ssave.val[i]);
 562:     printf("\n");
 563:     printf("rsave\t");
 564:     for (i = 0; i < sizeof (label_t) / sizeof (int); i++)
 565:         printf("%.1o ", U.u_rsave.val[i]);
 566:     printf("\n");
 567:     printf("uisa");
 568:     for (i = 0; i < sizeof (U.u_uisa) / sizeof (short); i++)
 569:         {
 570:         if  (i%8 == 0) printf("\t");
 571:         printf("%.1o ", U.u_uisa[i]);
 572:         if  (i%8 == 7) printf("\n");
 573:         }
 574:     if  (i%8) printf("\n");
 575:     printf("uisd");
 576:     for (i = 0; i < sizeof (U.u_uisd) / sizeof (short); i++)
 577:         {
 578:         if  (i%8 == 0) printf("\t");
 579:         printf("%.1o ", U.u_uisd[i]);
 580:         if  (i%8 == 7) printf("\n");
 581:         }
 582:     if  (i%8) printf("\n");
 583:     printf("sep\t%d\n", U.u_sep);
 584:     printf("ovdata\t%d %d %.1o %d\n", U.u_ovdata.uo_curov,
 585:         U.u_ovdata.uo_ovbase, U.u_ovdata.uo_dbase, U.u_ovdata.uo_nseg);
 586:     printf("ov_offst");
 587:     for (i = 0; i < NOVL; i++)
 588:         {
 589:         if  (i%8 == 0) printf("\t");
 590:         printf("%.1o ", U.u_ovdata.uo_ov_offst[i]);
 591:         if  (i%8 == 7) printf("\n");
 592:         }
 593:     if  (i%8) printf("\n");
 594:     printf("signal");
 595:     for (i = 0; i < NSIG; i++)
 596:         {
 597:         if  (i%8 == 0) printf("\t");
 598:         printf("%.1o ", U.u_signal[i]);
 599:         if  (i%8 == 7) printf("\n");
 600:         }
 601:     if  (i%8) printf("\n");
 602:     printf("sigmask");
 603:     for (i = 0; i < NSIG; i++)
 604:         {
 605:         if  (i%8 == 0) printf("\t");
 606:         printf("%.1lo ", U.u_sigmask[i]);
 607:         if  (i%8 == 7) printf("\n");
 608:         }
 609:     if  (i%8) printf("\n");
 610:     printf("sigonstack\t%.1lo\n", U.u_sigonstack);
 611:     printf("sigintr\t%.1lo\n", U.u_sigintr);
 612:     printf("oldmask\t%.1lo\n", U.u_oldmask);
 613:     printf("code\t%u\n", U.u_code);
 614:     printf("psflags\t%d\n", U.u_psflags);
 615:     printf("ss_base\t%.1o ss_size %.1o ss_flags %.1o\n",
 616:         U.u_sigstk.ss_base, U.u_sigstk.ss_size, U.u_sigstk.ss_flags);
 617:     printf("ofile");
 618:     for (i = 0; i < NOFILE; i++)
 619:         {
 620:         if  (i%8 == 0) printf("\t");
 621:         printf("%.1o ", U.u_ofile[i]);
 622:         if  (i%8 == 7) printf("\n");
 623:         }
 624:     if  (i%8) printf("\n");
 625:     printf("pofile");
 626:     for (i = 0; i < NOFILE; i++)
 627:         {
 628:         if  (i%8 == 0) printf("\t");
 629:         printf("%.1o ", U.u_pofile[i]);
 630:         if  (i%8 == 7) printf("\n");
 631:         }
 632:     if  (i%8) printf("\n");
 633:     printf("lastfile\t%d\n", U.u_lastfile);
 634:     printf("cdir\t%.1o\n", U.u_cdir);
 635:     printf("rdir\t%.1o\n", U.u_rdir);
 636:     printf("ttyp\t%.1o\n", U.u_ttyp);
 637:     printf("ttyd\t%d,%d\n", major(U.u_ttyd), minor(U.u_ttyd));
 638:     printf("cmask\t%.1o\n", U.u_cmask);
 639:     printf("ru\t");
 640:     ip = (long *)&U.u_ru;
 641:     for (i = 0; i < sizeof (U.u_ru) / sizeof (long); i++)
 642:         printf("%ld ", ip[i]);
 643:     printf("\n");
 644:     printf("cru\t");
 645:     ip = (long *)&U.u_cru;
 646:     for (i = 0; i < sizeof (U.u_cru) / sizeof (long); i++)
 647:         printf("%ld ", ip[i]);
 648:     printf("\n");
 649:     printf("timer\t%ld %ld %ld %ld\n", U.u_timer[0].it_interval,
 650:         U.u_timer[0].it_value, U.u_timer[1].it_interval,
 651:         U.u_timer[1].it_value);
 652:     printf("start\t%ld\n", U.u_start);
 653:     printf("acflag\t%d\n", U.u_acflag);
 654:     printf("prof\t%.1o %u %u %u\n", U.u_prof.pr_base, U.u_prof.pr_size,
 655:         U.u_prof.pr_off, U.u_prof.pr_scale);
 656:     printf("rlimit cur\t");
 657:     for (i = 0; i < RLIM_NLIMITS; i++)
 658:         {
 659:         if  (U.u_rlimit[i].rlim_cur == RLIM_INFINITY)
 660:             printf("infinite ");
 661:         else
 662:             printf("%ld ", U.u_rlimit[i].rlim_cur);
 663:         }
 664:     printf("\n");
 665:     printf("rlimit max\t");
 666:     for (i = 0; i < RLIM_NLIMITS; i++)
 667:         {
 668:         if  (U.u_rlimit[i].rlim_max == RLIM_INFINITY)
 669:             printf("infinite ");
 670:         else
 671:             printf("%ld ", U.u_rlimit[i].rlim_max);
 672:         }
 673:     printf("\n");
 674:     printf("quota\t%.1o\n", U.u_quota);
 675:     printf("ncache\t%ld %u %d,%d\n", U.u_ncache.nc_prevoffset,
 676:         U.u_ncache.nc_inumber, major(U.u_ncache.nc_dev),
 677:         minor(U.u_ncache.nc_dev));
 678:     printf("login\t%*s\n", MAXLOGNAME, U.u_login);
 679: }
 680: 
 681: oatoi(s)
 682: char *s;
 683: {
 684:     register v;
 685: 
 686:     v = 0;
 687:     while (*s)
 688:         v = (v<<3) + *s++ - '0';
 689:     return(v);
 690: }
 691: 
 692: dofile()
 693: {
 694:     int nfile;
 695:     struct file *xfile;
 696:     register struct file *fp;
 697:     register nf;
 698:     u_int loc, afile;
 699:     static char *dtypes[] = { "???", "inode", "socket", "pipe" };
 700: 
 701:     nf = 0;
 702:     nfile = getw((off_t)nl[SNFILE].n_value);
 703:     xfile = (struct file *)calloc(nfile, sizeof (struct file));
 704:     if (nfile < 0 || nfile > 10000) {
 705:         fprintf(stderr, "number of files is preposterous (%d)\n",
 706:             nfile);
 707:         return;
 708:     }
 709:     if (xfile == NULL) {
 710:         fprintf(stderr, "can't allocate memory for file table\n");
 711:         return;
 712:     }
 713:     afile = nl[SFIL].n_value;
 714:     lseek(fc, (off_t)afile, 0);
 715:     read(fc, xfile, nfile * sizeof (struct file));
 716:     for (fp=xfile; fp < &xfile[nfile]; fp++)
 717:         if (fp->f_count)
 718:             nf++;
 719:     if (totflg) {
 720:         printf("%3d/%3d files\n", nf, nfile);
 721:         return;
 722:     }
 723:     printf("%d/%d open files\n", nf, nfile);
 724:     printf("   LOC   TYPE   FLG        CNT  MSG   DATA    OFFSET\n");
 725:     loc = afile;
 726:     for (fp=xfile; fp < &xfile[nfile]; fp++, loc += sizeof (*fp))
 727:         {
 728:         if (fp->f_count==0)
 729:             continue;
 730:         printf("%7.1o ", loc);
 731:         if (fp->f_type <= DTYPE_PIPE)
 732:             printf("%-8.8s", dtypes[fp->f_type]);
 733:         else
 734:             printf("8d", fp->f_type);
 735:         putf((long)fp->f_flag&FREAD, 'R');
 736:         putf((long)fp->f_flag&FWRITE, 'W');
 737:         putf((long)fp->f_flag&FAPPEND, 'A');
 738:         putf((long)fp->f_flag&FSHLOCK, 'S');
 739:         putf((long)fp->f_flag&FEXLOCK, 'X');
 740:         putf((long)fp->f_flag&FASYNC, 'I');
 741:         putf((long)fp->f_flag&FNONBLOCK, 'n');
 742:         putf((long)fp->f_flag&FMARK, 'm');
 743:         putf((long)fp->f_flag&FDEFER, 'd');
 744:         printf("  %3d", fp->f_count);
 745:         printf("  %3d", fp->f_msgcount);
 746:         printf("  %7.1o", fp->f_data);
 747:         if (fp->f_offset < 0)
 748:             printf("  0%lo\n", fp->f_offset);
 749:         else
 750:             printf("  %ld\n", fp->f_offset);
 751:     }
 752:     free(xfile);
 753: }
 754: 
 755: doswap()
 756: {
 757:     u_int   nswap, used;
 758:     int i, num;
 759:     struct  map smap;
 760:     struct  mapent  *swp;
 761: 
 762:     nswap = getw((off_t)nl[SNSWAP].n_value);
 763:     lseek(fc, (off_t)nl[SWAPMAP].n_value, 0);
 764:     read(fc, &smap, sizeof (smap));
 765:     num = (smap.m_limit - smap.m_map);
 766:     swp = (struct mapent *)calloc(num, sizeof (*swp));
 767:     lseek(fc, (off_t)smap.m_map, 0);
 768:     read(fc, swp, num * sizeof (*swp));
 769:     for (used = 0, i = 0; swp[i].m_size; i++)
 770:         used += swp[i].m_size;
 771:     printf("%d/%d swapmap entries\n", i, num);
 772:     printf("%u kbytes swap used, %u kbytes free\n", (nswap-used)/2, used/2);
 773: }

Defined functions

dofile defined in line 692; used 1 times
doinode defined in line 210; used 1 times
doproc defined in line 356; used 1 times
doswap defined in line 755; used 1 times
dotext defined in line 298; used 1 times
dotty defined in line 421; used 1 times
dottytype defined in line 442; used 6 times
dousr defined in line 519; used 1 times
getw defined in line 277; used 6 times
main defined in line 102; never used
oatoi defined in line 681; never used
putf defined in line 288; used 44 times
ttyprt defined in line 466; used 1 times
usage defined in line 204; used 1 times

Defined variables

allflg defined in line 98; used 2 times
copyright defined in line 8; never used
fc defined in line 39; used 19 times
fcore defined in line 36; used 4 times
filf defined in line 95; used 3 times
fm defined in line 39; used 3 times
fmem defined in line 37; used 4 times
fnlist defined in line 38; used 2 times
inof defined in line 89; used 3 times
kflg defined in line 99; used 2 times
mesg defined in line 416; used 1 times
nl defined in line 41; used 22 times
prcf defined in line 91; used 3 times
sccsid defined in line 12; never used
swpf defined in line 96; used 3 times
totflg defined in line 97; used 11 times
tty defined in line 419; used 9 times
ttyf defined in line 92; used 3 times
ttyspace defined in line 418; used 4 times
txtf defined in line 90; used 3 times
ubase defined in line 94; used 2 times
usrf defined in line 93; used 3 times

Defined macros

KERNEL defined in line 20; used 1 times
  • in line 24
SDH defined in line 62; used 1 times
SDHU defined in line 78; used 1 times
SDHV defined in line 82; used 1 times
SDZ defined in line 48; used 1 times
SFIL defined in line 54; used 1 times
SINODE defined in line 42; used 1 times
SKL defined in line 52; used 1 times
SNDH defined in line 64; used 2 times
SNDHU defined in line 80; used 2 times
SNDHV defined in line 84; used 2 times
SNDZ defined in line 50; used 2 times
SNFILE defined in line 70; used 1 times
SNINODE defined in line 72; used 1 times
SNKL defined in line 58; used 1 times
SNPROC defined in line 66; used 1 times
SNPTY defined in line 76; used 2 times
SNSWAP defined in line 56; used 1 times
SNTEXT defined in line 68; used 1 times
SPROC defined in line 46; used 1 times
SPTY defined in line 74; used 1 times
STEXT defined in line 44; used 1 times
SWAPMAP defined in line 60; used 1 times
Last modified: 1999-09-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 7375
Valid CSS Valid XHTML 1.0 Strict