Commit | Line | Data |
---|---|---|
0947395d | 1 | static char *sccsid = "@(#)dumpfs.c 1.5 (Berkeley) %G%"; |
4abe96a0 KM |
2 | #include "../h/param.h" |
3 | #include "../h/fs.h" | |
56d45dcd | 4 | #include "../h/inode.h" |
4abe96a0 KM |
5 | |
6 | /* | |
7 | * dumpfs | |
8 | */ | |
9 | ||
10 | union { | |
11 | struct fs fs; | |
12 | char pad[BSIZE]; | |
13 | } fsun; | |
14 | #define afs fsun.fs | |
15 | ||
4abe96a0 KM |
16 | union { |
17 | struct cg cg; | |
18 | char pad[BSIZE]; | |
19 | } cgun; | |
20 | #define acg cgun.cg | |
21 | ||
22 | main(argc, argv) | |
23 | char **argv; | |
24 | { | |
743f1ef7 | 25 | int i, j, k; |
4abe96a0 KM |
26 | |
27 | close(0); | |
28 | if (open(argv[1], 0) != 0) | |
29 | perror(argv[1]), exit(1); | |
30 | lseek(0, SBLOCK*FSIZE, 0); | |
31 | if (read(0, &afs, BSIZE) != BSIZE) | |
32 | perror(argv[1]), exit(1); | |
33 | printf("magic\t%x\n", afs.fs_magic); | |
34 | printf("sblkno\t%d\n", afs.fs_sblkno); | |
35 | printf("time\t%s", ctime(&afs.fs_time)); | |
36 | printf("size\t%d\n", afs.fs_size); | |
0947395d | 37 | printf("blocks\t%d\n", afs.fs_dsize); |
4abe96a0 KM |
38 | printf("ncg\t%d\n", afs.fs_ncg); |
39 | printf("cssize\t%d\n", afs.fs_cssize); | |
40 | printf("cgsize\t%d\n", afs.fs_cgsize); | |
41 | printf("ntrak\t%d\nnsect\t%d\nspc\t%d\nncyl\t%d\n", | |
42 | afs.fs_ntrak, afs.fs_nsect, afs.fs_spc, afs.fs_ncyl); | |
43 | printf("cpg\t%d\nfpg\t%d\nipg\t%d\n", | |
44 | afs.fs_cpg, afs.fs_fpg, afs.fs_ipg); | |
0947395d KM |
45 | printf("ndir\t%d\nnffree\t%d\nnbfree\t%d\nnifree\t%d\n", |
46 | afs.fs_cstotal.cs_ndir, afs.fs_cstotal.cs_nffree, | |
47 | afs.fs_cstotal.cs_nbfree, afs.fs_cstotal.cs_nifree); | |
743f1ef7 KM |
48 | printf("cgrotor\t%d\nblocks available in each rotational position", |
49 | afs.fs_cgrotor); | |
50 | for (i = 0; i < NRPOS; i++) { | |
51 | if (afs.fs_postbl[i] > -1) | |
52 | printf("\nposition %d:\t", i); | |
53 | for (j = afs.fs_postbl[i], k = 1; j > -1; | |
54 | j = afs.fs_rotbl[j], k++) { | |
55 | if (k % 15 == 0) | |
56 | printf("\n\t\t"); | |
57 | printf("%4d", j); | |
58 | } | |
59 | } | |
0947395d | 60 | printf("\ncs[].cs_(nbfree,ndir,nifree,nffree):\n\t"); |
743f1ef7 KM |
61 | for (i = 0; i < howmany(cssize(&afs), BSIZE); i++) { |
62 | afs.fs_csp[i] = (struct csum *)calloc(1, BSIZE); | |
63 | lseek(0, (csaddr(&afs) + (i * FRAG)) * FSIZE, 0); | |
64 | if (read(0, afs.fs_csp[i], BSIZE) != BSIZE) | |
65 | perror(argv[1]), exit(1); | |
66 | } | |
4abe96a0 | 67 | for (i = 0; i < afs.fs_ncg; i++) { |
743f1ef7 | 68 | struct csum *cs = &afs.fs_cs(i); |
0947395d | 69 | if (i && i % 4 == 0) |
4abe96a0 | 70 | printf("\n\t"); |
0947395d KM |
71 | printf("(%d,%d,%d,%d) ", |
72 | cs->cs_nbfree, cs->cs_ndir, cs->cs_nifree, cs->cs_nffree); | |
4abe96a0 KM |
73 | } |
74 | printf("\n"); | |
75 | printf("fmod\t%d\n", afs.fs_fmod); | |
76 | printf("ronly\t%d\n", afs.fs_ronly); | |
77 | printf("\n"); | |
78 | for (i = 0; i < afs.fs_ncg; i++) | |
79 | dumpcg(i); | |
80 | }; | |
81 | ||
82 | dumpcg(c) | |
83 | int c; | |
84 | { | |
85 | int i,j; | |
86 | ||
87 | printf("\ncg %d:\n", c); | |
88 | lseek(0, cgtod(c,&afs)*FSIZE, 0); | |
89 | printf("tell\t%x\n", tell(0)); | |
90 | if (read(0, (char *)&acg, afs.fs_cgsize) != afs.fs_cgsize) { | |
91 | printf("\terror reading cg\n"); | |
92 | return; | |
93 | } | |
94 | printf("magic\t%x\ntime\t%s", acg.cg_magic, ctime(&acg.cg_time)); | |
95 | printf("cgx\t%d\nncyl\t%d\nniblk\t%d\nndblk\t%d\n", | |
96 | acg.cg_cgx, acg.cg_ncyl, acg.cg_niblk, acg.cg_ndblk); | |
743f1ef7 | 97 | printf("nifree\t%d\nndir\t%d\nnffree\t%d\nnbfree\t%d\n", |
0947395d KM |
98 | acg.cg_cs.cs_nifree, acg.cg_cs.cs_ndir, |
99 | acg.cg_cs.cs_nffree, acg.cg_cs.cs_nbfree); | |
743f1ef7 KM |
100 | printf("rotor\t%d\nirotor\t%d\nfrotor\t%d\nfrsum", |
101 | acg.cg_rotor, acg.cg_irotor, acg.cg_frotor); | |
f3c028b7 KM |
102 | for (i = 1, j = 0; i < FRAG; i++) { |
103 | printf("\t%d", acg.cg_frsum[i]); | |
104 | j += i * acg.cg_frsum[i]; | |
105 | } | |
106 | printf("\nsum of frsum: %d\niused:\t", j); | |
4abe96a0 KM |
107 | pbits(acg.cg_iused, afs.fs_ipg); |
108 | printf("free:\t"); | |
109 | pbits(acg.cg_free, afs.fs_fpg); | |
110 | printf("b:\n"); | |
111 | for (i = 0; i < afs.fs_cpg; i++) { | |
112 | printf(" c%d:\t", i); | |
113 | for (j = 0; j < NRPOS; j++) | |
114 | printf(" %d", acg.cg_b[i][j]); | |
115 | printf("\n"); | |
116 | } | |
117 | }; | |
118 | ||
4abe96a0 KM |
119 | pbits(cp, max) |
120 | register char *cp; | |
121 | int max; | |
122 | { | |
123 | register int i; | |
124 | int count = 0, j; | |
125 | ||
126 | for (i = 0; i < max; i++) | |
127 | if (isset(cp, i)) { | |
128 | if (count) | |
129 | printf(",%s", count %10 == 9 ? "\n\t" : " "); | |
130 | count++; | |
131 | printf("%d", i); | |
132 | j = i; | |
133 | while ((i+1)<max && isset(cp, i+1)) | |
134 | i++; | |
135 | if (i != j) | |
136 | printf("-%d", i); | |
137 | } | |
138 | printf("\n"); | |
139 | } |