4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 * University Copyright- Copyright (c) 1982, 1986, 1988
31 * The Regents of the University of California
34 * University Acknowledgment- Portions of this document are derived from
35 * software developed by the University of California, Berkeley, and its
39 #pragma ident "%Z%%M% %I% %E% SMI"
42 * libfstyp module for ufs
52 #include <sys/param.h>
53 #include <sys/types.h>
54 #include <sys/mntent.h>
55 #include <sys/errno.h>
56 #include <sys/fs/ufs_fs.h>
59 #include <sys/mnttab.h>
61 #include <sys/fs/ufs_log.h>
62 #include <sys/inttypes.h>
64 #include <libfstyp_module.h>
66 typedef struct fstyp_ufs
{
88 #define NRPOS 8 /* for pre FFFS compatibility */
90 static int is_ufs(fstyp_ufs_t
*h
);
91 static int get_attr(fstyp_ufs_t
*h
);
92 static int dumpfs(fstyp_ufs_t
*h
, FILE *fout
, FILE *ferr
);
93 static void dumplog(fstyp_ufs_t
*h
, FILE *fout
, FILE *ferr
);
94 static void dumpcg(fstyp_ufs_t
*h
, FILE *fout
, FILE *ferr
, const int c
);
95 static void pbits(FILE *out
, const void *cp
, const int max
);
97 int fstyp_mod_init(int fd
, off_t offset
, fstyp_mod_handle_t
*handle
);
98 void fstyp_mod_fini(fstyp_mod_handle_t handle
);
99 int fstyp_mod_ident(fstyp_mod_handle_t handle
);
100 int fstyp_mod_get_attr(fstyp_mod_handle_t handle
, nvlist_t
**attrp
);
101 int fstyp_mod_dump(fstyp_mod_handle_t handle
, FILE *fout
, FILE *ferr
);
105 fstyp_mod_init(int fd
, off_t offset
, fstyp_mod_handle_t
*handle
)
110 return (FSTYP_ERR_OFFSET
);
113 if ((h
= calloc(1, sizeof (struct fstyp_ufs
))) == NULL
) {
114 return (FSTYP_ERR_NOMEM
);
118 *handle
= (fstyp_mod_handle_t
)h
;
123 fstyp_mod_fini(fstyp_mod_handle_t handle
)
125 struct fstyp_ufs
*h
= (struct fstyp_ufs
*)handle
;
127 if (h
->attr
== NULL
) {
128 nvlist_free(h
->attr
);
135 fstyp_mod_ident(fstyp_mod_handle_t handle
)
137 struct fstyp_ufs
*h
= (struct fstyp_ufs
*)handle
;
143 fstyp_mod_get_attr(fstyp_mod_handle_t handle
, nvlist_t
**attrp
)
145 struct fstyp_ufs
*h
= (struct fstyp_ufs
*)handle
;
148 if (h
->attr
== NULL
) {
149 if (nvlist_alloc(&h
->attr
, NV_UNIQUE_NAME_TYPE
, 0)) {
150 return (FSTYP_ERR_NOMEM
);
152 if ((error
= get_attr(h
)) != 0) {
153 nvlist_free(h
->attr
);
164 fstyp_mod_dump(fstyp_mod_handle_t handle
, FILE *fout
, FILE *ferr
)
166 struct fstyp_ufs
*h
= (struct fstyp_ufs
*)handle
;
168 return (dumpfs(h
, fout
, ferr
));
172 is_ufs(fstyp_ufs_t
*h
)
174 (void) llseek(h
->fd
, (offset_t
)SBLOCK
* DEV_BSIZE
, 0);
175 if (read(h
->fd
, &h
->afs
, SBSIZE
) != SBSIZE
) {
176 return (FSTYP_ERR_IO
);
178 if ((h
->afs
.fs_magic
!= FS_MAGIC
) &&
179 (h
->afs
.fs_magic
!= MTB_UFS_MAGIC
)) {
180 return (FSTYP_ERR_NO_MATCH
);
182 if ((h
->afs
.fs_magic
== FS_MAGIC
) &&
183 (h
->afs
.fs_version
!= UFS_EFISTYLE4NONEFI_VERSION_2
&&
184 h
->afs
.fs_version
!= UFS_VERSION_MIN
)) {
185 return (FSTYP_ERR_NO_MATCH
);
187 if ((h
->afs
.fs_magic
== MTB_UFS_MAGIC
) &&
188 (h
->afs
.fs_version
> MTB_UFS_VERSION_1
||
189 h
->afs
.fs_version
< MTB_UFS_VERSION_MIN
)) {
190 return (FSTYP_ERR_NO_MATCH
);
195 #define ADD_STRING(h, name, value) \
196 if (nvlist_add_string(h->attr, name, value) != 0) { \
197 return (FSTYP_ERR_NOMEM); \
200 #define ADD_INT32(h, name, value) \
201 if (nvlist_add_int32(h->attr, name, value) != 0) { \
202 return (FSTYP_ERR_NOMEM); \
205 #define ADD_BOOL(h, name, value) \
206 if (nvlist_add_boolean_value(h->attr, name, value) != 0) { \
207 return (FSTYP_ERR_NOMEM); \
211 get_attr(fstyp_ufs_t
*h
)
213 struct fs
*fsp
= &h
->afs
;
217 ADD_INT32(h
, "magic", fsp
->fs_magic
);
218 ADD_STRING(h
, "format",
219 fsp
->fs_postblformat
== FS_42POSTBLFMT
? "static" : "dynamic");
220 t
= (time_t)fsp
->fs_time
;
221 (void) snprintf(s
, sizeof (s
), "%s", ctime(&t
));
222 s
[strlen(s
) - 1] = '\0';
223 ADD_STRING(h
, "time", s
);
224 ADD_INT32(h
, "sblkno", fsp
->fs_sblkno
);
225 ADD_INT32(h
, "cblkno", fsp
->fs_cblkno
);
226 ADD_INT32(h
, "iblkno", fsp
->fs_iblkno
);
227 ADD_INT32(h
, "dblkno", fsp
->fs_dblkno
);
228 ADD_INT32(h
, "sbsize", fsp
->fs_sbsize
);
229 ADD_INT32(h
, "cgsize", fsp
->fs_cgsize
);
230 ADD_INT32(h
, "cgoffset", fsp
->fs_cgoffset
);
231 ADD_INT32(h
, "cgmask", fsp
->fs_cgmask
);
232 ADD_INT32(h
, "ncg", fsp
->fs_ncg
);
233 ADD_INT32(h
, "size", fsp
->fs_size
);
234 ADD_INT32(h
, "blocks", fsp
->fs_dsize
);
235 ADD_INT32(h
, "bsize", fsp
->fs_bsize
);
236 ADD_INT32(h
, "bshift", fsp
->fs_bshift
);
237 ADD_INT32(h
, "bmask", fsp
->fs_bmask
);
238 ADD_INT32(h
, "fsize", fsp
->fs_fsize
);
239 ADD_INT32(h
, "fshift", fsp
->fs_fshift
);
240 ADD_INT32(h
, "fmask", fsp
->fs_fmask
);
241 ADD_INT32(h
, "frag", fsp
->fs_frag
);
242 ADD_INT32(h
, "fragshift", fsp
->fs_fragshift
);
243 ADD_INT32(h
, "fsbtodb", fsp
->fs_fsbtodb
);
244 ADD_INT32(h
, "minfree", fsp
->fs_minfree
);
245 ADD_INT32(h
, "maxbpg", fsp
->fs_maxbpg
);
246 ADD_STRING(h
, "optim",
247 fsp
->fs_optim
== FS_OPTSPACE
? "space" : "time");
248 ADD_INT32(h
, "maxcontig", fsp
->fs_maxcontig
);
249 ADD_INT32(h
, "rotdelay", fsp
->fs_rotdelay
);
250 ADD_INT32(h
, "rps", fsp
->fs_rps
);
251 ADD_INT32(h
, "csaddr", fsp
->fs_csaddr
);
252 ADD_INT32(h
, "cssize", fsp
->fs_cssize
);
253 ADD_INT32(h
, "csshift", fsp
->fs_csshift
);
254 ADD_INT32(h
, "csmask", fsp
->fs_csmask
);
255 ADD_INT32(h
, "ntrak", fsp
->fs_ntrak
);
256 ADD_INT32(h
, "nsect", fsp
->fs_nsect
);
257 ADD_INT32(h
, "spc", fsp
->fs_spc
);
258 ADD_INT32(h
, "ncyl", fsp
->fs_ncyl
);
259 ADD_INT32(h
, "cpg", fsp
->fs_cpg
);
260 ADD_INT32(h
, "bpg", fsp
->fs_fpg
/ fsp
->fs_frag
);
261 ADD_INT32(h
, "fpg", fsp
->fs_fpg
);
262 ADD_INT32(h
, "ipg", fsp
->fs_ipg
);
263 ADD_INT32(h
, "nindir", fsp
->fs_nindir
);
264 ADD_INT32(h
, "inopb", fsp
->fs_inopb
);
265 ADD_INT32(h
, "nspf", fsp
->fs_nspf
);
266 ADD_INT32(h
, "nbfree", fsp
->fs_cstotal
.cs_nbfree
);
267 ADD_INT32(h
, "ndir", fsp
->fs_cstotal
.cs_ndir
);
268 ADD_INT32(h
, "nifree", fsp
->fs_cstotal
.cs_nifree
);
269 ADD_INT32(h
, "nffree", fsp
->fs_cstotal
.cs_nffree
);
270 ADD_INT32(h
, "cgrotor", fsp
->fs_cgrotor
);
271 ADD_INT32(h
, "fmod", fsp
->fs_fmod
);
272 ADD_INT32(h
, "ronly", fsp
->fs_ronly
);
273 ADD_INT32(h
, "logbno", fsp
->fs_logbno
);
274 ADD_INT32(h
, "rolled", fsp
->fs_rolled
);
275 ADD_INT32(h
, "si", fsp
->fs_si
);
276 ADD_INT32(h
, "flags", fsp
->fs_flags
);
277 ADD_INT32(h
, "version", fsp
->fs_version
);
278 if (fsp
->fs_reclaim
& (FS_RECLAIM
| FS_RECLAIMING
)) {
279 (void) snprintf(s
, sizeof (s
), "%s%s",
280 (fsp
->fs_reclaim
& FS_RECLAIM
) ? " FS_RECLAIM" : "",
281 (fsp
->fs_reclaim
& FS_RECLAIMING
) ? " FS_RECLAIMING" : "");
282 ADD_STRING(h
, "fs_reclaim", s
);
284 ADD_INT32(h
, "clean", fsp
->fs_clean
);
286 if ((fsp
->fs_state
+ (long)fsp
->fs_time
== FSOKAY
) &&
287 (fsp
->fs_clean
== FSCLEAN
|| fsp
->fs_clean
== FSSTABLE
||
288 (fsp
->fs_clean
== FSLOG
))) {
289 ADD_BOOL(h
, "gen_clean", B_TRUE
);
291 ADD_BOOL(h
, "gen_clean", B_FALSE
);
294 (void) snprintf(s
, sizeof (s
), "%d", fsp
->fs_version
);
295 ADD_STRING(h
, "gen_version", s
);
302 dumpfs(fstyp_ufs_t
*h
, FILE *fout
, FILE *ferr
)
304 int c
, i
, j
, k
, size
, nrpos
;
305 struct fs
*fsp
= &h
->afs
;
310 t
= (time_t)fsp
->fs_time
;
311 (void) fprintf(fout
, "magic\t%x\tformat\t%s\ttime\t%s", fsp
->fs_magic
,
312 fsp
->fs_postblformat
== FS_42POSTBLFMT
? "static" : "dynamic",
314 (void) fprintf(fout
, "sblkno\t%d\tcblkno\t%d\tiblkno\t%d\tdblkno\t%d\n",
315 fsp
->fs_sblkno
, fsp
->fs_cblkno
, fsp
->fs_iblkno
, fsp
->fs_dblkno
);
317 "sbsize\t%d\tcgsize\t%d\tcgoffset %d\tcgmask\t0x%08x\n",
318 fsp
->fs_sbsize
, fsp
->fs_cgsize
, fsp
->fs_cgoffset
, fsp
->fs_cgmask
);
319 (void) fprintf(fout
, "ncg\t%d\tsize\t%d\tblocks\t%d\n",
320 fsp
->fs_ncg
, fsp
->fs_size
, fsp
->fs_dsize
);
321 (void) fprintf(fout
, "bsize\t%d\tshift\t%d\tmask\t0x%08x\n",
322 fsp
->fs_bsize
, fsp
->fs_bshift
, fsp
->fs_bmask
);
323 (void) fprintf(fout
, "fsize\t%d\tshift\t%d\tmask\t0x%08x\n",
324 fsp
->fs_fsize
, fsp
->fs_fshift
, fsp
->fs_fmask
);
325 (void) fprintf(fout
, "frag\t%d\tshift\t%d\tfsbtodb\t%d\n",
326 fsp
->fs_frag
, fsp
->fs_fragshift
, fsp
->fs_fsbtodb
);
327 (void) fprintf(fout
, "minfree\t%d%%\tmaxbpg\t%d\toptim\t%s\n",
328 fsp
->fs_minfree
, fsp
->fs_maxbpg
,
329 fsp
->fs_optim
== FS_OPTSPACE
? "space" : "time");
330 (void) fprintf(fout
, "maxcontig %d\trotdelay %dms\trps\t%d\n",
331 fsp
->fs_maxcontig
, fsp
->fs_rotdelay
, fsp
->fs_rps
);
333 "csaddr\t%d\tcssize\t%d\tshift\t%d\tmask\t0x%08x\n",
334 fsp
->fs_csaddr
, fsp
->fs_cssize
, fsp
->fs_csshift
, fsp
->fs_csmask
);
335 (void) fprintf(fout
, "ntrak\t%d\tnsect\t%d\tspc\t%d\tncyl\t%d\n",
336 fsp
->fs_ntrak
, fsp
->fs_nsect
, fsp
->fs_spc
, fsp
->fs_ncyl
);
337 (void) fprintf(fout
, "cpg\t%d\tbpg\t%d\tfpg\t%d\tipg\t%d\n",
338 fsp
->fs_cpg
, fsp
->fs_fpg
/ fsp
->fs_frag
, fsp
->fs_fpg
, fsp
->fs_ipg
);
339 (void) fprintf(fout
, "nindir\t%d\tinopb\t%d\tnspf\t%d\n",
340 fsp
->fs_nindir
, fsp
->fs_inopb
, fsp
->fs_nspf
);
341 (void) fprintf(fout
, "nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
342 fsp
->fs_cstotal
.cs_nbfree
, fsp
->fs_cstotal
.cs_ndir
,
343 fsp
->fs_cstotal
.cs_nifree
, fsp
->fs_cstotal
.cs_nffree
);
344 (void) fprintf(fout
, "cgrotor\t%d\tfmod\t%d\tronly\t%d\tlogbno\t%d\n",
345 fsp
->fs_cgrotor
, fsp
->fs_fmod
, fsp
->fs_ronly
, fsp
->fs_logbno
);
346 (void) fprintf(fout
, "rolled\t%d\tsi\t%d\tflags\t%x\n",
347 fsp
->fs_rolled
, fsp
->fs_si
, fsp
->fs_flags
);
348 (void) fprintf(fout
, "version\t%d\n", fsp
->fs_version
);
349 if (fsp
->fs_reclaim
& (FS_RECLAIM
| FS_RECLAIMING
)) {
350 (void) fprintf(fout
, "fs_reclaim%s%s\n",
351 (fsp
->fs_reclaim
& FS_RECLAIM
) ? " FS_RECLAIM" : "",
352 (fsp
->fs_reclaim
& FS_RECLAIMING
) ? " FS_RECLAIMING" : "");
354 (void) fprintf(fout
, "fs_reclaim is not set\n");
356 if (fsp
->fs_state
+ (long)fsp
->fs_time
== FSOKAY
) {
357 (void) fprintf(fout
, gettext(
358 "file system state is valid, fsclean is %d\n"),
362 gettext("file system state is not valid\n"));
364 if (fsp
->fs_cpc
!= 0) {
365 (void) fprintf(fout
, gettext(
366 "blocks available in each rotational position"));
368 (void) fprintf(fout
, gettext(
369 "insufficient space to maintain rotational tables\n"));
371 for (c
= 0; c
< fsp
->fs_cpc
; c
++) {
372 (void) fprintf(fout
, gettext("\ncylinder number %d:"), c
);
373 nrpos
= (((fsp
)->fs_postblformat
== FS_DYNAMICPOSTBLFMT
) ?
374 (fsp
)->fs_nrpos
: NRPOS
);
375 for (i
= 0; i
< nrpos
; i
++) {
376 if (fs_postbl(fsp
, c
)[i
] == -1)
378 (void) fprintf(fout
, gettext("\n position %d:\t"), i
);
380 for (j
= fs_postbl(fsp
, c
)[i
], k
= 1; ;
381 j
+= fs_rotbl(fsp
)[j
], k
++) {
382 (void) fprintf(fout
, "%5d", j
);
384 (void) fprintf(fout
, "\n\t\t");
385 if ((fs_rotbl(fsp
))[j
] == 0)
390 (void) fprintf(fout
, "\ncs[].cs_(nbfree,ndir,nifree,nffree):\n\t");
391 sip
= calloc(1, fsp
->fs_cssize
);
392 /* void * cast is to convince lint that sip really is aligned */
393 fsp
->fs_u
.fs_csp
= (struct csum
*)(void *)sip
;
394 for (i
= 0, j
= 0; i
< fsp
->fs_cssize
; i
+= fsp
->fs_bsize
, j
++) {
395 size
= fsp
->fs_cssize
- i
< fsp
->fs_bsize
?
396 fsp
->fs_cssize
- i
: fsp
->fs_bsize
;
397 offset
= (offset_t
)fsbtodb(
398 fsp
, (fsp
->fs_csaddr
+ j
* fsp
->fs_frag
)) * DEV_BSIZE
;
399 (void) llseek(h
->fd
, offset
, 0);
400 if (read(h
->fd
, sip
, size
) != size
) {
401 return (FSTYP_ERR_IO
);
405 for (i
= 0; i
< fsp
->fs_ncg
; i
++) {
406 struct csum
*cs
= &fsp
->fs_cs(fsp
, i
);
408 (void) fprintf(fout
, "\n\t");
409 (void) fprintf(fout
, "(%d,%d,%d,%d) ",
410 cs
->cs_nbfree
, cs
->cs_ndir
, cs
->cs_nifree
, cs
->cs_nffree
);
412 (void) fprintf(fout
, "\n");
413 if (fsp
->fs_ncyl
% fsp
->fs_cpg
) {
414 (void) fprintf(fout
, gettext("cylinders in last group %d\n"),
415 i
= fsp
->fs_ncyl
% fsp
->fs_cpg
);
416 (void) fprintf(fout
, gettext("blocks in last group %d\n"),
417 i
* fsp
->fs_spc
/ NSPB(fsp
));
419 (void) fprintf(fout
, "\n");
420 for (i
= 0; i
< fsp
->fs_ncg
; i
++)
421 dumpcg(h
, fout
, ferr
, i
);
423 dumplog(h
, fout
, ferr
);
428 setsum(int32_t *sp
, int32_t *lp
, int nb
)
433 nb
/= sizeof (int32_t);
440 checksum(int32_t *sp
, int32_t *lp
, int nb
)
454 dumplog(fstyp_ufs_t
*h
, FILE *fout
, FILE *ferr
)
461 struct fs
*fsp
= &h
->afs
;
463 (void) fprintf(fout
, "\nlog\n");
464 if (fsp
->fs_magic
== FS_MAGIC
)
466 "log allocation block %d\n", fsp
->fs_logbno
);
468 (void) fprintf(fout
, "log allocation block (in frags) %d\n",
470 (void) llseek(h
->fd
, (offset_t
)logbtodb(fsp
,
471 fsp
->fs_logbno
) * DEV_BSIZE
, 0);
472 if (read(h
->fd
, (char *)&h
->eg
, fsp
->fs_bsize
) != fsp
->fs_bsize
) {
473 (void) fprintf(fout
, gettext(
474 "dumplog: error reading log allocation\n"));
478 if (ebp
->type
!= LUFS_EXTENTS
)
480 gettext("Invalid log allocation type %x\n"), ebp
->type
);
481 if (!checksum(&ebp
->chksum
, (int32_t *)ebp
, fsp
->fs_bsize
))
482 (void) fprintf(fout
, gettext("Invalid log checksum\n"));
484 for (i
= 0, ep
= &ebp
->extents
[0]; i
< ebp
->nextents
; ++i
, ++ep
) {
485 (void) fprintf(fout
, "\tlogical block\t%" PRId32
486 "\tphysical block\t%" PRId32
487 "\tblocks\t%" PRId32
"\n",
488 ep
->lbno
, ep
->pbno
, ep
->nbno
);
489 tb
+= dbtob(ep
->nbno
);
491 (void) fprintf(fout
, "log size %" PRIu32
" bytes (%ld calculated)\n",
493 (void) fprintf(fout
, "\n");
494 ep
= &ebp
->extents
[0];
495 (void) llseek(h
->fd
, (offset_t
)logbtodb(fsp
, ep
->pbno
) * DEV_BSIZE
, 0);
496 if (read(h
->fd
, &h
->eg
, dbtob(LS_SECTORS
)) != dbtob(LS_SECTORS
)) {
497 (void) fprintf(fout
, gettext(
498 "dumplog: error reading log state\n"));
502 (void) fprintf(fout
, "version\t\t%" PRIu32
"\t\t", ud
->od_version
);
504 (void) fprintf(fout
, "logstate\tError\n");
506 (void) fprintf(fout
, "logstate\tOkay\n");
507 (void) fprintf(fout
, "bol\t\t%" PRId32
"\t\teol\t\t%" PRId32
"\n",
508 ud
->od_bol_lof
, ud
->od_eol_lof
);
509 (void) fprintf(fout
, "requestsize\t%" PRIu32
"\n", ud
->od_requestsize
);
510 (void) fprintf(fout
, "statesize\t%" PRIu32
"\n", ud
->od_statesize
);
511 (void) fprintf(fout
, "logsize\t\t%" PRIu32
"\n", ud
->od_logsize
);
513 "maxtransfer\t%" PRIu32
"\t\tdevbsize\t%" PRIu32
"\n",
514 ud
->od_maxtransfer
, ud
->od_devbsize
);
516 "head\t\t%" PRId32
"\t\thead ident\t%#" PRIx32
"\n",
517 ud
->od_head_lof
, ud
->od_head_ident
);
519 "tail\t\t%" PRId32
"\t\ttail ident\t%#" PRIx32
"\n",
520 ud
->od_tail_lof
, ud
->od_tail_ident
);
521 (void) fprintf(fout
, "\t\t\t\tdebug\t\t%#" PRIx32
"\n", ud
->od_debug
);
522 if (ud
->od_head_ident
+ ud
->od_tail_ident
!= ud
->od_chksum
)
524 "Bad chksum\t%#" PRIx32
"\n", ud
->od_chksum
);
527 "Good chksum\t%#" PRIx32
"\n", ud
->od_chksum
);
532 dumpcg(fstyp_ufs_t
*h
, FILE *fout
, FILE *ferr
, const int c
)
538 struct fs
*fsp
= &h
->afs
;
541 (void) fprintf(fout
, "\ncg %d:\n", c
);
543 (offset_t
)fsbtodb(fsp
, cgtod(fsp
, c
)) * DEV_BSIZE
, 0);
544 if (read(h
->fd
, (char *)&h
->acg
, fsp
->fs_bsize
) != fsp
->fs_bsize
) {
545 (void) fprintf(fout
, gettext("dumpfs: error reading cg\n"));
548 cgp
= (struct cg
*)&h
->acg
;
549 ocgp
= (struct ocg
*)&h
->acg
;
550 if (!cg_chkmagic(cgp
))
551 (void) fprintf(fout
, gettext(
552 "Invalid Cylinder grp magic fffs:%x 4.2 fs:%x\n"),
553 cgp
->cg_magic
, ocgp
->cg_magic
);
554 if (cgp
->cg_magic
== CG_MAGIC
) {
555 /* print FFFS 4.3 cyl grp format. */
556 t
= (time_t)cgp
->cg_time
;
557 (void) fprintf(fout
, "magic\t%x\ttell\t%llx\ttime\t%s",
558 cgp
->cg_magic
, off
, ctime(&t
)); /* *** */
560 "cgx\t%d\tncyl\t%d\tniblk\t%d\tndblk\t%d\n",
561 cgp
->cg_cgx
, cgp
->cg_ncyl
, cgp
->cg_niblk
, cgp
->cg_ndblk
);
563 "nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
564 cgp
->cg_cs
.cs_nbfree
, cgp
->cg_cs
.cs_ndir
,
565 cgp
->cg_cs
.cs_nifree
, cgp
->cg_cs
.cs_nffree
);
566 (void) fprintf(fout
, "rotor\t%d\tirotor\t%d\tfrotor\t%d\nfrsum",
567 cgp
->cg_rotor
, cgp
->cg_irotor
, cgp
->cg_frotor
);
568 for (i
= 1, j
= 0; i
< fsp
->fs_frag
; i
++) {
569 (void) fprintf(fout
, "\t%d", cgp
->cg_frsum
[i
]);
570 j
+= i
* cgp
->cg_frsum
[i
];
573 gettext("\nsum of frsum: %d\niused:\t"), j
);
574 pbits(fout
, cg_inosused(cgp
), fsp
->fs_ipg
);
575 (void) fprintf(fout
, gettext("free:\t"));
576 pbits(fout
, cg_blksfree(cgp
), fsp
->fs_fpg
);
577 (void) fprintf(fout
, "b:\n");
578 for (i
= 0; i
< fsp
->fs_cpg
; i
++) {
580 " c%d:\t(%d)\t", i
, cg_blktot(cgp
)[i
]);
581 for (j
= 0; j
< fsp
->fs_nrpos
; j
++) /* ****** */
583 " %d", cg_blks(fsp
, cgp
, i
)[j
]);
584 (void) fprintf(fout
, "\n");
586 } else if (ocgp
->cg_magic
== CG_MAGIC
) {
587 /* print Old cyl grp format. */
588 t
= (time_t)ocgp
->cg_time
;
589 (void) fprintf(fout
, "magic\t%x\ttell\t%llx\ttime\t%s",
590 ocgp
->cg_magic
, off
, ctime(&t
));
592 "cgx\t%d\tncyl\t%d\tniblk\t%d\tndblk\t%d\n",
593 ocgp
->cg_cgx
, ocgp
->cg_ncyl
, ocgp
->cg_niblk
,
596 "nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
597 ocgp
->cg_cs
.cs_nbfree
, ocgp
->cg_cs
.cs_ndir
,
598 ocgp
->cg_cs
.cs_nifree
, ocgp
->cg_cs
.cs_nffree
);
600 "rotor\t%d\tirotor\t%d\tfrotor\t%d\nfrsum",
601 ocgp
->cg_rotor
, ocgp
->cg_irotor
, ocgp
->cg_frotor
);
602 for (i
= 1, j
= 0; i
< fsp
->fs_frag
; i
++) {
603 (void) fprintf(fout
, "\t%d", ocgp
->cg_frsum
[i
]);
604 j
+= i
* ocgp
->cg_frsum
[i
];
607 gettext("\nsum of frsum: %d\niused:\t"), j
);
608 pbits(fout
, ocgp
->cg_iused
, fsp
->fs_ipg
);
609 (void) fprintf(fout
, gettext("free:\t"));
610 pbits(fout
, ocgp
->cg_free
, fsp
->fs_fpg
);
611 (void) fprintf(fout
, "b:\n");
612 for (i
= 0; i
< fsp
->fs_cpg
; i
++) {
614 " c%d:\t(%d)\t", i
, ocgp
->cg_btot
[i
]);
615 for (j
= 0; j
< NRPOS
; j
++)
616 (void) fprintf(fout
, " %d", ocgp
->cg_b
[i
][j
]);
617 (void) fprintf(fout
, "\n");
624 pbits(FILE *fout
, const void *p
, const int max
)
628 unsigned char *cp
= (unsigned char *)p
;
630 for (i
= 0; i
< max
; i
++) {
633 (void) fprintf(fout
, ",%s",
634 (count
% 9 == 8) ? "\n\t" : " ");
636 (void) fprintf(fout
, "%d", i
);
638 while ((i
+ 1) < max
&& isset(cp
, i
+1))
641 (void) fprintf(fout
, "-%d", i
);
644 (void) fprintf(fout
, "\n");