1: /*
   2:  * Copyright (c) 1983 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #ifndef lint
   8: char copyright[] =
   9: "@(#) Copyright (c) 1983 Regents of the University of California.\n\
  10:  All rights reserved.\n";
  11: #endif not lint
  12: 
  13: #ifndef lint
  14: static char sccsid[] = "@(#)dumpfs.c	5.3 (Berkeley) 9/11/85";
  15: #endif not lint
  16: 
  17: #include <sys/param.h>
  18: #include <sys/inode.h>
  19: #include <sys/fs.h>
  20: 
  21: #include <stdio.h>
  22: #include <fstab.h>
  23: 
  24: /*
  25:  * dumpfs
  26:  */
  27: 
  28: union {
  29:     struct fs fs;
  30:     char pad[MAXBSIZE];
  31: } fsun;
  32: #define afs fsun.fs
  33: 
  34: union {
  35:     struct cg cg;
  36:     char pad[MAXBSIZE];
  37: } cgun;
  38: #define acg cgun.cg
  39: 
  40: main(argc, argv)
  41:     char **argv;
  42: {
  43:     register struct fstab *fs;
  44: 
  45:     argc--, argv++;
  46:     if (argc < 1) {
  47:         fprintf(stderr, "usage: dumpfs fs ...\n");
  48:         exit(1);
  49:     }
  50:     for (; argc > 0; argv++, argc--) {
  51:         fs = getfsfile(*argv);
  52:         if (fs == 0)
  53:             dumpfs(*argv);
  54:         else
  55:             dumpfs(fs->fs_spec);
  56:     }
  57: }
  58: 
  59: dumpfs(name)
  60:     char *name;
  61: {
  62:     int c, i, j, k, size;
  63: 
  64:     close(0);
  65:     if (open(name, 0) != 0) {
  66:         perror(name);
  67:         return;
  68:     }
  69:     lseek(0, SBLOCK * DEV_BSIZE, 0);
  70:     if (read(0, &afs, SBSIZE) != SBSIZE) {
  71:         perror(name);
  72:         return;
  73:     }
  74:     printf("magic\t%x\ttime\t%s", afs.fs_magic, ctime(&afs.fs_time));
  75:     printf("sblkno\t%d\tcblkno\t%d\tiblkno\t%d\tdblkno\t%d\n",
  76:         afs.fs_sblkno, afs.fs_cblkno, afs.fs_iblkno, afs.fs_dblkno);
  77:     printf("sbsize\t%d\tcgsize\t%d\tcgoffset %d\tcgmask\t0x%08x\n",
  78:         afs.fs_sbsize, afs.fs_cgsize, afs.fs_cgoffset, afs.fs_cgmask);
  79:     printf("ncg\t%d\tsize\t%d\tblocks\t%d\n",
  80:         afs.fs_ncg, afs.fs_size, afs.fs_dsize);
  81:     printf("bsize\t%d\tshift\t%d\tmask\t0x%08x\n",
  82:         afs.fs_bsize, afs.fs_bshift, afs.fs_bmask);
  83:     printf("fsize\t%d\tshift\t%d\tmask\t0x%08x\n",
  84:         afs.fs_fsize, afs.fs_fshift, afs.fs_fmask);
  85:     printf("frag\t%d\tshift\t%d\tfsbtodb\t%d\n",
  86:         afs.fs_frag, afs.fs_fragshift, afs.fs_fsbtodb);
  87:     printf("minfree\t%d%%\tmaxbpg\t%d\toptim\t%s\n",
  88:         afs.fs_minfree, afs.fs_maxbpg,
  89:         afs.fs_optim == FS_OPTSPACE ? "space" : "time");
  90:     printf("maxcontig %d\trotdelay %dms\trps\t%d\n",
  91:         afs.fs_maxcontig, afs.fs_rotdelay, afs.fs_rps);
  92:     printf("csaddr\t%d\tcssize\t%d\tshift\t%d\tmask\t0x%08x\n",
  93:         afs.fs_csaddr, afs.fs_cssize, afs.fs_csshift, afs.fs_csmask);
  94:     printf("ntrak\t%d\tnsect\t%d\tspc\t%d\tncyl\t%d\n",
  95:         afs.fs_ntrak, afs.fs_nsect, afs.fs_spc, afs.fs_ncyl);
  96:     printf("cpg\t%d\tbpg\t%d\tfpg\t%d\tipg\t%d\n",
  97:         afs.fs_cpg, afs.fs_fpg / afs.fs_frag, afs.fs_fpg, afs.fs_ipg);
  98:     printf("nindir\t%d\tinopb\t%d\tnspf\t%d\n",
  99:         afs.fs_nindir, afs.fs_inopb, afs.fs_nspf);
 100:     printf("nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
 101:         afs.fs_cstotal.cs_nbfree, afs.fs_cstotal.cs_ndir,
 102:         afs.fs_cstotal.cs_nifree, afs.fs_cstotal.cs_nffree);
 103:     printf("cgrotor\t%d\tfmod\t%d\tronly\t%d\n",
 104:         afs.fs_cgrotor, afs.fs_fmod, afs.fs_ronly);
 105:     if (afs.fs_cpc != 0)
 106:         printf("blocks available in each rotational position");
 107:     else
 108:         printf("insufficient space to maintain rotational tables\n");
 109:     for (c = 0; c < afs.fs_cpc; c++) {
 110:         printf("\ncylinder number %d:", c);
 111:         for (i = 0; i < NRPOS; i++) {
 112:             if (afs.fs_postbl[c][i] == -1)
 113:                 continue;
 114:             printf("\n   position %d:\t", i);
 115:             for (j = afs.fs_postbl[c][i], k = 1; ;
 116:                  j += afs.fs_rotbl[j], k++) {
 117:                 printf("%5d", j);
 118:                 if (k % 12 == 0)
 119:                     printf("\n\t\t");
 120:                 if (afs.fs_rotbl[j] == 0)
 121:                     break;
 122:             }
 123:         }
 124:     }
 125:     printf("\ncs[].cs_(nbfree,ndir,nifree,nffree):\n\t");
 126:     for (i = 0, j = 0; i < afs.fs_cssize; i += afs.fs_bsize, j++) {
 127:         size = afs.fs_cssize - i < afs.fs_bsize ?
 128:             afs.fs_cssize - i : afs.fs_bsize;
 129:         afs.fs_csp[j] = (struct csum *)calloc(1, size);
 130:         lseek(0, fsbtodb(&afs, (afs.fs_csaddr + j * afs.fs_frag)) *
 131:             DEV_BSIZE, 0);
 132:         if (read(0, afs.fs_csp[j], size) != size) {
 133:             perror(name);
 134:             return;
 135:         }
 136:     }
 137:     for (i = 0; i < afs.fs_ncg; i++) {
 138:         struct csum *cs = &afs.fs_cs(&afs, i);
 139:         if (i && i % 4 == 0)
 140:             printf("\n\t");
 141:         printf("(%d,%d,%d,%d) ",
 142:             cs->cs_nbfree, cs->cs_ndir, cs->cs_nifree, cs->cs_nffree);
 143:     }
 144:     printf("\n");
 145:     if (afs.fs_ncyl % afs.fs_cpg) {
 146:         printf("cylinders in last group %d\n",
 147:             i = afs.fs_ncyl % afs.fs_cpg);
 148:         printf("blocks in last group %d\n",
 149:             i * afs.fs_spc / NSPB(&afs));
 150:     }
 151:     printf("\n");
 152:     for (i = 0; i < afs.fs_ncg; i++)
 153:         dumpcg(name, i);
 154:     close(0);
 155: };
 156: 
 157: dumpcg(name, c)
 158:     char *name;
 159:     int c;
 160: {
 161:     int i,j;
 162: 
 163:     printf("\ncg %d:\n", c);
 164:     lseek(0, fsbtodb(&afs, cgtod(&afs, c)) * DEV_BSIZE, 0);
 165:     i = lseek(0, 0, 1);
 166:     if (read(0, (char *)&acg, afs.fs_bsize) != afs.fs_bsize) {
 167:         printf("dumpfs: %s: error reading cg\n", name);
 168:         return;
 169:     }
 170:     printf("magic\t%x\ttell\t%x\ttime\t%s",
 171:         acg.cg_magic, i, ctime(&acg.cg_time));
 172:     printf("cgx\t%d\tncyl\t%d\tniblk\t%d\tndblk\t%d\n",
 173:         acg.cg_cgx, acg.cg_ncyl, acg.cg_niblk, acg.cg_ndblk);
 174:     printf("nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
 175:         acg.cg_cs.cs_nbfree, acg.cg_cs.cs_ndir,
 176:         acg.cg_cs.cs_nifree, acg.cg_cs.cs_nffree);
 177:     printf("rotor\t%d\tirotor\t%d\tfrotor\t%d\nfrsum",
 178:         acg.cg_rotor, acg.cg_irotor, acg.cg_frotor);
 179:     for (i = 1, j = 0; i < afs.fs_frag; i++) {
 180:         printf("\t%d", acg.cg_frsum[i]);
 181:         j += i * acg.cg_frsum[i];
 182:     }
 183:     printf("\nsum of frsum: %d\niused:\t", j);
 184:     pbits(acg.cg_iused, afs.fs_ipg);
 185:     printf("free:\t");
 186:     pbits(acg.cg_free, afs.fs_fpg);
 187:     printf("b:\n");
 188:     for (i = 0; i < afs.fs_cpg; i++) {
 189:         printf("   c%d:\t(%d)\t", i, acg.cg_btot[i]);
 190:         for (j = 0; j < NRPOS; j++)
 191:             printf(" %d", acg.cg_b[i][j]);
 192:         printf("\n");
 193:     }
 194: };
 195: 
 196: pbits(cp, max)
 197:     register char *cp;
 198:     int max;
 199: {
 200:     register int i;
 201:     int count = 0, j;
 202: 
 203:     for (i = 0; i < max; i++)
 204:         if (isset(cp, i)) {
 205:             if (count)
 206:                 printf(",%s", count %9 == 8 ? "\n\t" : " ");
 207:             count++;
 208:             printf("%d", i);
 209:             j = i;
 210:             while ((i+1)<max && isset(cp, i+1))
 211:                 i++;
 212:             if (i != j)
 213:                 printf("-%d", i);
 214:         }
 215:     printf("\n");
 216: }

Defined functions

dumpcg defined in line 157; used 1 times
dumpfs defined in line 59; used 2 times
main defined in line 40; never used
pbits defined in line 196; used 2 times

Defined variables

copyright defined in line 8; never used
sccsid defined in line 14; never used

Defined macros

acg defined in line 38; used 20 times
afs defined in line 32; used 87 times
Last modified: 1985-09-12
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1435
Valid CSS Valid XHTML 1.0 Strict