fstyp.c (6451fdbc) fstyp.c (0e42dee6)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21/*
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28/* All Rights Reserved */
29
30/*
31 * University Copyright- Copyright (c) 1982, 1986, 1988
32 * The Regents of the University of California
33 * All Rights Reserved
34 *
35 * University Acknowledgment- Portions of this document are derived from
36 * software developed by the University of California, Berkeley, and its
37 * contributors.
38 */
39
40#pragma ident "%Z%%M% %I% %E% SMI"
41
42/*
23 * Use is subject to license terms.
24 */
25
26/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27/* All Rights Reserved */
28
29/*
30 * University Copyright- Copyright (c) 1982, 1986, 1988
31 * The Regents of the University of California
32 * All Rights Reserved
33 *
34 * University Acknowledgment- Portions of this document are derived from
35 * software developed by the University of California, Berkeley, and its
36 * contributors.
37 */
38
39#pragma ident "%Z%%M% %I% %E% SMI"
40
41/*
43 * fstyp
42 * libfstyp module for ufs
44 */
45#include <stdio.h>
46#include <stdlib.h>
47#include <unistd.h>
48#include <locale.h>
49#include <fcntl.h>
50#include <errno.h>
51#include <strings.h>

--- 5 unchanged lines hidden (view full) ---

57#include <sys/fs/ufs_fs.h>
58#include <sys/stat.h>
59#include <sys/vfs.h>
60#include <sys/mnttab.h>
61
62#include <sys/fs/ufs_log.h>
63#include <sys/inttypes.h>
64
43 */
44#include <stdio.h>
45#include <stdlib.h>
46#include <unistd.h>
47#include <locale.h>
48#include <fcntl.h>
49#include <errno.h>
50#include <strings.h>

--- 5 unchanged lines hidden (view full) ---

