2 * Copyright (c) 1983, 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * @(#) Copyright (c) 1983, 1992, 1993 The Regents of the University of California. All rights reserved.
34 * @(#)dumpfs.c 8.5 (Berkeley) 4/29/95
35 * $FreeBSD: src/sbin/dumpfs/dumpfs.c,v 1.13.2.1 2001/01/22 18:10:11 iedowse Exp $
36 * $DragonFly: src/sbin/dumpfs/dumpfs.c,v 1.8 2006/04/03 03:58:49 dillon Exp $
39 #include <sys/param.h>
42 #include <vfs/ufs/dinode.h>
43 #include <vfs/ufs/fs.h>
67 int dumpcg(char *, int, int);
68 void pbits(void *, int);
72 main(int argc
, char **argv
)
77 while ((ch
= getopt(argc
, argv
, "")) != -1)
89 for (eval
= 0; *argv
; ++argv
)
90 if ((fs
= getfsfile(*argv
)) == NULL
)
91 eval
|= dumpfs(*argv
);
93 eval
|= dumpfs(fs
->fs_spec
);
101 int fd
, c
, i
, j
, k
, size
;
103 if ((fd
= open(name
, O_RDONLY
, 0)) < 0)
105 if (lseek(fd
, (off_t
)SBOFF
, SEEK_SET
) == (off_t
)-1)
107 if ((n
= read(fd
, &afs
, SBSIZE
)) == -1)
111 warnx("%s: non-existent or truncated superblock, skipped",
116 if (afs
.fs_magic
!= FS_MAGIC
) {
117 warnx("%s: superblock has bad magic number, skipped", name
);
122 if (afs
.fs_postblformat
== FS_42POSTBLFMT
)
124 dev_bsize
= afs
.fs_fsize
/ fsbtodb(&afs
, 1);
125 printf("magic\t%x\ttime\t%s", afs
.fs_magic
,
126 ctime(&afs
.fs_time
));
127 printf("id\t[ %x %x ]\n", afs
.fs_id
[0], afs
.fs_id
[1]);
128 printf("cylgrp\t%s\tinodes\t%s\n",
129 afs
.fs_postblformat
== FS_42POSTBLFMT
? "static" : "dynamic",
130 afs
.fs_inodefmt
< FS_44INODEFMT
? "4.2/4.3BSD" : "4.4BSD");
131 printf("nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
132 afs
.fs_cstotal
.cs_nbfree
, afs
.fs_cstotal
.cs_ndir
,
133 afs
.fs_cstotal
.cs_nifree
, afs
.fs_cstotal
.cs_nffree
);
134 printf("ncg\t%d\tncyl\t%d\tsize\t%d\tblocks\t%d\n",
135 afs
.fs_ncg
, afs
.fs_ncyl
, afs
.fs_size
, afs
.fs_dsize
);
136 printf("bsize\t%d\tshift\t%d\tmask\t0x%08x\n",
137 afs
.fs_bsize
, afs
.fs_bshift
, afs
.fs_bmask
);
138 printf("fsize\t%d\tshift\t%d\tmask\t0x%08x\n",
139 afs
.fs_fsize
, afs
.fs_fshift
, afs
.fs_fmask
);
140 printf("frag\t%d\tshift\t%d\tfsbtodb\t%d\n",
141 afs
.fs_frag
, afs
.fs_fragshift
, afs
.fs_fsbtodb
);
142 printf("cpg\t%d\tbpg\t%d\tfpg\t%d\tipg\t%d\n",
143 afs
.fs_cpg
, afs
.fs_fpg
/ afs
.fs_frag
, afs
.fs_fpg
, afs
.fs_ipg
);
144 printf("minfree\t%d%%\toptim\t%s\tmaxcontig %d\tmaxbpg\t%d\n",
145 afs
.fs_minfree
, afs
.fs_optim
== FS_OPTSPACE
? "space" : "time",
146 afs
.fs_maxcontig
, afs
.fs_maxbpg
);
147 printf("rotdelay %dms\trps\t%d\n",
148 afs
.fs_rotdelay
, afs
.fs_rps
);
149 printf("ntrak\t%d\tnsect\t%d\tnpsect\t%d\tspc\t%d\n",
150 afs
.fs_ntrak
, afs
.fs_nsect
, afs
.fs_npsect
, afs
.fs_spc
);
151 printf("symlinklen %d\ttrackskew %d\tinterleave %d\tcontigsumsize %d\n",
152 afs
.fs_maxsymlinklen
, afs
.fs_trackskew
, afs
.fs_interleave
,
153 afs
.fs_contigsumsize
);
154 printf("nindir\t%d\tinopb\t%d\tnspf\t%d\tmaxfilesize\t%qu\n",
155 afs
.fs_nindir
, afs
.fs_inopb
, afs
.fs_nspf
, afs
.fs_maxfilesize
);
156 printf("sblkno\t%d\tcblkno\t%d\tiblkno\t%d\tdblkno\t%d\n",
157 afs
.fs_sblkno
, afs
.fs_cblkno
, afs
.fs_iblkno
, afs
.fs_dblkno
);
158 printf("sbsize\t%d\tcgsize\t%d\tcgoffset %d\tcgmask\t0x%08x\n",
159 afs
.fs_sbsize
, afs
.fs_cgsize
, afs
.fs_cgoffset
, afs
.fs_cgmask
);
160 printf("csaddr\t%d\tcssize\t%d\tshift\t%d\tmask\t0x%08x\n",
161 afs
.fs_csaddr
, afs
.fs_cssize
, afs
.fs_csshift
, afs
.fs_csmask
);
162 printf("cgrotor\t%d\tfmod\t%d\tronly\t%d\tclean\t%d\n",
163 afs
.fs_cgrotor
, afs
.fs_fmod
, afs
.fs_ronly
, afs
.fs_clean
);
165 if (afs
.fs_flags
== 0)
167 if (afs
.fs_flags
& FS_UNCLEAN
)
169 if (afs
.fs_flags
& FS_DOSOFTDEP
)
170 printf("soft-updates ");
171 if ((afs
.fs_flags
& ~(FS_UNCLEAN
| FS_DOSOFTDEP
)) != 0)
172 printf("unknown flags (%#x)",
173 afs
.fs_flags
& ~(FS_UNCLEAN
| FS_DOSOFTDEP
));
176 printf("blocks available in each of %d rotational positions",
179 printf("(no rotational position table)\n");
180 for (c
= 0; c
< afs
.fs_cpc
; c
++) {
181 printf("\ncylinder number %d:", c
);
182 for (i
= 0; i
< afs
.fs_nrpos
; i
++) {
183 if (fs_postbl(&afs
, c
)[i
] == -1)
185 printf("\n position %d:\t", i
);
186 for (j
= fs_postbl(&afs
, c
)[i
], k
= 1; ;
187 j
+= fs_rotbl(&afs
)[j
], k
++) {
191 if (fs_rotbl(&afs
)[j
] == 0)
196 printf("\ncs[].cs_(nbfree,ndir,nifree,nffree):\n\t");
197 afs
.fs_csp
= calloc(1, afs
.fs_cssize
);
198 for (i
= 0, j
= 0; i
< afs
.fs_cssize
; i
+= afs
.fs_bsize
, j
++) {
199 size
= afs
.fs_cssize
- i
< afs
.fs_bsize
?
200 afs
.fs_cssize
- i
: afs
.fs_bsize
;
202 (off_t
)(fsbtodb(&afs
, (afs
.fs_csaddr
+ j
* afs
.fs_frag
))) *
203 (off_t
)dev_bsize
, SEEK_SET
) == (off_t
)-1)
205 if (read(fd
, (char *)afs
.fs_csp
+ i
, size
) != size
)
208 for (i
= 0; i
< afs
.fs_ncg
; i
++) {
209 struct csum
*cs
= &afs
.fs_cs(&afs
, i
);
212 printf("(%d,%d,%d,%d) ",
213 cs
->cs_nbfree
, cs
->cs_ndir
, cs
->cs_nifree
, cs
->cs_nffree
);
216 if (afs
.fs_ncyl
% afs
.fs_cpg
) {
217 printf("cylinders in last group %d\n",
218 i
= afs
.fs_ncyl
% afs
.fs_cpg
);
219 printf("blocks in last group %d\n",
220 i
* afs
.fs_spc
/ NSPB(&afs
));
223 for (i
= 0; i
< afs
.fs_ncg
; i
++)
224 if (dumpcg(name
, fd
, i
))
236 dumpcg(char *name
, int fd
, int c
)
241 printf("\ncg %d:\n", c
);
242 if ((cur
= lseek(fd
, (off_t
)(fsbtodb(&afs
, cgtod(&afs
, c
))) *
243 (off_t
)dev_bsize
, SEEK_SET
)) == (off_t
)-1)
245 if (read(fd
, &acg
, afs
.fs_bsize
) != afs
.fs_bsize
) {
246 warnx("%s: error reading cg", name
);
249 printf("magic\t%x\ttell\t%qx\ttime\t%s",
250 afs
.fs_postblformat
== FS_42POSTBLFMT
?
251 ((struct ocg
*)&acg
)->cg_magic
: acg
.cg_magic
,
252 cur
, ctime(&acg
.cg_time
));
253 printf("cgx\t%d\tncyl\t%d\tniblk\t%d\tndblk\t%d\n",
254 acg
.cg_cgx
, acg
.cg_ncyl
, acg
.cg_niblk
, acg
.cg_ndblk
);
255 printf("nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
256 acg
.cg_cs
.cs_nbfree
, acg
.cg_cs
.cs_ndir
,
257 acg
.cg_cs
.cs_nifree
, acg
.cg_cs
.cs_nffree
);
258 printf("rotor\t%d\tirotor\t%d\tfrotor\t%d\nfrsum",
259 acg
.cg_rotor
, acg
.cg_irotor
, acg
.cg_frotor
);
260 for (i
= 1, j
= 0; i
< afs
.fs_frag
; i
++) {
261 printf("\t%d", acg
.cg_frsum
[i
]);
262 j
+= i
* acg
.cg_frsum
[i
];
264 printf("\nsum of frsum: %d", j
);
265 if (afs
.fs_contigsumsize
> 0) {
266 for (i
= 1; i
< afs
.fs_contigsumsize
; i
++) {
267 if ((i
- 1) % 8 == 0)
268 printf("\nclusters %d-%d:", i
,
269 afs
.fs_contigsumsize
- 1 < i
+ 7 ?
270 afs
.fs_contigsumsize
- 1 : i
+ 7);
271 printf("\t%d", cg_clustersum(&acg
)[i
]);
273 printf("\nclusters size %d and over: %d\n",
274 afs
.fs_contigsumsize
,
275 cg_clustersum(&acg
)[afs
.fs_contigsumsize
]);
276 printf("clusters free:\t");
277 pbits(cg_clustersfree(&acg
), acg
.cg_nclusterblks
);
281 pbits(cg_inosused(&acg
), afs
.fs_ipg
);
283 pbits(cg_blksfree(&acg
), afs
.fs_fpg
);
285 for (i
= 0; i
< afs
.fs_cpg
; i
++) {
286 if (cg_blktot(&acg
)[i
] == 0)
288 printf(" c%d:\t(%d)\t", i
, cg_blktot(&acg
)[i
]);
289 for (j
= 0; j
< afs
.fs_nrpos
; j
++) {
290 if (afs
.fs_cpc
> 0 &&
291 fs_postbl(&afs
, i
% afs
.fs_cpc
)[j
] == -1)
293 printf(" %d", cg_blks(&afs
, &acg
, i
)[j
]);
301 pbits(void *vp
, int max
)
307 for (count
= i
= 0, p
= vp
; i
< max
; i
++)
310 printf(",%s", count
% 6 ? " " : "\n\t");
314 while ((i
+1)<max
&& isset(p
, i
+1))
325 fprintf(stderr
, "usage: dumpfs filesys | device\n");