1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3 * CDDL HEADER START
4 *
5 * The contents of this file are subject to the terms of the
6 * Common Development and Distribution License (the "License").
7 * 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 https://opensource.org/licenses/CDDL-1.0.
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
23 /*
24 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 *
27 * Portions Copyright 2012 Martin Matuska <martin@matuska.org>
28 */
29
30 /*
31 * Copyright (c) 2013, 2015 by Delphix. All rights reserved.
32 */
33
34 #include <ctype.h>
35 #include <libnvpair.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include <unistd.h>
40 #include <stddef.h>
41
42 #include <sys/dmu.h>
43 #include <sys/zfs_ioctl.h>
44 #include <sys/zio.h>
45 #include <zfs_fletcher.h>
46 #include "zstream.h"
47 #include "zstream_util.h"
48
49 /*
50 * If dump mode is enabled, the number of bytes to print per line
51 */
52 #define BYTES_PER_LINE 16
53 /*
54 * If dump mode is enabled, the number of bytes to group together, separated
55 * by newlines or spaces
56 */
57 #define DUMP_GROUPING 4
58
59 static uint64_t total_stream_len = 0;
60 static FILE *send_stream = 0;
61 static boolean_t do_byteswap = B_FALSE;
62 static boolean_t do_cksum = B_TRUE;
63
64 /*
65 * ssread - send stream read.
66 *
67 * Read while computing incremental checksum
68 */
69 static size_t
ssread(void * buf,size_t len,zio_cksum_t * cksum)70 ssread(void *buf, size_t len, zio_cksum_t *cksum)
71 {
72 size_t outlen;
73
74 if ((outlen = fread(buf, len, 1, send_stream)) == 0)
75 return (0);
76
77 if (do_cksum) {
78 if (do_byteswap)
79 fletcher_4_incremental_byteswap(buf, len, cksum);
80 else
81 fletcher_4_incremental_native(buf, len, cksum);
82 }
83 total_stream_len += len;
84 return (outlen);
85 }
86
87 static size_t
read_hdr(dmu_replay_record_t * drr,zio_cksum_t * cksum)88 read_hdr(dmu_replay_record_t *drr, zio_cksum_t *cksum)
89 {
90 ASSERT3U(offsetof(dmu_replay_record_t, drr_u.drr_checksum.drr_checksum),
91 ==, sizeof (dmu_replay_record_t) - sizeof (zio_cksum_t));
92 size_t r = ssread(drr, sizeof (*drr) - sizeof (zio_cksum_t), cksum);
93 if (r == 0)
94 return (0);
95 zio_cksum_t saved_cksum = *cksum;
96 r = ssread(&drr->drr_u.drr_checksum.drr_checksum,
97 sizeof (zio_cksum_t), cksum);
98 if (r == 0)
99 return (0);
100 if (do_cksum &&
101 !ZIO_CHECKSUM_IS_ZERO(&drr->drr_u.drr_checksum.drr_checksum) &&
102 !ZIO_CHECKSUM_EQUAL(saved_cksum,
103 drr->drr_u.drr_checksum.drr_checksum)) {
104 fprintf(stderr, "invalid checksum\n");
105 (void) printf("Incorrect checksum in record header.\n");
106 (void) printf("Expected checksum = %llx/%llx/%llx/%llx\n",
107 (longlong_t)saved_cksum.zc_word[0],
108 (longlong_t)saved_cksum.zc_word[1],
109 (longlong_t)saved_cksum.zc_word[2],
110 (longlong_t)saved_cksum.zc_word[3]);
111 return (0);
112 }
113 return (sizeof (*drr));
114 }
115
116 /*
117 * Print part of a block in ASCII characters
118 */
119 static void
print_ascii_block(char * subbuf,int length)120 print_ascii_block(char *subbuf, int length)
121 {
122 int i;
123
124 for (i = 0; i < length; i++) {
125 char char_print = isprint(subbuf[i]) ? subbuf[i] : '.';
126 if (i != 0 && i % DUMP_GROUPING == 0) {
127 (void) printf(" ");
128 }
129 (void) printf("%c", char_print);
130 }
131 (void) printf("\n");
132 }
133
134 /*
135 * print_block - Dump the contents of a modified block to STDOUT
136 *
137 * Assume that buf has capacity evenly divisible by BYTES_PER_LINE
138 */
139 static void
print_block(char * buf,int length)140 print_block(char *buf, int length)
141 {
142 int i;
143 /*
144 * Start printing ASCII characters at a constant offset, after
145 * the hex prints. Leave 3 characters per byte on a line (2 digit
146 * hex number plus 1 space) plus spaces between characters and
147 * groupings.
148 */
149 int ascii_start = BYTES_PER_LINE * 3 +
150 BYTES_PER_LINE / DUMP_GROUPING + 2;
151
152 for (i = 0; i < length; i += BYTES_PER_LINE) {
153 int j;
154 int this_line_length = MIN(BYTES_PER_LINE, length - i);
155 int print_offset = 0;
156
157 for (j = 0; j < this_line_length; j++) {
158 int buf_offset = i + j;
159
160 /*
161 * Separate every DUMP_GROUPING bytes by a space.
162 */
163 if (buf_offset % DUMP_GROUPING == 0) {
164 print_offset += printf(" ");
165 }
166
167 /*
168 * Print the two-digit hex value for this byte.
169 */
170 unsigned char hex_print = buf[buf_offset];
171 print_offset += printf("%02x ", hex_print);
172 }
173
174 (void) printf("%*s", ascii_start - print_offset, " ");
175
176 print_ascii_block(buf + i, this_line_length);
177 }
178 }
179
180 /*
181 * Print an array of bytes to stdout as hexadecimal characters. str must
182 * have buf_len * 2 + 1 bytes of space.
183 */
184 static void
sprintf_bytes(char * str,uint8_t * buf,uint_t buf_len)185 sprintf_bytes(char *str, uint8_t *buf, uint_t buf_len)
186 {
187 int i, n;
188
189 for (i = 0; i < buf_len; i++) {
190 n = sprintf(str, "%02x", buf[i] & 0xff);
191 str += n;
192 }
193
194 str[0] = '\0';
195 }
196
197 int
zstream_do_dump(int argc,char * argv[])198 zstream_do_dump(int argc, char *argv[])
199 {
200 char *buf = safe_malloc(SPA_MAXBLOCKSIZE);
201 uint64_t drr_record_count[DRR_NUMTYPES] = { 0 };
202 uint64_t total_payload_size = 0;
203 uint64_t total_overhead_size = 0;
204 uint64_t drr_byte_count[DRR_NUMTYPES] = { 0 };
205 char salt[ZIO_DATA_SALT_LEN * 2 + 1];
206 char iv[ZIO_DATA_IV_LEN * 2 + 1];
207 char mac[ZIO_DATA_MAC_LEN * 2 + 1];
208 uint64_t total_records = 0;
209 uint64_t payload_size;
210 dmu_replay_record_t thedrr;
211 dmu_replay_record_t *drr = &thedrr;
212 struct drr_begin *drrb = &thedrr.drr_u.drr_begin;
213 struct drr_end *drre = &thedrr.drr_u.drr_end;
214 struct drr_object *drro = &thedrr.drr_u.drr_object;
215 struct drr_freeobjects *drrfo = &thedrr.drr_u.drr_freeobjects;
216 struct drr_write *drrw = &thedrr.drr_u.drr_write;
217 struct drr_write_byref *drrwbr = &thedrr.drr_u.drr_write_byref;
218 struct drr_free *drrf = &thedrr.drr_u.drr_free;
219 struct drr_spill *drrs = &thedrr.drr_u.drr_spill;
220 struct drr_write_embedded *drrwe = &thedrr.drr_u.drr_write_embedded;
221 struct drr_object_range *drror = &thedrr.drr_u.drr_object_range;
222 struct drr_redact *drrr = &thedrr.drr_u.drr_redact;
223 struct drr_checksum *drrc = &thedrr.drr_u.drr_checksum;
224 int c;
225 boolean_t verbose = B_FALSE;
226 boolean_t very_verbose = B_FALSE;
227 boolean_t first = B_TRUE;
228 /*
229 * dump flag controls whether the contents of any modified data blocks
230 * are printed to the console during processing of the stream. Warning:
231 * for large streams, this can obviously lead to massive prints.
232 */
233 boolean_t dump = B_FALSE;
234 int err;
235 zio_cksum_t zc = { { 0 } };
236 zio_cksum_t pcksum = { { 0 } };
237
238 while ((c = getopt(argc, argv, ":vCd")) != -1) {
239 switch (c) {
240 case 'C':
241 do_cksum = B_FALSE;
242 break;
243 case 'v':
244 if (verbose)
245 very_verbose = B_TRUE;
246 verbose = B_TRUE;
247 break;
248 case 'd':
249 dump = B_TRUE;
250 verbose = B_TRUE;
251 very_verbose = B_TRUE;
252 break;
253 case ':':
254 (void) fprintf(stderr,
255 "missing argument for '%c' option\n", optopt);
256 zstream_usage();
257 break;
258 case '?':
259 (void) fprintf(stderr, "invalid option '%c'\n",
260 optopt);
261 zstream_usage();
262 break;
263 }
264 }
265
266 if (argc > optind) {
267 const char *filename = argv[optind];
268 send_stream = fopen(filename, "r");
269 if (send_stream == NULL) {
270 (void) fprintf(stderr,
271 "Error while opening file '%s': %s\n",
272 filename, strerror(errno));
273 exit(1);
274 }
275 } else {
276 if (isatty(STDIN_FILENO)) {
277 (void) fprintf(stderr,
278 "Error: The send stream is a binary format "
279 "and can not be read from a\n"
280 "terminal. Standard input must be redirected, "
281 "or a file must be\n"
282 "specified as a command-line argument.\n");
283 exit(1);
284 }
285 send_stream = stdin;
286 }
287
288 fletcher_4_init();
289 while (read_hdr(drr, &zc)) {
290 uint64_t featureflags = 0;
291
292 /*
293 * If this is the first DMU record being processed, check for
294 * the magic bytes and figure out the endian-ness based on them.
295 */
296 if (first) {
297 if (drrb->drr_magic == BSWAP_64(DMU_BACKUP_MAGIC)) {
298 do_byteswap = B_TRUE;
299 if (do_cksum) {
300 ZIO_SET_CHECKSUM(&zc, 0, 0, 0, 0);
301 /*
302 * recalculate header checksum now
303 * that we know it needs to be
304 * byteswapped.
305 */
306 fletcher_4_incremental_byteswap(drr,
307 sizeof (dmu_replay_record_t), &zc);
308 }
309 } else if (drrb->drr_magic != DMU_BACKUP_MAGIC) {
310 (void) fprintf(stderr, "Invalid stream "
311 "(bad magic number)\n");
312 exit(1);
313 }
314 first = B_FALSE;
315 }
316 if (do_byteswap) {
317 drr->drr_type = BSWAP_32(drr->drr_type);
318 drr->drr_payloadlen =
319 BSWAP_32(drr->drr_payloadlen);
320 }
321
322 /*
323 * At this point, the leading fields of the replay record
324 * (drr_type and drr_payloadlen) have been byte-swapped if
325 * necessary, but the rest of the data structure (the
326 * union of type-specific structures) is still in its
327 * original state.
328 */
329 if (drr->drr_type >= DRR_NUMTYPES) {
330 (void) printf("INVALID record found: type 0x%x\n",
331 drr->drr_type);
332 (void) printf("Aborting.\n");
333 exit(1);
334 }
335
336 drr_record_count[drr->drr_type]++;
337 total_overhead_size += sizeof (*drr);
338 total_records++;
339 payload_size = 0;
340
341 switch (drr->drr_type) {
342 case DRR_BEGIN:
343 if (do_byteswap) {
344 drrb->drr_magic = BSWAP_64(drrb->drr_magic);
345 drrb->drr_versioninfo =
346 BSWAP_64(drrb->drr_versioninfo);
347 drrb->drr_creation_time =
348 BSWAP_64(drrb->drr_creation_time);
349 drrb->drr_type = BSWAP_32(drrb->drr_type);
350 drrb->drr_flags = BSWAP_32(drrb->drr_flags);
351 drrb->drr_toguid = BSWAP_64(drrb->drr_toguid);
352 drrb->drr_fromguid =
353 BSWAP_64(drrb->drr_fromguid);
354 }
355
356 (void) printf("BEGIN record\n");
357 (void) printf("\thdrtype = %lld\n",
358 DMU_GET_STREAM_HDRTYPE(drrb->drr_versioninfo));
359 (void) printf("\tfeatures = %llx\n",
360 DMU_GET_FEATUREFLAGS(drrb->drr_versioninfo));
361 (void) printf("\tmagic = %llx\n",
362 (u_longlong_t)drrb->drr_magic);
363 (void) printf("\tcreation_time = %llx\n",
364 (u_longlong_t)drrb->drr_creation_time);
365 (void) printf("\ttype = %u\n", drrb->drr_type);
366 (void) printf("\tflags = 0x%x\n", drrb->drr_flags);
367 (void) printf("\ttoguid = %llx\n",
368 (u_longlong_t)drrb->drr_toguid);
369 (void) printf("\tfromguid = %llx\n",
370 (u_longlong_t)drrb->drr_fromguid);
371 (void) printf("\ttoname = %s\n", drrb->drr_toname);
372 (void) printf("\tpayloadlen = %u\n",
373 drr->drr_payloadlen);
374 if (verbose)
375 (void) printf("\n");
376
377 if (drr->drr_payloadlen != 0) {
378 nvlist_t *nv;
379 int sz = drr->drr_payloadlen;
380
381 if (sz > SPA_MAXBLOCKSIZE) {
382 free(buf);
383 buf = safe_malloc(sz);
384 }
385 (void) ssread(buf, sz, &zc);
386 if (ferror(send_stream))
387 perror("fread");
388 err = nvlist_unpack(buf, sz, &nv, 0);
389 if (err) {
390 perror(strerror(err));
391 } else {
392 nvlist_print(stdout, nv);
393 nvlist_free(nv);
394 }
395 payload_size = sz;
396 }
397 break;
398
399 case DRR_END:
400 if (do_byteswap) {
401 drre->drr_checksum.zc_word[0] =
402 BSWAP_64(drre->drr_checksum.zc_word[0]);
403 drre->drr_checksum.zc_word[1] =
404 BSWAP_64(drre->drr_checksum.zc_word[1]);
405 drre->drr_checksum.zc_word[2] =
406 BSWAP_64(drre->drr_checksum.zc_word[2]);
407 drre->drr_checksum.zc_word[3] =
408 BSWAP_64(drre->drr_checksum.zc_word[3]);
409 }
410 /*
411 * We compare against the *previous* checksum
412 * value, because the stored checksum is of
413 * everything before the DRR_END record.
414 */
415 if (do_cksum && !ZIO_CHECKSUM_EQUAL(drre->drr_checksum,
416 pcksum)) {
417 (void) printf("Expected checksum differs from "
418 "checksum in stream.\n");
419 (void) printf("Expected checksum = "
420 "%llx/%llx/%llx/%llx\n",
421 (long long unsigned int)pcksum.zc_word[0],
422 (long long unsigned int)pcksum.zc_word[1],
423 (long long unsigned int)pcksum.zc_word[2],
424 (long long unsigned int)pcksum.zc_word[3]);
425 }
426 (void) printf("END checksum = %llx/%llx/%llx/%llx\n",
427 (long long unsigned int)
428 drre->drr_checksum.zc_word[0],
429 (long long unsigned int)
430 drre->drr_checksum.zc_word[1],
431 (long long unsigned int)
432 drre->drr_checksum.zc_word[2],
433 (long long unsigned int)
434 drre->drr_checksum.zc_word[3]);
435
436 ZIO_SET_CHECKSUM(&zc, 0, 0, 0, 0);
437 break;
438
439 case DRR_OBJECT:
440 if (do_byteswap) {
441 drro->drr_object = BSWAP_64(drro->drr_object);
442 drro->drr_type = BSWAP_32(drro->drr_type);
443 drro->drr_bonustype =
444 BSWAP_32(drro->drr_bonustype);
445 drro->drr_blksz = BSWAP_32(drro->drr_blksz);
446 drro->drr_bonuslen =
447 BSWAP_32(drro->drr_bonuslen);
448 drro->drr_raw_bonuslen =
449 BSWAP_32(drro->drr_raw_bonuslen);
450 drro->drr_toguid = BSWAP_64(drro->drr_toguid);
451 drro->drr_maxblkid =
452 BSWAP_64(drro->drr_maxblkid);
453 }
454
455 featureflags =
456 DMU_GET_FEATUREFLAGS(drrb->drr_versioninfo);
457
458 if (featureflags & DMU_BACKUP_FEATURE_RAW &&
459 drro->drr_bonuslen > drro->drr_raw_bonuslen) {
460 (void) fprintf(stderr,
461 "Warning: Object %llu has bonuslen = "
462 "%u > raw_bonuslen = %u\n\n",
463 (u_longlong_t)drro->drr_object,
464 drro->drr_bonuslen, drro->drr_raw_bonuslen);
465 }
466
467 payload_size = DRR_OBJECT_PAYLOAD_SIZE(drro);
468
469 if (verbose) {
470 (void) printf("OBJECT object = %llu type = %u "
471 "bonustype = %u blksz = %u bonuslen = %u "
472 "dn_slots = %u raw_bonuslen = %u "
473 "flags = %u maxblkid = %llu "
474 "indblkshift = %u nlevels = %u "
475 "nblkptr = %u\n",
476 (u_longlong_t)drro->drr_object,
477 drro->drr_type,
478 drro->drr_bonustype,
479 drro->drr_blksz,
480 drro->drr_bonuslen,
481 drro->drr_dn_slots,
482 drro->drr_raw_bonuslen,
483 drro->drr_flags,
484 (u_longlong_t)drro->drr_maxblkid,
485 drro->drr_indblkshift,
486 drro->drr_nlevels,
487 drro->drr_nblkptr);
488 }
489 if (drro->drr_bonuslen > 0) {
490 (void) ssread(buf, payload_size, &zc);
491 if (dump)
492 print_block(buf, payload_size);
493 }
494 break;
495
496 case DRR_FREEOBJECTS:
497 if (do_byteswap) {
498 drrfo->drr_firstobj =
499 BSWAP_64(drrfo->drr_firstobj);
500 drrfo->drr_numobjs =
501 BSWAP_64(drrfo->drr_numobjs);
502 drrfo->drr_toguid = BSWAP_64(drrfo->drr_toguid);
503 }
504 if (verbose) {
505 (void) printf("FREEOBJECTS firstobj = %llu "
506 "numobjs = %llu\n",
507 (u_longlong_t)drrfo->drr_firstobj,
508 (u_longlong_t)drrfo->drr_numobjs);
509 }
510 break;
511
512 case DRR_WRITE:
513 if (do_byteswap) {
514 drrw->drr_object = BSWAP_64(drrw->drr_object);
515 drrw->drr_type = BSWAP_32(drrw->drr_type);
516 drrw->drr_offset = BSWAP_64(drrw->drr_offset);
517 drrw->drr_logical_size =
518 BSWAP_64(drrw->drr_logical_size);
519 drrw->drr_toguid = BSWAP_64(drrw->drr_toguid);
520 drrw->drr_key.ddk_prop =
521 BSWAP_64(drrw->drr_key.ddk_prop);
522 drrw->drr_compressed_size =
523 BSWAP_64(drrw->drr_compressed_size);
524 }
525
526 payload_size = DRR_WRITE_PAYLOAD_SIZE(drrw);
527
528 /*
529 * If this is verbose and/or dump output,
530 * print info on the modified block
531 */
532 if (verbose) {
533 sprintf_bytes(salt, drrw->drr_salt,
534 ZIO_DATA_SALT_LEN);
535 sprintf_bytes(iv, drrw->drr_iv,
536 ZIO_DATA_IV_LEN);
537 sprintf_bytes(mac, drrw->drr_mac,
538 ZIO_DATA_MAC_LEN);
539
540 (void) printf("WRITE object = %llu type = %u "
541 "checksum type = %u compression type = %u "
542 "flags = %u offset = %llu "
543 "logical_size = %llu "
544 "compressed_size = %llu "
545 "payload_size = %llu props = %llx "
546 "salt = %s iv = %s mac = %s\n",
547 (u_longlong_t)drrw->drr_object,
548 drrw->drr_type,
549 drrw->drr_checksumtype,
550 drrw->drr_compressiontype,
551 drrw->drr_flags,
552 (u_longlong_t)drrw->drr_offset,
553 (u_longlong_t)drrw->drr_logical_size,
554 (u_longlong_t)drrw->drr_compressed_size,
555 (u_longlong_t)payload_size,
556 (u_longlong_t)drrw->drr_key.ddk_prop,
557 salt,
558 iv,
559 mac);
560 }
561
562 /*
563 * Read the contents of the block in from STDIN to buf
564 */
565 (void) ssread(buf, payload_size, &zc);
566 /*
567 * If in dump mode
568 */
569 if (dump) {
570 print_block(buf, payload_size);
571 }
572 break;
573
574 case DRR_WRITE_BYREF:
575 if (do_byteswap) {
576 drrwbr->drr_object =
577 BSWAP_64(drrwbr->drr_object);
578 drrwbr->drr_offset =
579 BSWAP_64(drrwbr->drr_offset);
580 drrwbr->drr_length =
581 BSWAP_64(drrwbr->drr_length);
582 drrwbr->drr_toguid =
583 BSWAP_64(drrwbr->drr_toguid);
584 drrwbr->drr_refguid =
585 BSWAP_64(drrwbr->drr_refguid);
586 drrwbr->drr_refobject =
587 BSWAP_64(drrwbr->drr_refobject);
588 drrwbr->drr_refoffset =
589 BSWAP_64(drrwbr->drr_refoffset);
590 drrwbr->drr_key.ddk_prop =
591 BSWAP_64(drrwbr->drr_key.ddk_prop);
592 }
593 if (verbose) {
594 (void) printf("WRITE_BYREF object = %llu "
595 "checksum type = %u props = %llx "
596 "offset = %llu length = %llu "
597 "toguid = %llx refguid = %llx "
598 "refobject = %llu refoffset = %llu\n",
599 (u_longlong_t)drrwbr->drr_object,
600 drrwbr->drr_checksumtype,
601 (u_longlong_t)drrwbr->drr_key.ddk_prop,
602 (u_longlong_t)drrwbr->drr_offset,
603 (u_longlong_t)drrwbr->drr_length,
604 (u_longlong_t)drrwbr->drr_toguid,
605 (u_longlong_t)drrwbr->drr_refguid,
606 (u_longlong_t)drrwbr->drr_refobject,
607 (u_longlong_t)drrwbr->drr_refoffset);
608 }
609 break;
610
611 case DRR_FREE:
612 if (do_byteswap) {
613 drrf->drr_object = BSWAP_64(drrf->drr_object);
614 drrf->drr_offset = BSWAP_64(drrf->drr_offset);
615 drrf->drr_length = BSWAP_64(drrf->drr_length);
616 }
617 if (verbose) {
618 (void) printf("FREE object = %llu "
619 "offset = %llu length = %lld\n",
620 (u_longlong_t)drrf->drr_object,
621 (u_longlong_t)drrf->drr_offset,
622 (longlong_t)drrf->drr_length);
623 }
624 break;
625 case DRR_SPILL:
626 if (do_byteswap) {
627 drrs->drr_object = BSWAP_64(drrs->drr_object);
628 drrs->drr_length = BSWAP_64(drrs->drr_length);
629 drrs->drr_compressed_size =
630 BSWAP_64(drrs->drr_compressed_size);
631 drrs->drr_type = BSWAP_32(drrs->drr_type);
632 }
633
634 payload_size = DRR_SPILL_PAYLOAD_SIZE(drrs);
635
636 if (verbose) {
637 sprintf_bytes(salt, drrs->drr_salt,
638 ZIO_DATA_SALT_LEN);
639 sprintf_bytes(iv, drrs->drr_iv,
640 ZIO_DATA_IV_LEN);
641 sprintf_bytes(mac, drrs->drr_mac,
642 ZIO_DATA_MAC_LEN);
643
644 (void) printf("SPILL block for object = %llu "
645 "length = %llu flags = %u "
646 "compression type = %u "
647 "compressed_size = %llu "
648 "payload_size = %llu "
649 "salt = %s iv = %s mac = %s\n",
650 (u_longlong_t)drrs->drr_object,
651 (u_longlong_t)drrs->drr_length,
652 drrs->drr_flags,
653 drrs->drr_compressiontype,
654 (u_longlong_t)drrs->drr_compressed_size,
655 (u_longlong_t)payload_size,
656 salt,
657 iv,
658 mac);
659 }
660 (void) ssread(buf, payload_size, &zc);
661 if (dump) {
662 print_block(buf, payload_size);
663 }
664 break;
665 case DRR_WRITE_EMBEDDED:
666 if (do_byteswap) {
667 drrwe->drr_object =
668 BSWAP_64(drrwe->drr_object);
669 drrwe->drr_offset =
670 BSWAP_64(drrwe->drr_offset);
671 drrwe->drr_length =
672 BSWAP_64(drrwe->drr_length);
673 drrwe->drr_toguid =
674 BSWAP_64(drrwe->drr_toguid);
675 drrwe->drr_lsize =
676 BSWAP_32(drrwe->drr_lsize);
677 drrwe->drr_psize =
678 BSWAP_32(drrwe->drr_psize);
679 }
680 if (verbose) {
681 (void) printf("WRITE_EMBEDDED object = %llu "
682 "offset = %llu length = %llu "
683 "toguid = %llx comp = %u etype = %u "
684 "lsize = %u psize = %u\n",
685 (u_longlong_t)drrwe->drr_object,
686 (u_longlong_t)drrwe->drr_offset,
687 (u_longlong_t)drrwe->drr_length,
688 (u_longlong_t)drrwe->drr_toguid,
689 drrwe->drr_compression,
690 drrwe->drr_etype,
691 drrwe->drr_lsize,
692 drrwe->drr_psize);
693 }
694 (void) ssread(buf,
695 P2ROUNDUP(drrwe->drr_psize, 8), &zc);
696 if (dump) {
697 print_block(buf,
698 P2ROUNDUP(drrwe->drr_psize, 8));
699 }
700 payload_size = P2ROUNDUP(drrwe->drr_psize, 8);
701 break;
702 case DRR_OBJECT_RANGE:
703 if (do_byteswap) {
704 drror->drr_firstobj =
705 BSWAP_64(drror->drr_firstobj);
706 drror->drr_numslots =
707 BSWAP_64(drror->drr_numslots);
708 drror->drr_toguid = BSWAP_64(drror->drr_toguid);
709 }
710 if (verbose) {
711 sprintf_bytes(salt, drror->drr_salt,
712 ZIO_DATA_SALT_LEN);
713 sprintf_bytes(iv, drror->drr_iv,
714 ZIO_DATA_IV_LEN);
715 sprintf_bytes(mac, drror->drr_mac,
716 ZIO_DATA_MAC_LEN);
717
718 (void) printf("OBJECT_RANGE firstobj = %llu "
719 "numslots = %llu flags = %u "
720 "salt = %s iv = %s mac = %s\n",
721 (u_longlong_t)drror->drr_firstobj,
722 (u_longlong_t)drror->drr_numslots,
723 drror->drr_flags,
724 salt,
725 iv,
726 mac);
727 }
728 break;
729 case DRR_REDACT:
730 if (do_byteswap) {
731 drrr->drr_object = BSWAP_64(drrr->drr_object);
732 drrr->drr_offset = BSWAP_64(drrr->drr_offset);
733 drrr->drr_length = BSWAP_64(drrr->drr_length);
734 drrr->drr_toguid = BSWAP_64(drrr->drr_toguid);
735 }
736 if (verbose) {
737 (void) printf("REDACT object = %llu offset = "
738 "%llu length = %llu\n",
739 (u_longlong_t)drrr->drr_object,
740 (u_longlong_t)drrr->drr_offset,
741 (u_longlong_t)drrr->drr_length);
742 }
743 break;
744 case DRR_NUMTYPES:
745 /* should never be reached */
746 exit(1);
747 }
748 if (drr->drr_type != DRR_BEGIN && very_verbose) {
749 (void) printf(" checksum = %llx/%llx/%llx/%llx\n",
750 (longlong_t)drrc->drr_checksum.zc_word[0],
751 (longlong_t)drrc->drr_checksum.zc_word[1],
752 (longlong_t)drrc->drr_checksum.zc_word[2],
753 (longlong_t)drrc->drr_checksum.zc_word[3]);
754 }
755 pcksum = zc;
756 drr_byte_count[drr->drr_type] += payload_size;
757 total_payload_size += payload_size;
758 }
759 free(buf);
760 fletcher_4_fini();
761
762 /* Print final summary */
763
764 (void) printf("SUMMARY:\n");
765 (void) printf("\tTotal DRR_BEGIN records = %lld (%llu bytes)\n",
766 (u_longlong_t)drr_record_count[DRR_BEGIN],
767 (u_longlong_t)drr_byte_count[DRR_BEGIN]);
768 (void) printf("\tTotal DRR_END records = %lld (%llu bytes)\n",
769 (u_longlong_t)drr_record_count[DRR_END],
770 (u_longlong_t)drr_byte_count[DRR_END]);
771 (void) printf("\tTotal DRR_OBJECT records = %lld (%llu bytes)\n",
772 (u_longlong_t)drr_record_count[DRR_OBJECT],
773 (u_longlong_t)drr_byte_count[DRR_OBJECT]);
774 (void) printf("\tTotal DRR_FREEOBJECTS records = %lld (%llu bytes)\n",
775 (u_longlong_t)drr_record_count[DRR_FREEOBJECTS],
776 (u_longlong_t)drr_byte_count[DRR_FREEOBJECTS]);
777 (void) printf("\tTotal DRR_WRITE records = %lld (%llu bytes)\n",
778 (u_longlong_t)drr_record_count[DRR_WRITE],
779 (u_longlong_t)drr_byte_count[DRR_WRITE]);
780 (void) printf("\tTotal DRR_WRITE_BYREF records = %lld (%llu bytes)\n",
781 (u_longlong_t)drr_record_count[DRR_WRITE_BYREF],
782 (u_longlong_t)drr_byte_count[DRR_WRITE_BYREF]);
783 (void) printf("\tTotal DRR_WRITE_EMBEDDED records = %lld (%llu "
784 "bytes)\n", (u_longlong_t)drr_record_count[DRR_WRITE_EMBEDDED],
785 (u_longlong_t)drr_byte_count[DRR_WRITE_EMBEDDED]);
786 (void) printf("\tTotal DRR_FREE records = %lld (%llu bytes)\n",
787 (u_longlong_t)drr_record_count[DRR_FREE],
788 (u_longlong_t)drr_byte_count[DRR_FREE]);
789 (void) printf("\tTotal DRR_SPILL records = %lld (%llu bytes)\n",
790 (u_longlong_t)drr_record_count[DRR_SPILL],
791 (u_longlong_t)drr_byte_count[DRR_SPILL]);
792 (void) printf("\tTotal records = %lld\n",
793 (u_longlong_t)total_records);
794 (void) printf("\tTotal payload size = %lld (0x%llx)\n",
795 (u_longlong_t)total_payload_size, (u_longlong_t)total_payload_size);
796 (void) printf("\tTotal header overhead = %lld (0x%llx)\n",
797 (u_longlong_t)total_overhead_size,
798 (u_longlong_t)total_overhead_size);
799 (void) printf("\tTotal stream length = %lld (0x%llx)\n",
800 (u_longlong_t)total_stream_len, (u_longlong_t)total_stream_len);
801 return (0);
802 }
803