Commit | Line | Data |
---|---|---|
3352e84a | 1 | static char *sccsid = "@(#)dumpfs.c 1.11 (Berkeley) %G%"; |
b6407c9d | 2 | |
4abe96a0 KM |
3 | #include "../h/param.h" |
4 | #include "../h/fs.h" | |
56d45dcd | 5 | #include "../h/inode.h" |
4abe96a0 KM |
6 | |
7 | /* | |
8 | * dumpfs | |
9 | */ | |
10 | ||
11 | union { | |
12 | struct fs fs; | |
b6407c9d | 13 | char pad[MAXBSIZE]; |
4abe96a0 KM |
14 | } fsun; |
15 | #define afs fsun.fs | |
16 | ||
4abe96a0 KM |
17 | union { |
18 | struct cg cg; | |
b6407c9d | 19 | char pad[MAXBSIZE]; |
4abe96a0 KM |
20 | } cgun; |
21 | #define acg cgun.cg | |
22 | ||
23 | main(argc, argv) | |
24 | char **argv; | |
25 | { | |
aca50d72 | 26 | int c, i, j, k; |
4abe96a0 KM |
27 | |
28 | close(0); | |
29 | if (open(argv[1], 0) != 0) | |
30 | perror(argv[1]), exit(1); | |
b6407c9d | 31 | lseek(0, SBLOCK * DEV_BSIZE, 0); |
c312eebd | 32 | if (read(0, &afs, SBSIZE) != SBSIZE) |
4abe96a0 | 33 | perror(argv[1]), exit(1); |
3352e84a KM |
34 | printf("magic\t%x\ttime\t%s", afs.fs_magic, ctime(&afs.fs_time)); |
35 | printf("bblkno\t%d\tsblkno\t%d\n", afs.fs_bblkno, afs.fs_sblkno); | |
36 | printf("cblkno\t%d\tiblkno\t%d\tdblkno\t%d\n", | |
37 | afs.fs_cblkno, afs.fs_iblkno, afs.fs_dblkno); | |
38 | printf("ncg\t%d\tsize\t%d\tblocks\t%d\tcgsize\t%d\n", | |
39 | afs.fs_ncg, afs.fs_size, afs.fs_dsize, afs.fs_cgsize); | |
40 | printf("bsize\t%d\tshift\t%d\tmask\t0x%08x\n", | |
41 | afs.fs_bsize, afs.fs_bshift, afs.fs_bmask); | |
42 | printf("fsize\t%d\tshift\t%d\tmask\t0x%08x\n", | |
43 | afs.fs_fsize, afs.fs_fshift, afs.fs_fmask); | |
44 | printf("frag\t%d\tminfree\t%d%%\n", afs.fs_frag, afs.fs_minfree); | |
45 | printf("rotdelay %dms\trps\t%d\n", afs.fs_rotdelay, afs.fs_rps); | |
46 | printf("csaddr\t%d\tcssize\t%d\n", afs.fs_csaddr, afs.fs_cssize); | |
47 | printf("ntrak\t%d\tnsect\t%d\tspc\t%d\tncyl\t%d\n", | |
4abe96a0 | 48 | afs.fs_ntrak, afs.fs_nsect, afs.fs_spc, afs.fs_ncyl); |
3352e84a | 49 | printf("cpg\t%d\tbpg\t%d\tfpg\t%d\tipg\t%d\n", |
c312eebd | 50 | afs.fs_cpg, afs.fs_fpg / afs.fs_frag, afs.fs_fpg, afs.fs_ipg); |
3352e84a KM |
51 | printf("nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n", |
52 | afs.fs_cstotal.cs_nbfree, afs.fs_cstotal.cs_ndir, | |
53 | afs.fs_cstotal.cs_nifree, afs.fs_cstotal.cs_nffree); | |
54 | printf("cgrotor\t%d\tfmod\t%d\tronly\t%d\n", | |
c312eebd | 55 | afs.fs_cgrotor, afs.fs_fmod, afs.fs_ronly); |
aca50d72 KM |
56 | if (afs.fs_cpc != 0) |
57 | printf("blocks available in each rotational position"); | |
58 | else | |
59 | printf("insufficient space to maintain rotational tables\n"); | |
60 | for (c = 0; c < afs.fs_cpc; c++) { | |
61 | printf("\ncylinder number %d:", c); | |
62 | for (i = 0; i < NRPOS; i++) { | |
63 | if (afs.fs_postbl[c][i] == -1) | |
64 | continue; | |
65 | printf("\n position %d:\t", i); | |
66 | for (j = afs.fs_postbl[c][i], k = 1; ; | |
67 | j += afs.fs_rotbl[j], k++) { | |
68 | printf("%5d", j); | |
69 | if (k % 12 == 0) | |
70 | printf("\n\t\t"); | |
71 | if (afs.fs_rotbl[j] == 0) | |
72 | break; | |
73 | } | |
743f1ef7 KM |
74 | } |
75 | } | |
0947395d | 76 | printf("\ncs[].cs_(nbfree,ndir,nifree,nffree):\n\t"); |
b6407c9d KM |
77 | for (i = 0; i < howmany(afs.fs_cssize, afs.fs_bsize); i++) { |
78 | afs.fs_csp[i] = (struct csum *)calloc(1, afs.fs_bsize); | |
79 | lseek(0, fsbtodb(&afs, (afs.fs_csaddr + (i * afs.fs_frag))) * | |
80 | DEV_BSIZE, 0); | |
81 | if (read(0, afs.fs_csp[i], afs.fs_bsize) != afs.fs_bsize) | |
743f1ef7 KM |
82 | perror(argv[1]), exit(1); |
83 | } | |
4abe96a0 | 84 | for (i = 0; i < afs.fs_ncg; i++) { |
b6407c9d | 85 | struct csum *cs = &afs.fs_cs(&afs, i); |
0947395d | 86 | if (i && i % 4 == 0) |
4abe96a0 | 87 | printf("\n\t"); |
0947395d KM |
88 | printf("(%d,%d,%d,%d) ", |
89 | cs->cs_nbfree, cs->cs_ndir, cs->cs_nifree, cs->cs_nffree); | |
4abe96a0 KM |
90 | } |
91 | printf("\n"); | |
c312eebd KM |
92 | if (afs.fs_ncyl % afs.fs_cpg) { |
93 | printf("cylinders in last group %d\n", | |
94 | i = afs.fs_ncyl % afs.fs_cpg); | |
95 | printf("blocks in last group %d\n", | |
96 | i * afs.fs_spc / NSPB(&afs)); | |
97 | } | |
4abe96a0 KM |
98 | printf("\n"); |
99 | for (i = 0; i < afs.fs_ncg; i++) | |
100 | dumpcg(i); | |
101 | }; | |
102 | ||
103 | dumpcg(c) | |
104 | int c; | |
105 | { | |
106 | int i,j; | |
107 | ||
108 | printf("\ncg %d:\n", c); | |
6994bf5d | 109 | lseek(0, fsbtodb(&afs, cgtod(&afs, c)) * DEV_BSIZE, 0); |
3352e84a | 110 | i = tell(0); |
b6407c9d | 111 | if (read(0, (char *)&acg, afs.fs_bsize) != afs.fs_bsize) { |
4abe96a0 KM |
112 | printf("\terror reading cg\n"); |
113 | return; | |
114 | } | |
3352e84a KM |
115 | printf("magic\t%x\ttell\t%x\ttime\t%s", |
116 | acg.cg_magic, i, ctime(&acg.cg_time)); | |
117 | printf("cgx\t%d\tncyl\t%d\tniblk\t%d\tndblk\t%d\n", | |
4abe96a0 | 118 | acg.cg_cgx, acg.cg_ncyl, acg.cg_niblk, acg.cg_ndblk); |
3352e84a KM |
119 | printf("nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n", |
120 | acg.cg_cs.cs_nbfree, acg.cg_cs.cs_ndir, | |
121 | acg.cg_cs.cs_nifree, acg.cg_cs.cs_nffree); | |
122 | printf("rotor\t%d\tirotor\t%d\tfrotor\t%d\nfrsum", | |
743f1ef7 | 123 | acg.cg_rotor, acg.cg_irotor, acg.cg_frotor); |
b6407c9d | 124 | for (i = 1, j = 0; i < afs.fs_frag; i++) { |
f3c028b7 KM |
125 | printf("\t%d", acg.cg_frsum[i]); |
126 | j += i * acg.cg_frsum[i]; | |
127 | } | |
128 | printf("\nsum of frsum: %d\niused:\t", j); | |
4abe96a0 KM |
129 | pbits(acg.cg_iused, afs.fs_ipg); |
130 | printf("free:\t"); | |
131 | pbits(acg.cg_free, afs.fs_fpg); | |
132 | printf("b:\n"); | |
133 | for (i = 0; i < afs.fs_cpg; i++) { | |
43f6367c | 134 | printf(" c%d:\t(%d)\t", i, acg.cg_btot[i]); |
4abe96a0 KM |
135 | for (j = 0; j < NRPOS; j++) |
136 | printf(" %d", acg.cg_b[i][j]); | |
137 | printf("\n"); | |
138 | } | |
139 | }; | |
140 | ||
4abe96a0 KM |
141 | pbits(cp, max) |
142 | register char *cp; | |
143 | int max; | |
144 | { | |
145 | register int i; | |
146 | int count = 0, j; | |
147 | ||
148 | for (i = 0; i < max; i++) | |
149 | if (isset(cp, i)) { | |
150 | if (count) | |
3352e84a | 151 | printf(",%s", count %9 == 8 ? "\n\t" : " "); |
4abe96a0 KM |
152 | count++; |
153 | printf("%d", i); | |
154 | j = i; | |
155 | while ((i+1)<max && isset(cp, i+1)) | |
156 | i++; | |
157 | if (i != j) | |
158 | printf("-%d", i); | |
159 | } | |
160 | printf("\n"); | |
161 | } |