1495db6fbSLori Alt /*
2495db6fbSLori Alt * CDDL HEADER START
3495db6fbSLori Alt *
4495db6fbSLori Alt * The contents of this file are subject to the terms of the
5495db6fbSLori Alt * Common Development and Distribution License (the "License").
6495db6fbSLori Alt * You may not use this file except in compliance with the License.
7495db6fbSLori Alt *
8495db6fbSLori Alt * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9495db6fbSLori Alt * or http://www.opensolaris.org/os/licensing.
10495db6fbSLori Alt * See the License for the specific language governing permissions
11495db6fbSLori Alt * and limitations under the License.
12495db6fbSLori Alt *
13495db6fbSLori Alt * When distributing Covered Code, include this CDDL HEADER in each
14495db6fbSLori Alt * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15495db6fbSLori Alt * If applicable, add the following below this CDDL HEADER, with the
16495db6fbSLori Alt * fields enclosed by brackets "[]" replaced with your own identifying
17495db6fbSLori Alt * information: Portions Copyright [yyyy] [name of copyright owner]
18495db6fbSLori Alt *
19495db6fbSLori Alt * CDDL HEADER END
20495db6fbSLori Alt */
21495db6fbSLori Alt
22495db6fbSLori Alt /*
230a586ceaSMark Shellenbaum * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24495db6fbSLori Alt * Use is subject to license terms.
25495db6fbSLori Alt */
26495db6fbSLori Alt
27994fb6b8SMax Grossman /*
2898110f08SMatthew Ahrens * Copyright (c) 2013, 2014 by Delphix. All rights reserved.
29*c3d26abcSMatthew Ahrens * Copyright (c) 2014 Integros [integros.com]
30994fb6b8SMax Grossman */
31994fb6b8SMax Grossman
32994fb6b8SMax Grossman #include <ctype.h>
33495db6fbSLori Alt #include <libnvpair.h>
34495db6fbSLori Alt #include <stdio.h>
35495db6fbSLori Alt #include <stdlib.h>
36495db6fbSLori Alt #include <strings.h>
37495db6fbSLori Alt #include <unistd.h>
3898110f08SMatthew Ahrens #include <stddef.h>
39495db6fbSLori Alt
40495db6fbSLori Alt #include <sys/dmu.h>
41495db6fbSLori Alt #include <sys/zfs_ioctl.h>
42495db6fbSLori Alt #include <zfs_fletcher.h>
43495db6fbSLori Alt
44994fb6b8SMax Grossman /*
45994fb6b8SMax Grossman * If dump mode is enabled, the number of bytes to print per line
46994fb6b8SMax Grossman */
47994fb6b8SMax Grossman #define BYTES_PER_LINE 16
48994fb6b8SMax Grossman /*
49994fb6b8SMax Grossman * If dump mode is enabled, the number of bytes to group together, separated
50994fb6b8SMax Grossman * by newlines or spaces
51994fb6b8SMax Grossman */
52994fb6b8SMax Grossman #define DUMP_GROUPING 4
53994fb6b8SMax Grossman
54495db6fbSLori Alt uint64_t total_write_size = 0;
55495db6fbSLori Alt uint64_t total_stream_len = 0;
56495db6fbSLori Alt FILE *send_stream = 0;
57495db6fbSLori Alt boolean_t do_byteswap = B_FALSE;
58495db6fbSLori Alt boolean_t do_cksum = B_TRUE;
59495db6fbSLori Alt
60495db6fbSLori Alt static void
usage(void)61495db6fbSLori Alt usage(void)
62495db6fbSLori Alt {
63994fb6b8SMax Grossman (void) fprintf(stderr, "usage: zstreamdump [-v] [-C] [-d] < file\n");
64495db6fbSLori Alt (void) fprintf(stderr, "\t -v -- verbose\n");
65495db6fbSLori Alt (void) fprintf(stderr, "\t -C -- suppress checksum verification\n");
66994fb6b8SMax Grossman (void) fprintf(stderr, "\t -d -- dump contents of blocks modified, "
67994fb6b8SMax Grossman "implies verbose\n");
68495db6fbSLori Alt exit(1);
69495db6fbSLori Alt }
70495db6fbSLori Alt
71b5152584SMatthew Ahrens static void *
safe_malloc(size_t size)72b5152584SMatthew Ahrens safe_malloc(size_t size)
73b5152584SMatthew Ahrens {
74b5152584SMatthew Ahrens void *rv = malloc(size);
75b5152584SMatthew Ahrens if (rv == NULL) {
76b5152584SMatthew Ahrens (void) fprintf(stderr, "ERROR; failed to allocate %zu bytes\n",
77b5152584SMatthew Ahrens size);
78b5152584SMatthew Ahrens abort();
79b5152584SMatthew Ahrens }
80b5152584SMatthew Ahrens return (rv);
81b5152584SMatthew Ahrens }
82b5152584SMatthew Ahrens
83495db6fbSLori Alt /*
84495db6fbSLori Alt * ssread - send stream read.
85495db6fbSLori Alt *
86495db6fbSLori Alt * Read while computing incremental checksum
87495db6fbSLori Alt */
88495db6fbSLori Alt static size_t
ssread(void * buf,size_t len,zio_cksum_t * cksum)89495db6fbSLori Alt ssread(void *buf, size_t len, zio_cksum_t *cksum)
90495db6fbSLori Alt {
91495db6fbSLori Alt size_t outlen;
92495db6fbSLori Alt
93495db6fbSLori Alt if ((outlen = fread(buf, len, 1, send_stream)) == 0)
94495db6fbSLori Alt return (0);
95495db6fbSLori Alt
9698110f08SMatthew Ahrens if (do_cksum) {
97495db6fbSLori Alt if (do_byteswap)
98495db6fbSLori Alt fletcher_4_incremental_byteswap(buf, len, cksum);
99495db6fbSLori Alt else
100495db6fbSLori Alt fletcher_4_incremental_native(buf, len, cksum);
101495db6fbSLori Alt }
102495db6fbSLori Alt total_stream_len += len;
103495db6fbSLori Alt return (outlen);
104495db6fbSLori Alt }
105495db6fbSLori Alt
10698110f08SMatthew Ahrens static size_t
read_hdr(dmu_replay_record_t * drr,zio_cksum_t * cksum)10798110f08SMatthew Ahrens read_hdr(dmu_replay_record_t *drr, zio_cksum_t *cksum)
10898110f08SMatthew Ahrens {
10998110f08SMatthew Ahrens ASSERT3U(offsetof(dmu_replay_record_t, drr_u.drr_checksum.drr_checksum),
11098110f08SMatthew Ahrens ==, sizeof (dmu_replay_record_t) - sizeof (zio_cksum_t));
11198110f08SMatthew Ahrens size_t r = ssread(drr, sizeof (*drr) - sizeof (zio_cksum_t), cksum);
11298110f08SMatthew Ahrens if (r == 0)
11398110f08SMatthew Ahrens return (0);
11498110f08SMatthew Ahrens zio_cksum_t saved_cksum = *cksum;
11598110f08SMatthew Ahrens r = ssread(&drr->drr_u.drr_checksum.drr_checksum,
11698110f08SMatthew Ahrens sizeof (zio_cksum_t), cksum);
11798110f08SMatthew Ahrens if (r == 0)
11898110f08SMatthew Ahrens return (0);
11998110f08SMatthew Ahrens if (!ZIO_CHECKSUM_IS_ZERO(&drr->drr_u.drr_checksum.drr_checksum) &&
12098110f08SMatthew Ahrens !ZIO_CHECKSUM_EQUAL(saved_cksum,
12198110f08SMatthew Ahrens drr->drr_u.drr_checksum.drr_checksum)) {
12298110f08SMatthew Ahrens fprintf(stderr, "invalid checksum\n");
12398110f08SMatthew Ahrens (void) printf("Incorrect checksum in record header.\n");
12498110f08SMatthew Ahrens (void) printf("Expected checksum = %llx/%llx/%llx/%llx\n",
12598110f08SMatthew Ahrens saved_cksum.zc_word[0],
12698110f08SMatthew Ahrens saved_cksum.zc_word[1],
12798110f08SMatthew Ahrens saved_cksum.zc_word[2],
12898110f08SMatthew Ahrens saved_cksum.zc_word[3]);
1299c3fd121SMatthew Ahrens return (0);
13098110f08SMatthew Ahrens }
13198110f08SMatthew Ahrens return (sizeof (*drr));
13298110f08SMatthew Ahrens }
13398110f08SMatthew Ahrens
134994fb6b8SMax Grossman /*
135994fb6b8SMax Grossman * Print part of a block in ASCII characters
136994fb6b8SMax Grossman */
137994fb6b8SMax Grossman static void
print_ascii_block(char * subbuf,int length)138994fb6b8SMax Grossman print_ascii_block(char *subbuf, int length)
139994fb6b8SMax Grossman {
140994fb6b8SMax Grossman int i;
141994fb6b8SMax Grossman
142994fb6b8SMax Grossman for (i = 0; i < length; i++) {
143994fb6b8SMax Grossman char char_print = isprint(subbuf[i]) ? subbuf[i] : '.';
144994fb6b8SMax Grossman if (i != 0 && i % DUMP_GROUPING == 0) {
145994fb6b8SMax Grossman (void) printf(" ");
146994fb6b8SMax Grossman }
147994fb6b8SMax Grossman (void) printf("%c", char_print);
148994fb6b8SMax Grossman }
149994fb6b8SMax Grossman (void) printf("\n");
150994fb6b8SMax Grossman }
151994fb6b8SMax Grossman
152994fb6b8SMax Grossman /*
153994fb6b8SMax Grossman * print_block - Dump the contents of a modified block to STDOUT
154994fb6b8SMax Grossman *
155994fb6b8SMax Grossman * Assume that buf has capacity evenly divisible by BYTES_PER_LINE
156994fb6b8SMax Grossman */
157994fb6b8SMax Grossman static void
print_block(char * buf,int length)158994fb6b8SMax Grossman print_block(char *buf, int length)
159994fb6b8SMax Grossman {
160994fb6b8SMax Grossman int i;
161994fb6b8SMax Grossman /*
162994fb6b8SMax Grossman * Start printing ASCII characters at a constant offset, after
163994fb6b8SMax Grossman * the hex prints. Leave 3 characters per byte on a line (2 digit
164994fb6b8SMax Grossman * hex number plus 1 space) plus spaces between characters and
1655d7b4d43SMatthew Ahrens * groupings.
166994fb6b8SMax Grossman */
167994fb6b8SMax Grossman int ascii_start = BYTES_PER_LINE * 3 +
168994fb6b8SMax Grossman BYTES_PER_LINE / DUMP_GROUPING + 2;
169994fb6b8SMax Grossman
170994fb6b8SMax Grossman for (i = 0; i < length; i += BYTES_PER_LINE) {
171994fb6b8SMax Grossman int j;
172994fb6b8SMax Grossman int this_line_length = MIN(BYTES_PER_LINE, length - i);
173994fb6b8SMax Grossman int print_offset = 0;
174994fb6b8SMax Grossman
175994fb6b8SMax Grossman for (j = 0; j < this_line_length; j++) {
176994fb6b8SMax Grossman int buf_offset = i + j;
177994fb6b8SMax Grossman
178994fb6b8SMax Grossman /*
179994fb6b8SMax Grossman * Separate every DUMP_GROUPING bytes by a space.
180994fb6b8SMax Grossman */
181994fb6b8SMax Grossman if (buf_offset % DUMP_GROUPING == 0) {
182994fb6b8SMax Grossman print_offset += printf(" ");
183994fb6b8SMax Grossman }
184994fb6b8SMax Grossman
185994fb6b8SMax Grossman /*
186994fb6b8SMax Grossman * Print the two-digit hex value for this byte.
187994fb6b8SMax Grossman */
188994fb6b8SMax Grossman unsigned char hex_print = buf[buf_offset];
189994fb6b8SMax Grossman print_offset += printf("%02x ", hex_print);
190994fb6b8SMax Grossman }
191994fb6b8SMax Grossman
192994fb6b8SMax Grossman (void) printf("%*s", ascii_start - print_offset, " ");
193994fb6b8SMax Grossman
194994fb6b8SMax Grossman print_ascii_block(buf + i, this_line_length);
195994fb6b8SMax Grossman }
196994fb6b8SMax Grossman }
197994fb6b8SMax Grossman
198495db6fbSLori Alt int
main(int argc,char * argv[])199495db6fbSLori Alt main(int argc, char *argv[])
200495db6fbSLori Alt {
201b5152584SMatthew Ahrens char *buf = safe_malloc(SPA_MAXBLOCKSIZE);
2025d7b4d43SMatthew Ahrens uint64_t drr_record_count[DRR_NUMTYPES] = { 0 };
2035d7b4d43SMatthew Ahrens uint64_t total_records = 0;
204495db6fbSLori Alt dmu_replay_record_t thedrr;
205495db6fbSLori Alt dmu_replay_record_t *drr = &thedrr;
206495db6fbSLori Alt struct drr_begin *drrb = &thedrr.drr_u.drr_begin;
207495db6fbSLori Alt struct drr_end *drre = &thedrr.drr_u.drr_end;
208495db6fbSLori Alt struct drr_object *drro = &thedrr.drr_u.drr_object;
209495db6fbSLori Alt struct drr_freeobjects *drrfo = &thedrr.drr_u.drr_freeobjects;
210495db6fbSLori Alt struct drr_write *drrw = &thedrr.drr_u.drr_write;
2119e69d7d0SLori Alt struct drr_write_byref *drrwbr = &thedrr.drr_u.drr_write_byref;
212495db6fbSLori Alt struct drr_free *drrf = &thedrr.drr_u.drr_free;
2130a586ceaSMark Shellenbaum struct drr_spill *drrs = &thedrr.drr_u.drr_spill;
2145d7b4d43SMatthew Ahrens struct drr_write_embedded *drrwe = &thedrr.drr_u.drr_write_embedded;
21598110f08SMatthew Ahrens struct drr_checksum *drrc = &thedrr.drr_u.drr_checksum;
216495db6fbSLori Alt char c;
217495db6fbSLori Alt boolean_t verbose = B_FALSE;
21898110f08SMatthew Ahrens boolean_t very_verbose = B_FALSE;
219495db6fbSLori Alt boolean_t first = B_TRUE;
220994fb6b8SMax Grossman /*
221994fb6b8SMax Grossman * dump flag controls whether the contents of any modified data blocks
222994fb6b8SMax Grossman * are printed to the console during processing of the stream. Warning:
223994fb6b8SMax Grossman * for large streams, this can obviously lead to massive prints.
224994fb6b8SMax Grossman */
225994fb6b8SMax Grossman boolean_t dump = B_FALSE;
2268e714474SLori Alt int err;
227495db6fbSLori Alt zio_cksum_t zc = { 0 };
228495db6fbSLori Alt zio_cksum_t pcksum = { 0 };
229495db6fbSLori Alt
230994fb6b8SMax Grossman while ((c = getopt(argc, argv, ":vCd")) != -1) {
231495db6fbSLori Alt switch (c) {
232495db6fbSLori Alt case 'C':
233495db6fbSLori Alt do_cksum = B_FALSE;
234495db6fbSLori Alt break;
235495db6fbSLori Alt case 'v':
23698110f08SMatthew Ahrens if (verbose)
23798110f08SMatthew Ahrens very_verbose = B_TRUE;
238495db6fbSLori Alt verbose = B_TRUE;
239495db6fbSLori Alt break;
240994fb6b8SMax Grossman case 'd':
241994fb6b8SMax Grossman dump = B_TRUE;
242994fb6b8SMax Grossman verbose = B_TRUE;
24398110f08SMatthew Ahrens very_verbose = B_TRUE;
244994fb6b8SMax Grossman break;
245495db6fbSLori Alt case ':':
246495db6fbSLori Alt (void) fprintf(stderr,
247495db6fbSLori Alt "missing argument for '%c' option\n", optopt);
248495db6fbSLori Alt usage();
249495db6fbSLori Alt break;
250495db6fbSLori Alt case '?':
251495db6fbSLori Alt (void) fprintf(stderr, "invalid option '%c'\n",
252495db6fbSLori Alt optopt);
253495db6fbSLori Alt usage();
254495db6fbSLori Alt }
255495db6fbSLori Alt }
256495db6fbSLori Alt
257495db6fbSLori Alt if (isatty(STDIN_FILENO)) {
258495db6fbSLori Alt (void) fprintf(stderr,
259495db6fbSLori Alt "Error: Backup stream can not be read "
260495db6fbSLori Alt "from a terminal.\n"
261495db6fbSLori Alt "You must redirect standard input.\n");
262495db6fbSLori Alt exit(1);
263495db6fbSLori Alt }
264495db6fbSLori Alt
265495db6fbSLori Alt send_stream = stdin;
26698110f08SMatthew Ahrens while (read_hdr(drr, &zc)) {
267495db6fbSLori Alt
268994fb6b8SMax Grossman /*
269994fb6b8SMax Grossman * If this is the first DMU record being processed, check for
270994fb6b8SMax Grossman * the magic bytes and figure out the endian-ness based on them.
271994fb6b8SMax Grossman */
272495db6fbSLori Alt if (first) {
273495db6fbSLori Alt if (drrb->drr_magic == BSWAP_64(DMU_BACKUP_MAGIC)) {
274495db6fbSLori Alt do_byteswap = B_TRUE;
275495db6fbSLori Alt if (do_cksum) {
276495db6fbSLori Alt ZIO_SET_CHECKSUM(&zc, 0, 0, 0, 0);
277495db6fbSLori Alt /*
278495db6fbSLori Alt * recalculate header checksum now
279495db6fbSLori Alt * that we know it needs to be
280495db6fbSLori Alt * byteswapped.
281495db6fbSLori Alt */
282495db6fbSLori Alt fletcher_4_incremental_byteswap(drr,
283495db6fbSLori Alt sizeof (dmu_replay_record_t), &zc);
284495db6fbSLori Alt }
285495db6fbSLori Alt } else if (drrb->drr_magic != DMU_BACKUP_MAGIC) {
286495db6fbSLori Alt (void) fprintf(stderr, "Invalid stream "
287495db6fbSLori Alt "(bad magic number)\n");
288495db6fbSLori Alt exit(1);
289495db6fbSLori Alt }
290495db6fbSLori Alt first = B_FALSE;
291495db6fbSLori Alt }
292495db6fbSLori Alt if (do_byteswap) {
293495db6fbSLori Alt drr->drr_type = BSWAP_32(drr->drr_type);
294495db6fbSLori Alt drr->drr_payloadlen =
295495db6fbSLori Alt BSWAP_32(drr->drr_payloadlen);
296495db6fbSLori Alt }
297495db6fbSLori Alt
298495db6fbSLori Alt /*
299495db6fbSLori Alt * At this point, the leading fields of the replay record
300495db6fbSLori Alt * (drr_type and drr_payloadlen) have been byte-swapped if
301495db6fbSLori Alt * necessary, but the rest of the data structure (the
302495db6fbSLori Alt * union of type-specific structures) is still in its
303495db6fbSLori Alt * original state.
304495db6fbSLori Alt */
305495db6fbSLori Alt if (drr->drr_type >= DRR_NUMTYPES) {
306495db6fbSLori Alt (void) printf("INVALID record found: type 0x%x\n",
307495db6fbSLori Alt drr->drr_type);
308495db6fbSLori Alt (void) printf("Aborting.\n");
309495db6fbSLori Alt exit(1);
310495db6fbSLori Alt }
311495db6fbSLori Alt
312495db6fbSLori Alt drr_record_count[drr->drr_type]++;
3135d7b4d43SMatthew Ahrens total_records++;
314495db6fbSLori Alt
315495db6fbSLori Alt switch (drr->drr_type) {
316495db6fbSLori Alt case DRR_BEGIN:
317495db6fbSLori Alt if (do_byteswap) {
318495db6fbSLori Alt drrb->drr_magic = BSWAP_64(drrb->drr_magic);
3199e69d7d0SLori Alt drrb->drr_versioninfo =
3209e69d7d0SLori Alt BSWAP_64(drrb->drr_versioninfo);
321495db6fbSLori Alt drrb->drr_creation_time =
322495db6fbSLori Alt BSWAP_64(drrb->drr_creation_time);
323495db6fbSLori Alt drrb->drr_type = BSWAP_32(drrb->drr_type);
324495db6fbSLori Alt drrb->drr_flags = BSWAP_32(drrb->drr_flags);
325495db6fbSLori Alt drrb->drr_toguid = BSWAP_64(drrb->drr_toguid);
326495db6fbSLori Alt drrb->drr_fromguid =
327495db6fbSLori Alt BSWAP_64(drrb->drr_fromguid);
328495db6fbSLori Alt }
329495db6fbSLori Alt
330495db6fbSLori Alt (void) printf("BEGIN record\n");
3319e69d7d0SLori Alt (void) printf("\thdrtype = %lld\n",
3329e69d7d0SLori Alt DMU_GET_STREAM_HDRTYPE(drrb->drr_versioninfo));
3339e69d7d0SLori Alt (void) printf("\tfeatures = %llx\n",
3349e69d7d0SLori Alt DMU_GET_FEATUREFLAGS(drrb->drr_versioninfo));
335495db6fbSLori Alt (void) printf("\tmagic = %llx\n",
336495db6fbSLori Alt (u_longlong_t)drrb->drr_magic);
337495db6fbSLori Alt (void) printf("\tcreation_time = %llx\n",
338495db6fbSLori Alt (u_longlong_t)drrb->drr_creation_time);
339495db6fbSLori Alt (void) printf("\ttype = %u\n", drrb->drr_type);
340495db6fbSLori Alt (void) printf("\tflags = 0x%x\n", drrb->drr_flags);
341495db6fbSLori Alt (void) printf("\ttoguid = %llx\n",
342495db6fbSLori Alt (u_longlong_t)drrb->drr_toguid);
343495db6fbSLori Alt (void) printf("\tfromguid = %llx\n",
344495db6fbSLori Alt (u_longlong_t)drrb->drr_fromguid);
345495db6fbSLori Alt (void) printf("\ttoname = %s\n", drrb->drr_toname);
346495db6fbSLori Alt if (verbose)
347495db6fbSLori Alt (void) printf("\n");
348495db6fbSLori Alt
3499c3fd121SMatthew Ahrens if (drr->drr_payloadlen != 0) {
350495db6fbSLori Alt nvlist_t *nv;
351495db6fbSLori Alt int sz = drr->drr_payloadlen;
352495db6fbSLori Alt
353b5152584SMatthew Ahrens if (sz > SPA_MAXBLOCKSIZE) {
354495db6fbSLori Alt free(buf);
355b5152584SMatthew Ahrens buf = safe_malloc(sz);
356495db6fbSLori Alt }
357495db6fbSLori Alt (void) ssread(buf, sz, &zc);
358495db6fbSLori Alt if (ferror(send_stream))
359495db6fbSLori Alt perror("fread");
360495db6fbSLori Alt err = nvlist_unpack(buf, sz, &nv, 0);
361495db6fbSLori Alt if (err)
362495db6fbSLori Alt perror(strerror(err));
363495db6fbSLori Alt nvlist_print(stdout, nv);
364495db6fbSLori Alt nvlist_free(nv);
365495db6fbSLori Alt }
366495db6fbSLori Alt break;
367495db6fbSLori Alt
368495db6fbSLori Alt case DRR_END:
369495db6fbSLori Alt if (do_byteswap) {
370495db6fbSLori Alt drre->drr_checksum.zc_word[0] =
371495db6fbSLori Alt BSWAP_64(drre->drr_checksum.zc_word[0]);
372495db6fbSLori Alt drre->drr_checksum.zc_word[1] =
373495db6fbSLori Alt BSWAP_64(drre->drr_checksum.zc_word[1]);
374495db6fbSLori Alt drre->drr_checksum.zc_word[2] =
375495db6fbSLori Alt BSWAP_64(drre->drr_checksum.zc_word[2]);
376495db6fbSLori Alt drre->drr_checksum.zc_word[3] =
377495db6fbSLori Alt BSWAP_64(drre->drr_checksum.zc_word[3]);
378495db6fbSLori Alt }
379495db6fbSLori Alt /*
380495db6fbSLori Alt * We compare against the *previous* checksum
381495db6fbSLori Alt * value, because the stored checksum is of
382495db6fbSLori Alt * everything before the DRR_END record.
383495db6fbSLori Alt */
384495db6fbSLori Alt if (do_cksum && !ZIO_CHECKSUM_EQUAL(drre->drr_checksum,
385495db6fbSLori Alt pcksum)) {
386495db6fbSLori Alt (void) printf("Expected checksum differs from "
387495db6fbSLori Alt "checksum in stream.\n");
388495db6fbSLori Alt (void) printf("Expected checksum = "
389495db6fbSLori Alt "%llx/%llx/%llx/%llx\n",
390495db6fbSLori Alt pcksum.zc_word[0],
391495db6fbSLori Alt pcksum.zc_word[1],
392495db6fbSLori Alt pcksum.zc_word[2],
393495db6fbSLori Alt pcksum.zc_word[3]);
394495db6fbSLori Alt }
395495db6fbSLori Alt (void) printf("END checksum = %llx/%llx/%llx/%llx\n",
396495db6fbSLori Alt drre->drr_checksum.zc_word[0],
397495db6fbSLori Alt drre->drr_checksum.zc_word[1],
398495db6fbSLori Alt drre->drr_checksum.zc_word[2],
399495db6fbSLori Alt drre->drr_checksum.zc_word[3]);
400495db6fbSLori Alt
401495db6fbSLori Alt ZIO_SET_CHECKSUM(&zc, 0, 0, 0, 0);
402495db6fbSLori Alt break;
403495db6fbSLori Alt
404495db6fbSLori Alt case DRR_OBJECT:
405495db6fbSLori Alt if (do_byteswap) {
406495db6fbSLori Alt drro->drr_object = BSWAP_64(drro->drr_object);
407495db6fbSLori Alt drro->drr_type = BSWAP_32(drro->drr_type);
408495db6fbSLori Alt drro->drr_bonustype =
409495db6fbSLori Alt BSWAP_32(drro->drr_bonustype);
410495db6fbSLori Alt drro->drr_blksz = BSWAP_32(drro->drr_blksz);
411495db6fbSLori Alt drro->drr_bonuslen =
412495db6fbSLori Alt BSWAP_32(drro->drr_bonuslen);
4139e69d7d0SLori Alt drro->drr_toguid = BSWAP_64(drro->drr_toguid);
414495db6fbSLori Alt }
415495db6fbSLori Alt if (verbose) {
416495db6fbSLori Alt (void) printf("OBJECT object = %llu type = %u "
417495db6fbSLori Alt "bonustype = %u blksz = %u bonuslen = %u\n",
418495db6fbSLori Alt (u_longlong_t)drro->drr_object,
419495db6fbSLori Alt drro->drr_type,
420495db6fbSLori Alt drro->drr_bonustype,
421495db6fbSLori Alt drro->drr_blksz,
422495db6fbSLori Alt drro->drr_bonuslen);
423495db6fbSLori Alt }
424495db6fbSLori Alt if (drro->drr_bonuslen > 0) {
4255d7b4d43SMatthew Ahrens (void) ssread(buf,
4265d7b4d43SMatthew Ahrens P2ROUNDUP(drro->drr_bonuslen, 8), &zc);
427994fb6b8SMax Grossman if (dump) {
428994fb6b8SMax Grossman print_block(buf,
429994fb6b8SMax Grossman P2ROUNDUP(drro->drr_bonuslen, 8));
430994fb6b8SMax Grossman }
431495db6fbSLori Alt }
432495db6fbSLori Alt break;
433495db6fbSLori Alt
434495db6fbSLori Alt case DRR_FREEOBJECTS:
435495db6fbSLori Alt if (do_byteswap) {
436495db6fbSLori Alt drrfo->drr_firstobj =
437495db6fbSLori Alt BSWAP_64(drrfo->drr_firstobj);
438495db6fbSLori Alt drrfo->drr_numobjs =
439495db6fbSLori Alt BSWAP_64(drrfo->drr_numobjs);
4409e69d7d0SLori Alt drrfo->drr_toguid = BSWAP_64(drrfo->drr_toguid);
441495db6fbSLori Alt }
442495db6fbSLori Alt if (verbose) {
443495db6fbSLori Alt (void) printf("FREEOBJECTS firstobj = %llu "
444495db6fbSLori Alt "numobjs = %llu\n",
445495db6fbSLori Alt (u_longlong_t)drrfo->drr_firstobj,
446495db6fbSLori Alt (u_longlong_t)drrfo->drr_numobjs);
447495db6fbSLori Alt }
448495db6fbSLori Alt break;
449495db6fbSLori Alt
450495db6fbSLori Alt case DRR_WRITE:
451495db6fbSLori Alt if (do_byteswap) {
452495db6fbSLori Alt drrw->drr_object = BSWAP_64(drrw->drr_object);
453495db6fbSLori Alt drrw->drr_type = BSWAP_32(drrw->drr_type);
454495db6fbSLori Alt drrw->drr_offset = BSWAP_64(drrw->drr_offset);
455495db6fbSLori Alt drrw->drr_length = BSWAP_64(drrw->drr_length);
4569e69d7d0SLori Alt drrw->drr_toguid = BSWAP_64(drrw->drr_toguid);
4578e714474SLori Alt drrw->drr_key.ddk_prop =
4588e714474SLori Alt BSWAP_64(drrw->drr_key.ddk_prop);
459495db6fbSLori Alt }
460994fb6b8SMax Grossman /*
461994fb6b8SMax Grossman * If this is verbose and/or dump output,
462994fb6b8SMax Grossman * print info on the modified block
463994fb6b8SMax Grossman */
464495db6fbSLori Alt if (verbose) {
465495db6fbSLori Alt (void) printf("WRITE object = %llu type = %u "
4668e714474SLori Alt "checksum type = %u\n"
4678e714474SLori Alt " offset = %llu length = %llu "
4688e714474SLori Alt "props = %llx\n",
469495db6fbSLori Alt (u_longlong_t)drrw->drr_object,
470495db6fbSLori Alt drrw->drr_type,
4718e714474SLori Alt drrw->drr_checksumtype,
472495db6fbSLori Alt (u_longlong_t)drrw->drr_offset,
4738e714474SLori Alt (u_longlong_t)drrw->drr_length,
4748e714474SLori Alt (u_longlong_t)drrw->drr_key.ddk_prop);
475495db6fbSLori Alt }
476994fb6b8SMax Grossman /*
477994fb6b8SMax Grossman * Read the contents of the block in from STDIN to buf
478994fb6b8SMax Grossman */
479495db6fbSLori Alt (void) ssread(buf, drrw->drr_length, &zc);
480994fb6b8SMax Grossman /*
481994fb6b8SMax Grossman * If in dump mode
482994fb6b8SMax Grossman */
483994fb6b8SMax Grossman if (dump) {
484994fb6b8SMax Grossman print_block(buf, drrw->drr_length);
485994fb6b8SMax Grossman }
486495db6fbSLori Alt total_write_size += drrw->drr_length;
487495db6fbSLori Alt break;
488495db6fbSLori Alt
4899e69d7d0SLori Alt case DRR_WRITE_BYREF:
4909e69d7d0SLori Alt if (do_byteswap) {
4919e69d7d0SLori Alt drrwbr->drr_object =
4929e69d7d0SLori Alt BSWAP_64(drrwbr->drr_object);
4939e69d7d0SLori Alt drrwbr->drr_offset =
4949e69d7d0SLori Alt BSWAP_64(drrwbr->drr_offset);
4959e69d7d0SLori Alt drrwbr->drr_length =
4969e69d7d0SLori Alt BSWAP_64(drrwbr->drr_length);
4979e69d7d0SLori Alt drrwbr->drr_toguid =
4989e69d7d0SLori Alt BSWAP_64(drrwbr->drr_toguid);
4999e69d7d0SLori Alt drrwbr->drr_refguid =
5009e69d7d0SLori Alt BSWAP_64(drrwbr->drr_refguid);
5019e69d7d0SLori Alt drrwbr->drr_refobject =
5029e69d7d0SLori Alt BSWAP_64(drrwbr->drr_refobject);
5039e69d7d0SLori Alt drrwbr->drr_refoffset =
5049e69d7d0SLori Alt BSWAP_64(drrwbr->drr_refoffset);
5058e714474SLori Alt drrwbr->drr_key.ddk_prop =
5068e714474SLori Alt BSWAP_64(drrwbr->drr_key.ddk_prop);
5079e69d7d0SLori Alt }
5089e69d7d0SLori Alt if (verbose) {
5099e69d7d0SLori Alt (void) printf("WRITE_BYREF object = %llu "
5108e714474SLori Alt "checksum type = %u props = %llx\n"
5119e69d7d0SLori Alt " offset = %llu length = %llu\n"
5129e69d7d0SLori Alt "toguid = %llx refguid = %llx\n"
5139e69d7d0SLori Alt " refobject = %llu refoffset = %llu\n",
5149e69d7d0SLori Alt (u_longlong_t)drrwbr->drr_object,
5158e714474SLori Alt drrwbr->drr_checksumtype,
5168e714474SLori Alt (u_longlong_t)drrwbr->drr_key.ddk_prop,
5179e69d7d0SLori Alt (u_longlong_t)drrwbr->drr_offset,
5189e69d7d0SLori Alt (u_longlong_t)drrwbr->drr_length,
5199e69d7d0SLori Alt (u_longlong_t)drrwbr->drr_toguid,
5209e69d7d0SLori Alt (u_longlong_t)drrwbr->drr_refguid,
5219e69d7d0SLori Alt (u_longlong_t)drrwbr->drr_refobject,
5229e69d7d0SLori Alt (u_longlong_t)drrwbr->drr_refoffset);
5239e69d7d0SLori Alt }
5249e69d7d0SLori Alt break;
5259e69d7d0SLori Alt
526495db6fbSLori Alt case DRR_FREE:
527495db6fbSLori Alt if (do_byteswap) {
528495db6fbSLori Alt drrf->drr_object = BSWAP_64(drrf->drr_object);
529495db6fbSLori Alt drrf->drr_offset = BSWAP_64(drrf->drr_offset);
530495db6fbSLori Alt drrf->drr_length = BSWAP_64(drrf->drr_length);
531495db6fbSLori Alt }
532495db6fbSLori Alt if (verbose) {
533495db6fbSLori Alt (void) printf("FREE object = %llu "
534495db6fbSLori Alt "offset = %llu length = %lld\n",
535495db6fbSLori Alt (u_longlong_t)drrf->drr_object,
536495db6fbSLori Alt (u_longlong_t)drrf->drr_offset,
537495db6fbSLori Alt (longlong_t)drrf->drr_length);
538495db6fbSLori Alt }
539495db6fbSLori Alt break;
5400a586ceaSMark Shellenbaum case DRR_SPILL:
5410a586ceaSMark Shellenbaum if (do_byteswap) {
5420a586ceaSMark Shellenbaum drrs->drr_object = BSWAP_64(drrs->drr_object);
5430a586ceaSMark Shellenbaum drrs->drr_length = BSWAP_64(drrs->drr_length);
5440a586ceaSMark Shellenbaum }
5450a586ceaSMark Shellenbaum if (verbose) {
5460a586ceaSMark Shellenbaum (void) printf("SPILL block for object = %llu "
5470a586ceaSMark Shellenbaum "length = %llu\n", drrs->drr_object,
5480a586ceaSMark Shellenbaum drrs->drr_length);
5490a586ceaSMark Shellenbaum }
5500a586ceaSMark Shellenbaum (void) ssread(buf, drrs->drr_length, &zc);
551994fb6b8SMax Grossman if (dump) {
552994fb6b8SMax Grossman print_block(buf, drrs->drr_length);
553994fb6b8SMax Grossman }
5540a586ceaSMark Shellenbaum break;
5555d7b4d43SMatthew Ahrens case DRR_WRITE_EMBEDDED:
5565d7b4d43SMatthew Ahrens if (do_byteswap) {
5575d7b4d43SMatthew Ahrens drrwe->drr_object =
5585d7b4d43SMatthew Ahrens BSWAP_64(drrwe->drr_object);
5595d7b4d43SMatthew Ahrens drrwe->drr_offset =
5605d7b4d43SMatthew Ahrens BSWAP_64(drrwe->drr_offset);
5615d7b4d43SMatthew Ahrens drrwe->drr_length =
5625d7b4d43SMatthew Ahrens BSWAP_64(drrwe->drr_length);
5635d7b4d43SMatthew Ahrens drrwe->drr_toguid =
5645d7b4d43SMatthew Ahrens BSWAP_64(drrwe->drr_toguid);
5655d7b4d43SMatthew Ahrens drrwe->drr_lsize =
5665d7b4d43SMatthew Ahrens BSWAP_32(drrwe->drr_lsize);
5675d7b4d43SMatthew Ahrens drrwe->drr_psize =
5685d7b4d43SMatthew Ahrens BSWAP_32(drrwe->drr_psize);
5695d7b4d43SMatthew Ahrens }
5705d7b4d43SMatthew Ahrens if (verbose) {
5715d7b4d43SMatthew Ahrens (void) printf("WRITE_EMBEDDED object = %llu "
5725d7b4d43SMatthew Ahrens "offset = %llu length = %llu\n"
5735d7b4d43SMatthew Ahrens " toguid = %llx comp = %u etype = %u "
5745d7b4d43SMatthew Ahrens "lsize = %u psize = %u\n",
5755d7b4d43SMatthew Ahrens (u_longlong_t)drrwe->drr_object,
5765d7b4d43SMatthew Ahrens (u_longlong_t)drrwe->drr_offset,
5775d7b4d43SMatthew Ahrens (u_longlong_t)drrwe->drr_length,
5785d7b4d43SMatthew Ahrens (u_longlong_t)drrwe->drr_toguid,
5795d7b4d43SMatthew Ahrens drrwe->drr_compression,
5805d7b4d43SMatthew Ahrens drrwe->drr_etype,
5815d7b4d43SMatthew Ahrens drrwe->drr_lsize,
5825d7b4d43SMatthew Ahrens drrwe->drr_psize);
5835d7b4d43SMatthew Ahrens }
5845d7b4d43SMatthew Ahrens (void) ssread(buf,
5855d7b4d43SMatthew Ahrens P2ROUNDUP(drrwe->drr_psize, 8), &zc);
5865d7b4d43SMatthew Ahrens break;
587495db6fbSLori Alt }
58898110f08SMatthew Ahrens if (drr->drr_type != DRR_BEGIN && very_verbose) {
58998110f08SMatthew Ahrens (void) printf(" checksum = %llx/%llx/%llx/%llx\n",
59098110f08SMatthew Ahrens (longlong_t)drrc->drr_checksum.zc_word[0],
59198110f08SMatthew Ahrens (longlong_t)drrc->drr_checksum.zc_word[1],
59298110f08SMatthew Ahrens (longlong_t)drrc->drr_checksum.zc_word[2],
59398110f08SMatthew Ahrens (longlong_t)drrc->drr_checksum.zc_word[3]);
59498110f08SMatthew Ahrens }
595495db6fbSLori Alt pcksum = zc;
596495db6fbSLori Alt }
597495db6fbSLori Alt free(buf);
598495db6fbSLori Alt
599495db6fbSLori Alt /* Print final summary */
600495db6fbSLori Alt
601495db6fbSLori Alt (void) printf("SUMMARY:\n");
602495db6fbSLori Alt (void) printf("\tTotal DRR_BEGIN records = %lld\n",
603495db6fbSLori Alt (u_longlong_t)drr_record_count[DRR_BEGIN]);
604495db6fbSLori Alt (void) printf("\tTotal DRR_END records = %lld\n",
605495db6fbSLori Alt (u_longlong_t)drr_record_count[DRR_END]);
606495db6fbSLori Alt (void) printf("\tTotal DRR_OBJECT records = %lld\n",
607495db6fbSLori Alt (u_longlong_t)drr_record_count[DRR_OBJECT]);
608495db6fbSLori Alt (void) printf("\tTotal DRR_FREEOBJECTS records = %lld\n",
609495db6fbSLori Alt (u_longlong_t)drr_record_count[DRR_FREEOBJECTS]);
610495db6fbSLori Alt (void) printf("\tTotal DRR_WRITE records = %lld\n",
611495db6fbSLori Alt (u_longlong_t)drr_record_count[DRR_WRITE]);
6125d7b4d43SMatthew Ahrens (void) printf("\tTotal DRR_WRITE_BYREF records = %lld\n",
6135d7b4d43SMatthew Ahrens (u_longlong_t)drr_record_count[DRR_WRITE_BYREF]);
6145d7b4d43SMatthew Ahrens (void) printf("\tTotal DRR_WRITE_EMBEDDED records = %lld\n",
6155d7b4d43SMatthew Ahrens (u_longlong_t)drr_record_count[DRR_WRITE_EMBEDDED]);
616495db6fbSLori Alt (void) printf("\tTotal DRR_FREE records = %lld\n",
617495db6fbSLori Alt (u_longlong_t)drr_record_count[DRR_FREE]);
6180a586ceaSMark Shellenbaum (void) printf("\tTotal DRR_SPILL records = %lld\n",
6190a586ceaSMark Shellenbaum (u_longlong_t)drr_record_count[DRR_SPILL]);
620495db6fbSLori Alt (void) printf("\tTotal records = %lld\n",
6215d7b4d43SMatthew Ahrens (u_longlong_t)total_records);
622495db6fbSLori Alt (void) printf("\tTotal write size = %lld (0x%llx)\n",
623495db6fbSLori Alt (u_longlong_t)total_write_size, (u_longlong_t)total_write_size);
624495db6fbSLori Alt (void) printf("\tTotal stream length = %lld (0x%llx)\n",
625495db6fbSLori Alt (u_longlong_t)total_stream_len, (u_longlong_t)total_stream_len);
626495db6fbSLori Alt return (0);
627495db6fbSLori Alt }
628