1: /* 2: * Print system stuff 3: * Works on any number (MAXTTYS each) of kl,dh, and dz ports. 4: * Additional mods for use of /dev/kmem (except for -u), 5: * size parameters in kernel, and job control 6: */ 7: 8: #define MAXTTYS 48 9: #define mask(x) (x&0377) 10: #include <whoami.h> 11: #include <sys/param.h> 12: #include <stdio.h> 13: #include <a.out.h> 14: #include <sys/conf.h> 15: #include <sys/tty.h> 16: #include <sys/inode.h> 17: #include <sys/text.h> 18: #include <sys/proc.h> 19: #include <sys/dir.h> 20: #include <sys/user.h> 21: #include <sys/file.h> 22: 23: 24: char *fcore = "/dev/kmem"; 25: char *fmem = "/dev/mem"; 26: char *fnlist = "/unix"; 27: int fc, fm; 28: 29: struct nlist setup[] = { 30: #define SINODE 0 31: "_inode", 0, 0, 32: #define SNINODE 1 33: "_ninode", 0, 0, 34: #define STEXT 2 35: "_text", 0, 0, 36: #define SNTEXT 3 37: "_ntext", 0, 0, 38: #define SPROC 4 39: "_proc", 0, 0, 40: #define SNPROC 5 41: "_nproc", 0, 0, 42: #define SFILE 6 43: "_file", 0, 0, 44: #define SNFILE 7 45: "_nfile", 0, 0, 46: #define SDH 8 47: "_dh11", 0, 0, 48: #define SNDH 9 49: "_ndh11", 0, 0, 50: #define SKL 10 51: "_kl11", 0, 0, 52: #define SNKL 11 53: "_nkl11", 0, 0, 54: #define SDZ 12 55: "_dz11", 0, 0, 56: #define SNDZ 13 57: "_ndz11", 0, 0, 58: 0, 59: }; 60: 61: int inof; 62: int txtf; 63: int prcf; 64: int ttyf; 65: int usrf; 66: long ubase; 67: int filf; 68: int allflg; 69: 70: main(argc, argv) 71: char **argv; 72: { 73: 74: while (--argc && **++argv == '-') { 75: while (*++*argv) 76: switch (**argv) { 77: 78: case 'a': 79: allflg++; 80: break; 81: 82: case 'i': 83: inof++; 84: break; 85: 86: case 'x': 87: txtf++; 88: break; 89: case 'p': 90: prcf++; 91: break; 92: 93: case 't': 94: ttyf++; 95: break; 96: 97: case 'u': 98: if (--argc == 0) 99: break; 100: usrf++; 101: ubase = oatoi(*++argv); 102: break; 103: 104: case 'f': 105: filf++; 106: break; 107: } 108: } 109: if (argc>0) 110: fmem = fcore = argv[0]; 111: if ((fc = open(fcore, FATT_RDONLY)) < 0) { 112: perror(fcore); 113: exit(1); 114: } 115: if ((fm = open(fmem, FATT_RDONLY)) < 0) { 116: perror(fmem); 117: exit(1); 118: } 119: if (argc>1) 120: fnlist = argv[1]; 121: nlist(fnlist, setup); 122: if (setup[SINODE].n_type == 0) { 123: printf("no namelist\n"); 124: exit(1); 125: } 126: if (inof) 127: doinode(); 128: if (txtf) 129: dotext(); 130: if (ttyf) 131: dotty(); 132: if (prcf) 133: doproc(); 134: if (usrf) 135: dousr(); 136: if (filf) 137: dofil(); 138: } 139: 140: doinode() 141: { 142: register struct inode *ip; 143: struct inode *xinode; 144: register int nin, loc; 145: int ninode; 146: 147: /* 148: * Find number of inodes 149: */ 150: if (setup[SNINODE].n_value) { 151: lseek (fc, (off_t) setup[SNINODE].n_value, FSEEK_ABSOLUTE); 152: if (read(fc, (char *)&ninode,sizeof(ninode)) != sizeof(ninode)){ 153: perror("read"); 154: return; 155: } 156: } else { 157: fprintf(stderr, "ninode not in namelist\n"); 158: return; 159: } 160: xinode = (struct proc *)calloc(ninode, sizeof(struct inode)); 161: if (xinode == NULL) { 162: printf("Not enough memory for inodes\n"); 163: return; 164: } 165: 166: nin = 0; 167: lseek(fc, (long)setup[SINODE].n_value, FSEEK_ABSOLUTE); 168: read(fc, (char *)xinode, ninode * sizeof(struct inode)); 169: for (ip = xinode; ip < &xinode[ninode]; ip++) 170: if (ip->i_count) 171: nin++; 172: printf("%d active inodes\n", nin); 173: printf(" LOC FLAGS CNT DEVICE INO MODE NLK UID SIZE/DEV\n"); 174: loc = setup[SINODE].n_value; 175: for (ip = xinode; ip < &xinode[ninode]; ip++, loc += sizeof(xinode[0])) { 176: if (ip->i_count == 0) 177: continue; 178: printf("%7.1o ", loc); 179: putf(ip->i_flag&ILOCK, 'L'); 180: putf(ip->i_flag&IUPD, 'U'); 181: putf(ip->i_flag&IACC, 'A'); 182: putf(ip->i_flag&IMOUNT, 'M'); 183: putf(ip->i_flag&IWANT, 'W'); 184: putf(ip->i_flag&ITEXT, 'T'); 185: printf("%4d", ip->i_count&0377); 186: printf("%3d,%3d", major(ip->i_dev), minor(ip->i_dev)); 187: printf("%6l", ip->i_number); 188: printf("%7o", ip->i_mode); 189: printf("%4d", ip->i_nlink); 190: printf("%4d", ip->i_uid); 191: if ((ip->i_mode&IFMT)==IFBLK || (ip->i_mode&IFMT)==IFCHR) 192: printf("%6d,%3d", major(ip->i_un.i_rdev), minor(ip->i_un.i_rdev)); 193: else 194: printf("%10ld", ip->i_size); 195: printf("\n"); 196: } 197: free((char *)xinode); 198: } 199: 200: putf(v, n) 201: { 202: if (v) 203: printf("%c", n); 204: else 205: printf(" "); 206: } 207: 208: dotext() 209: { 210: register struct text *xp; 211: struct text *xtext; 212: register loc; 213: int ntx; 214: int ntext; 215: 216: /* 217: * Find number of texts 218: */ 219: if (setup[SNTEXT].n_value) { 220: lseek (fc, (off_t) setup[SNTEXT].n_value, FSEEK_ABSOLUTE); 221: if (read(fc, (char *)&ntext, sizeof(ntext)) != sizeof (ntext)) { 222: perror("read"); 223: return; 224: } 225: } else { 226: fprintf(stderr, "ntext not in namelist\n"); 227: return; 228: } 229: xtext = (struct text *)calloc(ntext, sizeof(struct text)); 230: if (xtext == NULL) { 231: printf("Not enough memory for text\n"); 232: return; 233: } 234: 235: ntx = 0; 236: lseek(fc, (long)setup[STEXT].n_value, FSEEK_ABSOLUTE); 237: read(fc, (char *)xtext, ntext * sizeof(struct text)); 238: for (xp = xtext; xp < &xtext[ntext]; xp++) 239: if (xp->x_iptr!=NULL) 240: ntx++; 241: printf("%d text segments\n", ntx); 242: printf(" LOC FLAGS DADDR CADDR SIZE IPTR CNT CCNT\n"); 243: loc = setup[STEXT].n_value; 244: for (xp = xtext; xp < &xtext[ntext]; xp++, loc+=sizeof(xtext[0])) { 245: if (xp->x_iptr == NULL) 246: continue; 247: printf("%7.1o", loc); 248: printf(" "); 249: putf(xp->x_flag&XTRC, 'T'); 250: putf(xp->x_flag&XWRIT, 'W'); 251: putf(xp->x_flag&XLOAD, 'L'); 252: putf(xp->x_flag&XLOCK, 'K'); 253: putf(xp->x_flag&XWANT, 'w'); 254: printf("%5u", xp->x_daddr); 255: printf("%7.1o", xp->x_caddr); 256: printf("%5d", xp->x_size); 257: printf("%8.1o", xp->x_iptr); 258: printf("%4d", xp->x_count&0377); 259: printf("%4d", xp->x_ccount); 260: printf("\n"); 261: } 262: free((char *)xtext); 263: } 264: 265: doproc() 266: { 267: struct proc *xproc; 268: register struct proc *pp; 269: register loc, np; 270: int nproc; 271: 272: /* 273: * Find number of procs 274: */ 275: if (setup[SNPROC].n_value) { 276: lseek (fc, (off_t) setup[SNPROC].n_value, FSEEK_ABSOLUTE); 277: if (read(fc, (char *)&nproc, sizeof(nproc)) != sizeof (nproc)) { 278: perror("read"); 279: return; 280: } 281: } else { 282: fprintf(stderr, "nproc not in namelist\n"); 283: return; 284: } 285: xproc = (struct proc *)calloc(nproc, sizeof(struct proc)); 286: if (xproc == NULL) { 287: printf("Not enough memory for procs\n"); 288: return; 289: } 290: lseek(fc, (long)setup[SPROC].n_value, FSEEK_ABSOLUTE); 291: read(fc, (char *)xproc, nproc * sizeof(struct proc)); 292: np = 0; 293: for (pp=xproc; pp < &xproc[nproc]; pp++) 294: if (pp->p_stat) 295: np++; 296: printf("%d processes\n", np); 297: #ifdef VIRUS_VFORK 298: printf( 299: " LOC S F PRI SIGNAL UID TIM CPU NI PGRP PID PPID ADDR DADR SADR\n\ 300: \tDSIZ SSIZ WCHAN LINK TEXTP CLKT\n"); 301: #else 302: printf(" LOC S F PRI SIGNAL UID TIM CPU NI PGRP PID PPID ADDR SIZE WCHAN LINK TEXTP CLKT\n"); 303: #endif 304: for (loc=setup[SPROC].n_value,pp=xproc; pp<&xproc[nproc]; pp++,loc+=sizeof(xproc[0])) { 305: if (pp->p_stat==0 && allflg==0) 306: continue; 307: printf("%6o", loc); 308: printf("%2d", pp->p_stat); 309: printf("%4o", pp->p_flag); 310: printf("%5d", pp->p_pri); 311: #ifdef MENLO_JCL 312: printf("%7O", pp->p_sig); 313: #else 314: printf("%7o", pp->p_sig); 315: #endif 316: printf("%4d", pp->p_uid&0377); 317: printf("%4d", pp->p_time&0377); 318: printf("%4d", pp->p_cpu&0377); 319: printf("%3d", pp->p_nice); 320: printf("%6d", pp->p_pgrp); 321: printf("%6d", pp->p_pid); 322: printf("%6d", pp->p_ppid); 323: printf("%5o", pp->p_addr); 324: #ifdef VIRUS_VFORK 325: printf("%5o", pp->p_daddr); 326: printf("%5o", pp->p_saddr); 327: printf("\n\t"); 328: printf("%5o", pp->p_dsize); 329: printf("%5o", pp->p_ssize); 330: #else 331: printf("%5o", pp->p_size); 332: #endif 333: printf("%7o", pp->p_wchan); 334: printf("%7o", pp->p_link); 335: printf("%7o", pp->p_textp); 336: printf(" %u", pp->p_clktim); 337: printf("\n"); 338: } 339: free((char *)xproc); 340: } 341: 342: dotty() 343: { 344: struct tty tty[MAXTTYS]; 345: int ntty; 346: register struct tty *tp; 347: register char *mesg; 348: 349: #ifdef MPX_FILS 350: mesg = " # RAW CAN OUT MODE ADDR DEL COL STATE PGRP CHAN\n"; 351: #else 352: mesg = " # RAW CAN OUT MODE ADDR DEL COL STATE PGRP\n"; 353: #endif 354: if (setup[SNKL].n_type != 0) { 355: lseek(fc, (long)setup[SNKL].n_value, FSEEK_ABSOLUTE); 356: read(fc, (char *)&ntty, sizeof(ntty)); 357: lseek(fc, (long)setup[SKL].n_value, FSEEK_ABSOLUTE); 358: read(fc, (char *)tty, ntty * sizeof(struct tty)); 359: printf("%d kl11 port%s\n", ntty, (ntty != 1) ? "s" : ""); 360: printf(mesg); 361: for(tp = tty; tp < &tty[ntty]; tp++) 362: ttyprt(tp-tty, tp); 363: } 364: if (setup[SNDZ].n_type != 0) { 365: lseek(fc, (long)setup[SNDZ].n_value, FSEEK_ABSOLUTE); 366: read(fc, (char *)&ntty, sizeof(ntty)); 367: lseek(fc, (long)setup[SDZ].n_value, FSEEK_ABSOLUTE); 368: read(fc, (char *)tty, ntty * sizeof(struct tty)); 369: printf("\n%d dz11 port%s\n", ntty, (ntty != 1) ? "s" : ""); 370: printf(mesg); 371: for(tp = tty; tp < &tty[ntty]; tp++) 372: ttyprt(tp-tty, tp); 373: } 374: if (setup[SNDH].n_type != 0) { 375: lseek(fc, (long)setup[SNDH].n_value, FSEEK_ABSOLUTE); 376: read(fc, (char *)&ntty, sizeof(ntty)); 377: lseek(fc, (long)setup[SDH].n_value, FSEEK_ABSOLUTE); 378: read(fc, (char *)tty, ntty * sizeof(struct tty)); 379: printf("\n%d dh11 port%s\n", ntty, (ntty != 1) ? "s" : ""); 380: printf(mesg); 381: for(tp = tty; tp < &tty[ntty]; tp++) 382: ttyprt(tp-tty, tp); 383: } 384: } 385: 386: ttyprt(n, atp) 387: struct tty *atp; 388: { 389: register struct tty *tp; 390: 391: tp = atp; 392: printf("%2d", n); 393: printf("%4d", tp->t_rawq.c_cc); 394: printf("%4d", tp->t_canq.c_cc); 395: printf("%4d", tp->t_outq.c_cc); 396: printf("%8.1o", tp->t_flags); 397: printf("%8.1o", tp->t_addr); 398: printf("%3d", tp->t_delct); 399: printf("%4d ", tp->t_col); 400: putf(tp->t_state&TIMEOUT, 'T'); 401: putf(tp->t_state&WOPEN, 'W'); 402: putf(tp->t_state&ISOPEN, 'O'); 403: putf(tp->t_state&CARR_ON, 'C'); 404: putf(tp->t_state&BUSY, 'B'); 405: putf(tp->t_state&ASLEEP, 'A'); 406: putf(tp->t_state&XCLUDE, 'X'); 407: putf(tp->t_state&TTSTOP, 'S'); 408: putf(tp->t_state&TBLOCK, 'M'); 409: putf(tp->t_state&HUPCLS, 'H'); 410: printf("%6d", tp->t_pgrp); 411: #ifdef MPX_FILS 412: printf("%4.1o", tp->t_chan); 413: #endif 414: printf("\n"); 415: } 416: 417: dousr() 418: { 419: union { 420: struct user rxu; 421: char fxu[ctob(USIZE)]; 422: } xu; 423: register struct user *up; 424: register i; 425: 426: lseek(fm, ubase<<6, FSEEK_ABSOLUTE); 427: read(fm, (char *)&xu, sizeof(xu)); 428: up = &xu.rxu; 429: dolabel("rsav", up->u_rsav); 430: printf("segflg, error %d, %d\n", up->u_segflg, up->u_error); 431: printf("uids %d,%d,%d,%d\n", up->u_uid,up->u_gid,up->u_ruid,up->u_rgid); 432: printf("procp %.1o\n", up->u_procp); 433: printf("base, count, offset %.1o %.1o %ld\n", up->u_base, 434: up->u_count, up->u_offset); 435: printf("cdir %.1o\n", up->u_cdir); 436: printf("dbuf %.14s\n", up->u_dbuf); 437: printf("dirp %.1o\n", up->u_dirp); 438: printf("dent %d %.14s\n", up->u_dent.d_ino, up->u_dent.d_name); 439: printf("pdir %.1o\n", up->u_pdir); 440: printf("dseg"); 441: for (i=0; i<8; i++) 442: printf("%8.1o", up->u_uisa[i]); 443: printf("\n "); 444: for (i=0; i<8; i++) 445: printf("%8.1o", up->u_uisd[i]); 446: if (up->u_sep) { 447: printf("\ntseg"); 448: for (i=8; i<16; i++) 449: printf("%8.1o", up->u_uisa[i]); 450: printf("\n "); 451: for (i=8; i<16; i++) 452: printf("%8.1o", up->u_uisd[i]); 453: } 454: printf("\nfile"); 455: for (i=0; i<10; i++) 456: printf("%8.1o", up->u_ofile[i]); 457: printf("\n "); 458: for (i=10; i<NOFILE; i++) 459: printf("%8.1o", up->u_ofile[i]); 460: printf("\nargs"); 461: for (i=0; i<5; i++) 462: printf(" %.1o", up->u_arg[i]); 463: printf("\nsizes %.1o %.1o %.1o\n", up->u_tsize, up->u_dsize, up->u_ssize); 464: printf("sep %d\n", up->u_sep); 465: dolabel("qsav", up->u_qsav); 466: dolabel("ssav", up->u_ssav); 467: printf("sigs"); 468: #ifdef MENLO_JCL 469: for (i=0; i<16; i++) 470: printf(" %.1o", up->u_signal[i]); 471: printf("\n "); 472: for (i=17; i<NSIG; i++) 473: printf(" %.1o", up->u_signal[i]); 474: #else 475: for (i=0; i<NSIG; i++) 476: printf(" %.1o", up->u_signal[i]); 477: #endif 478: printf("\ntimes %ld %ld\n", up->u_utime/60, up->u_stime/60); 479: printf("ctimes %ld %ld\n", up->u_cutime/60, up->u_cstime/60); 480: printf("ar0 %.1o\n", up->u_ar0); 481: /* 482: printf("prof"); 483: for (i=0; i<4; i++) 484: printf(" %.1o", up->u_prof[i]); 485: printf("\n"); 486: */ 487: printf("intflg %d\n", up->u_intflg); 488: printf("ttyp %.1o\n", up->u_ttyp); 489: printf("ttydev %d,%d\n", major(up->u_ttyd), minor(up->u_ttyd)); 490: printf("comm %.14s\n", up->u_comm); 491: #ifdef MENLO_OVLY 492: if (up->u_ovdata.uo_curov) { 493: printf("curov, ovbase, dbase, nseg %d %.1o %.1o %d\n", 494: up->u_ovdata.uo_curov, up->u_ovdata.uo_ovbase, 495: up->u_ovdata.uo_dbase, up->u_ovdata.uo_nseg); 496: printf("offst"); 497: for (i=0; i<8; i++) 498: printf(" %.1o", up->u_ovdata.uo_ov_offst[i]); 499: printf("\n"); 500: } 501: #endif 502: } 503: 504: dolabel(s, l) 505: char *s; 506: label_t l; 507: { 508: int i; 509: 510: printf("%s", s); 511: for (i=0; i < (sizeof(label_t) / sizeof(l[0])); i++) 512: printf(" %.1o", l[i]); 513: printf("\n"); 514: } 515: 516: oatoi(s) 517: char *s; 518: { 519: register v; 520: 521: v = 0; 522: while (*s) 523: v = (v<<3) + *s++ - '0'; 524: return(v); 525: } 526: 527: dofil() 528: { 529: struct file *xfile; 530: register struct file *fp; 531: register nf; 532: unsigned loc; 533: int nfile; 534: 535: /* 536: * Find number of files 537: */ 538: if (setup[SNFILE].n_value) { 539: lseek (fc, (off_t) setup[SNFILE].n_value, FSEEK_ABSOLUTE); 540: if (read(fc, (char *)&nfile, sizeof(nfile)) != sizeof (nfile)) { 541: perror("read"); 542: return; 543: } 544: } else { 545: fprintf(stderr, "nfile not in namelist\n"); 546: return; 547: } 548: xfile = (struct file *)calloc(nfile, sizeof(struct file)); 549: if (xfile == NULL) { 550: printf("Not enough memory for file table\n"); 551: return; 552: } 553: 554: nf = 0; 555: lseek(fc, (long)setup[SFILE].n_value, FSEEK_ABSOLUTE); 556: read(fc, (char *)xfile, nfile * sizeof(struct file)); 557: for (fp=xfile; fp < &xfile[nfile]; fp++) 558: if (fp->f_count) 559: nf++; 560: printf("%d open files\n", nf); 561: printf(" LOC FLG CNT INO OFFS\n"); 562: for (fp=xfile,loc=setup[SFILE].n_value; fp < &xfile[nfile]; 563: fp++,loc+=sizeof(xfile[0])) { 564: if (fp->f_count==0) 565: continue; 566: printf("%7.1o ", loc); 567: putf(fp->f_flag&FREAD, 'R'); 568: putf(fp->f_flag&FWRITE, 'W'); 569: putf(fp->f_flag&FPIPE, 'P'); 570: printf("%4d", mask(fp->f_count)); 571: printf("%8.1o", fp->f_inode); 572: printf(" %ld\n", fp->f_un.f_offset); 573: } 574: free((char *)xfile); 575: }