1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24*0Sstevel@tonic-gate * Use is subject to license terms.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate #include <unistd.h>
30*0Sstevel@tonic-gate #include <stdlib.h>
31*0Sstevel@tonic-gate #include <stdio.h>
32*0Sstevel@tonic-gate #include <libintl.h>
33*0Sstevel@tonic-gate #include <unistd.h>
34*0Sstevel@tonic-gate #include <string.h>
35*0Sstevel@tonic-gate #include <sys/types.h>
36*0Sstevel@tonic-gate #include <sys/stat.h>
37*0Sstevel@tonic-gate #include <kvm.h>
38*0Sstevel@tonic-gate #include <fcntl.h>
39*0Sstevel@tonic-gate #include <sys/mman.h>
40*0Sstevel@tonic-gate #include <sys/tnf.h>
41*0Sstevel@tonic-gate #include <sys/tnf_com.h>
42*0Sstevel@tonic-gate #include <nlist.h>
43*0Sstevel@tonic-gate #include <errno.h>
44*0Sstevel@tonic-gate
45*0Sstevel@tonic-gate #define TNFDEV "/dev/tnfmap"
46*0Sstevel@tonic-gate
47*0Sstevel@tonic-gate #define MAXFWTRY 5
48*0Sstevel@tonic-gate
49*0Sstevel@tonic-gate typedef struct {
50*0Sstevel@tonic-gate boolean_t ever_read;
51*0Sstevel@tonic-gate tnf_uint32_t generation;
52*0Sstevel@tonic-gate tnf_uint16_t bytes_valid;
53*0Sstevel@tonic-gate } BLOCK_STATUS;
54*0Sstevel@tonic-gate
55*0Sstevel@tonic-gate static char *dumpfile; /* Dump file if extracting from crashdump */
56*0Sstevel@tonic-gate static char *namelist; /* Symbol tbl. if extracting from crashdump */
57*0Sstevel@tonic-gate static kvm_t *kvm_p; /* Handle for kvm_open, kvm_read, ... */
58*0Sstevel@tonic-gate
59*0Sstevel@tonic-gate static struct nlist kvm_syms[] = {
60*0Sstevel@tonic-gate { "tnf_buf" },
61*0Sstevel@tonic-gate { "tnf_trace_file_size" },
62*0Sstevel@tonic-gate { NULL }
63*0Sstevel@tonic-gate };
64*0Sstevel@tonic-gate
65*0Sstevel@tonic-gate static uintptr_t dump_bufaddr;
66*0Sstevel@tonic-gate static size_t tnf_bufsize;
67*0Sstevel@tonic-gate static char *program_name;
68*0Sstevel@tonic-gate static int input_fd;
69*0Sstevel@tonic-gate static int output_fd;
70*0Sstevel@tonic-gate static tnf_file_header_t *tnf_header;
71*0Sstevel@tonic-gate
72*0Sstevel@tonic-gate /*
73*0Sstevel@tonic-gate * usage() - gives a description of the arguments, and exits
74*0Sstevel@tonic-gate */
75*0Sstevel@tonic-gate
76*0Sstevel@tonic-gate static void
usage(char * argv[],const char * msg)77*0Sstevel@tonic-gate usage(char *argv[], const char *msg)
78*0Sstevel@tonic-gate {
79*0Sstevel@tonic-gate if (msg)
80*0Sstevel@tonic-gate (void) fprintf(stderr,
81*0Sstevel@tonic-gate gettext("%s: %s\n"), argv[0], msg);
82*0Sstevel@tonic-gate
83*0Sstevel@tonic-gate (void) fprintf(stderr, gettext(
84*0Sstevel@tonic-gate "usage: %s [-d <dumpfile> -n <symbolfile> ] "
85*0Sstevel@tonic-gate "<output-filename>\n"), argv[0]);
86*0Sstevel@tonic-gate exit(1);
87*0Sstevel@tonic-gate } /* end usage */
88*0Sstevel@tonic-gate
89*0Sstevel@tonic-gate
90*0Sstevel@tonic-gate /*
91*0Sstevel@tonic-gate * Write 'size' bytes at offset 'offset' from 'addr'
92*0Sstevel@tonic-gate * to the output file. Bail out unceremoniously if anything goes wrong.
93*0Sstevel@tonic-gate */
94*0Sstevel@tonic-gate static void
writeout(char * addr,int offset,int size)95*0Sstevel@tonic-gate writeout(char *addr, int offset, int size)
96*0Sstevel@tonic-gate
97*0Sstevel@tonic-gate {
98*0Sstevel@tonic-gate if (lseek(output_fd, offset, SEEK_SET) < 0) {
99*0Sstevel@tonic-gate perror("lseek");
100*0Sstevel@tonic-gate exit(1);
101*0Sstevel@tonic-gate }
102*0Sstevel@tonic-gate if (write(output_fd, addr, size) != size) {
103*0Sstevel@tonic-gate perror("write");
104*0Sstevel@tonic-gate exit(1);
105*0Sstevel@tonic-gate }
106*0Sstevel@tonic-gate }
107*0Sstevel@tonic-gate
108*0Sstevel@tonic-gate
109*0Sstevel@tonic-gate static void
dumpfile_init()110*0Sstevel@tonic-gate dumpfile_init()
111*0Sstevel@tonic-gate
112*0Sstevel@tonic-gate {
113*0Sstevel@tonic-gate kvm_p = kvm_open(namelist, dumpfile, NULL, O_RDONLY, program_name);
114*0Sstevel@tonic-gate if (kvm_p == NULL) {
115*0Sstevel@tonic-gate /* kvm_open prints an error message */
116*0Sstevel@tonic-gate exit(1);
117*0Sstevel@tonic-gate }
118*0Sstevel@tonic-gate if (kvm_nlist(kvm_p, kvm_syms) != 0) {
119*0Sstevel@tonic-gate (void) fprintf(stderr, gettext(
120*0Sstevel@tonic-gate "Symbol lookup error in %s\n"), namelist);
121*0Sstevel@tonic-gate exit(1);
122*0Sstevel@tonic-gate }
123*0Sstevel@tonic-gate if (kvm_read(kvm_p, kvm_syms[0].n_value, (char *) &dump_bufaddr,
124*0Sstevel@tonic-gate sizeof (dump_bufaddr)) != sizeof (dump_bufaddr) ||
125*0Sstevel@tonic-gate kvm_read(kvm_p, kvm_syms[1].n_value, (char *) &tnf_bufsize,
126*0Sstevel@tonic-gate sizeof (tnf_bufsize)) != sizeof (tnf_bufsize)) {
127*0Sstevel@tonic-gate (void) fprintf(stderr, gettext(
128*0Sstevel@tonic-gate "kvm_read error in %s\n"), dumpfile);
129*0Sstevel@tonic-gate exit(1);
130*0Sstevel@tonic-gate }
131*0Sstevel@tonic-gate if (dump_bufaddr == NULL || tnf_bufsize == 0) {
132*0Sstevel@tonic-gate (void) fprintf(stderr, gettext(
133*0Sstevel@tonic-gate "No trace data available in the kernel.\n"));
134*0Sstevel@tonic-gate exit(1);
135*0Sstevel@tonic-gate }
136*0Sstevel@tonic-gate }
137*0Sstevel@tonic-gate
138*0Sstevel@tonic-gate static void
live_kernel_init()139*0Sstevel@tonic-gate live_kernel_init()
140*0Sstevel@tonic-gate
141*0Sstevel@tonic-gate {
142*0Sstevel@tonic-gate tifiocstate_t tstate;
143*0Sstevel@tonic-gate
144*0Sstevel@tonic-gate if ((input_fd = open(TNFDEV, O_RDWR)) < 0) {
145*0Sstevel@tonic-gate perror(TNFDEV);
146*0Sstevel@tonic-gate exit(1);
147*0Sstevel@tonic-gate }
148*0Sstevel@tonic-gate if (ioctl(input_fd, TIFIOCGSTATE, &tstate) < 0) {
149*0Sstevel@tonic-gate perror(gettext("Error getting trace system state"));
150*0Sstevel@tonic-gate exit(1);
151*0Sstevel@tonic-gate }
152*0Sstevel@tonic-gate if (tstate.buffer_state != TIFIOCBUF_OK) {
153*0Sstevel@tonic-gate (void) fprintf(stderr, gettext(
154*0Sstevel@tonic-gate "No trace data available in the kernel.\n"));
155*0Sstevel@tonic-gate exit(1);
156*0Sstevel@tonic-gate }
157*0Sstevel@tonic-gate tnf_bufsize = tstate.buffer_size;
158*0Sstevel@tonic-gate }
159*0Sstevel@tonic-gate
160*0Sstevel@tonic-gate static void
read_tnf_header(char * addr)161*0Sstevel@tonic-gate read_tnf_header(char *addr)
162*0Sstevel@tonic-gate
163*0Sstevel@tonic-gate {
164*0Sstevel@tonic-gate if (dumpfile != NULL) {
165*0Sstevel@tonic-gate if (kvm_read(kvm_p, dump_bufaddr, addr, 512) != 512) {
166*0Sstevel@tonic-gate (void) fprintf(stderr, gettext(
167*0Sstevel@tonic-gate "Error reading tnf header from dump file.\n"));
168*0Sstevel@tonic-gate exit(1);
169*0Sstevel@tonic-gate }
170*0Sstevel@tonic-gate } else {
171*0Sstevel@tonic-gate if (ioctl(input_fd, TIFIOCGHEADER, addr) != 0) {
172*0Sstevel@tonic-gate perror(gettext("Error reading tnf header from kernel"));
173*0Sstevel@tonic-gate exit(1);
174*0Sstevel@tonic-gate }
175*0Sstevel@tonic-gate }
176*0Sstevel@tonic-gate }
177*0Sstevel@tonic-gate
178*0Sstevel@tonic-gate static int
read_tnf_block(tnf_block_header_t * addr,int block_num)179*0Sstevel@tonic-gate read_tnf_block(tnf_block_header_t *addr, int block_num)
180*0Sstevel@tonic-gate
181*0Sstevel@tonic-gate {
182*0Sstevel@tonic-gate int offset;
183*0Sstevel@tonic-gate tifiocgblock_t ioctl_arg;
184*0Sstevel@tonic-gate
185*0Sstevel@tonic-gate if (dumpfile != NULL) {
186*0Sstevel@tonic-gate offset = tnf_header->directory_size +
187*0Sstevel@tonic-gate block_num * tnf_header->block_size;
188*0Sstevel@tonic-gate if (kvm_read(kvm_p, dump_bufaddr + offset, (char *) addr,
189*0Sstevel@tonic-gate tnf_header->block_size) != tnf_header->block_size) {
190*0Sstevel@tonic-gate (void) fprintf(stderr, gettext(
191*0Sstevel@tonic-gate "Error reading tnf block.\n"));
192*0Sstevel@tonic-gate exit(1);
193*0Sstevel@tonic-gate }
194*0Sstevel@tonic-gate } else {
195*0Sstevel@tonic-gate ioctl_arg.dst_addr = (char *) addr;
196*0Sstevel@tonic-gate ioctl_arg.block_num = block_num;
197*0Sstevel@tonic-gate if (ioctl(input_fd, TIFIOCGBLOCK, &ioctl_arg) < 0) {
198*0Sstevel@tonic-gate if (errno == EBUSY)
199*0Sstevel@tonic-gate return (EBUSY);
200*0Sstevel@tonic-gate perror(gettext("Error reading tnf block"));
201*0Sstevel@tonic-gate exit(1);
202*0Sstevel@tonic-gate }
203*0Sstevel@tonic-gate }
204*0Sstevel@tonic-gate return (0);
205*0Sstevel@tonic-gate }
206*0Sstevel@tonic-gate
207*0Sstevel@tonic-gate static void
read_tnf_fwzone(tnf_ref32_t * dest,int start,int slots)208*0Sstevel@tonic-gate read_tnf_fwzone(tnf_ref32_t *dest, int start, int slots)
209*0Sstevel@tonic-gate
210*0Sstevel@tonic-gate {
211*0Sstevel@tonic-gate int offset;
212*0Sstevel@tonic-gate int len;
213*0Sstevel@tonic-gate tifiocgfw_t ioctl_arg;
214*0Sstevel@tonic-gate
215*0Sstevel@tonic-gate if (dumpfile != NULL) {
216*0Sstevel@tonic-gate /* LINTED assignment of 64-bit integer to 32-bit integer */
217*0Sstevel@tonic-gate offset = tnf_header->block_size + start * sizeof (tnf_ref32_t);
218*0Sstevel@tonic-gate /* LINTED assignment of 64-bit integer to 32-bit integer */
219*0Sstevel@tonic-gate len = slots * sizeof (tnf_ref32_t);
220*0Sstevel@tonic-gate if (kvm_read(kvm_p, dump_bufaddr + offset, (char *) dest,
221*0Sstevel@tonic-gate len) != len) {
222*0Sstevel@tonic-gate (void) fprintf(stderr, gettext(
223*0Sstevel@tonic-gate "Error reading tnf forwarding zone.\n"));
224*0Sstevel@tonic-gate exit(1);
225*0Sstevel@tonic-gate }
226*0Sstevel@tonic-gate } else {
227*0Sstevel@tonic-gate /* LINTED pointer cast may result in improper alignment */
228*0Sstevel@tonic-gate ioctl_arg.dst_addr = (long *) dest;
229*0Sstevel@tonic-gate ioctl_arg.start = start;
230*0Sstevel@tonic-gate ioctl_arg.slots = slots;
231*0Sstevel@tonic-gate if (ioctl(input_fd, TIFIOCGFWZONE, &ioctl_arg) < 0) {
232*0Sstevel@tonic-gate perror(gettext("Error reading tnf block"));
233*0Sstevel@tonic-gate exit(1);
234*0Sstevel@tonic-gate }
235*0Sstevel@tonic-gate }
236*0Sstevel@tonic-gate }
237*0Sstevel@tonic-gate
238*0Sstevel@tonic-gate int
main(int argc,char * argv[])239*0Sstevel@tonic-gate main(int argc, char *argv[])
240*0Sstevel@tonic-gate {
241*0Sstevel@tonic-gate const char *optstr = "d:n:";
242*0Sstevel@tonic-gate const char *outfile;
243*0Sstevel@tonic-gate char *local_buf;
244*0Sstevel@tonic-gate int c;
245*0Sstevel@tonic-gate tnf_uint32_t *magicp;
246*0Sstevel@tonic-gate tnf_block_header_t *block_base, *blockp;
247*0Sstevel@tonic-gate BLOCK_STATUS *block_stat, *bsp;
248*0Sstevel@tonic-gate int block_num;
249*0Sstevel@tonic-gate boolean_t any_unread, any_different, retry;
250*0Sstevel@tonic-gate tnf_ref32_t *fwzone;
251*0Sstevel@tonic-gate int fwzonesize;
252*0Sstevel@tonic-gate int i;
253*0Sstevel@tonic-gate int fwtries;
254*0Sstevel@tonic-gate int block_count;
255*0Sstevel@tonic-gate
256*0Sstevel@tonic-gate program_name = argv[0];
257*0Sstevel@tonic-gate while ((c = getopt(argc, argv, optstr)) != EOF) {
258*0Sstevel@tonic-gate switch (c) {
259*0Sstevel@tonic-gate case 'd':
260*0Sstevel@tonic-gate dumpfile = optarg;
261*0Sstevel@tonic-gate break;
262*0Sstevel@tonic-gate case 'n':
263*0Sstevel@tonic-gate namelist = optarg;
264*0Sstevel@tonic-gate break;
265*0Sstevel@tonic-gate case '?':
266*0Sstevel@tonic-gate usage(argv, gettext("unrecognized argument"));
267*0Sstevel@tonic-gate }
268*0Sstevel@tonic-gate }
269*0Sstevel@tonic-gate if (optind != argc - 1) {
270*0Sstevel@tonic-gate usage(argv, gettext("too many or too few arguments"));
271*0Sstevel@tonic-gate } else {
272*0Sstevel@tonic-gate outfile = argv[optind];
273*0Sstevel@tonic-gate }
274*0Sstevel@tonic-gate if ((dumpfile != NULL) ^ (namelist != NULL)) {
275*0Sstevel@tonic-gate usage(argv, gettext("must specify both or neither of the "
276*0Sstevel@tonic-gate "-d and -n options"));
277*0Sstevel@tonic-gate }
278*0Sstevel@tonic-gate
279*0Sstevel@tonic-gate output_fd = open(outfile, O_WRONLY | O_CREAT | O_TRUNC, 0600);
280*0Sstevel@tonic-gate if (output_fd < 0) {
281*0Sstevel@tonic-gate perror(outfile);
282*0Sstevel@tonic-gate exit(1);
283*0Sstevel@tonic-gate }
284*0Sstevel@tonic-gate if (dumpfile != NULL)
285*0Sstevel@tonic-gate dumpfile_init();
286*0Sstevel@tonic-gate else
287*0Sstevel@tonic-gate live_kernel_init();
288*0Sstevel@tonic-gate
289*0Sstevel@tonic-gate if ((local_buf = malloc(tnf_bufsize)) == NULL) {
290*0Sstevel@tonic-gate (void) fprintf(stderr,
291*0Sstevel@tonic-gate gettext("tnfxtract memory allocation failure\n"));
292*0Sstevel@tonic-gate exit(1);
293*0Sstevel@tonic-gate }
294*0Sstevel@tonic-gate
295*0Sstevel@tonic-gate /* Read header, get block size, check for version mismatch */
296*0Sstevel@tonic-gate read_tnf_header(local_buf);
297*0Sstevel@tonic-gate /*LINTED pointer cast may result in improper alignment*/
298*0Sstevel@tonic-gate magicp = (tnf_uint32_t *) local_buf;
299*0Sstevel@tonic-gate /*LINTED pointer cast may result in improper alignment*/
300*0Sstevel@tonic-gate tnf_header = (tnf_file_header_t *)(local_buf + sizeof (*magicp));
301*0Sstevel@tonic-gate if (*magicp != TNF_MAGIC) {
302*0Sstevel@tonic-gate (void) fprintf(stderr, gettext(
303*0Sstevel@tonic-gate "Buffer is not in TNF format.\n"));
304*0Sstevel@tonic-gate exit(1);
305*0Sstevel@tonic-gate }
306*0Sstevel@tonic-gate if (tnf_header->file_version != TNF_FILE_VERSION) {
307*0Sstevel@tonic-gate (void) fprintf(stderr,
308*0Sstevel@tonic-gate gettext("Version mismatch (tnfxtract: %d; buffer: %d)\n"),
309*0Sstevel@tonic-gate TNF_FILE_VERSION, tnf_header->file_version);
310*0Sstevel@tonic-gate exit(1);
311*0Sstevel@tonic-gate }
312*0Sstevel@tonic-gate writeout(local_buf, 0, tnf_header->block_size);
313*0Sstevel@tonic-gate /* LINTED pointer cast may result in improper alignment */
314*0Sstevel@tonic-gate block_base = (tnf_block_header_t *)
315*0Sstevel@tonic-gate (local_buf + tnf_header->directory_size);
316*0Sstevel@tonic-gate block_count = tnf_header->block_count -
317*0Sstevel@tonic-gate tnf_header->directory_size / tnf_header->block_size;
318*0Sstevel@tonic-gate fwzonesize = tnf_header->directory_size - tnf_header->block_size;
319*0Sstevel@tonic-gate
320*0Sstevel@tonic-gate block_stat = (BLOCK_STATUS *)
321*0Sstevel@tonic-gate calloc(block_count, sizeof (BLOCK_STATUS));
322*0Sstevel@tonic-gate if (block_stat == NULL) {
323*0Sstevel@tonic-gate (void) fprintf(stderr,
324*0Sstevel@tonic-gate gettext("tnfxtract memory allocation failure\n"));
325*0Sstevel@tonic-gate exit(1);
326*0Sstevel@tonic-gate }
327*0Sstevel@tonic-gate
328*0Sstevel@tonic-gate for (bsp = block_stat; bsp != block_stat + block_count; ++bsp)
329*0Sstevel@tonic-gate bsp->ever_read = B_FALSE;
330*0Sstevel@tonic-gate /*
331*0Sstevel@tonic-gate * Make repeated passes until we've read every non-tag block.
332*0Sstevel@tonic-gate */
333*0Sstevel@tonic-gate do {
334*0Sstevel@tonic-gate any_unread = B_FALSE;
335*0Sstevel@tonic-gate bsp = block_stat;
336*0Sstevel@tonic-gate block_num = 0;
337*0Sstevel@tonic-gate blockp = block_base;
338*0Sstevel@tonic-gate while (block_num != block_count) {
339*0Sstevel@tonic-gate if (!bsp->ever_read) {
340*0Sstevel@tonic-gate if (read_tnf_block(blockp, block_num) != 0)
341*0Sstevel@tonic-gate any_unread = B_TRUE;
342*0Sstevel@tonic-gate else {
343*0Sstevel@tonic-gate bsp->ever_read = B_TRUE;
344*0Sstevel@tonic-gate bsp->generation = blockp->generation;
345*0Sstevel@tonic-gate bsp->bytes_valid = blockp->bytes_valid;
346*0Sstevel@tonic-gate writeout((char *) blockp,
347*0Sstevel@tonic-gate /* LINTED cast 64 to 32 bit */
348*0Sstevel@tonic-gate (int)((char *) blockp - local_buf),
349*0Sstevel@tonic-gate tnf_header->block_size);
350*0Sstevel@tonic-gate }
351*0Sstevel@tonic-gate }
352*0Sstevel@tonic-gate ++bsp;
353*0Sstevel@tonic-gate ++block_num;
354*0Sstevel@tonic-gate /* LINTED pointer cast may result in improper alignment */
355*0Sstevel@tonic-gate blockp = (tnf_block_header_t *)
356*0Sstevel@tonic-gate ((char *) blockp + tnf_header->block_size);
357*0Sstevel@tonic-gate }
358*0Sstevel@tonic-gate } while (any_unread);
359*0Sstevel@tonic-gate
360*0Sstevel@tonic-gate /*
361*0Sstevel@tonic-gate * Then read tag blocks only, until we have two consecutive,
362*0Sstevel@tonic-gate * consistent reads.
363*0Sstevel@tonic-gate */
364*0Sstevel@tonic-gate do {
365*0Sstevel@tonic-gate any_different = B_FALSE;
366*0Sstevel@tonic-gate bsp = block_stat;
367*0Sstevel@tonic-gate block_num = 0;
368*0Sstevel@tonic-gate blockp = block_base;
369*0Sstevel@tonic-gate while (block_num != block_count) {
370*0Sstevel@tonic-gate if (read_tnf_block(blockp, block_num) == 0 &&
371*0Sstevel@tonic-gate blockp->generation == TNF_TAG_GENERATION_NUM &&
372*0Sstevel@tonic-gate (bsp->generation != TNF_TAG_GENERATION_NUM ||
373*0Sstevel@tonic-gate bsp->bytes_valid != blockp->bytes_valid)) {
374*0Sstevel@tonic-gate bsp->generation = TNF_TAG_GENERATION_NUM;
375*0Sstevel@tonic-gate bsp->bytes_valid = blockp->bytes_valid;
376*0Sstevel@tonic-gate writeout((char *) blockp,
377*0Sstevel@tonic-gate /* LINTED cast 64bit to 32 bit */
378*0Sstevel@tonic-gate (int)((char *) blockp - local_buf),
379*0Sstevel@tonic-gate tnf_header->block_size);
380*0Sstevel@tonic-gate any_different = B_TRUE;
381*0Sstevel@tonic-gate }
382*0Sstevel@tonic-gate ++bsp;
383*0Sstevel@tonic-gate ++block_num;
384*0Sstevel@tonic-gate /* LINTED pointer cast may result in improper alignment */
385*0Sstevel@tonic-gate blockp = (tnf_block_header_t *)
386*0Sstevel@tonic-gate ((char *) blockp + tnf_header->block_size);
387*0Sstevel@tonic-gate }
388*0Sstevel@tonic-gate } while (any_different);
389*0Sstevel@tonic-gate
390*0Sstevel@tonic-gate /*
391*0Sstevel@tonic-gate * Then read the forwarding pointers. If any are -1:
392*0Sstevel@tonic-gate * sleep briefly, then make another pass.
393*0Sstevel@tonic-gate */
394*0Sstevel@tonic-gate /*LINTED pointer cast may result in improper alignment*/
395*0Sstevel@tonic-gate fwzone = (tnf_ref32_t *)(local_buf + tnf_header->block_size);
396*0Sstevel@tonic-gate
397*0Sstevel@tonic-gate read_tnf_fwzone(fwzone, 0,
398*0Sstevel@tonic-gate /* LINTED cast from 64-bit integer to 32-bit integer */
399*0Sstevel@tonic-gate (int)(fwzonesize / sizeof (fwzone[0])));
400*0Sstevel@tonic-gate fwtries = 0;
401*0Sstevel@tonic-gate while (fwtries != MAXFWTRY) {
402*0Sstevel@tonic-gate retry = B_FALSE;
403*0Sstevel@tonic-gate for (i = 0; i != fwzonesize / sizeof (fwzone[0]); ++i) {
404*0Sstevel@tonic-gate if (fwzone[i] == -1) {
405*0Sstevel@tonic-gate read_tnf_fwzone(&fwzone[i], i, 1);
406*0Sstevel@tonic-gate if (!retry) {
407*0Sstevel@tonic-gate retry = B_TRUE;
408*0Sstevel@tonic-gate ++fwtries;
409*0Sstevel@tonic-gate }
410*0Sstevel@tonic-gate }
411*0Sstevel@tonic-gate }
412*0Sstevel@tonic-gate if (!retry)
413*0Sstevel@tonic-gate break;
414*0Sstevel@tonic-gate sleep(2);
415*0Sstevel@tonic-gate }
416*0Sstevel@tonic-gate if (fwtries == MAXFWTRY) {
417*0Sstevel@tonic-gate (void) fprintf(stderr, gettext(
418*0Sstevel@tonic-gate "Warning: forwarding pointers may "
419*0Sstevel@tonic-gate "be invalid.\n"));
420*0Sstevel@tonic-gate }
421*0Sstevel@tonic-gate writeout((char *) fwzone, tnf_header->block_size, fwzonesize);
422*0Sstevel@tonic-gate return (0);
423*0Sstevel@tonic-gate }
424