Bell 32V development
[unix-history] / usr / src / cmd / pstat.c
CommitLineData
2a713cf9
TL
1/*
2 * Print system stuff
3 */
4
5#define mask(x) (x&0377)
6#include <sys/param.h>
7#include <sys/conf.h>
8#include <sys/tty.h>
9
10char *fcore = "/dev/kmem";
11char *fnlist = "/unix";
12int fc;
13
14struct setup {
15 char name[8];
16 int type;
17 unsigned value;
18} setup[] = {
19#define SINODE 0
20 "_inode", 0, 0,
21#define STEXT 1
22 "_text", 0, 0,
23#define SPROC 2
24 "_proc", 0, 0,
25#define SDZ 3
26 "_dz_tty", 0, 0,
27#define SNDZ 4
28 "_dz_cnt", 0, 0,
29#define SKL 5
30 "_cons", 0, 0,
31#define SFIL 6
32 "_file", 0, 0,
33#define SMPXC 7
34 "_mpx_chan", 0, 0,
35#define SMPXM 8
36 "_mpx_mach", 0, 0,
37#define SMPXB1 9
38 "_mptbc", 0, 0,
39#define SMPXB2 10
40 "_mptbuf", 0, 0,
41#define SMPSM 11
42 "_mpsm", 0, 0,
43 0,
44};
45
46int inof;
47int txtf;
48int prcf;
49int ttyf;
50int mpxf;
51int usrf;
52long ubase;
53int filf;
54char partab[1];
55struct cdevsw cdevsw[1];
56struct bdevsw bdevsw[1];
57int allflg;
58int kflg;
59
60main(argc, argv)
61char **argv;
62{
63
64 while (--argc && **++argv == '-') {
65 while (*++*argv)
66 switch (**argv) {
67
68 case 'a':
69 allflg++;
70 break;
71
72 case 'i':
73 inof++;
74 break;
75
76 case 'k':
77 kflg++;
78 break;
79
80 case 'x':
81 txtf++;
82 break;
83 case 'p':
84 prcf++;
85 break;
86
87 case 't':
88 ttyf++;
89 break;
90
91 case 'm':
92 mpxf++;
93 break;
94
95 case 'u':
96 printf("pstat: -u not implemented\n");
97 if (--argc == 0)
98 break;
99 usrf++;
100 sscanf( *++argv, "%x", &ubase);
101 break;
102
103 case 'f':
104 filf++;
105 break;
106 }
107 }
108 if (argc>0)
109 fcore = argv[0];
110 if ((fc = open(fcore, 0)) < 0) {
111 printf("Can't find %s\n", fcore);
112 exit(1);
113 }
114 if (argc>1)
115 fnlist = argv[1];
116 nlist(fnlist, setup);
117 if (kflg) {
118 register struct setup *sp;
119
120 for (sp=setup; sp->value; sp++)
121 sp->value &= 0x7fffffff;
122 }
123 if (setup[SINODE].type == -1) {
124 printf("no namelist\n");
125 exit(1);
126 }
127 if (inof)
128 doinode();
129 if (txtf)
130 dotext();
131 if (ttyf)
132 dotty();
133 if (prcf)
134 doproc();
135/*
136 if (usrf)
137 dousr();
138 */
139 if (filf)
140 dofil();
141/*
142 if(mpxf)
143 dompx();
144*/
145}
146
147doinode()
148{
149#include <sys/inode.h>
150 register struct inode *ip;
151 struct inode xinode[NINODE];
152 register int nin, loc;
153
154 nin = 0;
155 lseek(fc, (long)setup[SINODE].value, 0);
156 read(fc, xinode, sizeof(xinode));
157 for (ip = xinode; ip < &xinode[NINODE]; ip++)
158 if (ip->i_count)
159 nin++;
160 printf("%d active xinodes\n", nin);
161 printf(" LOC FLAGS CNT DEVICE INO MODE NLK UID SIZE/DEV\n");
162 loc = setup[SINODE].value;
163 for (ip = xinode; ip < &xinode[NINODE]; ip++, loc += sizeof(xinode[0])) {
164 if (ip->i_count == 0)
165 continue;
166 printf("%8.1x ", loc);
167 putf(ip->i_flag&ILOCK, 'L');
168 putf(ip->i_flag&IUPD, 'U');
169 putf(ip->i_flag&IACC, 'A');
170 putf(ip->i_flag&IMOUNT, 'M');
171 putf(ip->i_flag&IWANT, 'W');
172 putf(ip->i_flag&ITEXT, 'T');
173 printf("%4d", ip->i_count&0377);
174 printf("%4d,%3d", major(ip->i_dev), minor(ip->i_dev));
175 printf("%5l", ip->i_number);
176 printf("%6x", ip->i_mode & 0xffff);
177 printf("%4d", ip->i_nlink);
178 printf("%4d", ip->i_uid);
179 if ((ip->i_mode&IFMT)==IFBLK || (ip->i_mode&IFMT)==IFCHR)
180 printf("%6d,%3d", major(ip->i_un.i_rdev), minor(ip->i_un.i_rdev));
181 else
182 printf("%10ld", ip->i_size);
183 printf("\n");
184 }
185}
186
187putf(v, n)
188{
189 if (v)
190 printf("%c", n);
191 else
192 printf(" ");
193}
194
195dotext()
196{
197#include <sys/text.h>
198 struct text xtext[NTEXT], *xp;
199 register loc;
200 int ntx;
201
202 ntx = 0;
203 lseek(fc, (long)setup[STEXT].value, 0);
204 read(fc, xtext, sizeof(xtext));
205 for (xp = xtext; xp < &xtext[NTEXT]; xp++)
206 if (xp->x_iptr!=NULL)
207 ntx++;
208 printf("%d text segments\n", ntx);
209 printf(" LOC FLAGS DADDR CADDR SIZE ITPR CNT CCNT\n");
210 loc = setup[STEXT].value;
211 for (xp = xtext; xp < &xtext[NTEXT]; xp++, loc+=sizeof(xtext[0])) {
212 if (xp->x_iptr == NULL)
213 continue;
214 printf("%8.1x", loc);
215 printf(" ");
216 putf(xp->x_flag&XTRC, 'T');
217 putf(xp->x_flag&XWRIT, 'W');
218 putf(xp->x_flag&XLOAD, 'L');
219 putf(xp->x_flag&XLOCK, 'K');
220 putf(xp->x_flag&XWANT, 'w');
221 printf("%5u", xp->x_daddr);
222 printf("%11x", xp->x_caddr);
223 printf("%5d", xp->x_size);
224 printf("%10.1x", xp->x_iptr);
225 printf("%5d", xp->x_count&0377);
226 printf("%4d", xp->x_ccount);
227 printf("\n");
228 }
229}
230
231doproc()
232{
233#include <sys/proc.h>
234 struct proc xproc[NPROC];
235 register struct proc *pp;
236 register loc, np;
237
238 lseek(fc, (long)setup[SPROC].value, 0);
239 read(fc, xproc, sizeof(xproc));
240 np = 0;
241 for (pp=xproc; pp < &xproc[NPROC]; pp++)
242 if (pp->p_stat)
243 np++;
244 printf("%d processes\n", np);
245 printf(" LOC S F PRI SIGNAL UID TIM CPU NI PGRP PID PPID ADDR SIZE WCHAN LINK TEXTP CLKT\n");
246 for (loc=setup[SPROC].value,pp=xproc; pp<&xproc[NPROC]; pp++,loc+=sizeof(xproc[0])) {
247 if (pp->p_stat==0 && allflg==0)
248 continue;
249 printf("%8x", loc);
250 printf("%2d", pp->p_stat);
251 printf("%3o", pp->p_flag&0377);
252 printf("%5d", pp->p_pri);
253 printf("%7o", pp->p_sig);
254 printf("%4d", pp->p_uid&0377);
255 printf("%5d", pp->p_time&0377);
256 printf("%4d", pp->p_cpu&0377);
257 printf("%3d", pp->p_nice);
258 printf("%6d", pp->p_pgrp);
259 printf("%6d", pp->p_pid);
260 printf("%6d", pp->p_ppid);
261 printf("%8x", pp->p_addr[0]);
262 printf("%5x", pp->p_size);
263 printf("%9x", pp->p_wchan);
264 printf("%9x", pp->p_link);
265 printf("%9x", pp->p_textp);
266 printf(" %u", pp->p_clktim);
267 printf("\n");
268 }
269}
270
271dotty()
272{
273 struct tty dz_tty[32];
274 int ndz;
275 register struct tty *tp;
276 register char *mesg;
277
278 printf("1 cons\n");
279 lseek(fc, (long)setup[SKL].value, 0);
280 read(fc, dz_tty, sizeof(dz_tty[0]));
281 mesg = " RAW CAN OUT MODE ADDR DEL COL STATE PGRP\n";
282 printf(mesg);
283 ttyprt(&dz_tty[0]);
284 if (setup[SNDZ].type == -1)
285 return;
286 lseek(fc, (long)setup[SNDZ].value, 0);
287 read(fc, &ndz, sizeof(ndz));
288 printf("%d dz lines\n", ndz);
289 lseek(fc, (long)setup[SDZ].value, 0);
290 read(fc, dz_tty, sizeof(dz_tty));
291 for (tp = dz_tty; tp < &dz_tty[ndz]; tp++)
292 ttyprt(tp);
293}
294
295ttyprt(atp)
296struct tty *atp;
297{
298 register struct tty *tp;
299
300 tp = atp;
301 printf("%4d", tp->t_rawq.c_cc);
302 printf("%4d", tp->t_canq.c_cc);
303 printf("%4d", tp->t_outq.c_cc);
304 printf("%8.1o", tp->t_flags);
305 printf(" %8.1x", tp->t_addr);
306 printf("%3d", tp->t_delct);
307 printf("%4d ", tp->t_col);
308 putf(tp->t_state&TIMEOUT, 'T');
309 putf(tp->t_state&WOPEN, 'W');
310 putf(tp->t_state&ISOPEN, 'O');
311 putf(tp->t_state&CARR_ON, 'C');
312 putf(tp->t_state&BUSY, 'B');
313 putf(tp->t_state&ASLEEP, 'A');
314 putf(tp->t_state&XCLUDE, 'X');
315/*
316 putf(tp->t_state&HUPCLS, 'H');
317 */
318 printf("%6d", tp->t_pgrp);
319 printf("\n");
320}
321
322dousr()
323{
324#include <sys/dir.h>
325#include <sys/user.h>
326 struct user U;
327 register i, j, *ip;
328
329 lseek(fc, ubase, 0);
330 read(fc, &U, sizeof(U));
331/*
332 printf("rsav %.1o %.1o\n", U.u_rsav[0], U.u_rsav[1]);
333 */
334 printf("segflg, error %d, %d\n", U.u_segflg, U.u_error);
335 printf("uids %d,%d,%d,%d\n", U.u_uid,U.u_gid,U.u_ruid,U.u_rgid);
336 printf("procp %.1x\n", U.u_procp);
337 printf("base, count, offset %.1x %.1x %ld\n", U.u_base,
338 U.u_count, U.u_offset);
339 printf("cdir %.1x\n", U.u_cdir);
340 printf("dbuf %.14s\n", U.u_dbuf);
341 printf("dirp %.1x\n", U.u_dirp);
342 printf("dent %d %.14s\n", U.u_dent.d_ino, U.u_dent.d_name);
343 printf("pdir %.1o\n", U.u_pdir);
344/*
345 printf("dseg");
346 for (i=0; i<8; i++)
347 printf("%8.1o", U.u_uisa[i]);
348 printf("\n ");
349 for (i=0; i<8; i++)
350 printf("%8.1o", U.u_uisd[i]);
351 if (U.u_sep) {
352 printf("\ntseg");
353 for (i=8; i<16; i++)
354 printf("%8.1o", U.u_uisa[i]);
355 printf("\n ");
356 for (i=8; i<16; i++)
357 printf("%8.1o", U.u_uisd[i]);
358 }
359 */
360 printf("\nfile");
361 for (i=0; i<10; i++)
362 printf("%9.1x", U.u_ofile[i]);
363 printf("\n ");
364 for (i=10; i<NOFILE; i++)
365 printf("%9.1x", U.u_ofile[i]);
366 printf("\nargs");
367 for (i=0; i<5; i++)
368 printf(" %.1x", U.u_arg[i]);
369 printf("\nsizes %.1x %.1x %.1x\n", U.u_tsize, U.u_dsize, U.u_ssize);
370 printf("sep %d\n", U.u_sep);
371 printf("qsav %.1x %.1x\n", U.u_qsav[0], U.u_qsav[1]);
372 printf("ssav %.1x %.1x\n", U.u_ssav[0], U.u_ssav[1]);
373 printf("sigs");
374 for (i=0; i<NSIG; i++)
375 printf(" %.1x", U.u_signal[i]);
376 printf("\ntimes %ld %ld\n", U.u_utime/60, U.u_stime/60);
377 printf("ctimes %ld %ld\n", U.u_cutime/60, U.u_cstime/60);
378 printf("ar0 %.1x\n", U.u_ar0);
379/*
380 printf("prof");
381 for (i=0; i<4; i++)
382 printf(" %.1o", U.u_prof[i]);
383*/
384 printf("\nintflg %d\n", U.u_intflg);
385 printf("ttyp %.1x\n", U.u_ttyp);
386 printf("ttydev %d,%d\n", major(U.u_ttyd), minor(U.u_ttyd));
387 printf("comm %.14s\n", U.u_comm);
388/*
389 i = U.u_stack - &U;
390 while (U[++i] == 0);
391 i &= ~07;
392 while (i < 512) {
393 printf("%x ", 0140000+2*i);
394 for (j=0; j<8; j++)
395 printf("%9x", U[i++]);
396 printf("\n");
397 }
398*/
399}
400
401oatoi(s)
402char *s;
403{
404 register v;
405
406 v = 0;
407 while (*s)
408 v = (v<<3) + *s++ - '0';
409 return(v);
410}
411
412dofil()
413{
414#include <sys/file.h>
415 struct file xfile[NFILE];
416 register struct file *fp;
417 register nf;
418 int loc;
419
420 nf = 0;
421 lseek(fc, (long)setup[SFIL].value, 0);
422 read(fc, xfile, sizeof(xfile));
423 for (fp=xfile; fp < &xfile[NFILE]; fp++)
424 if (fp->f_count)
425 nf++;
426 printf("%d open files\n", nf);
427 printf(" LOC FLG CNT INO OFFS\n");
428 for (fp=xfile,loc=setup[SFIL].value; fp < &xfile[NFILE]; fp++,loc+=sizeof(xfile[0])) {
429 if (fp->f_count==0)
430 continue;
431 printf("%8x ", loc);
432 putf(fp->f_flag&FREAD, 'R');
433 putf(fp->f_flag&FWRITE, 'W');
434 putf(fp->f_flag&FPIPE, 'P');
435 printf("%4d", mask(fp->f_count));
436 printf("%9.1x", fp->f_inode);
437 printf(" %ld\n", fp->f_un.f_offset);
438 }
439}
440
441/*********
442dompx()
443{
444#include <sys/mpx.h>
445 struct chan chan[C];
446 struct mach mach[M];
447 struct line line[M-1];
448 int mptbc;
449 char mptbuf[TBSIZ];
450 register struct chan *cp;
451 register struct mach *mp;
452 register struct line *lp;
453 int loc, nc;
454
455 lseek(fc, (long)setup[SMPXC].value, 0);
456 read(fc, chan, sizeof(chan));
457 lseek(fc, (long)setup[SMPXM].value, 0);
458 read(fc, mach, sizeof(mach));
459 lseek(fc, (long)setup[SMPXB1].value, 0);
460 read(fc, &mptbc, sizeof(mptbc));
461 lseek(fc, (long)setup[SMPXB2].value, 0);
462 read(fc, mptbuf, sizeof(mptbuf));
463 lseek(fc, (long)setup[SMPSM].value, 0);
464 read(fc, line, sizeof(line));
465 nc = 0;
466 for(cp=chan; cp < &chan[C]; cp++)
467 if(cp->cflag&ALLOC)
468 nc++;
469 printf("%d mpx channels\n", nc);
470 printf(" LOC FLG M C DEST\n");
471 for(cp=chan,loc=setup[SMPXC].value; cp < &chan[C]; cp++,loc=+sizeof(chan[0])) {
472 if((cp->cflag&ALLOC) == 0)
473 continue;
474 printf("%7.1o ", loc);
475 putf(cp->cflag&BLOCK, 'B');
476 putf(cp->cflag&WWAIT, 'B');
477 putf(cp->cflag&CRUN, 'R');
478 putf(cp->cflag&RWAIT, 'W');
479 putf(cp->cflag&ALLOC, 'A');
480 putf(cp->cflag&DIS, 'D');
481 putf(cp->cflag&DLY, 'D');
482 printf(" %1d %3d ", mask(cp->m), mask(cp->c));
483 printf("%7.1o ", cp->dest);
484 printf("\n");
485 }
486
487 printf("%d mpx machines\n", M);
488 printf(" LOC FLG RCH RCN XCH XCN\n");
489 for(mp=mach,loc=setup[SMPXM].value; mp < &mach[M]; mp++,loc=+sizeof(mach[0])) {
490 printf("%7.1o ", loc);
491 putf(mp->mflag&RNEXT, 'N');
492 putf(mp->mflag&MRUN, 'R');
493 putf(mp->mflag&XNEXT, 'N');
494 printf(" %3d", mask(mp->rchan));
495 printf(" %3d", mask(mp->rcount));
496 printf(" %3d", mask(mp->xchan));
497 printf(" %3d", mask(mp->xcount));
498 for(nc=0; nc<128; nc++) {
499 cp = mp->chanp[nc];
500 if(cp == 0)
501 continue;
502 printf(" %d-%o", nc, cp);
503 }
504 printf("\n");
505 }
506 printf("%d mpx lines\n", M-1);
507 printf(" LOC RSQ XSQ AKF XMF STE TIM SUM\n");
508 for(lp=line,loc=setup[SMPSM].value; lp < &line[M-1]; lp++, loc =+ sizeof(line[0])) {
509 printf("%7.1o ", loc);
510 printf("%3o ", lp->rseq);
511 printf("%3o ", lp->xseq);
512 printf("%3o ", lp->ackf);
513 printf("%3o ", lp->xflag);
514 printf("%3d ", lp->state);
515 printf("%3d ", lp->time);
516 printf("%7o\n", lp->sum);
517 }
518 printf("last characters recieved\n");
519 nc = -1;
520 loc = mptbc;
521 for(;;) {
522 if(nc != mptbuf[loc]) {
523 if(nc >= 0)
524 printf(")\n");
525 nc = mptbuf[loc];
526 printf("%d(", nc);
527 } else
528 printf(",");
529 loc++;
530 if(loc >= TBSIZ)
531 loc = 0;
532 if(loc == mptbc)
533 break;
534 printf("%o", mask(mptbuf[loc]));
535 loc++;
536 if(loc >= TBSIZ)
537 loc = 0;
538 if(loc == mptbc)
539 break;
540 }
541 printf(")\n");
542}
543*********/