xref: /illumos-gate/usr/src/cmd/fs.d/ufs/fstyp/fstyp.c (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
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 /*
40*0e42dee6Sartem  * libfstyp module for ufs
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate #include <stdio.h>
437c478bd9Sstevel@tonic-gate #include <stdlib.h>
447c478bd9Sstevel@tonic-gate #include <unistd.h>
457c478bd9Sstevel@tonic-gate #include <locale.h>
467c478bd9Sstevel@tonic-gate #include <fcntl.h>
477c478bd9Sstevel@tonic-gate #include <errno.h>
487c478bd9Sstevel@tonic-gate #include <strings.h>
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #include <sys/param.h>
517c478bd9Sstevel@tonic-gate #include <sys/types.h>
527c478bd9Sstevel@tonic-gate #include <sys/mntent.h>
537c478bd9Sstevel@tonic-gate #include <sys/errno.h>
547c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_fs.h>
557c478bd9Sstevel@tonic-gate #include <sys/stat.h>
567c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
577c478bd9Sstevel@tonic-gate #include <sys/mnttab.h>
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_log.h>
607c478bd9Sstevel@tonic-gate #include <sys/inttypes.h>
617c478bd9Sstevel@tonic-gate 
62*0e42dee6Sartem #include <libfstyp_module.h>
63*0e42dee6Sartem 
64*0e42dee6Sartem typedef struct fstyp_ufs {
65*0e42dee6Sartem 	int		fd;
66*0e42dee6Sartem 	nvlist_t	*attr;
67*0e42dee6Sartem 
68*0e42dee6Sartem 	union {
69*0e42dee6Sartem 		struct fs fs;
70*0e42dee6Sartem 		char pad[MAXBSIZE];
71*0e42dee6Sartem 	} fsun;
72*0e42dee6Sartem 
73*0e42dee6Sartem 	union {
74*0e42dee6Sartem 		struct cg cg;
75*0e42dee6Sartem 		char pad[MAXBSIZE];
76*0e42dee6Sartem 	} cgun;
77*0e42dee6Sartem 
78*0e42dee6Sartem 	char		eg[MAXBSIZE];
79*0e42dee6Sartem } fstyp_ufs_t;
80*0e42dee6Sartem 
81*0e42dee6Sartem #define	afs	fsun.fs
82*0e42dee6Sartem #define	acg	cgun.cg
83*0e42dee6Sartem 
847c478bd9Sstevel@tonic-gate #define	MAXLABELS	20
857c478bd9Sstevel@tonic-gate #define	LINEMAX		256
867c478bd9Sstevel@tonic-gate #define	NRPOS		8	/* for pre FFFS compatibility */
877c478bd9Sstevel@tonic-gate 
88*0e42dee6Sartem static int	is_ufs(fstyp_ufs_t *h);
89*0e42dee6Sartem static int	get_attr(fstyp_ufs_t *h);
90*0e42dee6Sartem static int	dumpfs(fstyp_ufs_t *h, FILE *fout, FILE *ferr);
91*0e42dee6Sartem static void	dumplog(fstyp_ufs_t *h, FILE *fout, FILE *ferr);
92*0e42dee6Sartem static void	dumpcg(fstyp_ufs_t *h, FILE *fout, FILE *ferr, const int c);
93*0e42dee6Sartem static void	pbits(FILE *out, const void *cp, const int max);
947c478bd9Sstevel@tonic-gate 
95*0e42dee6Sartem int	fstyp_mod_init(int fd, off_t offset, fstyp_mod_handle_t *handle);
96*0e42dee6Sartem void	fstyp_mod_fini(fstyp_mod_handle_t handle);
97*0e42dee6Sartem int	fstyp_mod_ident(fstyp_mod_handle_t handle);
98*0e42dee6Sartem int	fstyp_mod_get_attr(fstyp_mod_handle_t handle, nvlist_t **attrp);
99*0e42dee6Sartem int	fstyp_mod_dump(fstyp_mod_handle_t handle, FILE *fout, FILE *ferr);
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate int
fstyp_mod_init(int fd,off_t offset,fstyp_mod_handle_t * handle)103*0e42dee6Sartem fstyp_mod_init(int fd, off_t offset, fstyp_mod_handle_t *handle)
1047c478bd9Sstevel@tonic-gate {
105*0e42dee6Sartem 	struct fstyp_ufs *h;
1067c478bd9Sstevel@tonic-gate 
107*0e42dee6Sartem 	if (offset != 0) {
108*0e42dee6Sartem 		return (FSTYP_ERR_OFFSET);
1097c478bd9Sstevel@tonic-gate 	}
1107c478bd9Sstevel@tonic-gate 
111*0e42dee6Sartem 	if ((h = calloc(1, sizeof (struct fstyp_ufs))) == NULL) {
112*0e42dee6Sartem 		return (FSTYP_ERR_NOMEM);
113*0e42dee6Sartem 	}
114*0e42dee6Sartem 	h->fd = fd;
1157c478bd9Sstevel@tonic-gate 
116*0e42dee6Sartem 	*handle = (fstyp_mod_handle_t)h;
117*0e42dee6Sartem 	return (0);
1187c478bd9Sstevel@tonic-gate }
1197c478bd9Sstevel@tonic-gate 
120*0e42dee6Sartem void
fstyp_mod_fini(fstyp_mod_handle_t handle)121*0e42dee6Sartem fstyp_mod_fini(fstyp_mod_handle_t handle)
1227c478bd9Sstevel@tonic-gate {
123*0e42dee6Sartem 	struct fstyp_ufs *h = (struct fstyp_ufs *)handle;
124*0e42dee6Sartem 
125*0e42dee6Sartem 	if (h->attr == NULL) {
126*0e42dee6Sartem 		nvlist_free(h->attr);
127*0e42dee6Sartem 		h->attr = NULL;
128*0e42dee6Sartem 	}
129*0e42dee6Sartem 	free(h);
1307c478bd9Sstevel@tonic-gate }
1317c478bd9Sstevel@tonic-gate 
132*0e42dee6Sartem int
fstyp_mod_ident(fstyp_mod_handle_t handle)133*0e42dee6Sartem fstyp_mod_ident(fstyp_mod_handle_t handle)
134*0e42dee6Sartem {
135*0e42dee6Sartem 	struct fstyp_ufs *h = (struct fstyp_ufs *)handle;
1367c478bd9Sstevel@tonic-gate 
137*0e42dee6Sartem 	return (is_ufs(h));
138*0e42dee6Sartem }
1397c478bd9Sstevel@tonic-gate 
140*0e42dee6Sartem int
fstyp_mod_get_attr(fstyp_mod_handle_t handle,nvlist_t ** attrp)141*0e42dee6Sartem fstyp_mod_get_attr(fstyp_mod_handle_t handle, nvlist_t **attrp)
142*0e42dee6Sartem {
143*0e42dee6Sartem 	struct fstyp_ufs *h = (struct fstyp_ufs *)handle;
144*0e42dee6Sartem 	int error;
145*0e42dee6Sartem 
146*0e42dee6Sartem 	if (h->attr == NULL) {
147*0e42dee6Sartem 		if (nvlist_alloc(&h->attr, NV_UNIQUE_NAME_TYPE, 0)) {
148*0e42dee6Sartem 			return (FSTYP_ERR_NOMEM);
149*0e42dee6Sartem 		}
150*0e42dee6Sartem 		if ((error = get_attr(h)) != 0) {
151*0e42dee6Sartem 			nvlist_free(h->attr);
152*0e42dee6Sartem 			h->attr = NULL;
153*0e42dee6Sartem 			return (error);
154*0e42dee6Sartem 		}
155*0e42dee6Sartem 	}
156*0e42dee6Sartem 
157*0e42dee6Sartem 	*attrp = h->attr;
158*0e42dee6Sartem 	return (0);
159*0e42dee6Sartem }
160*0e42dee6Sartem 
161*0e42dee6Sartem int
fstyp_mod_dump(fstyp_mod_handle_t handle,FILE * fout,FILE * ferr)162*0e42dee6Sartem fstyp_mod_dump(fstyp_mod_handle_t handle, FILE *fout, FILE *ferr)
163*0e42dee6Sartem {
164*0e42dee6Sartem 	struct fstyp_ufs *h = (struct fstyp_ufs *)handle;
165*0e42dee6Sartem 
166*0e42dee6Sartem 	return (dumpfs(h, fout, ferr));
167*0e42dee6Sartem }
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate static int
is_ufs(fstyp_ufs_t * h)170*0e42dee6Sartem is_ufs(fstyp_ufs_t *h)
171*0e42dee6Sartem {
172*0e42dee6Sartem 	(void) llseek(h->fd, (offset_t)SBLOCK * DEV_BSIZE, 0);
173*0e42dee6Sartem 	if (read(h->fd, &h->afs, SBSIZE) != SBSIZE) {
174*0e42dee6Sartem 		return (FSTYP_ERR_IO);
175*0e42dee6Sartem 	}
176*0e42dee6Sartem 	if ((h->afs.fs_magic != FS_MAGIC) &&
177*0e42dee6Sartem 	    (h->afs.fs_magic != MTB_UFS_MAGIC)) {
178*0e42dee6Sartem 		return (FSTYP_ERR_NO_MATCH);
179*0e42dee6Sartem 	}
180*0e42dee6Sartem 	if ((h->afs.fs_magic == FS_MAGIC) &&
181*0e42dee6Sartem 	    (h->afs.fs_version != UFS_EFISTYLE4NONEFI_VERSION_2 &&
182*0e42dee6Sartem 	    h->afs.fs_version != UFS_VERSION_MIN)) {
183*0e42dee6Sartem 		return (FSTYP_ERR_NO_MATCH);
184*0e42dee6Sartem 	}
185*0e42dee6Sartem 	if ((h->afs.fs_magic == MTB_UFS_MAGIC) &&
186*0e42dee6Sartem 	    (h->afs.fs_version > MTB_UFS_VERSION_1 ||
187*0e42dee6Sartem 	    h->afs.fs_version < MTB_UFS_VERSION_MIN)) {
188*0e42dee6Sartem 		return (FSTYP_ERR_NO_MATCH);
189*0e42dee6Sartem 	}
190*0e42dee6Sartem 	return (0);
191*0e42dee6Sartem }
192*0e42dee6Sartem 
193*0e42dee6Sartem #define	ADD_STRING(h, name, value) \
194*0e42dee6Sartem 	if (nvlist_add_string(h->attr, name, value) != 0) { \
195*0e42dee6Sartem 		return (FSTYP_ERR_NOMEM); \
196*0e42dee6Sartem 	}
197*0e42dee6Sartem 
198*0e42dee6Sartem #define	ADD_INT32(h, name, value) \
199*0e42dee6Sartem 	if (nvlist_add_int32(h->attr, name, value) != 0) { \
200*0e42dee6Sartem 		return (FSTYP_ERR_NOMEM); \
201*0e42dee6Sartem 	}
202*0e42dee6Sartem 
203*0e42dee6Sartem #define	ADD_BOOL(h, name, value) \
204*0e42dee6Sartem 	if (nvlist_add_boolean_value(h->attr, name, value) != 0) { \
205*0e42dee6Sartem 		return (FSTYP_ERR_NOMEM); \
206*0e42dee6Sartem 	}
207*0e42dee6Sartem 
208*0e42dee6Sartem static int
get_attr(fstyp_ufs_t * h)209*0e42dee6Sartem get_attr(fstyp_ufs_t *h)
210*0e42dee6Sartem {
211*0e42dee6Sartem 	struct fs *fsp = &h->afs;
212*0e42dee6Sartem 	char	s[128];
213*0e42dee6Sartem 	time_t	t;
214*0e42dee6Sartem 
215*0e42dee6Sartem 	ADD_INT32(h, "magic", fsp->fs_magic);
216*0e42dee6Sartem 	ADD_STRING(h, "format",
217*0e42dee6Sartem 	    fsp->fs_postblformat == FS_42POSTBLFMT ? "static" : "dynamic");
218*0e42dee6Sartem 	t = (time_t)fsp->fs_time;
219*0e42dee6Sartem 	(void) snprintf(s, sizeof (s), "%s", ctime(&t));
220*0e42dee6Sartem 	s[strlen(s) - 1] = '\0';
221*0e42dee6Sartem 	ADD_STRING(h, "time", s);
222*0e42dee6Sartem 	ADD_INT32(h, "sblkno", fsp->fs_sblkno);
223*0e42dee6Sartem 	ADD_INT32(h, "cblkno", fsp->fs_cblkno);
224*0e42dee6Sartem 	ADD_INT32(h, "iblkno", fsp->fs_iblkno);
225*0e42dee6Sartem 	ADD_INT32(h, "dblkno", fsp->fs_dblkno);
226*0e42dee6Sartem 	ADD_INT32(h, "sbsize", fsp->fs_sbsize);
227*0e42dee6Sartem 	ADD_INT32(h, "cgsize", fsp->fs_cgsize);
228*0e42dee6Sartem 	ADD_INT32(h, "cgoffset", fsp->fs_cgoffset);
229*0e42dee6Sartem 	ADD_INT32(h, "cgmask", fsp->fs_cgmask);
230*0e42dee6Sartem 	ADD_INT32(h, "ncg", fsp->fs_ncg);
231*0e42dee6Sartem 	ADD_INT32(h, "size", fsp->fs_size);
232*0e42dee6Sartem 	ADD_INT32(h, "blocks", fsp->fs_dsize);
233*0e42dee6Sartem 	ADD_INT32(h, "bsize", fsp->fs_bsize);
234*0e42dee6Sartem 	ADD_INT32(h, "bshift", fsp->fs_bshift);
235*0e42dee6Sartem 	ADD_INT32(h, "bmask", fsp->fs_bmask);
236*0e42dee6Sartem 	ADD_INT32(h, "fsize", fsp->fs_fsize);
237*0e42dee6Sartem 	ADD_INT32(h, "fshift", fsp->fs_fshift);
238*0e42dee6Sartem 	ADD_INT32(h, "fmask", fsp->fs_fmask);
239*0e42dee6Sartem 	ADD_INT32(h, "frag", fsp->fs_frag);
240*0e42dee6Sartem 	ADD_INT32(h, "fragshift", fsp->fs_fragshift);
241*0e42dee6Sartem 	ADD_INT32(h, "fsbtodb", fsp->fs_fsbtodb);
242*0e42dee6Sartem 	ADD_INT32(h, "minfree", fsp->fs_minfree);
243*0e42dee6Sartem 	ADD_INT32(h, "maxbpg", fsp->fs_maxbpg);
244*0e42dee6Sartem 	ADD_STRING(h, "optim",
245*0e42dee6Sartem 	    fsp->fs_optim == FS_OPTSPACE ? "space" : "time");
246*0e42dee6Sartem 	ADD_INT32(h, "maxcontig", fsp->fs_maxcontig);
247*0e42dee6Sartem 	ADD_INT32(h, "rotdelay", fsp->fs_rotdelay);
248*0e42dee6Sartem 	ADD_INT32(h, "rps", fsp->fs_rps);
249*0e42dee6Sartem 	ADD_INT32(h, "csaddr", fsp->fs_csaddr);
250*0e42dee6Sartem 	ADD_INT32(h, "cssize", fsp->fs_cssize);
251*0e42dee6Sartem 	ADD_INT32(h, "csshift", fsp->fs_csshift);
252*0e42dee6Sartem 	ADD_INT32(h, "csmask", fsp->fs_csmask);
253*0e42dee6Sartem 	ADD_INT32(h, "ntrak", fsp->fs_ntrak);
254*0e42dee6Sartem 	ADD_INT32(h, "nsect", fsp->fs_nsect);
255*0e42dee6Sartem 	ADD_INT32(h, "spc", fsp->fs_spc);
256*0e42dee6Sartem 	ADD_INT32(h, "ncyl", fsp->fs_ncyl);
257*0e42dee6Sartem 	ADD_INT32(h, "cpg", fsp->fs_cpg);
258*0e42dee6Sartem 	ADD_INT32(h, "bpg", fsp->fs_fpg / fsp->fs_frag);
259*0e42dee6Sartem 	ADD_INT32(h, "fpg", fsp->fs_fpg);
260*0e42dee6Sartem 	ADD_INT32(h, "ipg", fsp->fs_ipg);
261*0e42dee6Sartem 	ADD_INT32(h, "nindir", fsp->fs_nindir);
262*0e42dee6Sartem 	ADD_INT32(h, "inopb", fsp->fs_inopb);
263*0e42dee6Sartem 	ADD_INT32(h, "nspf", fsp->fs_nspf);
264*0e42dee6Sartem 	ADD_INT32(h, "nbfree", fsp->fs_cstotal.cs_nbfree);
265*0e42dee6Sartem 	ADD_INT32(h, "ndir", fsp->fs_cstotal.cs_ndir);
266*0e42dee6Sartem 	ADD_INT32(h, "nifree", fsp->fs_cstotal.cs_nifree);
267*0e42dee6Sartem 	ADD_INT32(h, "nffree", fsp->fs_cstotal.cs_nffree);
268*0e42dee6Sartem 	ADD_INT32(h, "cgrotor", fsp->fs_cgrotor);
269*0e42dee6Sartem 	ADD_INT32(h, "fmod", fsp->fs_fmod);
270*0e42dee6Sartem 	ADD_INT32(h, "ronly", fsp->fs_ronly);
271*0e42dee6Sartem 	ADD_INT32(h, "logbno", fsp->fs_logbno);
272*0e42dee6Sartem 	ADD_INT32(h, "rolled", fsp->fs_rolled);
273*0e42dee6Sartem 	ADD_INT32(h, "si", fsp->fs_si);
274*0e42dee6Sartem 	ADD_INT32(h, "flags", fsp->fs_flags);
275*0e42dee6Sartem 	ADD_INT32(h, "version", fsp->fs_version);
276*0e42dee6Sartem 	if (fsp->fs_reclaim & (FS_RECLAIM | FS_RECLAIMING)) {
277*0e42dee6Sartem 		(void) snprintf(s, sizeof (s), "%s%s",
278*0e42dee6Sartem 		    (fsp->fs_reclaim & FS_RECLAIM)    ? " FS_RECLAIM"    : "",
279*0e42dee6Sartem 		    (fsp->fs_reclaim & FS_RECLAIMING) ? " FS_RECLAIMING" : "");
280*0e42dee6Sartem 		ADD_STRING(h, "fs_reclaim", s);
281*0e42dee6Sartem 	}
282*0e42dee6Sartem 	ADD_INT32(h, "clean", fsp->fs_clean);
283*0e42dee6Sartem 
284*0e42dee6Sartem 	if ((fsp->fs_state + (long)fsp->fs_time == FSOKAY) &&
285*0e42dee6Sartem 	    (fsp->fs_clean == FSCLEAN || fsp->fs_clean == FSSTABLE ||
286*0e42dee6Sartem 	    (fsp->fs_clean == FSLOG))) {
287*0e42dee6Sartem 		ADD_BOOL(h, "gen_clean", B_TRUE);
288*0e42dee6Sartem 	} else {
289*0e42dee6Sartem 		ADD_BOOL(h, "gen_clean", B_FALSE);
290*0e42dee6Sartem 	}
291*0e42dee6Sartem 
292*0e42dee6Sartem 	(void) snprintf(s, sizeof (s), "%d", fsp->fs_version);
293*0e42dee6Sartem 	ADD_STRING(h, "gen_version", s);
294*0e42dee6Sartem 
295*0e42dee6Sartem 	return (0);
296*0e42dee6Sartem }
297*0e42dee6Sartem 
298*0e42dee6Sartem 
299*0e42dee6Sartem static int
dumpfs(fstyp_ufs_t * h,FILE * fout,FILE * ferr)300*0e42dee6Sartem dumpfs(fstyp_ufs_t *h, FILE *fout, FILE *ferr)
3017c478bd9Sstevel@tonic-gate {
3027c478bd9Sstevel@tonic-gate 	int c, i, j, k, size, nrpos;
303*0e42dee6Sartem 	struct fs *fsp = &h->afs;
3047c478bd9Sstevel@tonic-gate 	offset_t offset;
3057c478bd9Sstevel@tonic-gate 	caddr_t sip;
3067c478bd9Sstevel@tonic-gate 	time_t t;
3077c478bd9Sstevel@tonic-gate 
308*0e42dee6Sartem 	t = (time_t)fsp->fs_time;
309*0e42dee6Sartem 	(void) fprintf(fout, "magic\t%x\tformat\t%s\ttime\t%s", fsp->fs_magic,
310*0e42dee6Sartem 	    fsp->fs_postblformat == FS_42POSTBLFMT ? "static" : "dynamic",
3117c478bd9Sstevel@tonic-gate 	    ctime(&t));
312*0e42dee6Sartem 	(void) fprintf(fout, "sblkno\t%d\tcblkno\t%d\tiblkno\t%d\tdblkno\t%d\n",
313*0e42dee6Sartem 	    fsp->fs_sblkno, fsp->fs_cblkno, fsp->fs_iblkno, fsp->fs_dblkno);
314*0e42dee6Sartem 	(void) fprintf(fout,
315*0e42dee6Sartem 	    "sbsize\t%d\tcgsize\t%d\tcgoffset %d\tcgmask\t0x%08x\n",
316*0e42dee6Sartem 	    fsp->fs_sbsize, fsp->fs_cgsize, fsp->fs_cgoffset, fsp->fs_cgmask);
317*0e42dee6Sartem 	(void) fprintf(fout, "ncg\t%d\tsize\t%d\tblocks\t%d\n",
318*0e42dee6Sartem 	    fsp->fs_ncg, fsp->fs_size, fsp->fs_dsize);
319*0e42dee6Sartem 	(void) fprintf(fout, "bsize\t%d\tshift\t%d\tmask\t0x%08x\n",
320*0e42dee6Sartem 	    fsp->fs_bsize, fsp->fs_bshift, fsp->fs_bmask);
321*0e42dee6Sartem 	(void) fprintf(fout, "fsize\t%d\tshift\t%d\tmask\t0x%08x\n",
322*0e42dee6Sartem 	    fsp->fs_fsize, fsp->fs_fshift, fsp->fs_fmask);
323*0e42dee6Sartem 	(void) fprintf(fout, "frag\t%d\tshift\t%d\tfsbtodb\t%d\n",
324*0e42dee6Sartem 	    fsp->fs_frag, fsp->fs_fragshift, fsp->fs_fsbtodb);
325*0e42dee6Sartem 	(void) fprintf(fout, "minfree\t%d%%\tmaxbpg\t%d\toptim\t%s\n",
326*0e42dee6Sartem 	    fsp->fs_minfree, fsp->fs_maxbpg,
327*0e42dee6Sartem 	    fsp->fs_optim == FS_OPTSPACE ? "space" : "time");
328*0e42dee6Sartem 	(void) fprintf(fout, "maxcontig %d\trotdelay %dms\trps\t%d\n",
329*0e42dee6Sartem 	    fsp->fs_maxcontig, fsp->fs_rotdelay, fsp->fs_rps);
330*0e42dee6Sartem 	(void) fprintf(fout,
331*0e42dee6Sartem 	    "csaddr\t%d\tcssize\t%d\tshift\t%d\tmask\t0x%08x\n",
332*0e42dee6Sartem 	    fsp->fs_csaddr, fsp->fs_cssize, fsp->fs_csshift, fsp->fs_csmask);
333*0e42dee6Sartem 	(void) fprintf(fout, "ntrak\t%d\tnsect\t%d\tspc\t%d\tncyl\t%d\n",
334*0e42dee6Sartem 	    fsp->fs_ntrak, fsp->fs_nsect, fsp->fs_spc, fsp->fs_ncyl);
335*0e42dee6Sartem 	(void) fprintf(fout, "cpg\t%d\tbpg\t%d\tfpg\t%d\tipg\t%d\n",
336*0e42dee6Sartem 	    fsp->fs_cpg, fsp->fs_fpg / fsp->fs_frag, fsp->fs_fpg, fsp->fs_ipg);
337*0e42dee6Sartem 	(void) fprintf(fout, "nindir\t%d\tinopb\t%d\tnspf\t%d\n",
338*0e42dee6Sartem 	    fsp->fs_nindir, fsp->fs_inopb, fsp->fs_nspf);
339*0e42dee6Sartem 	(void) fprintf(fout, "nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
340*0e42dee6Sartem 	    fsp->fs_cstotal.cs_nbfree, fsp->fs_cstotal.cs_ndir,
341*0e42dee6Sartem 	    fsp->fs_cstotal.cs_nifree, fsp->fs_cstotal.cs_nffree);
342*0e42dee6Sartem 	(void) fprintf(fout, "cgrotor\t%d\tfmod\t%d\tronly\t%d\tlogbno\t%d\n",
343*0e42dee6Sartem 	    fsp->fs_cgrotor, fsp->fs_fmod, fsp->fs_ronly, fsp->fs_logbno);
344*0e42dee6Sartem 	(void) fprintf(fout, "rolled\t%d\tsi\t%d\tflags\t%x\n",
345*0e42dee6Sartem 	    fsp->fs_rolled, fsp->fs_si, fsp->fs_flags);
346*0e42dee6Sartem 	(void) fprintf(fout, "version\t%d\n", fsp->fs_version);
347*0e42dee6Sartem 	if (fsp->fs_reclaim & (FS_RECLAIM | FS_RECLAIMING)) {
348*0e42dee6Sartem 		(void) fprintf(fout, "fs_reclaim%s%s\n",
349*0e42dee6Sartem 		    (fsp->fs_reclaim & FS_RECLAIM)    ? " FS_RECLAIM"    : "",
350*0e42dee6Sartem 		    (fsp->fs_reclaim & FS_RECLAIMING) ? " FS_RECLAIMING" : "");
3517c478bd9Sstevel@tonic-gate 	} else {
352*0e42dee6Sartem 		(void) fprintf(fout, "fs_reclaim is not set\n");
3537c478bd9Sstevel@tonic-gate 	}
354*0e42dee6Sartem 	if (fsp->fs_state + (long)fsp->fs_time == FSOKAY) {
355*0e42dee6Sartem 		(void) fprintf(fout, gettext(
356d49934b4Sdmick 		    "file system state is valid, fsclean is %d\n"),
357*0e42dee6Sartem 		    fsp->fs_clean);
3587c478bd9Sstevel@tonic-gate 	} else {
359*0e42dee6Sartem 		(void) fprintf(fout,
360*0e42dee6Sartem 		    gettext("file system state is not valid\n"));
3617c478bd9Sstevel@tonic-gate 	}
362*0e42dee6Sartem 	if (fsp->fs_cpc != 0) {
363*0e42dee6Sartem 		(void) fprintf(fout, gettext(
364d49934b4Sdmick 		    "blocks available in each rotational position"));
3657c478bd9Sstevel@tonic-gate 	} else {
366*0e42dee6Sartem 		(void) fprintf(fout, gettext(
3677c478bd9Sstevel@tonic-gate 		    "insufficient space to maintain rotational tables\n"));
3687c478bd9Sstevel@tonic-gate 	}
369*0e42dee6Sartem 	for (c = 0; c < fsp->fs_cpc; c++) {
370*0e42dee6Sartem 		(void) fprintf(fout, gettext("\ncylinder number %d:"), c);
3717c478bd9Sstevel@tonic-gate 		nrpos = (((fsp)->fs_postblformat == FS_DYNAMICPOSTBLFMT) ?
3727c478bd9Sstevel@tonic-gate 		    (fsp)->fs_nrpos : NRPOS);
3737c478bd9Sstevel@tonic-gate 		for (i = 0; i < nrpos; i++) {
3747c478bd9Sstevel@tonic-gate 			if (fs_postbl(fsp, c)[i] == -1)
3757c478bd9Sstevel@tonic-gate 				continue;
376*0e42dee6Sartem 			(void) fprintf(fout, gettext("\n   position %d:\t"), i);
3777c478bd9Sstevel@tonic-gate 			/*CSTYLED*/
3787c478bd9Sstevel@tonic-gate 			for (j = fs_postbl(fsp, c)[i], k = 1; ;
3797c478bd9Sstevel@tonic-gate 			    j += fs_rotbl(fsp)[j], k++) {
380*0e42dee6Sartem 				(void) fprintf(fout, "%5d", j);
3817c478bd9Sstevel@tonic-gate 				if (k % 12 == 0)
382*0e42dee6Sartem 					(void) fprintf(fout, "\n\t\t");
3837c478bd9Sstevel@tonic-gate 				if ((fs_rotbl(fsp))[j] == 0)
3847c478bd9Sstevel@tonic-gate 					break;
3857c478bd9Sstevel@tonic-gate 			}
3867c478bd9Sstevel@tonic-gate 		}
3877c478bd9Sstevel@tonic-gate 	}
388*0e42dee6Sartem 	(void) fprintf(fout, "\ncs[].cs_(nbfree,ndir,nifree,nffree):\n\t");
389*0e42dee6Sartem 	sip = calloc(1, fsp->fs_cssize);
390d49934b4Sdmick 	/* void * cast is to convince lint that sip really is aligned */
391*0e42dee6Sartem 	fsp->fs_u.fs_csp = (struct csum *)(void *)sip;
392*0e42dee6Sartem 	for (i = 0, j = 0; i < fsp->fs_cssize; i += fsp->fs_bsize, j++) {
393*0e42dee6Sartem 		size = fsp->fs_cssize - i < fsp->fs_bsize ?
394*0e42dee6Sartem 		    fsp->fs_cssize - i : fsp->fs_bsize;
3957c478bd9Sstevel@tonic-gate 		offset = (offset_t)fsbtodb(
396*0e42dee6Sartem 		    fsp, (fsp->fs_csaddr + j * fsp->fs_frag)) * DEV_BSIZE;
397*0e42dee6Sartem 		(void) llseek(h->fd, offset, 0);
398*0e42dee6Sartem 		if (read(h->fd, sip, size) != size) {
399*0e42dee6Sartem 			return (FSTYP_ERR_IO);
4007c478bd9Sstevel@tonic-gate 		}
4017c478bd9Sstevel@tonic-gate 		sip += size;
4027c478bd9Sstevel@tonic-gate 	}
403*0e42dee6Sartem 	for (i = 0; i < fsp->fs_ncg; i++) {
404*0e42dee6Sartem 		struct csum *cs = &fsp->fs_cs(fsp, i);
4057c478bd9Sstevel@tonic-gate 		if (i && i % 4 == 0)
406*0e42dee6Sartem 			(void) fprintf(fout, "\n\t");
407*0e42dee6Sartem 		(void) fprintf(fout, "(%d,%d,%d,%d) ",
4087c478bd9Sstevel@tonic-gate 		    cs->cs_nbfree, cs->cs_ndir, cs->cs_nifree, cs->cs_nffree);
4097c478bd9Sstevel@tonic-gate 	}
410*0e42dee6Sartem 	(void) fprintf(fout, "\n");
411*0e42dee6Sartem 	if (fsp->fs_ncyl % fsp->fs_cpg) {
412*0e42dee6Sartem 		(void) fprintf(fout, gettext("cylinders in last group %d\n"),
413*0e42dee6Sartem 		    i = fsp->fs_ncyl % fsp->fs_cpg);
414*0e42dee6Sartem 		(void) fprintf(fout, gettext("blocks in last group %d\n"),
415*0e42dee6Sartem 		    i * fsp->fs_spc / NSPB(fsp));
4167c478bd9Sstevel@tonic-gate 	}
417*0e42dee6Sartem 	(void) fprintf(fout, "\n");
418*0e42dee6Sartem 	for (i = 0; i < fsp->fs_ncg; i++)
419*0e42dee6Sartem 		dumpcg(h, fout, ferr, i);
420*0e42dee6Sartem 	if (fsp->fs_logbno)
421*0e42dee6Sartem 		dumplog(h, fout, ferr);
4227c478bd9Sstevel@tonic-gate 	return (0);
4237c478bd9Sstevel@tonic-gate }
4247c478bd9Sstevel@tonic-gate 
4257c478bd9Sstevel@tonic-gate static void
setsum(int32_t * sp,int32_t * lp,int nb)4267c478bd9Sstevel@tonic-gate setsum(int32_t *sp, int32_t *lp, int nb)
4277c478bd9Sstevel@tonic-gate {
4287c478bd9Sstevel@tonic-gate 	int32_t csum = 0;
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate 	*sp = 0;
4317c478bd9Sstevel@tonic-gate 	nb /= sizeof (int32_t);
4327c478bd9Sstevel@tonic-gate 	while (nb--)
4337c478bd9Sstevel@tonic-gate 		csum += *lp++;
4347c478bd9Sstevel@tonic-gate 	*sp = csum;
4357c478bd9Sstevel@tonic-gate }
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate static int
checksum(int32_t * sp,int32_t * lp,int nb)4387c478bd9Sstevel@tonic-gate checksum(int32_t *sp, int32_t *lp, int nb)
4397c478bd9Sstevel@tonic-gate {
4407c478bd9Sstevel@tonic-gate 	int32_t ssum = *sp;
4417c478bd9Sstevel@tonic-gate 
4427c478bd9Sstevel@tonic-gate 	setsum(sp, lp, nb);
4437c478bd9Sstevel@tonic-gate 	if (ssum != *sp) {
4447c478bd9Sstevel@tonic-gate 		*sp = ssum;
4457c478bd9Sstevel@tonic-gate 		return (0);
4467c478bd9Sstevel@tonic-gate 	}
4477c478bd9Sstevel@tonic-gate 	return (1);
4487c478bd9Sstevel@tonic-gate }
4497c478bd9Sstevel@tonic-gate 
450*0e42dee6Sartem /* ARGSUSED */
4517c478bd9Sstevel@tonic-gate static void
dumplog(fstyp_ufs_t * h,FILE * fout,FILE * ferr)452*0e42dee6Sartem dumplog(fstyp_ufs_t *h, FILE *fout, FILE *ferr)
4537c478bd9Sstevel@tonic-gate {
4547c478bd9Sstevel@tonic-gate 	int i;
4557c478bd9Sstevel@tonic-gate 	long		tb = 0;
4567c478bd9Sstevel@tonic-gate 	extent_block_t	*ebp;
4577c478bd9Sstevel@tonic-gate 	extent_t	*ep;
4587c478bd9Sstevel@tonic-gate 	ml_odunit_t	*ud;
459*0e42dee6Sartem 	struct fs *fsp = &h->afs;
4607c478bd9Sstevel@tonic-gate 
461*0e42dee6Sartem 	(void) fprintf(fout, "\nlog\n");
462*0e42dee6Sartem 	if (fsp->fs_magic == FS_MAGIC)
463*0e42dee6Sartem 		(void) fprintf(fout,
464*0e42dee6Sartem 		    "log allocation block %d\n", fsp->fs_logbno);
4657c478bd9Sstevel@tonic-gate 	else
466*0e42dee6Sartem 		(void) fprintf(fout, "log allocation block (in frags) %d\n",
467*0e42dee6Sartem 		    fsp->fs_logbno);
468*0e42dee6Sartem 	(void) llseek(h->fd, (offset_t)logbtodb(fsp,
469*0e42dee6Sartem 	    fsp->fs_logbno) * DEV_BSIZE, 0);
470*0e42dee6Sartem 	if (read(h->fd, (char *)&h->eg, fsp->fs_bsize) != fsp->fs_bsize) {
471*0e42dee6Sartem 		(void) fprintf(fout, gettext(
472*0e42dee6Sartem 		    "dumplog: error reading log allocation\n"));
4737c478bd9Sstevel@tonic-gate 		return;
4747c478bd9Sstevel@tonic-gate 	}
475*0e42dee6Sartem 	ebp = (void *)h->eg;
4767c478bd9Sstevel@tonic-gate 	if (ebp->type != LUFS_EXTENTS)
477*0e42dee6Sartem 		(void) fprintf(fout,
478*0e42dee6Sartem 		    gettext("Invalid log allocation type %x\n"), ebp->type);
479*0e42dee6Sartem 	if (!checksum(&ebp->chksum, (int32_t *)ebp, fsp->fs_bsize))
480*0e42dee6Sartem 		(void) fprintf(fout, gettext("Invalid log checksum\n"));
4817c478bd9Sstevel@tonic-gate 
4827c478bd9Sstevel@tonic-gate 	for (i = 0, ep = &ebp->extents[0]; i < ebp->nextents; ++i, ++ep) {
483*0e42dee6Sartem 		(void) fprintf(fout, "\tlogical block\t%" PRId32
4847c478bd9Sstevel@tonic-gate 		    "\tphysical block\t%" PRId32
4857c478bd9Sstevel@tonic-gate 		    "\tblocks\t%" PRId32 "\n",
4867c478bd9Sstevel@tonic-gate 		    ep->lbno, ep->pbno, ep->nbno);
4877c478bd9Sstevel@tonic-gate 		tb += dbtob(ep->nbno);
4887c478bd9Sstevel@tonic-gate 	}
489*0e42dee6Sartem 	(void) fprintf(fout, "log size %" PRIu32 " bytes (%ld calculated)\n",
4907c478bd9Sstevel@tonic-gate 		ebp->nbytes, tb);
491*0e42dee6Sartem 	(void) fprintf(fout, "\n");
4927c478bd9Sstevel@tonic-gate 	ep = &ebp->extents[0];
493*0e42dee6Sartem 	(void) llseek(h->fd, (offset_t)logbtodb(fsp, ep->pbno) * DEV_BSIZE, 0);
494*0e42dee6Sartem 	if (read(h->fd, &h->eg, dbtob(LS_SECTORS)) != dbtob(LS_SECTORS)) {
495*0e42dee6Sartem 		(void) fprintf(fout, gettext(
496*0e42dee6Sartem 		    "dumplog: error reading log state\n"));
4977c478bd9Sstevel@tonic-gate 		return;
4987c478bd9Sstevel@tonic-gate 	}
499*0e42dee6Sartem 	ud = (void *)&h->eg;
500*0e42dee6Sartem 	(void) fprintf(fout, "version\t\t%" PRIu32 "\t\t", ud->od_version);
5017c478bd9Sstevel@tonic-gate 	if (ud->od_badlog)
502*0e42dee6Sartem 		(void) fprintf(fout, "logstate\tError\n");
5037c478bd9Sstevel@tonic-gate 	else
504*0e42dee6Sartem 		(void) fprintf(fout, "logstate\tOkay\n");
505*0e42dee6Sartem 	(void) fprintf(fout, "bol\t\t%" PRId32 "\t\teol\t\t%" PRId32 "\n",
5067c478bd9Sstevel@tonic-gate 		ud->od_bol_lof, ud->od_eol_lof);
507*0e42dee6Sartem 	(void) fprintf(fout, "requestsize\t%" PRIu32 "\n", ud->od_requestsize);
508*0e42dee6Sartem 	(void) fprintf(fout, "statesize\t%" PRIu32 "\n", ud->od_statesize);
509*0e42dee6Sartem 	(void) fprintf(fout, "logsize\t\t%" PRIu32 "\n", ud->od_logsize);
510*0e42dee6Sartem 	(void) fprintf(fout,
511*0e42dee6Sartem 	    "maxtransfer\t%" PRIu32 "\t\tdevbsize\t%" PRIu32 "\n",
5127c478bd9Sstevel@tonic-gate 	    ud->od_maxtransfer, ud->od_devbsize);
513*0e42dee6Sartem 	(void) fprintf(fout,
514*0e42dee6Sartem 	    "head\t\t%" PRId32 "\t\thead ident\t%#" PRIx32 "\n",
5157c478bd9Sstevel@tonic-gate 	    ud->od_head_lof, ud->od_head_ident);
516*0e42dee6Sartem 	(void) fprintf(fout,
517*0e42dee6Sartem 	    "tail\t\t%" PRId32 "\t\ttail ident\t%#" PRIx32 "\n",
5187c478bd9Sstevel@tonic-gate 	    ud->od_tail_lof, ud->od_tail_ident);
519*0e42dee6Sartem 	(void) fprintf(fout, "\t\t\t\tdebug\t\t%#" PRIx32 "\n", ud->od_debug);
5207c478bd9Sstevel@tonic-gate 	if (ud->od_head_ident + ud->od_tail_ident != ud->od_chksum)
521*0e42dee6Sartem 		(void) fprintf(fout,
522*0e42dee6Sartem 		    "Bad chksum\t%#" PRIx32 "\n", ud->od_chksum);
5237c478bd9Sstevel@tonic-gate 	else
524*0e42dee6Sartem 		(void) fprintf(fout,
525*0e42dee6Sartem 		    "Good chksum\t%#" PRIx32 "\n", ud->od_chksum);
5267c478bd9Sstevel@tonic-gate }
5277c478bd9Sstevel@tonic-gate 
528*0e42dee6Sartem /* ARGSUSED */
5297c478bd9Sstevel@tonic-gate static void
dumpcg(fstyp_ufs_t * h,FILE * fout,FILE * ferr,const int c)530*0e42dee6Sartem dumpcg(fstyp_ufs_t *h, FILE *fout, FILE *ferr, const int c)
5317c478bd9Sstevel@tonic-gate {
5327c478bd9Sstevel@tonic-gate 	int		i, j;
5337c478bd9Sstevel@tonic-gate 	offset_t	off;
5347c478bd9Sstevel@tonic-gate 	struct cg	*cgp;
5357c478bd9Sstevel@tonic-gate 	struct ocg	*ocgp;
536*0e42dee6Sartem 	struct fs	*fsp = &h->afs;
5377c478bd9Sstevel@tonic-gate 	time_t		t;
5387c478bd9Sstevel@tonic-gate 
539*0e42dee6Sartem 	(void) fprintf(fout, "\ncg %d:\n", c);
540*0e42dee6Sartem 	off = llseek(h->fd,
541*0e42dee6Sartem 	    (offset_t)fsbtodb(fsp, cgtod(fsp, c)) * DEV_BSIZE, 0);
542*0e42dee6Sartem 	if (read(h->fd, (char *)&h->acg, fsp->fs_bsize) != fsp->fs_bsize) {
543*0e42dee6Sartem 		(void) fprintf(fout, gettext("dumpfs: error reading cg\n"));
5447c478bd9Sstevel@tonic-gate 		return;
5457c478bd9Sstevel@tonic-gate 	}
546*0e42dee6Sartem 	cgp = (struct cg *)&h->acg;
547*0e42dee6Sartem 	ocgp = (struct ocg *)&h->acg;
5487c478bd9Sstevel@tonic-gate 	if (!cg_chkmagic(cgp))
549*0e42dee6Sartem 	    (void) fprintf(fout, gettext(
550d49934b4Sdmick 		"Invalid Cylinder grp magic fffs:%x  4.2 fs:%x\n"),
5517c478bd9Sstevel@tonic-gate 		cgp->cg_magic, ocgp->cg_magic);
5527c478bd9Sstevel@tonic-gate 	if (cgp->cg_magic == CG_MAGIC) {
5537c478bd9Sstevel@tonic-gate 		/* print FFFS 4.3 cyl grp format. */
5547c478bd9Sstevel@tonic-gate 		t = (time_t)cgp->cg_time;
555*0e42dee6Sartem 		(void) fprintf(fout, "magic\t%x\ttell\t%llx\ttime\t%s",
556d49934b4Sdmick 		    cgp->cg_magic, off, ctime(&t)); /* *** */
557*0e42dee6Sartem 		(void) fprintf(fout,
558*0e42dee6Sartem 		    "cgx\t%d\tncyl\t%d\tniblk\t%d\tndblk\t%d\n",
5597c478bd9Sstevel@tonic-gate 		    cgp->cg_cgx, cgp->cg_ncyl, cgp->cg_niblk, cgp->cg_ndblk);
560*0e42dee6Sartem 		(void) fprintf(fout,
561*0e42dee6Sartem 		    "nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
5627c478bd9Sstevel@tonic-gate 		    cgp->cg_cs.cs_nbfree, cgp->cg_cs.cs_ndir,
5637c478bd9Sstevel@tonic-gate 		    cgp->cg_cs.cs_nifree, cgp->cg_cs.cs_nffree);
564*0e42dee6Sartem 		(void) fprintf(fout, "rotor\t%d\tirotor\t%d\tfrotor\t%d\nfrsum",
5657c478bd9Sstevel@tonic-gate 		    cgp->cg_rotor, cgp->cg_irotor, cgp->cg_frotor);
566*0e42dee6Sartem 		for (i = 1, j = 0; i < fsp->fs_frag; i++) {
567*0e42dee6Sartem 			(void) fprintf(fout, "\t%d", cgp->cg_frsum[i]);
5687c478bd9Sstevel@tonic-gate 			j += i * cgp->cg_frsum[i];
5697c478bd9Sstevel@tonic-gate 		}
570*0e42dee6Sartem 		(void) fprintf(fout,
571*0e42dee6Sartem 		    gettext("\nsum of frsum: %d\niused:\t"), j);
572*0e42dee6Sartem 		pbits(fout, cg_inosused(cgp), fsp->fs_ipg);
573*0e42dee6Sartem 		(void) fprintf(fout, gettext("free:\t"));
574*0e42dee6Sartem 		pbits(fout, cg_blksfree(cgp), fsp->fs_fpg);
575*0e42dee6Sartem 		(void) fprintf(fout, "b:\n");
576*0e42dee6Sartem 		for (i = 0; i < fsp->fs_cpg; i++) {
577*0e42dee6Sartem 			(void) fprintf(fout,
578*0e42dee6Sartem 			    "   c%d:\t(%d)\t", i, cg_blktot(cgp)[i]);
5797c478bd9Sstevel@tonic-gate 			for (j = 0; j < fsp->fs_nrpos; j++)	/* ****** */
580*0e42dee6Sartem 				(void) fprintf(fout,
581*0e42dee6Sartem 				    " %d", cg_blks(fsp, cgp, i)[j]);
582*0e42dee6Sartem 			(void) fprintf(fout, "\n");
5837c478bd9Sstevel@tonic-gate 		}
5847c478bd9Sstevel@tonic-gate 	} else if (ocgp->cg_magic == CG_MAGIC) {
5857c478bd9Sstevel@tonic-gate 		/* print Old cyl grp format. */
5867c478bd9Sstevel@tonic-gate 		t = (time_t)ocgp->cg_time;
587*0e42dee6Sartem 		(void) fprintf(fout, "magic\t%x\ttell\t%llx\ttime\t%s",
588d49934b4Sdmick 		    ocgp->cg_magic, off, ctime(&t));
589*0e42dee6Sartem 		(void) fprintf(fout,
590*0e42dee6Sartem 		    "cgx\t%d\tncyl\t%d\tniblk\t%d\tndblk\t%d\n",
5917c478bd9Sstevel@tonic-gate 		    ocgp->cg_cgx, ocgp->cg_ncyl, ocgp->cg_niblk,
5927c478bd9Sstevel@tonic-gate 		    ocgp->cg_ndblk);
593*0e42dee6Sartem 		(void) fprintf(fout,
594*0e42dee6Sartem 		    "nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
5957c478bd9Sstevel@tonic-gate 		    ocgp->cg_cs.cs_nbfree, ocgp->cg_cs.cs_ndir,
5967c478bd9Sstevel@tonic-gate 		    ocgp->cg_cs.cs_nifree, ocgp->cg_cs.cs_nffree);
597*0e42dee6Sartem 		(void) fprintf(fout,
598*0e42dee6Sartem 		    "rotor\t%d\tirotor\t%d\tfrotor\t%d\nfrsum",
5997c478bd9Sstevel@tonic-gate 		    ocgp->cg_rotor, ocgp->cg_irotor, ocgp->cg_frotor);
600*0e42dee6Sartem 		for (i = 1, j = 0; i < fsp->fs_frag; i++) {
601*0e42dee6Sartem 			(void) fprintf(fout, "\t%d", ocgp->cg_frsum[i]);
6027c478bd9Sstevel@tonic-gate 			j += i * ocgp->cg_frsum[i];
6037c478bd9Sstevel@tonic-gate 		}
604*0e42dee6Sartem 		(void) fprintf(fout,
605*0e42dee6Sartem 		    gettext("\nsum of frsum: %d\niused:\t"), j);
606*0e42dee6Sartem 		pbits(fout, ocgp->cg_iused, fsp->fs_ipg);
607*0e42dee6Sartem 		(void) fprintf(fout, gettext("free:\t"));
608*0e42dee6Sartem 		pbits(fout, ocgp->cg_free, fsp->fs_fpg);
609*0e42dee6Sartem 		(void) fprintf(fout, "b:\n");
610*0e42dee6Sartem 		for (i = 0; i < fsp->fs_cpg; i++) {
611*0e42dee6Sartem 			(void) fprintf(fout,
612*0e42dee6Sartem 			    "   c%d:\t(%d)\t", i, ocgp->cg_btot[i]);
6137c478bd9Sstevel@tonic-gate 			for (j = 0; j < NRPOS; j++)
614*0e42dee6Sartem 				(void) fprintf(fout, " %d", ocgp->cg_b[i][j]);
615*0e42dee6Sartem 			(void) fprintf(fout, "\n");
6167c478bd9Sstevel@tonic-gate 		}
6177c478bd9Sstevel@tonic-gate 	}
6187c478bd9Sstevel@tonic-gate }
6197c478bd9Sstevel@tonic-gate 
6207c478bd9Sstevel@tonic-gate 
6217c478bd9Sstevel@tonic-gate static void
pbits(FILE * fout,const void * p,const int max)622*0e42dee6Sartem pbits(FILE *fout, const void *p, const int max)
6237c478bd9Sstevel@tonic-gate {
6247c478bd9Sstevel@tonic-gate 	int i;
6257c478bd9Sstevel@tonic-gate 	int count = 0, j;
6267c478bd9Sstevel@tonic-gate 	unsigned char *cp = (unsigned char *)p;
6277c478bd9Sstevel@tonic-gate 
6287c478bd9Sstevel@tonic-gate 	for (i = 0; i < max; i++) {
6297c478bd9Sstevel@tonic-gate 		if (isset(cp, i)) {
6307c478bd9Sstevel@tonic-gate 			if (count)
631*0e42dee6Sartem 				(void) fprintf(fout, ",%s",
632d49934b4Sdmick 				    (count % 9 == 8) ? "\n\t" : " ");
6337c478bd9Sstevel@tonic-gate 			count++;
634*0e42dee6Sartem 			(void) fprintf(fout, "%d", i);
6357c478bd9Sstevel@tonic-gate 			j = i;
6367c478bd9Sstevel@tonic-gate 			while ((i + 1) < max && isset(cp, i+1))
6377c478bd9Sstevel@tonic-gate 				i++;
6387c478bd9Sstevel@tonic-gate 			if (i != j)
639*0e42dee6Sartem 				(void) fprintf(fout, "-%d", i);
6407c478bd9Sstevel@tonic-gate 		}
6417c478bd9Sstevel@tonic-gate 	}
642*0e42dee6Sartem 	(void) fprintf(fout, "\n");
6437c478bd9Sstevel@tonic-gate }
644