|
|
1.1 root 1:
2: #include <nlist.h>
3: #include <sys/param.h>
4: #include <ctype.h>
5: #include <sys/stream.h>
6: #include <sys/inode.h>
7: #include <sys/conf.h>
8: #include <sys/dkp.h>
9: #include <sys/dz.h>
10:
11: struct nlist nl[] ={
12: #define QNL 0
13: {"_queue"},
14: #define BLNL 1
15: {"_cblock"},
16: #define STNL 2
17: {"_streams"},
18: #define QFNL 3
19: {"_qfreelist"},
20: #define DKPNL 4
21: { "_dkpstream" },
22: #define NBLOCK 5
23: { "_blkcnt"},
24: #define NQUEUE 6
25: { "_queuecnt"},
26: #define NSTREAM 7
27: { "_streamcnt"},
28: #define DZNL 8
29: {"_dzinfo"},
30: #define CDKPNL 9
31: { "_cdkpstream" },
32: #define BLKALL 10
33: { "_blkall" },
34: #define BLKMAX 11
35: { "_blkmax" },
36: #define BLKFREE 12
37: { "_blkfree" },
38: #define STWNL 13
39: { "_stwdata" },
40: #define BLKOWN 14
41: { "_blkowner" },
42: #define STRDATA 15
43: { "_strdata" },
44: #define STREAMSTART 16
45: { "_bufldstream" },
46: { "_rdkstream" },
47: { "_connstream" },
48: { "_connginfo" },
49: { "_kcinfo" },
50: { "_rcureinfo" },
51: { "_qesinfo" },
52: { "_dhvinfo" },
53: { "_dkinfo" },
54: { "_dkpstream" },
55: { "_cdkpstream" },
56: { "_dzinfo" },
57: { "_kbinfo" },
58: { "_kdiinfo" },
59: { "_msgstream" },
60: { "_rmsgstream" },
61: { "_mginfo" },
62: { "_ilsinfo" },
63: { "_nttystream" },
64: { "_spinfo" },
65: { "_ttystream" },
66: { "_xpstream" },
67: { "_ipdinfo" },
68: { "_ipstream" },
69: { "_tcpdinfo" },
70: { "_tcpstream" },
71: { "_udpdinfo" },
72: { "_udpstream" },
73: { "_nilinfo" },
74: { "_cnstream" },
75: { "" },
76: };
77:
78: struct infoinfo {
79: char *name;
80: struct streamtab inf;
81: } inf[50];
82:
83: struct qinit **qall;
84: char *ball;
85: char *strall;
86: char *core = "/dev/mem";
87: char *sys = "/unix";
88: int mem;
89: int blkcnt;
90: int queuecnt;
91: int streamcnt;
92: short blkall[6];
93: short blkmax[6];
94: short blkfree[6];
95:
96: #define DK_OPEN 01
97: #define DK_LCLOSE 02
98: #define DK_RCLOSE 04
99: #define DK_XCHARMODE 010
100: #define DK_RCHARMODE 0200
101: #define DK_OPENING 020
102:
103: #define getme(s, kind, off, type) _get(kind, off, sizeof(type), &s)
104:
105: struct flags {
106: int flag;
107: char *name;
108: };
109:
110: struct flags stflags[] = {
111: IOCWAIT, "IOC",
112: RSLEEP, "RSLEEP",
113: WSLEEP, "WSLEEP",
114: HUNGUP, "HUNGUP",
115: RSEL, "RSEL",
116: WSEL, "WSEL",
117: EXCL, "EXCL",
118: STWOPEN, "WOPEN",
119: 0
120: };
121:
122: struct flags qflags[] = {
123: QUSE, "use",
124: QREADR, "read",
125: QNOENB, "noenb",
126: QENAB, "enab",
127: QWANTR, "wantr",
128: QWANTW, "wantw",
129: QFULL, "full",
130: QDELIM, "delim",
131: QBIGB, "bigb",
132: 0
133: };
134:
135: struct flags dkpflags[] = {
136: DK_OPEN, "open",
137: DK_LCLOSE, "lclose",
138: DK_RCLOSE, "rclose",
139: DK_XCHARMODE, "xcharmode",
140: DK_RCHARMODE, "rcharmode",
141: DK_OPENING, "opening",
142: 0
143: };
144:
145: #define DZEXIST 01
146: #define DZISOPEN 02
147: #define DZWOPEN 04
148: #define DZTIME 010
149: #define DZCARR 020
150: #define DZSTOP 040
151: #define DZHUPCL 0100
152:
153: struct flags dzflags[] = {
154: DZEXIST, "exists",
155: DZISOPEN, "open",
156: DZWOPEN, "wopen",
157: DZTIME, "time",
158: DZCARR, "carrier",
159: DZSTOP, "stop",
160: DZHUPCL, "hupcl",
161: 0
162: };
163:
164: int vflag;
165: int sflag;
166: int mflag;
167: char *infstr();
168:
169: main(argc, argv)
170: char **argv;
171: {
172: struct queue q;
173: struct block b;
174: struct stdata s;
175: int i;
176: int nq = 0;
177:
178: for (;;argc--, argv++) {
179: if (argc>1 && strcmp(argv[1], "-v")==0) {
180: vflag++;
181: continue;
182: }
183: if (argc>1 && strcmp(argv[1], "-m")==0) {
184: mflag++;
185: continue;
186: }
187: if (argc>1 && strcmp(argv[1], "-V")==0) {
188: vflag = 2;
189: continue;
190: }
191: if (argc>1 && strcmp(argv[1], "-s")==0) {
192: sflag++;
193: continue;
194: }
195: break;
196: }
197: if (argc>1)
198: sys = argv[1];
199: if (argc>2)
200: core = argv[2];
201: nlist(sys, nl);
202: mem = open(core, 0);
203: if (mem<0) {
204: printf("can't open %s\n", core);
205: exit(1);
206: }
207: getme(queuecnt, NQUEUE, 0, int);
208: getme(streamcnt, NSTREAM, 0, int);
209: getme(blkcnt, NBLOCK, 0, int);
210: getme(blkmax[0], BLKMAX, 0, blkmax);
211: getme(blkall[0], BLKALL, 0, blkall);
212: getme(blkfree[0], BLKFREE, 0, blkfree);
213: printf("blocks max: (%d,%d,%d,%d,%d,%d)\n",
214: blkmax[0], blkmax[1], blkmax[2], blkmax[3], blkmax[4], blkmax[5]);
215: printf("blocks cur: (%d,%d,%d,%d,%d,%d)\n",
216: blkall[0], blkall[1], blkall[2], blkall[3], blkall[4], blkall[5]);
217: printf("blocks free: (%d,%d,%d,%d,%d,%d)\n",
218: blkfree[0], blkfree[1], blkfree[2], blkfree[3], blkfree[4], blkfree[5]);
219: initinfo();
220: ball = (char *)malloc(blkcnt*sizeof(char));
221: strall = (char *)malloc(streamcnt*sizeof(char));
222: qall = (struct qinit **)malloc(queuecnt*sizeof(struct queue *));
223: for (i=0; i<blkcnt; i++)
224: ball[i] = 0;
225: for (i=0; i<streamcnt; i++)
226: strall[i] = 0;
227: for (i=0; i<queuecnt; i++) {
228: getme(q, QNL, i, struct queue);
229: if (q.flag==0)
230: qall[i] = 0;
231: else {
232: qall[i] = q.qinfo;
233: nq++;
234: }
235: }
236: for (i=0; i<streamcnt; i++)
237: pstream(i);
238: for (i=0; i<queuecnt; i++) {
239: if (qall[i])
240: printf("Loose queue %d, info #%x\n", i, qall[i]);
241: }
242: printf("%d queues in use\n", nq);
243: bfreecount();
244: nq = 0;
245: for (i=0; i<blkcnt; i++)
246: if (ball[i]==0) {
247: struct block b;
248: long owner;
249:
250: if (mflag) {
251: getme(b, BLNL, i, struct block);
252: #if BLKOWNER
253: getme(owner, BLKOWN, i, long);
254: printf(" owner=##%x\n", owner);
255: #endif
256: pblock(&b);
257: }
258: nq++;
259: }
260: if (!sflag)
261: printf("%d blocks missing\n", nq);
262: nq = 0;
263: for (i=0; i<blkcnt; i++) {
264: if (ball[i])
265: continue;
266: if (nq >= 5 && vflag < 2)
267: continue;
268: printf("#%x\n", (struct block *)nl[BLNL].n_value+i);
269: nq++;
270: }
271: exit(0);
272: }
273:
274: pstream(i)
275: {
276: struct stdata s;
277: struct queue rq, wq;
278: struct inode ino;
279: struct queue *rqp, *wqp;
280: struct stdata *sp;
281: static struct streamtab dkpinfo, dzinfo, cdkpinfo;
282: static int stread = 0;
283: int d;
284: int forward = 1;
285:
286: if (strall[i])
287: return;
288: strall[i]++;
289: sp = (struct stdata *)getme(s, STNL, i, struct stdata);
290: if (s.wrq==NULL)
291: return;
292: if (!sflag)
293: printf("\nstream %d: ", i);
294: getme(ino, s.inode, 0, struct inode);
295: d = ino.i_un.i_rdev;
296: if (!sflag) {
297: printf("dev %d,%d ", major(d), minor(d));
298: printf("ino %d ", ino.i_number);
299: printf("count %d ", s.count);
300: flags(stflags, s.flag);
301: if (vflag)
302: printf(" pgrp %d", s.pgrp);
303: printf("\n");
304: }
305: wqp = (struct queue *)getme(wq, s.wrq, 0, struct queue);
306: rqp = (struct queue *)getme(rq, RD(s.wrq), 0, struct queue);
307: if ((struct stdata *)rq.ptr != sp)
308: printf("rq ptr? = #%x\n", rq.ptr);
309: if (stread == 0) {
310: getme(dkpinfo, DKPNL, 0, struct streamtab);
311: getme(cdkpinfo, CDKPNL, 0, struct streamtab);
312: getme(dzinfo, DZNL, 0, struct streamtab);
313: stread++;
314: }
315: for (;;) {
316: d = rqp - (struct queue *)nl[QNL].n_value;
317: if (d<0 || d>=queuecnt)
318: printf("?");
319: else
320: qall[d] = 0;
321: d = wqp - (struct queue *)nl[QNL].n_value;
322: if (d<0 || d>=queuecnt)
323: printf("?");
324: else
325: qall[d] = 0;
326: if (!sflag) {
327: printf(" RQ #%x: ", rqp);
328: printf("%s; ", infstr(rq.qinfo));
329: flags(qflags, rq.flag);
330: printf(". ptr #%x", rq.ptr);
331: printf("\n");
332: pblocks(&rq);
333: printf(" WQ #%x: ", wqp);
334: flags(qflags, wq.flag);
335: printf(". ptr #%x", wq.ptr);
336: printf("\n");
337: pblocks(&wq);
338: if ((long)wq.qinfo == nl[STWNL].n_value)
339: strfacts(&wq);
340: if (wq.qinfo == dkpinfo.wrinit || wq.qinfo == cdkpinfo.wrinit)
341: dkpline(&wq);
342: if (wq.qinfo == dzinfo.wrinit)
343: dzfacts(&wq);
344: }
345: if (forward) {
346: if (wq.next == NULL)
347: break;
348: wqp = (struct queue *)
349: getme(wq, wq.next, 0, struct queue);
350: if (wq.flag&QREADR) {
351: printf(" <>\n");
352: forward = 0;
353: rqp = wqp;
354: rq = wq;
355: wqp = (struct queue *)
356: getme(wq, WR(rqp), 0, struct queue);
357: } else
358: rqp = (struct queue *)
359: getme(rq, RD(wqp), 0, struct queue);
360: } else {
361: if (rq.next == NULL)
362: break;
363: rqp = (struct queue *)
364: getme(rq, rq.next, 0, struct queue);
365: if ((rq.flag&QREADR) == 0) {
366: printf(" <>\n");
367: forward = 1;
368: wqp = rqp;
369: wq = rq;
370: rqp = (struct queue *)
371: getme(rq, RD(wqp), 0, struct queue);
372: } else
373: wqp = (struct queue *)
374: getme(wq, WR(rqp), 0, struct queue);
375: }
376: }
377: }
378:
379: strfacts(q)
380: register struct queue *q;
381: {
382: register int i;
383: struct stdata s;
384: dev_t d;
385: struct inode ino;
386:
387: i = (struct stdata *)q->ptr - (struct stdata *)nl[STNL].n_value;
388: if (i < 0 || i > streamcnt)
389: return;
390: if (strall[i])
391: return;
392: strall[i]++;
393: getme(s, STNL, i, struct stdata);
394: if (s.wrq==NULL)
395: return;
396: if (!sflag)
397: printf("stream %d: ", i);
398: getme(ino, s.inode, 0, struct inode);
399: d = ino.i_un.i_rdev;
400: if (!sflag) {
401: printf("dev %d,%d ", major(d), minor(d));
402: printf("ino %d ", ino.i_number);
403: printf("count %d ", s.count);
404: flags(stflags, s.flag);
405: if (vflag)
406: printf(" pgrp %d", s.pgrp);
407: printf("\n");
408: }
409: }
410:
411: dzfacts(q)
412: register struct queue *q;
413: {
414: struct dz dz;
415:
416: getme(dz, q->ptr, 0, struct dz);
417: printf(" DZ: ");
418: flags(dzflags, dz.state);
419: printf("\n");
420: }
421:
422: dkpline(q)
423: register struct queue *q;
424: {
425: struct dkp dkp;
426: register i;
427:
428: getme(dkp, q->ptr, 0, struct dkp);
429: printf(" WS %o WACK %o WNX %o iseq %o; ", dkp.WS, dkp.WACK,
430: dkp.WNX, dkp.iseq);
431: printf("window %d x %d; ", dkp.XW, dkp.xsize);
432: flags(dkpflags, dkp.state);
433: printf("\n ");
434: for (i=0; i<8; i++)
435: printf(" #%x", dkp.xb[i]);
436: printf("\n");
437: }
438:
439: pblocks(q)
440: register struct queue *q;
441: {
442: struct block b, *bp;
443: int nb = 0;
444: u_char buf[512];
445: register i, bno;
446:
447: bp = q->first;
448: for (i = 0; i < 1000; i++) {
449: if (bp==NULL)
450: break;
451: bno = bp - (struct block *)nl[BLNL].n_value;
452: nb++;
453: baccount(bno);
454: getme(b, bp, 0, struct block);
455: if (vflag && (i<10 || vflag>1))
456: pblock(&b);
457: bp = b.next;
458: }
459: if (vflag && i>=10)
460: printf("(gave up) ");
461: if (nb > 0)
462: printf(" %d blocks\n", nb);
463: }
464:
465: pblock(bp)
466: register struct block *bp;
467: {
468: register u_char *cp;
469: register i = 0;
470: u_char buf[4096];
471:
472: printf(" %c%.3o:", bp->class&0200?'D':' ', bp->type);
473: cp = buf;
474: getme(buf[0], bp->base, 0, buf);
475: printf("%3d:", bp->wptr-bp->base);
476: while (bp->base < bp->wptr) {
477: if (i >= 16) {
478: printf("\n ");
479: i = 0;
480: }
481: if (*cp<040 || *cp>=0177)
482: printf(" %.3o", *cp);
483: else
484: printf(" %c ", *cp);
485: cp++;
486: bp->base++;
487: i++;
488: }
489: printf("\n");
490: }
491:
492: flags(fp, w)
493: register struct flags *fp;
494: {
495: int any = 0;
496: while (fp->name) {
497: if (fp->flag&w) {
498: if (any)
499: printf(", ");
500: any++;
501: printf("%s", fp->name);
502: }
503: fp++;
504: }
505: }
506:
507: _get(addr, off, size, loc)
508: unsigned long addr;
509: char *loc;
510: {
511:
512: if (addr < 20)
513: addr = nl[addr].n_value;
514: addr += off*size;
515: lseek(mem, addr&0x7fffffff, 0);
516: read(mem, loc, size);
517: return(addr);
518: }
519:
520: bfreecount()
521: {
522: struct block b;
523: struct block *bp;
524: register i;
525:
526: for (i=0; i<6; i++) {
527: getme(bp, QFNL, i, struct block *);
528: while (bp) {
529: baccount(bp - (struct block *)nl[BLNL].n_value);
530: getme(b, bp, 0, struct block);
531: bp = b.next;
532: }
533: }
534: }
535:
536: baccount(bno)
537: {
538: if (bno < 0 || bno >= blkcnt)
539: printf("funny block %d\n", bno);
540: else if (ball[bno])
541: printf("dup block %d\n", bno);
542: else
543: ball[bno]++;
544: }
545:
546: initinfo()
547: {
548: register i, j;
549:
550: inf[0].name = "head";
551: inf[0].inf.rdinit = (struct qinit *)nl[STRDATA].n_value;
552: for (j=1, i=STREAMSTART; nl[i].n_name[0]; i++) {
553: if (nl[i].n_type!=0) {
554: getme(inf[j].inf, nl[i].n_value, 0, struct streamtab);
555: inf[j].name = nl[i].n_name;
556: if (inf[j].name[0]=='_')
557: inf[j].name++;
558: j++;
559: }
560: }
561: }
562:
563: char *
564: infstr(s)
565: long s;
566: {
567: register i;
568: static char buf[64];
569:
570: for (i=0; inf[i].name; i++) {
571: if (inf[i].inf.rdinit == (struct qinit *)s
572: || inf[i].inf.wrinit == (struct qinit *)s) {
573: sprintf(buf, "%s", inf[i].name);
574: break;
575: }
576: }
577: if (inf[i].name == NULL)
578: sprintf(buf, "qinfo #%x", s);
579: return(buf);
580: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.