+ printf("%9.1x", fp->f_inode);
+ printf(" %ld\n", fp->f_un.f_offset);
+ }
+}
+
+doswap()
+{
+ struct proc *proc;
+ int nproc;
+ struct text *xtext;
+ int ntext;
+ struct map *swapmap;
+ int nswapmap;
+ register struct proc *pp;
+ int nswap, used, tused, free;
+ register struct mapent *me;
+ register struct text *xp;
+
+ nproc = getw(nl[SNPROC].n_value);
+ proc = (struct proc *)calloc(nproc, sizeof (struct proc));
+ lseek(fc, getw(nl[SPROC].n_value), 0);
+ read(fc, proc, nproc * sizeof (struct proc));
+ nswapmap = getw(nl[SNSWAPMAP].n_value);
+ swapmap = (struct map *)calloc(nswapmap, sizeof (struct map));
+ lseek(fc, getw(nl[SWAPMAP].n_value), 0);
+ read(fc, swapmap, nswapmap * sizeof (struct map));
+ nswap = getw(nl[SNSWAP].n_value);
+ free = 0;
+ for (me = (struct mapent *)(swapmap+1);
+ me < (struct mapent *)&swapmap[nswapmap]; me++)
+ free += me->m_size;
+ ntext = getw(nl[SNTEXT].n_value);
+ xtext = (struct text *)calloc(ntext, sizeof (struct text));
+ lseek(fc, getw(nl[STEXT].n_value), 0);
+ read(fc, xtext, ntext * sizeof (struct text));
+ tused = 0;
+ for (xp = xtext; xp < &xtext[ntext]; xp++)
+ if (xp->x_iptr!=NULL)
+ tused += xdsize(xp);
+ used = tused;
+ for (pp = proc; pp < &proc[nproc]; pp++) {
+ if (pp->p_stat == 0 || pp->p_stat == SZOMB)
+ continue;
+ if (pp->p_flag & SSYS)
+ continue;
+ used += up(pp->p_dsize) + up(pp->p_ssize);
+ if ((pp->p_flag&SLOAD) == 0)
+ used += vusize(pp);
+ }
+ /* a DMMAX/2 block goes to argmap */
+ if (totflg) {
+ printf("%3d/%3d 00k swap\n", used/2/100, (used+free)/2/100);
+ return;
+ }
+ printf("%d used (%d text), %d free, %d missing\n",
+ used/2, tused/2, free/2, (nswap - DMMAX/2 - (used + free))/2);
+}
+
+up(size)
+ register int size;
+{
+ register int i, block;
+
+ i = 0;
+ block = DMMIN;
+ while (i < size) {
+ i += block;
+ if (block < DMMAX)
+ block *= 2;
+ }
+ return (i);
+}
+
+vusize(p)
+struct proc *p;
+{
+ register int tsz = p->p_tsize / NPTEPG;
+
+ return (clrnd(UPAGES + clrnd(ctopt(p->p_tsize+p->p_dsize+p->p_ssize+UPAGES)) - tsz));
+}
+
+xdsize(xp)
+struct text *xp;
+{
+
+ if (xp->x_flag & XPAGI)
+ return (clrnd(xp->x_size + ctopt(xp->x_size)));
+ return (xp->x_size);
+}
+
+dompx()
+{
+ register int i;
+ struct chan chans[NCHANS];
+ struct schan schans[NPORTS];
+
+ lseek(fc, (long)nl[SCHANS].n_value, 0);
+ read(fc, chans, sizeof chans);
+ lseek(fc, (long)nl[SSCHANS].n_value, 0);
+ read(fc, schans, sizeof schans);
+
+ printf("CHAN FLAGS INDEX LINE GROUP FILE TTYP CTLX PGRP OTTYP OLINE DATQ CTLY\n");
+ for (i = 0; i < NCHANS; i++) {
+ printf("%3d ", i);
+ putf(chans[i].c_flags&INUSE, 'I');
+ putf(chans[i].c_flags&SIOCTL, 'S');
+ putf(chans[i].c_flags&XGRP, 'X');
+ putf(chans[i].c_flags&YGRP, 'Y');
+ putf(chans[i].c_flags&WCLOSE, 'W');
+ putf(chans[i].c_flags&ISGRP, 'i');
+ putf(chans[i].c_flags&BLOCK, 'B');
+ putf(chans[i].c_flags&EOTMARK, 'E');
+ putf(chans[i].c_flags&SIGBLK, 's');
+ putf(chans[i].c_flags&BLKMSG, 'b');
+ putf(chans[i].c_flags&ENAMSG, 'e');
+ putf(chans[i].c_flags&WFLUSH, 'w');
+ putf(chans[i].c_flags&NMBUF, 'N');
+ putf(chans[i].c_flags&PORT, 'P');
+ putf(chans[i].c_flags&ALT, 'A');
+ putf(chans[i].c_flags&FBLOCK, 'F');
+ printf("%8x ", chans[i].c_index);
+ printf("%3d ", chans[i].c_line);
+ printf("%8x ", chans[i].c_group);
+ printf("%8x ", chans[i].c_fy);
+ printf("%8x ", chans[i].c_ttyp);
+ printf("%8x ", chans[i].c_ctlx);
+ printf("%6d ", chans[i].c_pgrp);
+ printf("%8x ", chans[i].c_ottyp);
+ printf("%3d ", chans[i].c_oline);
+ printf("%8x ", chans[i].cx.datq);
+ printf("%8x\n", chans[i].c_ctly);
+ }
+
+ printf("\nCHAN FLAGS INDEX LINE GROUP FILE TTYP CTLX PGRP\n");
+ for (i = 0; i < NPORTS; i++) {
+ printf("%3d ", i);
+ putf(schans[i].c_flags&INUSE, 'I');
+ putf(schans[i].c_flags&SIOCTL, 'S');
+ putf(schans[i].c_flags&XGRP, 'X');
+ putf(schans[i].c_flags&YGRP, 'Y');
+ putf(schans[i].c_flags&WCLOSE, 'W');
+ putf(schans[i].c_flags&ISGRP, 'i');
+ putf(schans[i].c_flags&BLOCK, 'B');
+ putf(schans[i].c_flags&EOTMARK, 'E');
+ putf(schans[i].c_flags&SIGBLK, 's');
+ putf(schans[i].c_flags&BLKMSG, 'b');
+ putf(schans[i].c_flags&ENAMSG, 'e');
+ putf(schans[i].c_flags&WFLUSH, 'w');
+ putf(schans[i].c_flags&NMBUF, 'N');
+ putf(schans[i].c_flags&PORT, 'P');
+ putf(schans[i].c_flags&ALT, 'A');
+ putf(schans[i].c_flags&FBLOCK, 'F');
+ printf("%8x ", schans[i].c_index);
+ printf("%3d ", schans[i].c_line);
+ printf("%8x ", schans[i].c_group);
+ printf("%8x ", schans[i].c_fy);
+ printf("%8x ", schans[i].c_ttyp);
+ printf("%8x ", schans[i].c_ctlx);
+ printf("%6d\n", schans[i].c_pgrp);
+ }
+}
+
+dogroup()
+{
+ register int i, j;
+ struct group *groups[NGROUPS];
+ struct group g;
+
+ lseek(fc, (long)nl[SGROUP].n_value, 0);
+ read(fc, groups, sizeof groups);
+ printf("GROUP STATE INDEX ROT *GROUP *INODE *FILE ROTM DATQ\n");
+ for (i = 0; i < NGROUPS; i++) {
+ if (groups[i] == 0)
+ continue;
+ lseek(fc, (long) groups[i], 0);
+ read(fc, &g, sizeof g);
+ printf("%3d ", i);
+ printf("%8x ", g.g_state);
+ printf("%8x ", g.g_index);
+ printf("%3d ", g.g_rot);
+ printf("%8x ", g.g_group);
+ printf("%8x ", g.g_inode);
+ printf("%8x ", g.g_file);
+ printf("%3d ", g.g_rotmask);
+ printf("%3d\n", g.g_datq);