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