zstreamdump.c revision 8e7144747a94247ce9dbb4fb1f67bdcb666b30d8
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <libnvpair.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include <sys/zfs_ioctl.h>
#include <zfs_fletcher.h>
uint64_t total_write_size = 0;
uint64_t total_stream_len = 0;
FILE *send_stream = 0;
static void
usage(void)
{
exit(1);
}
/*
* ssread - send stream read.
*
* Read while computing incremental checksum
*/
static size_t
{
return (0);
if (do_byteswap)
else
}
total_stream_len += len;
return (outlen);
}
int
{
char c;
int err;
zio_cksum_t zc = { 0 };
zio_cksum_t pcksum = { 0 };
switch (c) {
case 'C':
break;
case 'v':
break;
case ':':
"missing argument for '%c' option\n", optopt);
usage();
break;
case '?':
optopt);
usage();
}
}
if (isatty(STDIN_FILENO)) {
"Error: Backup stream can not be read "
"from a terminal.\n"
"You must redirect standard input.\n");
exit(1);
}
send_stream = stdin;
if (first) {
if (do_cksum) {
ZIO_SET_CHECKSUM(&zc, 0, 0, 0, 0);
/*
* recalculate header checksum now
* that we know it needs to be
* byteswapped.
*/
sizeof (dmu_replay_record_t), &zc);
}
"(bad magic number)\n");
exit(1);
}
}
if (do_byteswap) {
}
/*
* At this point, the leading fields of the replay record
* (drr_type and drr_payloadlen) have been byte-swapped if
* necessary, but the rest of the data structure (the
* union of type-specific structures) is still in its
* original state.
*/
(void) printf("INVALID record found: type 0x%x\n",
(void) printf("Aborting.\n");
exit(1);
}
case DRR_BEGIN:
if (do_byteswap) {
drrb->drr_fromguid =
}
(void) printf("BEGIN record\n");
(void) printf("\thdrtype = %lld\n",
(void) printf("\tfeatures = %llx\n",
(void) printf("\tmagic = %llx\n",
(void) printf("\tcreation_time = %llx\n",
(void) printf("\ttoguid = %llx\n",
(void) printf("\tfromguid = %llx\n",
if (verbose)
(void) printf("\n");
}
if (ferror(send_stream))
perror("fread");
if (err)
}
break;
case DRR_END:
if (do_byteswap) {
}
/*
* We compare against the *previous* checksum
* value, because the stored checksum is of
* everything before the DRR_END record.
*/
pcksum)) {
(void) printf("Expected checksum differs from "
"checksum in stream.\n");
(void) printf("Expected checksum = "
"%llx/%llx/%llx/%llx\n",
}
(void) printf("END checksum = %llx/%llx/%llx/%llx\n",
ZIO_SET_CHECKSUM(&zc, 0, 0, 0, 0);
break;
case DRR_OBJECT:
if (do_byteswap) {
drro->drr_bonuslen =
}
if (verbose) {
(void) printf("OBJECT object = %llu type = %u "
"bonustype = %u blksz = %u bonuslen = %u\n",
drro->drr_bonuslen);
}
if (drro->drr_bonuslen > 0) {
8), &zc);
}
break;
case DRR_FREEOBJECTS:
if (do_byteswap) {
drrfo->drr_numobjs =
}
if (verbose) {
(void) printf("FREEOBJECTS firstobj = %llu "
"numobjs = %llu\n",
}
break;
case DRR_WRITE:
if (do_byteswap) {
}
if (verbose) {
(void) printf("WRITE object = %llu type = %u "
"checksum type = %u\n"
"offset = %llu length = %llu "
"props = %llx\n",
}
break;
case DRR_WRITE_BYREF:
if (do_byteswap) {
drrwbr->drr_object =
drrwbr->drr_offset =
drrwbr->drr_length =
drrwbr->drr_toguid =
}
if (verbose) {
(void) printf("WRITE_BYREF object = %llu "
"checksum type = %u props = %llx\n"
"offset = %llu length = %llu\n"
"toguid = %llx refguid = %llx\n"
"refobject = %llu refoffset = %llu\n",
}
break;
case DRR_FREE:
if (do_byteswap) {
}
if (verbose) {
(void) printf("FREE object = %llu "
"offset = %llu length = %lld\n",
}
break;
}
}
/* Print final summary */
(void) printf("SUMMARY:\n");
(void) printf("\tTotal DRR_BEGIN records = %lld\n",
(void) printf("\tTotal DRR_END records = %lld\n",
(void) printf("\tTotal DRR_OBJECT records = %lld\n",
(void) printf("\tTotal DRR_FREEOBJECTS records = %lld\n",
(void) printf("\tTotal DRR_WRITE records = %lld\n",
(void) printf("\tTotal DRR_FREE records = %lld\n",
(void) printf("\tTotal records = %lld\n",
(void) printf("\tTotal write size = %lld (0x%llx)\n",
(void) printf("\tTotal stream length = %lld (0x%llx)\n",
return (0);
}