56#include <sys/fs/ufs_fs.h>
57#include <sys/stat.h>
58#include <sys/vfs.h>
59#include <sys/mnttab.h>
60
61#include <sys/fs/ufs_log.h>
62#include <sys/inttypes.h>
63
64#include <libfstyp_module.h>
65
66typedef struct fstyp_ufs {
67 int fd;
68 nvlist_t *attr;
69
70 union {
71 struct fs fs;
72 char pad[MAXBSIZE];
73 } fsun;
74
75 union {
76 struct cg cg;
77 char pad[MAXBSIZE];
78 } cgun;
79
80 char eg[MAXBSIZE];
81} fstyp_ufs_t;
82
83#define afs fsun.fs
84#define acg cgun.cg
85
65#define MAXLABELS 20
66#define LINEMAX 256
67#define NRPOS 8 /* for pre FFFS compatibility */
68
86#define MAXLABELS 20
87#define LINEMAX 256
88#define NRPOS 8 /* for pre FFFS compatibility */
89
69static int vflag = 0; /* verbose output */
70static int errflag = 0;
71static char *special;
90static int is_ufs(fstyp_ufs_t *h);
91static int get_attr(fstyp_ufs_t *h);
92static int dumpfs(fstyp_ufs_t *h, FILE *fout, FILE *ferr);
93static void dumplog(fstyp_ufs_t *h, FILE *fout, FILE *ferr);
94static void dumpcg(fstyp_ufs_t *h, FILE *fout, FILE *ferr, const int c);
95static void pbits(FILE *out, const void *cp, const int max);
72
96
73static void usage(void);
74static int dumpfs(const char *name);
75static void dumpcg(const char *name, const int c);
76static void pbits(const void *cp, const int max);
97int fstyp_mod_init(int fd, off_t offset, fstyp_mod_handle_t *handle);
98void fstyp_mod_fini(fstyp_mod_handle_t handle);
99int fstyp_mod_ident(fstyp_mod_handle_t handle);
100int fstyp_mod_get_attr(fstyp_mod_handle_t handle, nvlist_t **attrp);
101int fstyp_mod_dump(fstyp_mod_handle_t handle, FILE *fout, FILE *ferr);
77
102
78static void dumplog(const char *name);
79
103
80extern char *getfullrawname();
81
82int
104int
83main(int argc, char *argv[])
105fstyp_mod_init(int fd, off_t offset, fstyp_mod_handle_t *handle)
84{
106{
85 int c;
86 struct stat64 st;
87 char device[MAXPATHLEN];
107 struct fstyp_ufs *h;
88
108
89 (void) setlocale(LC_ALL, "");
90#if !defined(TEXT_DOMAIN)
91#define TEXT_DOMAIN "SYS_TEST"
92#endif
93 (void) textdomain(TEXT_DOMAIN);
109 if (offset != 0) {
110 return (FSTYP_ERR_OFFSET);
111 }
94
112
95 while ((c = getopt(argc, argv, "v")) != EOF) {
96 switch (c) {
97 case 'v': /* dump super block */
98 vflag++;
99 break;
100
101 case '?':
102 errflag++;
103 }
113 if ((h = calloc(1, sizeof (struct fstyp_ufs))) == NULL) {
114 return (FSTYP_ERR_NOMEM);
104 }
115 }
105 if (errflag || argc <= optind) {
106 usage();
107 return (31+1);
108 }
116 h->fd = fd;
109
117
110 /*
111 * insure that the special device is raw since > 32-bit seeks
112 * will not work with block devices (bugs 1248701 and 4045593).
113 */
118 *handle = (fstyp_mod_handle_t)h;
119 return (0);
120}
114
121
115 special = getfullrawname(argv[optind]);
116 if (special == NULL) {
117 (void) fprintf(stderr, gettext("fstyp: malloc failed\n"));
118 exit(31+1);
122void
123fstyp_mod_fini(fstyp_mod_handle_t handle)
124{
125 struct fstyp_ufs *h = (struct fstyp_ufs *)handle;
126
127 if (h->attr == NULL) {
128 nvlist_free(h->attr);
129 h->attr = NULL;
119 }
130 }
131 free(h);
132}
120
133
121 if (*special == '\0') {
122 if (strchr(argv[optind], '/') != NULL) {
123 if (stat64(argv[optind], &st) < 0) {
124 (void) fprintf(stderr, "fstyp: %s: %s\n",
125 argv[optind], strerror(errno));
126 usage();
127 exit(31+1);
128 }
129 (void) fprintf(stderr,
130 gettext("%s: not a raw disk device\n"),
131 argv[optind]);
132 usage();
133 exit(31+1);
134 }
135 (void) snprintf(device, MAXPATHLEN, "/dev/rdsk/%s",
136 argv[optind]);
137 if ((special = getfullrawname(device)) == NULL) {
138 (void) fprintf(stderr,
139 gettext("fstyp: malloc failed\n"));
140 exit(31+1);
141 }
134int
135fstyp_mod_ident(fstyp_mod_handle_t handle)
136{
137 struct fstyp_ufs *h = (struct fstyp_ufs *)handle;
142
138
143 if (*special == '\0') {
144 (void) snprintf(device, MAXPATHLEN, "/dev/%s",
145 argv[optind]);
146 if ((special = getfullrawname(device)) == NULL) {
147 (void) fprintf(stderr,
148 gettext("fstyp: malloc failed\n"));
149 exit(31+1);
150 }
151 if (*special == '\0') {
152 (void) fprintf(stderr,
153 gettext("%s: not a raw disk device\n"),
154 argv[optind]);
155 usage();
156 exit(31+1);
157 }
139 return (is_ufs(h));
140}
141
142int
143fstyp_mod_get_attr(fstyp_mod_handle_t handle, nvlist_t **attrp)
144{
145 struct fstyp_ufs *h = (struct fstyp_ufs *)handle;
146 int error;
147
148 if (h->attr == NULL) {
149 if (nvlist_alloc(&h->attr, NV_UNIQUE_NAME_TYPE, 0)) {
150 return (FSTYP_ERR_NOMEM);
158 }
151 }
152 if ((error = get_attr(h)) != 0) {
153 nvlist_free(h->attr);
154 h->attr = NULL;
155 return (error);
156 }
159 }
160
157 }
158
161 return (dumpfs(special));
159 *attrp = h->attr;
160 return (0);
162}
163
161}
162
163int
164fstyp_mod_dump(fstyp_mod_handle_t handle, FILE *fout, FILE *ferr)
165{
166 struct fstyp_ufs *h = (struct fstyp_ufs *)handle;
164
167
165static void
166usage(void)
168 return (dumpfs(h, fout, ferr));
169}
170
171static int
172is_ufs(fstyp_ufs_t *h)
167{
173{
168 (void) fprintf(stderr, gettext("ufs usage: fstyp [-v] special\n"));
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);
177 }
178 if ((h->afs.fs_magic != FS_MAGIC) &&
179 (h->afs.fs_magic != MTB_UFS_MAGIC)) {
180 return (FSTYP_ERR_NO_MATCH);
181 }
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);
186 }
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);
191 }
192 return (0);
169}
170
193}
194
171static union {
172 struct fs fs;
173 char pad[MAXBSIZE];
174} fsun;
175#define afs fsun.fs
195#define ADD_STRING(h, name, value) \
196 if (nvlist_add_string(h->attr, name, value) != 0) { \
197 return (FSTYP_ERR_NOMEM); \
198 }
176
199
177static union {
178 struct cg cg;
179 char pad[MAXBSIZE];
180} cgun;
181#define acg cgun.cg
200#define ADD_INT32(h, name, value) \
201 if (nvlist_add_int32(h->attr, name, value) != 0) { \
202 return (FSTYP_ERR_NOMEM); \
203 }
182
204
183char eg[MAXBSIZE];
205#define ADD_BOOL(h, name, value) \
206 if (nvlist_add_boolean_value(h->attr, name, value) != 0) { \
207 return (FSTYP_ERR_NOMEM); \
208 }
184
185static int
209
210static int
186dumpfs(const char *name)
211get_attr(fstyp_ufs_t *h)
187{
212{
213 struct fs *fsp = &h->afs;
214 char s[128];
215 time_t t;
216
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);
283 }
284 ADD_INT32(h, "clean", fsp->fs_clean);
285
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);
290 } else {
291 ADD_BOOL(h, "gen_clean", B_FALSE);
292 }
293
294 (void) snprintf(s, sizeof (s), "%d", fsp->fs_version);
295 ADD_STRING(h, "gen_version", s);
296
297 return (0);
298}
299
300
301static int
302dumpfs(fstyp_ufs_t *h, FILE *fout, FILE *ferr)
303{
188 int c, i, j, k, size, nrpos;
304 int c, i, j, k, size, nrpos;
189 struct fs *fsp;
305 struct fs *fsp = &h->afs;
190 offset_t offset;
191 caddr_t sip;
192 time_t t;
193
306 offset_t offset;
307 caddr_t sip;
308 time_t t;
309
194 (void) close(0);
195 if (open64(name, 0) != 0) {
196 perror(name);
197 return (1);
198 }
199 (void) llseek(0, (offset_t)SBLOCK * DEV_BSIZE, 0);
200 if (read(0, &afs, SBSIZE) != SBSIZE) {
201 perror(name);
202 return (1);
203 }
204 if ((afs.fs_magic != FS_MAGIC) && (afs.fs_magic != MTB_UFS_MAGIC))
205 return (31+1);
206 if ((afs.fs_magic == FS_MAGIC) &&
207 (afs.fs_version != UFS_EFISTYLE4NONEFI_VERSION_2 &&
208 afs.fs_version != UFS_VERSION_MIN))
209 return (31+1);
210 if ((afs.fs_magic == MTB_UFS_MAGIC) &&
211 (afs.fs_version > MTB_UFS_VERSION_1 ||
212 afs.fs_version < MTB_UFS_VERSION_MIN))
213 return (31+1);
214 (void) printf("%s\n", "ufs");
215 if (!vflag)
216 return (0);
217 fsp = &afs;
218 t = (time_t)afs.fs_time;
219 (void) printf("magic\t%x\tformat\t%s\ttime\t%s", afs.fs_magic,
220 afs.fs_postblformat == FS_42POSTBLFMT ? "static" : "dynamic",
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",
221 ctime(&t));
313 ctime(&t));
222 (void) printf("sblkno\t%d\tcblkno\t%d\tiblkno\t%d\tdblkno\t%d\n",
223 afs.fs_sblkno, afs.fs_cblkno, afs.fs_iblkno, afs.fs_dblkno);
224 (void) printf("sbsize\t%d\tcgsize\t%d\tcgoffset %d\tcgmask\t0x%08x\n",
225 afs.fs_sbsize, afs.fs_cgsize, afs.fs_cgoffset, afs.fs_cgmask);
226 (void) printf("ncg\t%d\tsize\t%d\tblocks\t%d\n",
227 afs.fs_ncg, afs.fs_size, afs.fs_dsize);
228 (void) printf("bsize\t%d\tshift\t%d\tmask\t0x%08x\n",
229 afs.fs_bsize, afs.fs_bshift, afs.fs_bmask);
230 (void) printf("fsize\t%d\tshift\t%d\tmask\t0x%08x\n",
231 afs.fs_fsize, afs.fs_fshift, afs.fs_fmask);
232 (void) printf("frag\t%d\tshift\t%d\tfsbtodb\t%d\n",
233 afs.fs_frag, afs.fs_fragshift, afs.fs_fsbtodb);
234 (void) printf("minfree\t%d%%\tmaxbpg\t%d\toptim\t%s\n",
235 afs.fs_minfree, afs.fs_maxbpg,
236 afs.fs_optim == FS_OPTSPACE ? "space" : "time");
237 (void) printf("maxcontig %d\trotdelay %dms\trps\t%d\n",
238 afs.fs_maxcontig, afs.fs_rotdelay, afs.fs_rps);
239 (void) printf("csaddr\t%d\tcssize\t%d\tshift\t%d\tmask\t0x%08x\n",
240 afs.fs_csaddr, afs.fs_cssize, afs.fs_csshift, afs.fs_csmask);
241 (void) printf("ntrak\t%d\tnsect\t%d\tspc\t%d\tncyl\t%d\n",
242 afs.fs_ntrak, afs.fs_nsect, afs.fs_spc, afs.fs_ncyl);
243 (void) printf("cpg\t%d\tbpg\t%d\tfpg\t%d\tipg\t%d\n",
244 afs.fs_cpg, afs.fs_fpg / afs.fs_frag, afs.fs_fpg, afs.fs_ipg);
245 (void) printf("nindir\t%d\tinopb\t%d\tnspf\t%d\n",
246 afs.fs_nindir, afs.fs_inopb, afs.fs_nspf);
247 (void) printf("nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
248 afs.fs_cstotal.cs_nbfree, afs.fs_cstotal.cs_ndir,
249 afs.fs_cstotal.cs_nifree, afs.fs_cstotal.cs_nffree);
250 (void) printf("cgrotor\t%d\tfmod\t%d\tronly\t%d\tlogbno\t%d\n",
251 afs.fs_cgrotor, afs.fs_fmod, afs.fs_ronly, afs.fs_logbno);
252 (void) printf("version\t%d\n", afs.fs_version);
253 if (afs.fs_reclaim & (FS_RECLAIM | FS_RECLAIMING)) {
254 (void) printf("fs_reclaim%s%s\n",
255 (afs.fs_reclaim & FS_RECLAIM) ? " FS_RECLAIM" : "",
256 (afs.fs_reclaim & FS_RECLAIMING) ? " FS_RECLAIMING" : "");
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);
316 (void) fprintf(fout,
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);
332 (void) fprintf(fout,
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" : "");
257 } else {
353 } else {
258 (void) printf("fs_reclaim is not set\n");
354 (void) fprintf(fout, "fs_reclaim is not set\n");
259 }
355 }
260 if (afs.fs_state + (long)afs.fs_time == FSOKAY) {
261 (void) printf(gettext(
356 if (fsp->fs_state + (long)fsp->fs_time == FSOKAY) {
357 (void) fprintf(fout, gettext(
262 "file system state is valid, fsclean is %d\n"),
358 "file system state is valid, fsclean is %d\n"),
263 afs.fs_clean);
359 fsp->fs_clean);
264 } else {
360 } else {
265 (void) printf(gettext("file system state is not valid\n"));
361 (void) fprintf(fout,
362 gettext("file system state is not valid\n"));
266 }
363 }
267 if (afs.fs_cpc != 0) {
268 (void) printf(gettext(
364 if (fsp->fs_cpc != 0) {
365 (void) fprintf(fout, gettext(
269 "blocks available in each rotational position"));
270 } else {
366 "blocks available in each rotational position"));
367 } else {
271 (void) printf(gettext(
368 (void) fprintf(fout, gettext(
272 "insufficient space to maintain rotational tables\n"));
273 }
369 "insufficient space to maintain rotational tables\n"));
370 }
274 for (c = 0; c < afs.fs_cpc; c++) {
275 (void) printf(gettext("\ncylinder number %d:"), c);
371 for (c = 0; c < fsp->fs_cpc; c++) {
372 (void) fprintf(fout, gettext("\ncylinder number %d:"), c);
276 nrpos = (((fsp)->fs_postblformat == FS_DYNAMICPOSTBLFMT) ?
277 (fsp)->fs_nrpos : NRPOS);
278 for (i = 0; i < nrpos; i++) {
279 if (fs_postbl(fsp, c)[i] == -1)
280 continue;
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)
377 continue;
281 (void) printf(gettext("\n position %d:\t"), i);
378 (void) fprintf(fout, gettext("\n position %d:\t"), i);
282 /*CSTYLED*/
283 for (j = fs_postbl(fsp, c)[i], k = 1; ;
284 j += fs_rotbl(fsp)[j], k++) {
379 /*CSTYLED*/
380 for (j = fs_postbl(fsp, c)[i], k = 1; ;
381 j += fs_rotbl(fsp)[j], k++) {
285 (void) printf("%5d", j);
382 (void) fprintf(fout, "%5d", j);
286 if (k % 12 == 0)
383 if (k % 12 == 0)
287 (void) printf("\n\t\t");
384 (void) fprintf(fout, "\n\t\t");
288 if ((fs_rotbl(fsp))[j] == 0)
289 break;
290 }
291 }
292 }
385 if ((fs_rotbl(fsp))[j] == 0)
386 break;
387 }
388 }
389 }
293 (void) printf("\ncs[].cs_(nbfree,ndir,nifree,nffree):\n\t");
294 sip = calloc(1, afs.fs_cssize);
390 (void) fprintf(fout, "\ncs[].cs_(nbfree,ndir,nifree,nffree):\n\t");
391 sip = calloc(1, fsp->fs_cssize);
295 /* void * cast is to convince lint that sip really is aligned */
392 /* void * cast is to convince lint that sip really is aligned */
296 afs.fs_u.fs_csp = (struct csum *)(void *)sip;
297 for (i = 0, j = 0; i < afs.fs_cssize; i += afs.fs_bsize, j++) {
298 size = afs.fs_cssize - i < afs.fs_bsize ?
299 afs.fs_cssize - i : afs.fs_bsize;
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;
300 offset = (offset_t)fsbtodb(
397 offset = (offset_t)fsbtodb(
301 &afs, (afs.fs_csaddr + j * afs.fs_frag)) * DEV_BSIZE;
302 (void) llseek(0, offset, 0);
303 if (read(0, sip, size) != size) {
304 perror(name);
305 return (1);
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);
306 }
307 sip += size;
308 }
402 }
403 sip += size;
404 }
309 for (i = 0; i < afs.fs_ncg; i++) {
310 struct csum *cs = &afs.fs_cs(&afs, i);
405 for (i = 0; i < fsp->fs_ncg; i++) {
406 struct csum *cs = &fsp->fs_cs(fsp, i);
311 if (i && i % 4 == 0)
407 if (i && i % 4 == 0)
312 (void) printf("\n\t");
313 (void) printf("(%d,%d,%d,%d) ",
408 (void) fprintf(fout, "\n\t");
409 (void) fprintf(fout, "(%d,%d,%d,%d) ",
314 cs->cs_nbfree, cs->cs_ndir, cs->cs_nifree, cs->cs_nffree);
315 }
410 cs->cs_nbfree, cs->cs_ndir, cs->cs_nifree, cs->cs_nffree);
411 }
316 (void) printf("\n");
317 if (afs.fs_ncyl % afs.fs_cpg) {
318 (void) printf(gettext("cylinders in last group %d\n"),
319 i = afs.fs_ncyl % afs.fs_cpg);
320 (void) printf(gettext("blocks in last group %d\n"),
321 i * afs.fs_spc / NSPB(&afs));
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));
322 }
418 }
323 (void) printf("\n");
324 for (i = 0; i < afs.fs_ncg; i++)
325 dumpcg(name, i);
326 if (afs.fs_logbno)
327 dumplog(name);
328 (void) close(0);
419 (void) fprintf(fout, "\n");
420 for (i = 0; i < fsp->fs_ncg; i++)
421 dumpcg(h, fout, ferr, i);
422 if (fsp->fs_logbno)
423 dumplog(h, fout, ferr);
329 return (0);
330}
331
332static void
333setsum(int32_t *sp, int32_t *lp, int nb)
334{
335 int32_t csum = 0;
336

--- 12 unchanged lines hidden (view full) ---

349 setsum(sp, lp, nb);
350 if (ssum != *sp) {
351 *sp = ssum;
352 return (0);
353 }
354 return (1);
355}
356
424 return (0);
425}
426
427static void
428setsum(int32_t *sp, int32_t *lp, int nb)
429{
430 int32_t csum = 0;
431

--- 12 unchanged lines hidden (view full) ---

444 setsum(sp, lp, nb);
445 if (ssum != *sp) {
446 *sp = ssum;
447 return (0);
448 }
449 return (1);
450}
451
452/* ARGSUSED */
357static void
453static void
358dumplog(const char *name)
454dumplog(fstyp_ufs_t *h, FILE *fout, FILE *ferr)
359{
360 int i;
361 long tb = 0;
362 extent_block_t *ebp;
363 extent_t *ep;
364 ml_odunit_t *ud;
455{
456 int i;
457 long tb = 0;
458 extent_block_t *ebp;
459 extent_t *ep;
460 ml_odunit_t *ud;
461 struct fs *fsp = &h->afs;
365
462
366 (void) printf("\nlog\n");
367 if (afs.fs_magic == FS_MAGIC)
368 (void) printf("log allocation block %d\n", afs.fs_logbno);
463 (void) fprintf(fout, "\nlog\n");
464 if (fsp->fs_magic == FS_MAGIC)
465 (void) fprintf(fout,
466 "log allocation block %d\n", fsp->fs_logbno);
369 else
467 else
370 (void) printf("log allocation block (in frags) %d\n",
371 afs.fs_logbno);
372 (void) llseek(0, (offset_t)logbtodb(&afs, afs.fs_logbno) * DEV_BSIZE,
373 0);
374 if (read(0, (char *)&eg, afs.fs_bsize) != afs.fs_bsize) {
375 (void) printf(gettext(
376 "dumplog: %s: error reading log allocation\n"),
377 name);
468 (void) fprintf(fout, "log allocation block (in frags) %d\n",
469 fsp->fs_logbno);
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"));
378 return;
379 }
475 return;
476 }
380 ebp = (void *)eg;
477 ebp = (void *)h->eg;
381 if (ebp->type != LUFS_EXTENTS)
478 if (ebp->type != LUFS_EXTENTS)
382 (void) printf(gettext("Invalid log allocation type %x\n"),
383 ebp->type);
384 if (!checksum(&ebp->chksum, (int32_t *)ebp, afs.fs_bsize))
385 (void) printf(gettext("Invalid log checksum\n"));
479 (void) fprintf(fout,
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"));
386
387 for (i = 0, ep = &ebp->extents[0]; i < ebp->nextents; ++i, ++ep) {
483
484 for (i = 0, ep = &ebp->extents[0]; i < ebp->nextents; ++i, ++ep) {
388 (void) printf("\tlogical block\t%" PRId32
389 "\tphysical block\t%" PRId32
390 "\tblocks\t%" PRId32 "\n",
391 ep->lbno, ep->pbno, ep->nbno);
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);
392 tb += dbtob(ep->nbno);
393 }
489 tb += dbtob(ep->nbno);
490 }
394 (void) printf("log size %" PRIu32 " bytes (%ld calculated)\n",
491 (void) fprintf(fout, "log size %" PRIu32 " bytes (%ld calculated)\n",
395 ebp->nbytes, tb);
492 ebp->nbytes, tb);
396 (void) printf("\n");
493 (void) fprintf(fout, "\n");
397 ep = &ebp->extents[0];
494 ep = &ebp->extents[0];
398 (void) llseek(0, (offset_t)logbtodb(&afs, ep->pbno) * DEV_BSIZE, 0);
399 if (read(0, (char *)&eg, dbtob(LS_SECTORS)) != dbtob(LS_SECTORS)) {
400 (void) printf(gettext(
401 "dumplog: %s: error reading log state\n"), name);
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"));
402 return;
403 }
499 return;
500 }
404 ud = (void *)&eg;
405 (void) printf("version\t\t%" PRIu32 "\t\t", ud->od_version);
501 ud = (void *)&h->eg;
502 (void) fprintf(fout, "version\t\t%" PRIu32 "\t\t", ud->od_version);
406 if (ud->od_badlog)
503 if (ud->od_badlog)
407 (void) printf("logstate\tError\n");
504 (void) fprintf(fout, "logstate\tError\n");
408 else
505 else
409 (void) printf("logstate\tOkay\n");
410 (void) printf("bol\t\t%" PRId32 "\t\teol\t\t%" PRId32 "\n",
506 (void) fprintf(fout, "logstate\tOkay\n");
507 (void) fprintf(fout, "bol\t\t%" PRId32 "\t\teol\t\t%" PRId32 "\n",
411 ud->od_bol_lof, ud->od_eol_lof);
508 ud->od_bol_lof, ud->od_eol_lof);
412 (void) printf("requestsize\t%" PRIu32 "\n", ud->od_requestsize);
413 (void) printf("statesize\t%" PRIu32 "\n", ud->od_statesize);
414 (void) printf("logsize\t\t%" PRIu32 "\n", ud->od_logsize);
415 (void) printf("maxtransfer\t%" PRIu32 "\t\tdevbsize\t%" PRIu32 "\n",
416 ud->od_maxtransfer, ud->od_devbsize);
417 (void) printf("head\t\t%" PRId32 "\t\thead ident\t%#" PRIx32 "\n",
418 ud->od_head_lof, ud->od_head_ident);
419 (void) printf("tail\t\t%" PRId32 "\t\ttail ident\t%#" PRIx32 "\n",
420 ud->od_tail_lof, ud->od_tail_ident);
421 (void) printf("\t\t\t\tdebug\t\t%#" PRIx32 "\n", ud->od_debug);
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);
512 (void) fprintf(fout,
513 "maxtransfer\t%" PRIu32 "\t\tdevbsize\t%" PRIu32 "\n",
514 ud->od_maxtransfer, ud->od_devbsize);
515 (void) fprintf(fout,
516 "head\t\t%" PRId32 "\t\thead ident\t%#" PRIx32 "\n",
517 ud->od_head_lof, ud->od_head_ident);
518 (void) fprintf(fout,
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);
422 if (ud->od_head_ident + ud->od_tail_ident != ud->od_chksum)
522 if (ud->od_head_ident + ud->od_tail_ident != ud->od_chksum)
423 (void) printf("Bad chksum\t%#" PRIx32 "\n", ud->od_chksum);
523 (void) fprintf(fout,
524 "Bad chksum\t%#" PRIx32 "\n", ud->od_chksum);
424 else
525 else
425 (void) printf("Good chksum\t%#" PRIx32 "\n", ud->od_chksum);
526 (void) fprintf(fout,
527 "Good chksum\t%#" PRIx32 "\n", ud->od_chksum);
426}
427
528}
529
530/* ARGSUSED */
428static void
531static void
429dumpcg(const char *name, const int c)
532dumpcg(fstyp_ufs_t *h, FILE *fout, FILE *ferr, const int c)
430{
533{
431 int i, j;
534 int i, j;
432 offset_t off;
433 struct cg *cgp;
434 struct ocg *ocgp;
535 offset_t off;
536 struct cg *cgp;
537 struct ocg *ocgp;
435 struct fs *fsp;
538 struct fs *fsp = &h->afs;
436 time_t t;
437
539 time_t t;
540
438 (void) printf("\ncg %d:\n", c);
439 off = llseek(0, (offset_t)fsbtodb(&afs, cgtod(&afs, c)) * DEV_BSIZE, 0);
440 if (read(0, (char *)&acg, afs.fs_bsize) != afs.fs_bsize) {
441 (void) printf(gettext("dumpfs: %s: error reading cg\n"), name);
541 (void) fprintf(fout, "\ncg %d:\n", c);
542 off = llseek(h->fd,
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"));
442 return;
443 }
546 return;
547 }
444 cgp = (struct cg *)&acg;
445 ocgp = (struct ocg *)&acg;
446 fsp = &afs;
548 cgp = (struct cg *)&h->acg;
549 ocgp = (struct ocg *)&h->acg;
447 if (!cg_chkmagic(cgp))
550 if (!cg_chkmagic(cgp))
448 (void) printf(gettext(
551 (void) fprintf(fout, gettext(
449 "Invalid Cylinder grp magic fffs:%x 4.2 fs:%x\n"),
450 cgp->cg_magic, ocgp->cg_magic);
451 if (cgp->cg_magic == CG_MAGIC) {
452 /* print FFFS 4.3 cyl grp format. */
453 t = (time_t)cgp->cg_time;
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;
454 (void) printf("magic\t%x\ttell\t%llx\ttime\t%s",
557 (void) fprintf(fout, "magic\t%x\ttell\t%llx\ttime\t%s",
455 cgp->cg_magic, off, ctime(&t)); /* *** */
558 cgp->cg_magic, off, ctime(&t)); /* *** */
456 (void) printf("cgx\t%d\tncyl\t%d\tniblk\t%d\tndblk\t%d\n",
559 (void) fprintf(fout,
560 "cgx\t%d\tncyl\t%d\tniblk\t%d\tndblk\t%d\n",
457 cgp->cg_cgx, cgp->cg_ncyl, cgp->cg_niblk, cgp->cg_ndblk);
561 cgp->cg_cgx, cgp->cg_ncyl, cgp->cg_niblk, cgp->cg_ndblk);
458 (void) printf("nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
562 (void) fprintf(fout,
563 "nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
459 cgp->cg_cs.cs_nbfree, cgp->cg_cs.cs_ndir,
460 cgp->cg_cs.cs_nifree, cgp->cg_cs.cs_nffree);
564 cgp->cg_cs.cs_nbfree, cgp->cg_cs.cs_ndir,
565 cgp->cg_cs.cs_nifree, cgp->cg_cs.cs_nffree);
461 (void) printf("rotor\t%d\tirotor\t%d\tfrotor\t%d\nfrsum",
566 (void) fprintf(fout, "rotor\t%d\tirotor\t%d\tfrotor\t%d\nfrsum",
462 cgp->cg_rotor, cgp->cg_irotor, cgp->cg_frotor);
567 cgp->cg_rotor, cgp->cg_irotor, cgp->cg_frotor);
463 for (i = 1, j = 0; i < afs.fs_frag; i++) {
464 (void) printf("\t%d", cgp->cg_frsum[i]);
568 for (i = 1, j = 0; i < fsp->fs_frag; i++) {
569 (void) fprintf(fout, "\t%d", cgp->cg_frsum[i]);
465 j += i * cgp->cg_frsum[i];
466 }
570 j += i * cgp->cg_frsum[i];
571 }
467 (void) printf(gettext("\nsum of frsum: %d\niused:\t"), j);
468 pbits(cg_inosused(cgp), afs.fs_ipg);
469 (void) printf(gettext("free:\t"));
470 pbits(cg_blksfree(cgp), afs.fs_fpg);
471 (void) printf("b:\n");
472 for (i = 0; i < afs.fs_cpg; i++) {
473 (void) printf(" c%d:\t(%d)\t", i, cg_blktot(cgp)[i]);
572 (void) fprintf(fout,
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++) {
579 (void) fprintf(fout,
580 " c%d:\t(%d)\t", i, cg_blktot(cgp)[i]);
474 for (j = 0; j < fsp->fs_nrpos; j++) /* ****** */
581 for (j = 0; j < fsp->fs_nrpos; j++) /* ****** */
475 (void) printf(" %d", cg_blks(fsp, cgp, i)[j]);
476 (void) printf("\n");
582 (void) fprintf(fout,
583 " %d", cg_blks(fsp, cgp, i)[j]);
584 (void) fprintf(fout, "\n");
477 }
478 } else if (ocgp->cg_magic == CG_MAGIC) {
479 /* print Old cyl grp format. */
480 t = (time_t)ocgp->cg_time;
585 }
586 } else if (ocgp->cg_magic == CG_MAGIC) {
587 /* print Old cyl grp format. */
588 t = (time_t)ocgp->cg_time;
481 (void) printf("magic\t%x\ttell\t%llx\ttime\t%s",
589 (void) fprintf(fout, "magic\t%x\ttell\t%llx\ttime\t%s",
482 ocgp->cg_magic, off, ctime(&t));
590 ocgp->cg_magic, off, ctime(&t));
483 (void) printf("cgx\t%d\tncyl\t%d\tniblk\t%d\tndblk\t%d\n",
591 (void) fprintf(fout,
592 "cgx\t%d\tncyl\t%d\tniblk\t%d\tndblk\t%d\n",
484 ocgp->cg_cgx, ocgp->cg_ncyl, ocgp->cg_niblk,
485 ocgp->cg_ndblk);
593 ocgp->cg_cgx, ocgp->cg_ncyl, ocgp->cg_niblk,
594 ocgp->cg_ndblk);
486 (void) printf("nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
595 (void) fprintf(fout,
596 "nbfree\t%d\tndir\t%d\tnifree\t%d\tnffree\t%d\n",
487 ocgp->cg_cs.cs_nbfree, ocgp->cg_cs.cs_ndir,
488 ocgp->cg_cs.cs_nifree, ocgp->cg_cs.cs_nffree);
597 ocgp->cg_cs.cs_nbfree, ocgp->cg_cs.cs_ndir,
598 ocgp->cg_cs.cs_nifree, ocgp->cg_cs.cs_nffree);
489 (void) printf("rotor\t%d\tirotor\t%d\tfrotor\t%d\nfrsum",
599 (void) fprintf(fout,
600 "rotor\t%d\tirotor\t%d\tfrotor\t%d\nfrsum",
490 ocgp->cg_rotor, ocgp->cg_irotor, ocgp->cg_frotor);
601 ocgp->cg_rotor, ocgp->cg_irotor, ocgp->cg_frotor);
491 for (i = 1, j = 0; i < afs.fs_frag; i++) {
492 (void) printf("\t%d", ocgp->cg_frsum[i]);
602 for (i = 1, j = 0; i < fsp->fs_frag; i++) {
603 (void) fprintf(fout, "\t%d", ocgp->cg_frsum[i]);
493 j += i * ocgp->cg_frsum[i];
494 }
604 j += i * ocgp->cg_frsum[i];
605 }
495 (void) printf(gettext("\nsum of frsum: %d\niused:\t"), j);
496 pbits(ocgp->cg_iused, afs.fs_ipg);
497 (void) printf(gettext("free:\t"));
498 pbits(ocgp->cg_free, afs.fs_fpg);
499 (void) printf("b:\n");
500 for (i = 0; i < afs.fs_cpg; i++) {
501 (void) printf(" c%d:\t(%d)\t", i, ocgp->cg_btot[i]);
606 (void) fprintf(fout,
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++) {
613 (void) fprintf(fout,
614 " c%d:\t(%d)\t", i, ocgp->cg_btot[i]);
502 for (j = 0; j < NRPOS; j++)
615 for (j = 0; j < NRPOS; j++)
503 (void) printf(" %d", ocgp->cg_b[i][j]);
504 (void) printf("\n");
616 (void) fprintf(fout, " %d", ocgp->cg_b[i][j]);
617 (void) fprintf(fout, "\n");
505 }
506 }
507}
508
509
510static void
618 }
619 }
620}
621
622
623static void
511pbits(const void *p, const int max)
624pbits(FILE *fout, const void *p, const int max)
512{
513 int i;
514 int count = 0, j;
515 unsigned char *cp = (unsigned char *)p;
516
517 for (i = 0; i < max; i++) {
518 if (isset(cp, i)) {
519 if (count)
625{
626 int i;
627 int count = 0, j;
628 unsigned char *cp = (unsigned char *)p;
629
630 for (i = 0; i < max; i++) {
631 if (isset(cp, i)) {
632 if (count)
520 (void) printf(",%s",
633 (void) fprintf(fout, ",%s",
521 (count % 9 == 8) ? "\n\t" : " ");
522 count++;
634 (count % 9 == 8) ? "\n\t" : " ");
635 count++;
523 (void) printf("%d", i);
636 (void) fprintf(fout, "%d", i);
524 j = i;
525 while ((i + 1) < max && isset(cp, i+1))
526 i++;
527 if (i != j)
637 j = i;
638 while ((i + 1) < max && isset(cp, i+1))
639 i++;
640 if (i != j)
528 (void) printf("-%d", i);
641 (void) fprintf(fout, "-%d", i);
529 }
530 }
642 }
643 }
531 (void) printf("\n");
644 (void) fprintf(fout, "\n");
532}
645}