2 * Copyright (c) 2002 Networks Associates Technology, Inc.
5 * This software was developed for the FreeBSD Project by Marshall
6 * Kirk McKusick and Network Associates Laboratories, the Security
7 * Research Division of Network Associates, Inc. under DARPA/SPAWAR
8 * contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
11 * Copyright (c) 1983, 1992, 1993
12 * The Regents of the University of California. All rights reserved.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 static const char copyright[] =
41 "@(#) Copyright (c) 1983, 1992, 1993\n\
42 The Regents of the University of California. All rights reserved.\n";
47 static char sccsid[] = "@(#)dumpfs.c 8.5 (Berkeley) 4/29/95";
49 static const char rcsid[] =
53 #include <sys/param.h>
55 #include <sys/disklabel.h>
57 #include <ufs/ufs/dinode.h>
58 #include <ufs/ffs/fs.h>
75 int dumpfs(const char *);
77 int marshal(const char *);
78 void pbits(void *, int);
79 void ufserr(const char *);
80 void usage(void) __dead2;
83 main(int argc, char *argv[])
86 int ch, domarshal, eval;
90 while ((ch = getopt(argc, argv, "m")) != -1) {
106 while ((name = *argv++) != NULL) {
107 if (ufs_disk_fillout(&disk, name) == -1) {
113 eval |= marshal(name);
115 eval |= dumpfs(name);
116 ufs_disk_close(&disk);
122 dumpfs(const char *name)
129 switch (disk.d_ufs) {
131 fssize = afs.fs_size;
132 fstime = afs.fs_time;
133 printf("magic\t%x (UFS2)\ttime\t%s",
134 afs.fs_magic, ctime(&fstime));
135 printf("superblock location\t%jd\tid\t[ %x %x ]\n",
136 (intmax_t)afs.fs_sblockloc, afs.fs_id[0], afs.fs_id[1]);
137 printf("ncg\t%d\tsize\t%jd\tblocks\t%jd\n",
138 afs.fs_ncg, (intmax_t)fssize, (intmax_t)afs.fs_dsize);
141 fssize = afs.fs_old_size;
142 fstime = afs.fs_old_time;
143 printf("magic\t%x (UFS1)\ttime\t%s",
144 afs.fs_magic, ctime(&fstime));
145 printf("id\t[ %x %x ]\n", afs.fs_id[0], afs.fs_id[1]);
146 printf("ncg\t%d\tsize\t%jd\tblocks\t%jd\n",
147 afs.fs_ncg, (intmax_t)fssize, (intmax_t)afs.fs_dsize);
152 printf("bsize\t%d\tshift\t%d\tmask\t0x%08x\n",
153 afs.fs_bsize, afs.fs_bshift, afs.fs_bmask);
154 printf("fsize\t%d\tshift\t%d\tmask\t0x%08x\n",
155 afs.fs_fsize, afs.fs_fshift, afs.fs_fmask);
156 printf("frag\t%d\tshift\t%d\tfsbtodb\t%d\n",
157 afs.fs_frag, afs.fs_fragshift, afs.fs_fsbtodb);
158 printf("minfree\t%d%%\toptim\t%s\tsymlinklen %d\n",
159 afs.fs_minfree, afs.fs_optim == FS_OPTSPACE ? "space" : "time",
160 afs.fs_maxsymlinklen);
161 switch (disk.d_ufs) {
163 printf("%s %d\tmaxbpg\t%d\tmaxcontig %d\tcontigsumsize %d\n",
164 "maxbsize", afs.fs_maxbsize, afs.fs_maxbpg,
165 afs.fs_maxcontig, afs.fs_contigsumsize);
166 printf("nbfree\t%jd\tndir\t%jd\tnifree\t%jd\tnffree\t%jd\n",
167 (intmax_t)afs.fs_cstotal.cs_nbfree,
168 (intmax_t)afs.fs_cstotal.cs_ndir,
169 (intmax_t)afs.fs_cstotal.cs_nifree,
170 (intmax_t)afs.fs_cstotal.cs_nffree);
171 printf("bpg\t%d\tfpg\t%d\tipg\t%d\n",
172 afs.fs_fpg / afs.fs_frag, afs.fs_fpg, afs.fs_ipg);
173 printf("nindir\t%d\tinopb\t%d\tmaxfilesize\t%ju\n",
174 afs.fs_nindir, afs.fs_inopb,
175 (uintmax_t)afs.fs_maxfilesize);
176 printf("sbsize\t%d\tcgsize\t%d\tcsaddr\t%jd\tcssize\t%d\n",
177 afs.fs_sbsize, afs.fs_cgsize, (intmax_t)afs.fs_csaddr,
181 printf("maxbpg\t%d\tmaxcontig %d\tcontigsumsize %d\n",
182 afs.fs_maxbpg, afs.fs_maxcontig, afs.fs_contigsumsize);
183 printf("nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
184 afs.fs_old_cstotal.cs_nbfree, afs.fs_old_cstotal.cs_ndir,
185 afs.fs_old_cstotal.cs_nifree, afs.fs_old_cstotal.cs_nffree);
186 printf("cpg\t%d\tbpg\t%d\tfpg\t%d\tipg\t%d\n",
187 afs.fs_old_cpg, afs.fs_fpg / afs.fs_frag, afs.fs_fpg,
189 printf("nindir\t%d\tinopb\t%d\tnspf\t%d\tmaxfilesize\t%ju\n",
190 afs.fs_nindir, afs.fs_inopb, afs.fs_old_nspf,
191 (uintmax_t)afs.fs_maxfilesize);
192 printf("sbsize\t%d\tcgsize\t%d\tcgoffset %d\tcgmask\t0x%08x\n",
193 afs.fs_sbsize, afs.fs_cgsize, afs.fs_old_cgoffset,
195 printf("csaddr\t%d\tcssize\t%d\n",
196 afs.fs_old_csaddr, afs.fs_cssize);
197 printf("rotdelay %dms\trps\t%d\ttrackskew %d\tinterleave %d\n",
198 afs.fs_old_rotdelay, afs.fs_old_rps, afs.fs_old_trackskew,
199 afs.fs_old_interleave);
200 printf("nsect\t%d\tnpsect\t%d\tspc\t%d\n",
201 afs.fs_old_nsect, afs.fs_old_npsect, afs.fs_old_spc);
206 printf("sblkno\t%d\tcblkno\t%d\tiblkno\t%d\tdblkno\t%d\n",
207 afs.fs_sblkno, afs.fs_cblkno, afs.fs_iblkno, afs.fs_dblkno);
208 printf("cgrotor\t%d\tfmod\t%d\tronly\t%d\tclean\t%d\n",
209 afs.fs_cgrotor, afs.fs_fmod, afs.fs_ronly, afs.fs_clean);
210 printf("avgfpdir %d\tavgfilesize %d\n",
211 afs.fs_avgfpdir, afs.fs_avgfilesize);
213 if (afs.fs_old_flags & FS_FLAGS_UPDATED)
214 fsflags = afs.fs_flags;
216 fsflags = afs.fs_old_flags;
219 if (fsflags & FS_UNCLEAN)
221 if (fsflags & FS_DOSOFTDEP)
222 printf("soft-updates ");
223 if (fsflags & FS_NEEDSFSCK)
224 printf("needs fsck run ");
225 if (fsflags & FS_INDEXDIRS)
226 printf("indexed directories ");
227 if (fsflags & FS_ACLS)
229 if (fsflags & FS_MULTILABEL)
230 printf("multilabel ");
231 if (fsflags & FS_FLAGS_UPDATED)
232 printf("fs_flags expanded ");
233 fsflags &= ~(FS_UNCLEAN | FS_DOSOFTDEP | FS_NEEDSFSCK | FS_INDEXDIRS |
234 FS_ACLS | FS_MULTILABEL | FS_FLAGS_UPDATED);
236 printf("unknown flags (%#x)", fsflags);
238 printf("fsmnt\t%s\n", afs.fs_fsmnt);
239 printf("volname\t%s\tswuid\t%ju\n",
240 afs.fs_volname, (uintmax_t)afs.fs_swuid);
241 printf("\ncs[].cs_(nbfree,ndir,nifree,nffree):\n\t");
242 afs.fs_csp = calloc(1, afs.fs_cssize);
243 if (bread(&disk, fsbtodb(&afs, afs.fs_csaddr), afs.fs_csp, afs.fs_cssize) == -1)
245 for (i = 0; i < afs.fs_ncg; i++) {
246 struct csum *cs = &afs.fs_cs(&afs, i);
249 printf("(%d,%d,%d,%d) ",
250 cs->cs_nbfree, cs->cs_ndir, cs->cs_nifree, cs->cs_nffree);
253 if (fssize % afs.fs_fpg) {
255 printf("cylinders in last group %d\n",
256 howmany(afs.fs_old_size % afs.fs_fpg,
257 afs.fs_old_spc / afs.fs_old_nspf));
258 printf("blocks in last group %ld\n\n",
259 (long)((fssize % afs.fs_fpg) / afs.fs_frag));
261 while ((i = cgread(&disk)) != 0) {
262 if (i == -1 || dumpcg())
278 printf("\ncg %d:\n", disk.d_lcg);
279 cur = fsbtodb(&afs, cgtod(&afs, disk.d_lcg)) * disk.d_bsize;
280 switch (disk.d_ufs) {
282 cgtime = acg.cg_time;
283 printf("magic\t%x\ttell\t%jx\ttime\t%s",
284 acg.cg_magic, (intmax_t)cur, ctime(&cgtime));
285 printf("cgx\t%d\tndblk\t%d\tniblk\t%d\tinitiblk %d\n",
286 acg.cg_cgx, acg.cg_ndblk, acg.cg_niblk, acg.cg_initediblk);
289 cgtime = acg.cg_old_time;
290 printf("magic\t%x\ttell\t%jx\ttime\t%s",
291 acg.cg_magic, (intmax_t)cur, ctime(&cgtime));
292 printf("cgx\t%d\tncyl\t%d\tniblk\t%d\tndblk\t%d\n",
293 acg.cg_cgx, acg.cg_old_ncyl, acg.cg_old_niblk,
299 printf("nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
300 acg.cg_cs.cs_nbfree, acg.cg_cs.cs_ndir,
301 acg.cg_cs.cs_nifree, acg.cg_cs.cs_nffree);
302 printf("rotor\t%d\tirotor\t%d\tfrotor\t%d\nfrsum",
303 acg.cg_rotor, acg.cg_irotor, acg.cg_frotor);
304 for (i = 1, j = 0; i < afs.fs_frag; i++) {
305 printf("\t%d", acg.cg_frsum[i]);
306 j += i * acg.cg_frsum[i];
308 printf("\nsum of frsum: %d", j);
309 if (afs.fs_contigsumsize > 0) {
310 for (i = 1; i < afs.fs_contigsumsize; i++) {
311 if ((i - 1) % 8 == 0)
312 printf("\nclusters %d-%d:", i,
313 afs.fs_contigsumsize - 1 < i + 7 ?
314 afs.fs_contigsumsize - 1 : i + 7);
315 printf("\t%d", cg_clustersum(&acg)[i]);
317 printf("\nclusters size %d and over: %d\n",
318 afs.fs_contigsumsize,
319 cg_clustersum(&acg)[afs.fs_contigsumsize]);
320 printf("clusters free:\t");
321 pbits(cg_clustersfree(&acg), acg.cg_nclusterblks);
324 printf("inodes used:\t");
325 pbits(cg_inosused(&acg), afs.fs_ipg);
326 printf("blks free:\t");
327 pbits(cg_blksfree(&acg), afs.fs_fpg);
332 marshal(const char *name)
338 printf("# newfs command for %s (%s)\n", name, disk.d_name);
340 if (fs->fs_volname[0] != '\0')
341 printf("-L %s ", fs->fs_volname);
342 printf("-O %d ", disk.d_ufs);
343 if (fs->fs_flags & FS_DOSOFTDEP)
345 printf("-a %d ", fs->fs_maxcontig);
346 printf("-b %d ", fs->fs_bsize);
348 printf("-d %d ", fs->fs_maxbsize);
349 printf("-e %d ", fs->fs_maxbpg);
350 printf("-f %d ", fs->fs_fsize);
351 printf("-g %d ", fs->fs_avgfilesize);
352 printf("-h %d ", fs->fs_avgfpdir);
354 /* -j..l unimplemented */
355 printf("-m %d ", fs->fs_minfree);
356 /* -n unimplemented */
358 switch (fs->fs_optim) {
369 /* -p..r unimplemented */
370 printf("-s %jd ", (intmax_t)fs->fs_size);
371 printf("%s ", disk.d_name);
378 pbits(void *vp, int max)
384 for (count = i = 0, p = vp; i < max; i++)
387 printf(",%s", count % 6 ? " " : "\n\t");
391 while ((i+1)<max && isset(p, i+1))
400 ufserr(const char *name)
402 if (disk.d_error != NULL)
403 warnx("%s: %s", name, disk.d_error);
411 (void)fprintf(stderr, "usage: dumpfs [-m] filesys | device\n");