xref: /illumos-gate/usr/src/cmd/fs.d/ufs/fstyp/fstyp.c (revision 0e42dee6)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0e42dee6Sartem  * Common Development and Distribution License (the "License").
6*0e42dee6Sartem  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*0e42dee6Sartem  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
277c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
317c478bd9Sstevel@tonic-gate  * The Regents of the University of California
327c478bd9Sstevel@tonic-gate  * All Rights Reserved
337c478bd9Sstevel@tonic-gate  *
347c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
357c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
367c478bd9Sstevel@tonic-gate  * contributors.
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /*
42*0e42dee6Sartem  * libfstyp module for ufs
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate #include <stdio.h>
457c478bd9Sstevel@tonic-gate #include <stdlib.h>
467c478bd9Sstevel@tonic-gate #include <unistd.h>
477c478bd9Sstevel@tonic-gate #include <locale.h>
487c478bd9Sstevel@tonic-gate #include <fcntl.h>
497c478bd9Sstevel@tonic-gate #include <errno.h>
507c478bd9Sstevel@tonic-gate #include <strings.h>
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #include <sys/param.h>
537c478bd9Sstevel@tonic-gate #include <sys/types.h>
547c478bd9Sstevel@tonic-gate #include <sys/mntent.h>
557c478bd9Sstevel@tonic-gate #include <sys/errno.h>
567c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_fs.h>
577c478bd9Sstevel@tonic-gate #include <sys/stat.h>
587c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
597c478bd9Sstevel@tonic-gate #include <sys/mnttab.h>
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_log.h>
627c478bd9Sstevel@tonic-gate #include <sys/inttypes.h>
637c478bd9Sstevel@tonic-gate 
64*0e42dee6Sartem #include <libfstyp_module.h>
65*0e42dee6Sartem 
66*0e42dee6Sartem typedef struct fstyp_ufs {
67*0e42dee6Sartem 	int		fd;
68*0e42dee6Sartem 	nvlist_t	*attr;
69*0e42dee6Sartem 
70*0e42dee6Sartem 	union {
71*0e42dee6Sartem 		struct fs fs;
72*0e42dee6Sartem 		char pad[MAXBSIZE];
73*0e42dee6Sartem 	} fsun;
74*0e42dee6Sartem 
75*0e42dee6Sartem 	union {
76*0e42dee6Sartem 		struct cg cg;
77*0e42dee6Sartem 		char pad[MAXBSIZE];
78*0e42dee6Sartem 	} cgun;
79*0e42dee6Sartem 
80*0e42dee6Sartem 	char		eg[MAXBSIZE];
81*0e42dee6Sartem } fstyp_ufs_t;
82*0e42dee6Sartem 
83*0e42dee6Sartem #define	afs	fsun.fs
84*0e42dee6Sartem #define	acg	cgun.cg
85*0e42dee6Sartem 
867c478bd9Sstevel@tonic-gate #define	MAXLABELS	20
877c478bd9Sstevel@tonic-gate #define	LINEMAX		256
887c478bd9Sstevel@tonic-gate #define	NRPOS		8	/* for pre FFFS compatibility */
897c478bd9Sstevel@tonic-gate 
90*0e42dee6Sartem static int	is_ufs(fstyp_ufs_t *h);
91*0e42dee6Sartem static int	get_attr(fstyp_ufs_t *h);
92*0e42dee6Sartem static int	dumpfs(fstyp_ufs_t *h, FILE *fout, FILE *ferr);
93*0e42dee6Sartem static void	dumplog(fstyp_ufs_t *h, FILE *fout, FILE *ferr);
94*0e42dee6Sartem static void	dumpcg(fstyp_ufs_t *h, FILE *fout, FILE *ferr, const int c);
95*0e42dee6Sartem static void	pbits(FILE *out, const void *cp, const int max);
967c478bd9Sstevel@tonic-gate 
97*0e42dee6Sartem int	fstyp_mod_init(int fd, off_t offset, fstyp_mod_handle_t *handle);
98*0e42dee6Sartem void	fstyp_mod_fini(fstyp_mod_handle_t handle);
99*0e42dee6Sartem int	fstyp_mod_ident(fstyp_mod_handle_t handle);
100*0e42dee6Sartem int	fstyp_mod_get_attr(fstyp_mod_handle_t handle, nvlist_t **attrp);
101*0e42dee6Sartem int	fstyp_mod_dump(fstyp_mod_handle_t handle, FILE *fout, FILE *ferr);
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate int
fstyp_mod_init(int fd,off_t offset,fstyp_mod_handle_t * handle)105*0e42dee6Sartem fstyp_mod_init(int fd, off_t offset, fstyp_mod_handle_t *handle)
1067c478bd9Sstevel@tonic-gate {
107*0e42dee6Sartem 	struct fstyp_ufs *h;
108*0e42dee6Sartem 
109*0e42dee6Sartem 	if (offset != 0) {
110*0e42dee6Sartem 		return (FSTYP_ERR_OFFSET);
1117c478bd9Sstevel@tonic-gate 	}
112*0e42dee6Sartem 
113*0e42dee6Sartem 	if ((h = calloc(1, sizeof (struct fstyp_ufs))) == NULL) {
114*0e42dee6Sartem 		return (FSTYP_ERR_NOMEM);
1157c478bd9Sstevel@tonic-gate 	}
116*0e42dee6Sartem 	h->fd = fd;
1177c478bd9Sstevel@tonic-gate 
118*0e42dee6Sartem 	*handle = (fstyp_mod_handle_t)h;
119*0e42dee6Sartem 	return (0);
120*0e42dee6Sartem }
121*0e42dee6Sartem 
122*0e42dee6Sartem void
fstyp_mod_fini(fstyp_mod_handle_t handle)123*0e42dee6Sartem fstyp_mod_fini(fstyp_mod_handle_t handle)
124*0e42dee6Sartem {
125*0e42dee6Sartem 	struct fstyp_ufs *h = (struct fstyp_ufs *)handle;
1267c478bd9Sstevel@tonic-gate 
127*0e42dee6Sartem 	if (h->attr == NULL) {
128*0e42dee6Sartem 		nvlist_free(h->attr);
129*0e42dee6Sartem 		h->attr = NULL;
1307c478bd9Sstevel@tonic-gate 	}
131*0e42dee6Sartem 	free(h);
132*0e42dee6Sartem }
1337c478bd9Sstevel@tonic-gate 
134*0e42dee6Sartem int
fstyp_mod_ident(fstyp_mod_handle_t handle)135*0e42dee6Sartem fstyp_mod_ident(fstyp_mod_handle_t handle)
136*0e42dee6Sartem {
137*0e42dee6Sartem 	struct fstyp_ufs *h = (struct fstyp_ufs *)handle;
1387c478bd9Sstevel@tonic-gate 
139*0e42dee6Sartem 	return (is_ufs(h));
140*0e42dee6Sartem }
141*0e42dee6Sartem 
142*0e42dee6Sartem int
fstyp_mod_get_attr(fstyp_mod_handle_t handle,nvlist_t ** attrp)143*0e42dee6Sartem fstyp_mod_get_attr(fstyp_mod_handle_t handle, nvlist_t **attrp)
144*0e42dee6Sartem {
145*0e42dee6Sartem 	struct fstyp_ufs *h = (struct fstyp_ufs *)handle;
146*0e42dee6Sartem 	int error;
147*0e42dee6Sartem 
148*0e42dee6Sartem 	if (h->attr == NULL) {
149*0e42dee6Sartem 		if (nvlist_alloc(&h->attr, NV_UNIQUE_NAME_TYPE, 0)) {
150*0e42dee6Sartem 			return (FSTYP_ERR_NOMEM);
151*0e42dee6Sartem 		}
152*0e42dee6Sartem 		if ((error = get_attr(h)) != 0) {
153*0e42dee6Sartem 			nvlist_free(h->attr);
154*0e42dee6Sartem 			h->attr = NULL;
155*0e42dee6Sartem 			return (error);
1567c478bd9Sstevel@tonic-gate 		}
1577c478bd9Sstevel@tonic-gate 	}
1587c478bd9Sstevel@tonic-gate 
159*0e42dee6Sartem 	*attrp = h->attr;
160*0e42dee6Sartem 	return (0);
1617c478bd9Sstevel@tonic-gate }
1627c478bd9Sstevel@tonic-gate 
163*0e42dee6Sartem int
fstyp_mod_dump(fstyp_mod_handle_t handle,FILE * fout,FILE * ferr)164*0e42dee6Sartem fstyp_mod_dump(fstyp_mod_handle_t handle, FILE *fout, FILE *ferr)
165*0e42dee6Sartem {
166*0e42dee6Sartem 	struct fstyp_ufs *h = (struct fstyp_ufs *)handle;
1677c478bd9Sstevel@tonic-gate 
168*0e42dee6Sartem 	return (dumpfs(h, fout, ferr));
169*0e42dee6Sartem }
170*0e42dee6Sartem 
171*0e42dee6Sartem static int
is_ufs(fstyp_ufs_t * h)172*0e42dee6Sartem is_ufs(fstyp_ufs_t *h)
1737c478bd9Sstevel@tonic-gate {
174*0e42dee6Sartem 	(void) llseek(h->fd, (offset_t)SBLOCK * DEV_BSIZE, 0);
175*0e42dee6Sartem 	if (read(h->fd, &h->afs, SBSIZE) != SBSIZE) {
176*0e42dee6Sartem 		return (FSTYP_ERR_IO);
177*0e42dee6Sartem 	}
178*0e42dee6Sartem 	if ((h->afs.fs_magic != FS_MAGIC) &&
179*0e42dee6Sartem 	    (h->afs.fs_magic != MTB_UFS_MAGIC)) {
180*0e42dee6Sartem 		return (FSTYP_ERR_NO_MATCH);
181*0e42dee6Sartem 	}
182*0e42dee6Sartem 	if ((h->afs.fs_magic == FS_MAGIC) &&
183*0e42dee6Sartem 	    (h->afs.fs_version != UFS_EFISTYLE4NONEFI_VERSION_2 &&
184*0e42dee6Sartem 	    h->afs.fs_version != UFS_VERSION_MIN)) {
185*0e42dee6Sartem 		return (FSTYP_ERR_NO_MATCH);
186*0e42dee6Sartem 	}
187*0e42dee6Sartem 	if ((h->afs.fs_magic == MTB_UFS_MAGIC) &&
188*0e42dee6Sartem 	    (h->afs.fs_version > MTB_UFS_VERSION_1 ||
189*0e42dee6Sartem 	    h->afs.fs_version < MTB_UFS_VERSION_MIN)) {
190*0e42dee6Sartem 		return (FSTYP_ERR_NO_MATCH);
191*0e42dee6Sartem 	}
192*0e42dee6Sartem 	return (0);
1937c478bd9Sstevel@tonic-gate }
1947c478bd9Sstevel@tonic-gate 
195*0e42dee6Sartem #define	ADD_STRING(h, name, value) \
196*0e42dee6Sartem 	if (nvlist_add_string(h->attr, name, value) != 0) { \
197*0e42dee6Sartem 		return (FSTYP_ERR_NOMEM); \
198*0e42dee6Sartem 	}
1997c478bd9Sstevel@tonic-gate 
200*0e42dee6Sartem #define	ADD_INT32(h, name, value) \
201*0e42dee6Sartem 	if (nvlist_add_int32(h->attr, name, value) != 0) { \
202*0e42dee6Sartem 		return (FSTYP_ERR_NOMEM); \
203*0e42dee6Sartem 	}
2047c478bd9Sstevel@tonic-gate 
205*0e42dee6Sartem #define	ADD_BOOL(h, name, value) \
206*0e42dee6Sartem 	if (nvlist_add_boolean_value(h->attr, name, value) != 0) { \
207*0e42dee6Sartem 		return (FSTYP_ERR_NOMEM); \
208*0e42dee6Sartem 	}
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate static int
get_attr(fstyp_ufs_t * h)211*0e42dee6Sartem get_attr(fstyp_ufs_t *h)
212*0e42dee6Sartem {
213*0e42dee6Sartem 	struct fs *fsp = &h->afs;
214*0e42dee6Sartem 	char	s[128];
215*0e42dee6Sartem 	time_t	t;
216*0e42dee6Sartem 
217*0e42dee6Sartem 	ADD_INT32(h, "magic", fsp->fs_magic);
218*0e42dee6Sartem 	ADD_STRING(h, "format",
219*0e42dee6Sartem 	    fsp->fs_postblformat == FS_42POSTBLFMT ? "static" : "dynamic");
220*0e42dee6Sartem 	t = (time_t)fsp->fs_time;
221*0e42dee6Sartem 	(void) snprintf(s, sizeof (s), "%s", ctime(&t));
222*0e42dee6Sartem 	s[strlen(s) - 1] = '\0';
223*0e42dee6Sartem 	ADD_STRING(h, "time", s);
224*0e42dee6Sartem 	ADD_INT32(h, "sblkno", fsp->fs_sblkno);
225*0e42dee6Sartem 	ADD_INT32(h, "cblkno", fsp->fs_cblkno);
226*0e42dee6Sartem 	ADD_INT32(h, "iblkno", fsp->fs_iblkno);
227*0e42dee6Sartem 	ADD_INT32(h, "dblkno", fsp->fs_dblkno);
228*0e42dee6Sartem 	ADD_INT32(h, "sbsize", fsp->fs_sbsize);
229*0e42dee6Sartem 	ADD_INT32(h, "cgsize", fsp->fs_cgsize);
230*0e42dee6Sartem 	ADD_INT32(h, "cgoffset", fsp->fs_cgoffset);
231*0e42dee6Sartem 	ADD_INT32(h, "cgmask", fsp->fs_cgmask);
232*0e42dee6Sartem 	ADD_INT32(h, "ncg", fsp->fs_ncg);
233*0e42dee6Sartem 	ADD_INT32(h, "size", fsp->fs_size);
234*0e42dee6Sartem 	ADD_INT32(h, "blocks", fsp->fs_dsize);
235*0e42dee6Sartem 	ADD_INT32(h, "bsize", fsp->fs_bsize);
236*0e42dee6Sartem 	ADD_INT32(h, "bshift", fsp->fs_bshift);
237*0e42dee6Sartem 	ADD_INT32(h, "bmask", fsp->fs_bmask);
238*0e42dee6Sartem 	ADD_INT32(h, "fsize", fsp->fs_fsize);
239*0e42dee6Sartem 	ADD_INT32(h, "fshift", fsp->fs_fshift);
240*0e42dee6Sartem 	ADD_INT32(h, "fmask", fsp->fs_fmask);
241*0e42dee6Sartem 	ADD_INT32(h, "frag", fsp->fs_frag);
242*0e42dee6Sartem 	ADD_INT32(h, "fragshift", fsp->fs_fragshift);
243*0e42dee6Sartem 	ADD_INT32(h, "fsbtodb", fsp->fs_fsbtodb);
244*0e42dee6Sartem 	ADD_INT32(h, "minfree", fsp->fs_minfree);
245*0e42dee6Sartem 	ADD_INT32(h, "maxbpg", fsp->fs_maxbpg);
246*0e42dee6Sartem 	ADD_STRING(h, "optim",
247*0e42dee6Sartem 	    fsp->fs_optim == FS_OPTSPACE ? "space" : "time");
248*0e42dee6Sartem 	ADD_INT32(h, "maxcontig", fsp->fs_maxcontig);
249*0e42dee6Sartem 	ADD_INT32(h, "rotdelay", fsp->fs_rotdelay);
250*0e42dee6Sartem 	ADD_INT32(h, "rps", fsp->fs_rps);
251*0e42dee6Sartem 	ADD_INT32(h, "csaddr", fsp->fs_csaddr);
252*0e42dee6Sartem 	ADD_INT32(h, "cssize", fsp->fs_cssize);
253*0e42dee6Sartem 	ADD_INT32(h, "csshift", fsp->fs_csshift);
254*0e42dee6Sartem 	ADD_INT32(h, "csmask", fsp->fs_csmask);
255*0e42dee6Sartem 	ADD_INT32(h, "ntrak", fsp->fs_ntrak);
256*0e42dee6Sartem 	ADD_INT32(h, "nsect", fsp->fs_nsect);
257*0e42dee6Sartem 	ADD_INT32(h, "spc", fsp->fs_spc);
258*0e42dee6Sartem 	ADD_INT32(h, "ncyl", fsp->fs_ncyl);
259*0e42dee6Sartem 	ADD_INT32(h, "cpg", fsp->fs_cpg);
260*0e42dee6Sartem 	ADD_INT32(h, "bpg", fsp->fs_fpg / fsp->fs_frag);
261*0e42dee6Sartem 	ADD_INT32(h, "fpg", fsp->fs_fpg);
262*0e42dee6Sartem 	ADD_INT32(h, "ipg", fsp->fs_ipg);
263*0e42dee6Sartem 	ADD_INT32(h, "nindir", fsp->fs_nindir);
264*0e42dee6Sartem 	ADD_INT32(h, "inopb", fsp->fs_inopb);
265*0e42dee6Sartem 	ADD_INT32(h, "nspf", fsp->fs_nspf);
266*0e42dee6Sartem 	ADD_INT32(h, "nbfree", fsp->fs_cstotal.cs_nbfree);
267*0e42dee6Sartem 	ADD_INT32(h, "ndir", fsp->fs_cstotal.cs_ndir);
268*0e42dee6Sartem 	ADD_INT32(h, "nifree", fsp->fs_cstotal.cs_nifree);
269*0e42dee6Sartem 	ADD_INT32(h, "nffree", fsp->fs_cstotal.cs_nffree);
270*0e42dee6Sartem 	ADD_INT32(h, "cgrotor", fsp->fs_cgrotor);
271*0e42dee6Sartem 	ADD_INT32(h, "fmod", fsp->fs_fmod);
272*0e42dee6Sartem 	ADD_INT32(h, "ronly", fsp->fs_ronly);
273*0e42dee6Sartem 	ADD_INT32(h, "logbno", fsp->fs_logbno);
274*0e42dee6Sartem 	ADD_INT32(h, "rolled", fsp->fs_rolled);
275*0e42dee6Sartem 	ADD_INT32(h, "si", fsp->fs_si);
276*0e42dee6Sartem 	ADD_INT32(h, "flags", fsp->fs_flags);
277*0e42dee6Sartem 	ADD_INT32(h, "version", fsp->fs_version);
278*0e42dee6Sartem 	if (fsp->fs_reclaim & (FS_RECLAIM | FS_RECLAIMING)) {
279*0e42dee6Sartem 		(void) snprintf(s, sizeof (s), "%s%s",
280*0e42dee6Sartem 		    (fsp->fs_reclaim & FS_RECLAIM)    ? " FS_RECLAIM"    : "",
281*0e42dee6Sartem 		    (fsp->fs_reclaim & FS_RECLAIMING) ? " FS_RECLAIMING" : "");
282*0e42dee6Sartem 		ADD_STRING(h, "fs_reclaim", s);
283*0e42dee6Sartem 	}
284*0e42dee6Sartem 	ADD_INT32(h, "clean", fsp->fs_clean);
285*0e42dee6Sartem 
286*0e42dee6Sartem 	if ((fsp->fs_state + (long)fsp->fs_time == FSOKAY) &&
287*0e42dee6Sartem 	    (fsp->fs_clean == FSCLEAN || fsp->fs_clean == FSSTABLE ||
288*0e42dee6Sartem 	    (fsp->fs_clean == FSLOG))) {
289*0e42dee6Sartem 		ADD_BOOL(h, "gen_clean", B_TRUE);
290*0e42dee6Sartem 	} else {
291*0e42dee6Sartem 		ADD_BOOL(h, "gen_clean", B_FALSE);
292*0e42dee6Sartem 	}
293*0e42dee6Sartem 
294*0e42dee6Sartem 	(void) snprintf(s, sizeof (s), "%d", fsp->fs_version);
295*0e42dee6Sartem 	ADD_STRING(h, "gen_version", s);
296*0e42dee6Sartem 
297*0e42dee6Sartem 	return (0);
298*0e42dee6Sartem }
299*0e42dee6Sartem 
300*0e42dee6Sartem 
301*0e42dee6Sartem static int
dumpfs(fstyp_ufs_t * h,FILE * fout,FILE * ferr)302*0e42dee6Sartem dumpfs(fstyp_ufs_t *h, FILE *fout, FILE *ferr)
3037c478bd9Sstevel@tonic-gate {
3047c478bd9Sstevel@tonic-gate 	int c, i, j, k, size, nrpos;
305*0e42dee6Sartem 	struct fs *fsp = &h->afs;
3067c478bd9Sstevel@tonic-gate 	offset_t offset;
3077c478bd9Sstevel@tonic-gate 	caddr_t sip;
3087c478bd9Sstevel@tonic-gate 	time_t t;
3097c478bd9Sstevel@tonic-gate 
310*0e42dee6Sartem 	t = (time_t)fsp->fs_time;
311*0e42dee6Sartem 	(void) fprintf(fout, "magic\t%x\tformat\t%s\ttime\t%s", fsp->fs_magic,
312*0e42dee6Sartem 	    fsp->fs_postblformat == FS_42POSTBLFMT ? "static" : "dynamic",
3137c478bd9Sstevel@tonic-gate 	    ctime(&t));
314*0e42dee6Sartem 	(void) fprintf(fout, "sblkno\t%d\tcblkno\t%d\tiblkno\t%d\tdblkno\t%d\n",
315*0e42dee6Sartem 	    fsp->fs_sblkno, fsp->fs_cblkno, fsp->fs_iblkno, fsp->fs_dblkno);
316*0e42dee6Sartem 	(void) fprintf(fout,
317*0e42dee6Sartem 	    "sbsize\t%d\tcgsize\t%d\tcgoffset %d\tcgmask\t0x%08x\n",
318*0e42dee6Sartem 	    fsp->fs_sbsize, fsp->fs_cgsize, fsp->fs_cgoffset, fsp->fs_cgmask);
319*0e42dee6Sartem 	(void) fprintf(fout, "ncg\t%d\tsize\t%d\tblocks\t%d\n",
320*0e42dee6Sartem 	    fsp->fs_ncg, fsp->fs_size, fsp->fs_dsize);
321*0e42dee6Sartem 	(void) fprintf(fout, "bsize\t%d\tshift\t%d\tmask\t0x%08x\n",
322*0e42dee6Sartem 	    fsp->fs_bsize, fsp->fs_bshift, fsp->fs_bmask);
323*0e42dee6Sartem 	(void) fprintf(fout, "fsize\t%d\tshift\t%d\tmask\t0x%08x\n",
324*0e42dee6Sartem 	    fsp->fs_fsize, fsp->fs_fshift, fsp->fs_fmask);
325*0e42dee6Sartem 	(void) fprintf(fout, "frag\t%d\tshift\t%d\tfsbtodb\t%d\n",
326*0e42dee6Sartem 	    fsp->fs_frag, fsp->fs_fragshift, fsp->fs_fsbtodb);
327*0e42dee6Sartem 	(void) fprintf(fout, "minfree\t%d%%\tmaxbpg\t%d\toptim\t%s\n",
328*0e42dee6Sartem 	    fsp->fs_minfree, fsp->fs_maxbpg,
329*0e42dee6Sartem 	    fsp->fs_optim == FS_OPTSPACE ? "space" : "time");
330*0e42dee6Sartem 	(void) fprintf(fout, "maxcontig %d\trotdelay %dms\trps\t%d\n",
331*0e42dee6Sartem 	    fsp->fs_maxcontig, fsp->fs_rotdelay, fsp->fs_rps);
332*0e42dee6Sartem 	(void) fprintf(fout,
333*0e42dee6Sartem 	    "csaddr\t%d\tcssize\t%d\tshift\t%d\tmask\t0x%08x\n",
334*0e42dee6Sartem 	    fsp->fs_csaddr, fsp->fs_cssize, fsp->fs_csshift, fsp->fs_csmask);
335*0e42dee6Sartem 	(void) fprintf(fout, "ntrak\t%d\tnsect\t%d\tspc\t%d\tncyl\t%d\n",
336*0e42dee6Sartem 	    fsp->fs_ntrak, fsp->fs_nsect, fsp->fs_spc, fsp->fs_ncyl);
337*0e42dee6Sartem 	(void) fprintf(fout, "cpg\t%d\tbpg\t%d\tfpg\t%d\tipg\t%d\n",
338*0e42dee6Sartem 	    fsp->fs_cpg, fsp->fs_fpg / fsp->fs_frag, fsp->fs_fpg, fsp->fs_ipg);
339*0e42dee6Sartem 	(void) fprintf(fout, "nindir\t%d\tinopb\t%d\tnspf\t%d\n",
340*0e42dee6Sartem 	    fsp->fs_nindir, fsp->fs_inopb, fsp->fs_nspf);
341*0e42dee6Sartem 	(void) fprintf(fout, "nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
342*0e42dee6Sartem 	    fsp->fs_cstotal.cs_nbfree, fsp->fs_cstotal.cs_ndir,
343*0e42dee6Sartem 	    fsp->fs_cstotal.cs_nifree, fsp->fs_cstotal.cs_nffree);
344*0e42dee6Sartem 	(void) fprintf(fout, "cgrotor\t%d\tfmod\t%d\tronly\t%d\tlogbno\t%d\n",
345*0e42dee6Sartem 	    fsp->fs_cgrotor, fsp->fs_fmod, fsp->fs_ronly, fsp->fs_logbno);
346*0e42dee6Sartem 	(void) fprintf(fout, "rolled\t%d\tsi\t%d\tflags\t%x\n",
347*0e42dee6Sartem 	    fsp->fs_rolled, fsp->fs_si, fsp->fs_flags);
348*0e42dee6Sartem 	(void) fprintf(fout, "version\t%d\n", fsp->fs_version);
349*0e42dee6Sartem 	if (fsp->fs_reclaim & (FS_RECLAIM | FS_RECLAIMING)) {
350*0e42dee6Sartem 		(void) fprintf(fout, "fs_reclaim%s%s\n",
351*0e42dee6Sartem 		    (fsp->fs_reclaim & FS_RECLAIM)    ? " FS_RECLAIM"    : "",
352*0e42dee6Sartem 		    (fsp->fs_reclaim & FS_RECLAIMING) ? " FS_RECLAIMING" : "");
3537c478bd9Sstevel@tonic-gate 	} else {
354*0e42dee6Sartem 		(void) fprintf(fout, "fs_reclaim is not set\n");
3557c478bd9Sstevel@tonic-gate 	}
356*0e42dee6Sartem 	if (fsp->fs_state + (long)fsp->fs_time == FSOKAY) {
357*0e42dee6Sartem 		(void) fprintf(fout, gettext(
358d49934b4Sdmick 		    "file system state is valid, fsclean is %d\n"),
359*0e42dee6Sartem 		    fsp->fs_clean);
3607c478bd9Sstevel@tonic-gate 	} else {
361*0e42dee6Sartem 		(void) fprintf(fout,
362*0e42dee6Sartem 		    gettext("file system state is not valid\n"));
3637c478bd9Sstevel@tonic-gate 	}
364*0e42dee6Sartem 	if (fsp->fs_cpc != 0) {
365*0e42dee6Sartem 		(void) fprintf(fout, gettext(
366d49934b4Sdmick 		    "blocks available in each rotational position"));
3677c478bd9Sstevel@tonic-gate 	} else {
368*0e42dee6Sartem 		(void) fprintf(fout, gettext(
3697c478bd9Sstevel@tonic-gate 		    "insufficient space to maintain rotational tables\n"));
3707c478bd9Sstevel@tonic-gate 	}
371*0e42dee6Sartem 	for (c = 0; c < fsp->fs_cpc; c++) {
372*0e42dee6Sartem 		(void) fprintf(fout, gettext("\ncylinder number %d:"), c);
3737c478bd9Sstevel@tonic-gate 		nrpos = (((fsp)->fs_postblformat == FS_DYNAMICPOSTBLFMT) ?
3747c478bd9Sstevel@tonic-gate 		    (fsp)->fs_nrpos : NRPOS);
3757c478bd9Sstevel@tonic-gate 		for (i = 0; i < nrpos; i++) {
3767c478bd9Sstevel@tonic-gate 			if (fs_postbl(fsp, c)[i] == -1)
3777c478bd9Sstevel@tonic-gate 				continue;
378*0e42dee6Sartem 			(void) fprintf(fout, gettext("\n   position %d:\t"), i);
3797c478bd9Sstevel@tonic-gate 			/*CSTYLED*/
3807c478bd9Sstevel@tonic-gate 			for (j = fs_postbl(fsp, c)[i], k = 1; ;
3817c478bd9Sstevel@tonic-gate 			    j += fs_rotbl(fsp)[j], k++) {
382*0e42dee6Sartem 				(void) fprintf(fout, "%5d", j);
3837c478bd9Sstevel@tonic-gate 				if (k % 12 == 0)
384*0e42dee6Sartem 					(void) fprintf(fout, "\n\t\t");
3857c478bd9Sstevel@tonic-gate 				if ((fs_rotbl(fsp))[j] == 0)
3867c478bd9Sstevel@tonic-gate 					break;
3877c478bd9Sstevel@tonic-gate 			}
3887c478bd9Sstevel@tonic-gate 		}
3897c478bd9Sstevel@tonic-gate 	}
390*0e42dee6Sartem 	(void) fprintf(fout, "\ncs[].cs_(nbfree,ndir,nifree,nffree):\n\t");
391*0e42dee6Sartem 	sip = calloc(1, fsp->fs_cssize);
392d49934b4Sdmick 	/* void * cast is to convince lint that sip really is aligned */
393*0e42dee6Sartem 	fsp->fs_u.fs_csp = (struct csum *)(void *)sip;
394*0e42dee6Sartem 	for (i = 0, j = 0; i < fsp->fs_cssize; i += fsp->fs_bsize, j++) {
395*0e42dee6Sartem 		size = fsp->fs_cssize - i < fsp->fs_bsize ?
396*0e42dee6Sartem 		    fsp->fs_cssize - i : fsp->fs_bsize;
3977c478bd9Sstevel@tonic-gate 		offset = (offset_t)fsbtodb(
398*0e42dee6Sartem 		    fsp, (fsp->fs_csaddr + j * fsp->fs_frag)) * DEV_BSIZE;
399*0e42dee6Sartem 		(void) llseek(h->fd, offset, 0);
400*0e42dee6Sartem 		if (read(h->fd, sip, size) != size) {
401*0e42dee6Sartem 			return (FSTYP_ERR_IO);
4027c478bd9Sstevel@tonic-gate 		}
4037c478bd9Sstevel@tonic-gate 		sip += size;
4047c478bd9Sstevel@tonic-gate 	}
405*0e42dee6Sartem 	for (i = 0; i < fsp->fs_ncg; i++) {
406*0e42dee6Sartem 		struct csum *cs = &fsp->fs_cs(fsp, i);
4077c478bd9Sstevel@tonic-gate 		if (i && i % 4 == 0)
408*0e42dee6Sartem 			(void) fprintf(fout, "\n\t");
409*0e42dee6Sartem 		(void) fprintf(fout, "(%d,%d,%d,%d) ",
4107c478bd9Sstevel@tonic-gate 		    cs->cs_nbfree, cs->cs_ndir, cs->cs_nifree, cs->cs_nffree);
4117c478bd9Sstevel@tonic-gate 	}
412*0e42dee6Sartem 	(void) fprintf(fout, "\n");
413*0e42dee6Sartem 	if (fsp->fs_ncyl % fsp->fs_cpg) {
414*0e42dee6Sartem 		(void) fprintf(fout, gettext("cylinders in last group %d\n"),
415*0e42dee6Sartem 		    i = fsp->fs_ncyl % fsp->fs_cpg);
416*0e42dee6Sartem 		(void) fprintf(fout, gettext("blocks in last group %d\n"),
417*0e42dee6Sartem 		    i * fsp->fs_spc / NSPB(fsp));
4187c478bd9Sstevel@tonic-gate 	}
419*0e42dee6Sartem 	(void) fprintf(fout, "\n");
420*0e42dee6Sartem 	for (i = 0; i < fsp->fs_ncg; i++)
421*0e42dee6Sartem 		dumpcg(h, fout, ferr, i);
422*0e42dee6Sartem 	if (fsp->fs_logbno)
423*0e42dee6Sartem 		dumplog(h, fout, ferr);
4247c478bd9Sstevel@tonic-gate 	return (0);
4257c478bd9Sstevel@tonic-gate }
4267c478bd9Sstevel@tonic-gate 
4277c478bd9Sstevel@tonic-gate static void
setsum(int32_t * sp,int32_t * lp,int nb)4287c478bd9Sstevel@tonic-gate setsum(int32_t *sp, int32_t *lp, int nb)
4297c478bd9Sstevel@tonic-gate {
4307c478bd9Sstevel@tonic-gate 	int32_t csum = 0;
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate 	*sp = 0;
4337c478bd9Sstevel@tonic-gate 	nb /= sizeof (int32_t);
4347c478bd9Sstevel@tonic-gate 	while (nb--)
4357c478bd9Sstevel@tonic-gate 		csum += *lp++;
4367c478bd9Sstevel@tonic-gate 	*sp = csum;
4377c478bd9Sstevel@tonic-gate }
4387c478bd9Sstevel@tonic-gate 
4397c478bd9Sstevel@tonic-gate static int
checksum(int32_t * sp,int32_t * lp,int nb)4407c478bd9Sstevel@tonic-gate checksum(int32_t *sp, int32_t *lp, int nb)
4417c478bd9Sstevel@tonic-gate {
4427c478bd9Sstevel@tonic-gate 	int32_t ssum = *sp;
4437c478bd9Sstevel@tonic-gate 
4447c478bd9Sstevel@tonic-gate 	setsum(sp, lp, nb);
4457c478bd9Sstevel@tonic-gate 	if (ssum != *sp) {
4467c478bd9Sstevel@tonic-gate 		*sp = ssum;
4477c478bd9Sstevel@tonic-gate 		return (0);
4487c478bd9Sstevel@tonic-gate 	}
4497c478bd9Sstevel@tonic-gate 	return (1);
4507c478bd9Sstevel@tonic-gate }
4517c478bd9Sstevel@tonic-gate 
452*0e42dee6Sartem /* ARGSUSED */
4537c478bd9Sstevel@tonic-gate static void
dumplog(fstyp_ufs_t * h,FILE * fout,FILE * ferr)454*0e42dee6Sartem dumplog(fstyp_ufs_t *h, FILE *fout, FILE *ferr)
4557c478bd9Sstevel@tonic-gate {
4567c478bd9Sstevel@tonic-gate 	int i;
4577c478bd9Sstevel@tonic-gate 	long		tb = 0;
4587c478bd9Sstevel@tonic-gate 	extent_block_t	*ebp;
4597c478bd9Sstevel@tonic-gate 	extent_t	*ep;
4607c478bd9Sstevel@tonic-gate 	ml_odunit_t	*ud;
461*0e42dee6Sartem 	struct fs *fsp = &h->afs;
4627c478bd9Sstevel@tonic-gate 
463*0e42dee6Sartem 	(void) fprintf(fout, "\nlog\n");
464*0e42dee6Sartem 	if (fsp->fs_magic == FS_MAGIC)
465*0e42dee6Sartem 		(void) fprintf(fout,
466*0e42dee6Sartem 		    "log allocation block %d\n", fsp->fs_logbno);
4677c478bd9Sstevel@tonic-gate 	else
468*0e42dee6Sartem 		(void) fprintf(fout, "log allocation block (in frags) %d\n",
469*0e42dee6Sartem 		    fsp->fs_logbno);
470*0e42dee6Sartem 	(void) llseek(h->fd, (offset_t)logbtodb(fsp,
471*0e42dee6Sartem 	    fsp->fs_logbno) * DEV_BSIZE, 0);
472*0e42dee6Sartem 	if (read(h->fd, (char *)&h->eg, fsp->fs_bsize) != fsp->fs_bsize) {
473*0e42dee6Sartem 		(void) fprintf(fout, gettext(
474*0e42dee6Sartem 		    "dumplog: error reading log allocation\n"));
4757c478bd9Sstevel@tonic-gate 		return;
4767c478bd9Sstevel@tonic-gate 	}
477*0e42dee6Sartem 	ebp = (void *)h->eg;
4787c478bd9Sstevel@tonic-gate 	if (ebp->type != LUFS_EXTENTS)
479*0e42dee6Sartem 		(void) fprintf(fout,
480*0e42dee6Sartem 		    gettext("Invalid log allocation type %x\n"), ebp->type);
481*0e42dee6Sartem 	if (!checksum(&ebp->chksum, (int32_t *)ebp, fsp->fs_bsize))
482*0e42dee6Sartem 		(void) fprintf(fout, gettext("Invalid log checksum\n"));
4837c478bd9Sstevel@tonic-gate 
4847c478bd9Sstevel@tonic-gate 	for (i = 0, ep = &ebp->extents[0]; i < ebp->nextents; ++i, ++ep) {
485*0e42dee6Sartem 		(void) fprintf(fout, "\tlogical block\t%" PRId32
486*0e42dee6Sartem 		    "\tphysical block\t%" PRId32
487*0e42dee6Sartem 		    "\tblocks\t%" PRId32 "\n",
488*0e42dee6Sartem 		    ep->lbno, ep->pbno, ep->nbno);
4897c478bd9Sstevel@tonic-gate 		tb += dbtob(ep->nbno);
4907c478bd9Sstevel@tonic-gate 	}
491*0e42dee6Sartem 	(void) fprintf(fout, "log size %" PRIu32 " bytes (%ld calculated)\n",
4927c478bd9Sstevel@tonic-gate 		ebp->nbytes, tb);
493*0e42dee6Sartem 	(void) fprintf(fout, "\n");
4947c478bd9Sstevel@tonic-gate 	ep = &ebp->extents[0];
495*0e42dee6Sartem 	(void) llseek(h->fd, (offset_t)logbtodb(fsp, ep->pbno) * DEV_BSIZE, 0);
496*0e42dee6Sartem 	if (read(h->fd, &h->eg, dbtob(LS_SECTORS)) != dbtob(LS_SECTORS)) {
497*0e42dee6Sartem 		(void) fprintf(fout, gettext(
498*0e42dee6Sartem 		    "dumplog: error reading log state\n"));
4997c478bd9Sstevel@tonic-gate 		return;
5007c478bd9Sstevel@tonic-gate 	}
501*0e42dee6Sartem 	ud = (void *)&h->eg;
502*0e42dee6Sartem 	(void) fprintf(fout, "version\t\t%" PRIu32 "\t\t", ud->od_version);
5037c478bd9Sstevel@tonic-gate 	if (ud->od_badlog)
504*0e42dee6Sartem 		(void) fprintf(fout, "logstate\tError\n");
5057c478bd9Sstevel@tonic-gate 	else
506*0e42dee6Sartem 		(void) fprintf(fout, "logstate\tOkay\n");
507*0e42dee6Sartem 	(void) fprintf(fout, "bol\t\t%" PRId32 "\t\teol\t\t%" PRId32 "\n",
5087c478bd9Sstevel@tonic-gate 		ud->od_bol_lof, ud->od_eol_lof);
509*0e42dee6Sartem 	(void) fprintf(fout, "requestsize\t%" PRIu32 "\n", ud->od_requestsize);
510*0e42dee6Sartem 	(void) fprintf(fout, "statesize\t%" PRIu32 "\n", ud->od_statesize);
511*0e42dee6Sartem 	(void) fprintf(fout, "logsize\t\t%" PRIu32 "\n", ud->od_logsize);
512*0e42dee6Sartem 	(void) fprintf(fout,
513*0e42dee6Sartem 	    "maxtransfer\t%" PRIu32 "\t\tdevbsize\t%" PRIu32 "\n",
514*0e42dee6Sartem 	    ud->od_maxtransfer, ud->od_devbsize);
515*0e42dee6Sartem 	(void) fprintf(fout,
516*0e42dee6Sartem 	    "head\t\t%" PRId32 "\t\thead ident\t%#" PRIx32 "\n",
517*0e42dee6Sartem 	    ud->od_head_lof, ud->od_head_ident);
518*0e42dee6Sartem 	(void) fprintf(fout,
519*0e42dee6Sartem 	    "tail\t\t%" PRId32 "\t\ttail ident\t%#" PRIx32 "\n",
520*0e42dee6Sartem 	    ud->od_tail_lof, ud->od_tail_ident);
521*0e42dee6Sartem 	(void) fprintf(fout, "\t\t\t\tdebug\t\t%#" PRIx32 "\n", ud->od_debug);
5227c478bd9Sstevel@tonic-gate 	if (ud->od_head_ident + ud->od_tail_ident != ud->od_chksum)
523*0e42dee6Sartem 		(void) fprintf(fout,
524*0e42dee6Sartem 		    "Bad chksum\t%#" PRIx32 "\n", ud->od_chksum);
5257c478bd9Sstevel@tonic-gate 	else
526*0e42dee6Sartem 		(void) fprintf(fout,
527*0e42dee6Sartem 		    "Good chksum\t%#" PRIx32 "\n", ud->od_chksum);
5287c478bd9Sstevel@tonic-gate }
5297c478bd9Sstevel@tonic-gate 
530*0e42dee6Sartem /* ARGSUSED */
5317c478bd9Sstevel@tonic-gate static void
dumpcg(fstyp_ufs_t * h,FILE * fout,FILE * ferr,const int c)532*0e42dee6Sartem dumpcg(fstyp_ufs_t *h, FILE *fout, FILE *ferr, const int c)
5337c478bd9Sstevel@tonic-gate {
534*0e42dee6Sartem 	int		i, j;
5357c478bd9Sstevel@tonic-gate 	offset_t	off;
5367c478bd9Sstevel@tonic-gate 	struct cg	*cgp;
5377c478bd9Sstevel@tonic-gate 	struct ocg	*ocgp;
538*0e42dee6Sartem 	struct fs	*fsp = &h->afs;
5397c478bd9Sstevel@tonic-gate 	time_t		t;
5407c478bd9Sstevel@tonic-gate 
541*0e42dee6Sartem 	(void) fprintf(fout, "\ncg %d:\n", c);
542*0e42dee6Sartem 	off = llseek(h->fd,
543*0e42dee6Sartem 	    (offset_t)fsbtodb(fsp, cgtod(fsp, c)) * DEV_BSIZE, 0);
544*0e42dee6Sartem 	if (read(h->fd, (char *)&h->acg, fsp->fs_bsize) != fsp->fs_bsize) {
545*0e42dee6Sartem 		(void) fprintf(fout, gettext("dumpfs: error reading cg\n"));
5467c478bd9Sstevel@tonic-gate 		return;
5477c478bd9Sstevel@tonic-gate 	}
548*0e42dee6Sartem 	cgp = (struct cg *)&h->acg;
549*0e42dee6Sartem 	ocgp = (struct ocg *)&h->acg;
5507c478bd9Sstevel@tonic-gate 	if (!cg_chkmagic(cgp))
551*0e42dee6Sartem 	    (void) fprintf(fout, gettext(
552d49934b4Sdmick 		"Invalid Cylinder grp magic fffs:%x  4.2 fs:%x\n"),
5537c478bd9Sstevel@tonic-gate 		cgp->cg_magic, ocgp->cg_magic);
5547c478bd9Sstevel@tonic-gate 	if (cgp->cg_magic == CG_MAGIC) {
5557c478bd9Sstevel@tonic-gate 		/* print FFFS 4.3 cyl grp format. */
5567c478bd9Sstevel@tonic-gate 		t = (time_t)cgp->cg_time;
557*0e42dee6Sartem 		(void) fprintf(fout, "magic\t%x\ttell\t%llx\ttime\t%s",
558d49934b4Sdmick 		    cgp->cg_magic, off, ctime(&t)); /* *** */
559*0e42dee6Sartem 		(void) fprintf(fout,
560*0e42dee6Sartem 		    "cgx\t%d\tncyl\t%d\tniblk\t%d\tndblk\t%d\n",
5617c478bd9Sstevel@tonic-gate 		    cgp->cg_cgx, cgp->cg_ncyl, cgp->cg_niblk, cgp->cg_ndblk);
562*0e42dee6Sartem 		(void) fprintf(fout,
563*0e42dee6Sartem 		    "nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
5647c478bd9Sstevel@tonic-gate 		    cgp->cg_cs.cs_nbfree, cgp->cg_cs.cs_ndir,
5657c478bd9Sstevel@tonic-gate 		    cgp->cg_cs.cs_nifree, cgp->cg_cs.cs_nffree);
566*0e42dee6Sartem 		(void) fprintf(fout, "rotor\t%d\tirotor\t%d\tfrotor\t%d\nfrsum",
5677c478bd9Sstevel@tonic-gate 		    cgp->cg_rotor, cgp->cg_irotor, cgp->cg_frotor);
568*0e42dee6Sartem 		for (i = 1, j = 0; i < fsp->fs_frag; i++) {
569*0e42dee6Sartem 			(void) fprintf(fout, "\t%d", cgp->cg_frsum[i]);
5707c478bd9Sstevel@tonic-gate 			j += i * cgp->cg_frsum[i];
5717c478bd9Sstevel@tonic-gate 		}
572*0e42dee6Sartem 		(void) fprintf(fout,
573*0e42dee6Sartem 		    gettext("\nsum of frsum: %d\niused:\t"), j);
574*0e42dee6Sartem 		pbits(fout, cg_inosused(cgp), fsp->fs_ipg);
575*0e42dee6Sartem 		(void) fprintf(fout, gettext("free:\t"));
576*0e42dee6Sartem 		pbits(fout, cg_blksfree(cgp), fsp->fs_fpg);
577*0e42dee6Sartem 		(void) fprintf(fout, "b:\n");
578*0e42dee6Sartem 		for (i = 0; i < fsp->fs_cpg; i++) {
579*0e42dee6Sartem 			(void) fprintf(fout,
580*0e42dee6Sartem 			    "   c%d:\t(%d)\t", i, cg_blktot(cgp)[i]);
5817c478bd9Sstevel@tonic-gate 			for (j = 0; j < fsp->fs_nrpos; j++)	/* ****** */
582*0e42dee6Sartem 				(void) fprintf(fout,
583*0e42dee6Sartem 				    " %d", cg_blks(fsp, cgp, i)[j]);
584*0e42dee6Sartem 			(void) fprintf(fout, "\n");
5857c478bd9Sstevel@tonic-gate 		}
5867c478bd9Sstevel@tonic-gate 	} else if (ocgp->cg_magic == CG_MAGIC) {
5877c478bd9Sstevel@tonic-gate 		/* print Old cyl grp format. */
5887c478bd9Sstevel@tonic-gate 		t = (time_t)ocgp->cg_time;
589*0e42dee6Sartem 		(void) fprintf(fout, "magic\t%x\ttell\t%llx\ttime\t%s",
590d49934b4Sdmick 		    ocgp->cg_magic, off, ctime(&t));
591*0e42dee6Sartem 		(void) fprintf(fout,
592*0e42dee6Sartem 		    "cgx\t%d\tncyl\t%d\tniblk\t%d\tndblk\t%d\n",
5937c478bd9Sstevel@tonic-gate 		    ocgp->cg_cgx, ocgp->cg_ncyl, ocgp->cg_niblk,
5947c478bd9Sstevel@tonic-gate 		    ocgp->cg_ndblk);
595*0e42dee6Sartem 		(void) fprintf(fout,
596*0e42dee6Sartem 		    "nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
5977c478bd9Sstevel@tonic-gate 		    ocgp->cg_cs.cs_nbfree, ocgp->cg_cs.cs_ndir,
5987c478bd9Sstevel@tonic-gate 		    ocgp->cg_cs.cs_nifree, ocgp->cg_cs.cs_nffree);
599*0e42dee6Sartem 		(void) fprintf(fout,
600*0e42dee6Sartem 		    "rotor\t%d\tirotor\t%d\tfrotor\t%d\nfrsum",
6017c478bd9Sstevel@tonic-gate 		    ocgp->cg_rotor, ocgp->cg_irotor, ocgp->cg_frotor);
602*0e42dee6Sartem 		for (i = 1, j = 0; i < fsp->fs_frag; i++) {
603*0e42dee6Sartem 			(void) fprintf(fout, "\t%d", ocgp->cg_frsum[i]);
6047c478bd9Sstevel@tonic-gate 			j += i * ocgp->cg_frsum[i];
6057c478bd9Sstevel@tonic-gate 		}
606*0e42dee6Sartem 		(void) fprintf(fout,
607*0e42dee6Sartem 		    gettext("\nsum of frsum: %d\niused:\t"), j);
608*0e42dee6Sartem 		pbits(fout, ocgp->cg_iused, fsp->fs_ipg);
609*0e42dee6Sartem 		(void) fprintf(fout, gettext("free:\t"));
610*0e42dee6Sartem 		pbits(fout, ocgp->cg_free, fsp->fs_fpg);
611*0e42dee6Sartem 		(void) fprintf(fout, "b:\n");
612*0e42dee6Sartem 		for (i = 0; i < fsp->fs_cpg; i++) {
613*0e42dee6Sartem 			(void) fprintf(fout,
614*0e42dee6Sartem 			    "   c%d:\t(%d)\t", i, ocgp->cg_btot[i]);
6157c478bd9Sstevel@tonic-gate 			for (j = 0; j < NRPOS; j++)
616*0e42dee6Sartem 				(void) fprintf(fout, " %d", ocgp->cg_b[i][j]);
617*0e42dee6Sartem 			(void) fprintf(fout, "\n");
6187c478bd9Sstevel@tonic-gate 		}
6197c478bd9Sstevel@tonic-gate 	}
6207c478bd9Sstevel@tonic-gate }
6217c478bd9Sstevel@tonic-gate 
6227c478bd9Sstevel@tonic-gate 
6237c478bd9Sstevel@tonic-gate static void
pbits(FILE * fout,const void * p,const int max)624*0e42dee6Sartem pbits(FILE *fout, const void *p, const int max)
6257c478bd9Sstevel@tonic-gate {
6267c478bd9Sstevel@tonic-gate 	int i;
6277c478bd9Sstevel@tonic-gate 	int count = 0, j;
6287c478bd9Sstevel@tonic-gate 	unsigned char *cp = (unsigned char *)p;
6297c478bd9Sstevel@tonic-gate 
6307c478bd9Sstevel@tonic-gate 	for (i = 0; i < max; i++) {
6317c478bd9Sstevel@tonic-gate 		if (isset(cp, i)) {
6327c478bd9Sstevel@tonic-gate 			if (count)
633*0e42dee6Sartem 				(void) fprintf(fout, ",%s",
634d49934b4Sdmick 				    (count % 9 == 8) ? "\n\t" : " ");
6357c478bd9Sstevel@tonic-gate 			count++;
636*0e42dee6Sartem 			(void) fprintf(fout, "%d", i);
6377c478bd9Sstevel@tonic-gate 			j = i;
6387c478bd9Sstevel@tonic-gate 			while ((i + 1) < max && isset(cp, i+1))
6397c478bd9Sstevel@tonic-gate 				i++;
6407c478bd9Sstevel@tonic-gate 			if (i != j)
641*0e42dee6Sartem 				(void) fprintf(fout, "-%d", i);
6427c478bd9Sstevel@tonic-gate 		}
6437c478bd9Sstevel@tonic-gate 	}
644*0e42dee6Sartem 	(void) fprintf(fout, "\n");
6457c478bd9Sstevel@tonic-gate }
646