Exemplo n.º 1
0
void
zap_leaf_byteswap(zap_leaf_phys_t *buf, int size)
{
	int i;
	zap_leaf_t l;
	dmu_buf_t l_dbuf;

	l_dbuf.db_data = buf;
	l.l_bs = highbit64(size) - 1;
	l.l_dbuf = &l_dbuf;

	buf->l_hdr.lh_block_type =	BSWAP_64(buf->l_hdr.lh_block_type);
	buf->l_hdr.lh_prefix =		BSWAP_64(buf->l_hdr.lh_prefix);
	buf->l_hdr.lh_magic =		BSWAP_32(buf->l_hdr.lh_magic);
	buf->l_hdr.lh_nfree =		BSWAP_16(buf->l_hdr.lh_nfree);
	buf->l_hdr.lh_nentries =	BSWAP_16(buf->l_hdr.lh_nentries);
	buf->l_hdr.lh_prefix_len =	BSWAP_16(buf->l_hdr.lh_prefix_len);
	buf->l_hdr.lh_freelist =	BSWAP_16(buf->l_hdr.lh_freelist);

	for (i = 0; i < ZAP_LEAF_HASH_NUMENTRIES(&l); i++)
		buf->l_hash[i] = BSWAP_16(buf->l_hash[i]);

	for (i = 0; i < ZAP_LEAF_NUMCHUNKS(&l); i++) {
		zap_leaf_chunk_t *lc = &ZAP_LEAF_CHUNK(&l, i);
		struct zap_leaf_entry *le;

		switch (lc->l_free.lf_type) {
		case ZAP_CHUNK_ENTRY:
			le = &lc->l_entry;

			le->le_type =		BSWAP_8(le->le_type);
			le->le_value_intlen =	BSWAP_8(le->le_value_intlen);
			le->le_next =		BSWAP_16(le->le_next);
			le->le_name_chunk =	BSWAP_16(le->le_name_chunk);
			le->le_name_numints =	BSWAP_16(le->le_name_numints);
			le->le_value_chunk =	BSWAP_16(le->le_value_chunk);
			le->le_value_numints =	BSWAP_16(le->le_value_numints);
			le->le_cd =		BSWAP_32(le->le_cd);
			le->le_hash =		BSWAP_64(le->le_hash);
			break;
		case ZAP_CHUNK_FREE:
			lc->l_free.lf_type =	BSWAP_8(lc->l_free.lf_type);
			lc->l_free.lf_next =	BSWAP_16(lc->l_free.lf_next);
			break;
		case ZAP_CHUNK_ARRAY:
			lc->l_array.la_type =	BSWAP_8(lc->l_array.la_type);
			lc->l_array.la_next =	BSWAP_16(lc->l_array.la_next);
			/* la_array doesn't need swapping */
			break;
		default:
			cmn_err(CE_PANIC, "bad leaf type %d",
			    lc->l_free.lf_type);
		}
	}
}
Exemplo n.º 2
0
/*
 * Byteswapped zio_checksum interface for the Edon-R hash function.
 */
static void
zio_checksum_edonr_byteswap(const void *buf, uint64_t size,
    const void *ctx_template, zio_cksum_t *zcp)
{
	zio_cksum_t	tmp;

	zio_checksum_edonr_native(buf, size, ctx_template, &tmp);
	zcp->zc_word[0] = BSWAP_64(zcp->zc_word[0]);
	zcp->zc_word[1] = BSWAP_64(zcp->zc_word[1]);
	zcp->zc_word[2] = BSWAP_64(zcp->zc_word[2]);
	zcp->zc_word[3] = BSWAP_64(zcp->zc_word[3]);
}
Exemplo n.º 3
0
/*
 * Byteswapped zio_checksum interface for the Edon-R hash function.
 */
void
abd_checksum_edonr_byteswap(abd_t *abd, uint64_t size,
    const void *ctx_template, zio_cksum_t *zcp)
{
	zio_cksum_t	tmp;

	abd_checksum_edonr_native(abd, size, ctx_template, &tmp);
	zcp->zc_word[0] = BSWAP_64(zcp->zc_word[0]);
	zcp->zc_word[1] = BSWAP_64(zcp->zc_word[1]);
	zcp->zc_word[2] = BSWAP_64(zcp->zc_word[2]);
	zcp->zc_word[3] = BSWAP_64(zcp->zc_word[3]);
}
Exemplo n.º 4
0
static void
mzap_byteswap(mzap_phys_t *buf, size_t size)
{
	int i, maximum;
	buf->mz_block_type = BSWAP_64(buf->mz_block_type);
	buf->mz_salt = BSWAP_64(buf->mz_salt);
	maximum = (size / MZAP_ENT_LEN) - 1;
	for (i = 0; i < maximum; i++) {
		buf->mz_chunk[i].mze_value =
		    BSWAP_64(buf->mz_chunk[i].mze_value);
		buf->mz_chunk[i].mze_cd =
		    BSWAP_32(buf->mz_chunk[i].mze_cd);
	}
}
Exemplo n.º 5
0
void
dmu_objset_byteswap(void *buf, size_t size)
{
	objset_phys_t *osp = buf;

	ASSERT(size == OBJSET_OLD_PHYS_SIZE || size == sizeof (objset_phys_t));
	dnode_byteswap(&osp->os_meta_dnode);
	byteswap_uint64_array(&osp->os_zil_header, sizeof (zil_header_t));
	osp->os_type = BSWAP_64(osp->os_type);
	osp->os_flags = BSWAP_64(osp->os_flags);
	if (size == sizeof (objset_phys_t)) {
		dnode_byteswap(&osp->os_userused_dnode);
		dnode_byteswap(&osp->os_groupused_dnode);
	}
}
Exemplo n.º 6
0
void
fletcher_2_byteswap(const void *buf, uint64_t size, zio_cksum_t *zcp)
{
	const uint64_t *ip = buf;
	const uint64_t *ipend = ip + (size / sizeof (uint64_t));
	uint64_t a0, b0, a1, b1;

	for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2) {
		a0 += BSWAP_64(ip[0]);
		a1 += BSWAP_64(ip[1]);
		b0 += a0;
		b1 += a1;
	}

	ZIO_SET_CHECKSUM(zcp, a0, a1, b0, b1);
}
Exemplo n.º 7
0
// 测试位操作
void test_bo(uint64_t i) {
    uint64_t r;
    uint32_t count;
    count = OP_COUNT;
    while (count--) {
        r = BSWAP_64(i);
    }
    printf("bo result is %llu\n", r);
}
Exemplo n.º 8
0
void
dmu_objset_byteswap(void *buf, size_t size)
{
	objset_phys_t *osp = buf;

	ASSERT(size == sizeof (objset_phys_t));
	dnode_byteswap(&osp->os_meta_dnode);
	byteswap_uint64_array(&osp->os_zil_header, sizeof (zil_header_t));
	osp->os_type = BSWAP_64(osp->os_type);
}
Exemplo n.º 9
0
Arquivo: uberblock.c Projeto: LLNL/zfs
int
uberblock_verify(uberblock_t *ub)
{
	if (ub->ub_magic == BSWAP_64((uint64_t)UBERBLOCK_MAGIC))
		byteswap_uint64_array(ub, sizeof (uberblock_t));

	if (ub->ub_magic != UBERBLOCK_MAGIC)
		return (SET_ERROR(EINVAL));

	return (0);
}
Exemplo n.º 10
0
void
fzap_byteswap(void *vbuf, size_t size)
{
	uint64_t block_type = *(uint64_t *)vbuf;

	if (block_type == ZBT_LEAF || block_type == BSWAP_64(ZBT_LEAF))
		zap_leaf_byteswap(vbuf, size);
	else {
		/* it's a ptrtbl block */
		byteswap_uint64_array(vbuf, size);
	}
}
Exemplo n.º 11
0
void
zap_byteswap(void *buf, size_t size)
{
	uint64_t block_type;

	block_type = *(uint64_t *)buf;

	if (block_type == ZBT_MICRO || block_type == BSWAP_64(ZBT_MICRO)) {
		/* ASSERT(magic == ZAP_LEAF_MAGIC); */
		mzap_byteswap(buf, size);
	} else {
		fzap_byteswap(buf, size);
	}
}
Exemplo n.º 12
0
int
fletcher_2_incremental_byteswap(void *buf, size_t size, void *data)
{
	zio_cksum_t *zcp = data;

	const uint64_t *ip = buf;
	const uint64_t *ipend = ip + (size / sizeof (uint64_t));
	uint64_t a0, b0, a1, b1;

	a0 = zcp->zc_word[0];
	a1 = zcp->zc_word[1];
	b0 = zcp->zc_word[2];
	b1 = zcp->zc_word[3];

	for (; ip < ipend; ip += 2) {
		a0 += BSWAP_64(ip[0]);
		a1 += BSWAP_64(ip[1]);
		b0 += a0;
		b1 += a1;
	}

	ZIO_SET_CHECKSUM(zcp, a0, a1, b0, b1);
	return (0);
}
Exemplo n.º 13
0
static void test_swap_double() {
    union {
        double d;
        uint64_t u;
    } ud = {
        .u = 0x7856341283C0F33F
    };
    double x = 1.2344999991522893623141499119810760021209716796875;
    ud.u = BSWAP_64(ud.u);
    double r = ud.d;
    if (r == x) {
        printf("%.64f\n", ud.d);
        printf("swap okay\n");
    } else {
        printf("swap failed\n");
        printf("%.64f\n", ud.d);
    }

    double td = 1.2344999991522893623141499119810760021209716796875;
    if (memcmp(&td, "\x78\x56\x34\x12\x83\xC0\xF3\x3F", 8) == 0) {
        printf("little endian double\n");
    } else if (memcmp(&td, "\x3F\xF3\xC0\x83\x12\x34\x56\x78", 8) == 0) {
        printf("big endian double\n");
    } else {
        printf("not support number format to dump!");
    }

}

int main(int argc, char const* argv[]) {
    test_swap_double();
    test_b32();
    union_test();
    uint64_t i = 0x123456789abcdeff;
    measure_time(test_mc, i, "memory copy");
    measure_time(test_mc2, i, "memory copy 2");
    measure_time(test_bo, i, "bitwise operation");
    return 0;
}
Exemplo n.º 14
0
int
zio_checksum_error(zio_t *zio, zio_bad_cksum_t *info)
{
	blkptr_t *bp = zio->io_bp;
	uint_t checksum = (bp == NULL ? zio->io_prop.zp_checksum :
	    (BP_IS_GANG(bp) ? ZIO_CHECKSUM_GANG_HEADER : BP_GET_CHECKSUM(bp)));
	int byteswap;
	int error;
	uint64_t size = (bp == NULL ? zio->io_size :
	    (BP_IS_GANG(bp) ? SPA_GANGBLOCKSIZE : BP_GET_PSIZE(bp)));
	uint64_t offset = zio->io_offset;
	void *data = zio->io_data;
	zio_checksum_info_t *ci = &zio_checksum_table[checksum];
	zio_cksum_t actual_cksum, expected_cksum, verifier;

	if (checksum >= ZIO_CHECKSUM_FUNCTIONS || ci->ci_func[0] == NULL)
		return (EINVAL);

	if (ci->ci_eck) {
		zio_eck_t *eck;

		if (checksum == ZIO_CHECKSUM_ZILOG2) {
			zil_chain_t *zilc = data;
			uint64_t nused;

			eck = &zilc->zc_eck;
			if (eck->zec_magic == ZEC_MAGIC)
				nused = zilc->zc_nused;
			else if (eck->zec_magic == BSWAP_64(ZEC_MAGIC))
				nused = BSWAP_64(zilc->zc_nused);
			else
				return (ECKSUM);

			if (nused > size)
				return (ECKSUM);

			size = P2ROUNDUP_TYPED(nused, ZIL_MIN_BLKSZ, uint64_t);
		} else {
			eck = (zio_eck_t *)((char *)data + size) - 1;
		}

		if (checksum == ZIO_CHECKSUM_GANG_HEADER)
			zio_checksum_gang_verifier(&verifier, bp);
		else if (checksum == ZIO_CHECKSUM_LABEL)
			zio_checksum_label_verifier(&verifier, offset);
		else
			verifier = bp->blk_cksum;

		byteswap = (eck->zec_magic == BSWAP_64(ZEC_MAGIC));

		if (byteswap)
			byteswap_uint64_array(&verifier, sizeof (zio_cksum_t));

		expected_cksum = eck->zec_cksum;
		eck->zec_cksum = verifier;
		ci->ci_func[byteswap](data, size, &actual_cksum);
		eck->zec_cksum = expected_cksum;

		if (byteswap)
			byteswap_uint64_array(&expected_cksum,
			    sizeof (zio_cksum_t));
	} else {
		ASSERT(!BP_IS_GANG(bp));
		byteswap = BP_SHOULD_BYTESWAP(bp);
		expected_cksum = bp->blk_cksum;
		ci->ci_func[byteswap](data, size, &actual_cksum);
	}

	info->zbc_expected = expected_cksum;
	info->zbc_actual = actual_cksum;
	info->zbc_checksum_name = ci->ci_name;
	info->zbc_byteswapped = byteswap;
	info->zbc_injected = 0;
	info->zbc_has_cksum = 1;

	if (!ZIO_CHECKSUM_EQUAL(actual_cksum, expected_cksum)) {
		return (ECKSUM);
    }

	if (zio_injection_enabled && !zio->io_error &&
	    (error = zio_handle_fault_injection(zio, ECKSUM)) != 0) {

		info->zbc_injected = 1;
		return (error);
	}

	return (0);
}
Exemplo n.º 15
0
/*
 * swap ace_t and ace_oject_t
 */
void
zfs_ace_byteswap(void *buf, size_t size, boolean_t zfs_layout)
{
#ifdef TODO
	caddr_t end;
	caddr_t ptr;
	zfs_ace_t *zacep;
	ace_t *acep;
	uint16_t entry_type;
	size_t entry_size;
	int ace_type;

	end = (caddr_t)buf + size;
	ptr = buf;

	while (ptr < end) {
		if (zfs_layout) {
			zacep = (zfs_ace_t *)ptr;
			zacep->z_hdr.z_access_mask =
			    BSWAP_32(zacep->z_hdr.z_access_mask);
			zacep->z_hdr.z_flags = BSWAP_16(zacep->z_hdr.z_flags);
			ace_type = zacep->z_hdr.z_type =
			    BSWAP_16(zacep->z_hdr.z_type);
			entry_type = zacep->z_hdr.z_flags & ACE_TYPE_FLAGS;
		} else {
			acep = (ace_t *)ptr;
			acep->a_access_mask = BSWAP_32(acep->a_access_mask);
			acep->a_flags = BSWAP_16(acep->a_flags);
			ace_type = acep->a_type = BSWAP_16(acep->a_type);
			acep->a_who = BSWAP_32(acep->a_who);
			entry_type = acep->a_flags & ACE_TYPE_FLAGS;
		}
		switch (entry_type) {
		case ACE_OWNER:
		case ACE_EVERYONE:
		case (ACE_IDENTIFIER_GROUP | ACE_GROUP):
			entry_size = zfs_layout ?
			    sizeof (zfs_ace_hdr_t) : sizeof (ace_t);
			break;
		case ACE_IDENTIFIER_GROUP:
		default:
			if (zfs_layout) {
				zacep->z_fuid = BSWAP_64(zacep->z_fuid);
			}
			switch (ace_type) {
			case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE:
			case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE:
			case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE:
			case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE:
				entry_size = zfs_layout ?
				    sizeof (zfs_object_ace_t) :
				    sizeof (ace_object_t);
				break;
			default:
				entry_size = zfs_layout ? sizeof (zfs_ace_t) :
				    sizeof (ace_t);
				break;
			}
		}
		ptr = ptr + entry_size;
	}
#else	/* TODO */
	panic("%s:%u: TODO", __func__, __LINE__);
#endif	/* TODO */
}
Exemplo n.º 16
0
void
zfs_znode_byteswap(void *buf, size_t size)
{
	znode_phys_t *zp = buf;

	ASSERT(size >= sizeof (znode_phys_t));

	zp->zp_crtime[0] = BSWAP_64(zp->zp_crtime[0]);
	zp->zp_crtime[1] = BSWAP_64(zp->zp_crtime[1]);
	zp->zp_atime[0] = BSWAP_64(zp->zp_atime[0]);
	zp->zp_atime[1] = BSWAP_64(zp->zp_atime[1]);
	zp->zp_mtime[0] = BSWAP_64(zp->zp_mtime[0]);
	zp->zp_mtime[1] = BSWAP_64(zp->zp_mtime[1]);
	zp->zp_ctime[0] = BSWAP_64(zp->zp_ctime[0]);
	zp->zp_ctime[1] = BSWAP_64(zp->zp_ctime[1]);
	zp->zp_gen = BSWAP_64(zp->zp_gen);
	zp->zp_mode = BSWAP_64(zp->zp_mode);
	zp->zp_size = BSWAP_64(zp->zp_size);
	zp->zp_parent = BSWAP_64(zp->zp_parent);
	zp->zp_links = BSWAP_64(zp->zp_links);
	zp->zp_xattr = BSWAP_64(zp->zp_xattr);
	zp->zp_rdev = BSWAP_64(zp->zp_rdev);
	zp->zp_flags = BSWAP_64(zp->zp_flags);
	zp->zp_uid = BSWAP_64(zp->zp_uid);
	zp->zp_gid = BSWAP_64(zp->zp_gid);
	zp->zp_zap = BSWAP_64(zp->zp_zap);
	zp->zp_pad[0] = BSWAP_64(zp->zp_pad[0]);
	zp->zp_pad[1] = BSWAP_64(zp->zp_pad[1]);
	zp->zp_pad[2] = BSWAP_64(zp->zp_pad[2]);

	zp->zp_acl.z_acl_extern_obj = BSWAP_64(zp->zp_acl.z_acl_extern_obj);
	zp->zp_acl.z_acl_size = BSWAP_32(zp->zp_acl.z_acl_size);
	zp->zp_acl.z_acl_version = BSWAP_16(zp->zp_acl.z_acl_version);
	zp->zp_acl.z_acl_count = BSWAP_16(zp->zp_acl.z_acl_count);
	if (zp->zp_acl.z_acl_version == ZFS_ACL_VERSION) {
		zfs_acl_byteswap((void *)&zp->zp_acl.z_ace_data[0],
		    ZFS_ACE_SPACE);
	} else
		zfs_oldace_byteswap((ace_t *)&zp->zp_acl.z_ace_data[0],
		    ACE_SLOT_CNT);
}
Exemplo n.º 17
0
int
main(int argc, char *argv[])
{
    char *buf = malloc(INITIAL_BUFLEN);
    dmu_replay_record_t thedrr;
    dmu_replay_record_t *drr = &thedrr;
    struct drr_begin *drrb = &thedrr.drr_u.drr_begin;
    struct drr_end *drre = &thedrr.drr_u.drr_end;
    struct drr_object *drro = &thedrr.drr_u.drr_object;
    struct drr_freeobjects *drrfo = &thedrr.drr_u.drr_freeobjects;
    struct drr_write *drrw = &thedrr.drr_u.drr_write;
    struct drr_write_byref *drrwbr = &thedrr.drr_u.drr_write_byref;
    struct drr_free *drrf = &thedrr.drr_u.drr_free;
    struct drr_spill *drrs = &thedrr.drr_u.drr_spill;
    char c;
    boolean_t verbose = B_FALSE;
    boolean_t first = B_TRUE;
    int err;
    zio_cksum_t zc = { 0 };
    zio_cksum_t pcksum = { 0 };

    while ((c = getopt(argc, argv, ":vC")) != -1) {
        switch (c) {
        case 'C':
            do_cksum = B_FALSE;
            break;
        case 'v':
            verbose = B_TRUE;
            break;
        case ':':
            (void) fprintf(stderr,
                           "missing argument for '%c' option\n", optopt);
            usage();
            break;
        case '?':
            (void) fprintf(stderr, "invalid option '%c'\n",
                           optopt);
            usage();
        }
    }

    if (isatty(STDIN_FILENO)) {
        (void) fprintf(stderr,
                       "Error: Backup stream can not be read "
                       "from a terminal.\n"
                       "You must redirect standard input.\n");
        exit(1);
    }

    send_stream = stdin;
    pcksum = zc;
    while (ssread(drr, sizeof (dmu_replay_record_t), &zc)) {

        if (first) {
            if (drrb->drr_magic == BSWAP_64(DMU_BACKUP_MAGIC)) {
                do_byteswap = B_TRUE;
                if (do_cksum) {
                    ZIO_SET_CHECKSUM(&zc, 0, 0, 0, 0);
                    /*
                     * recalculate header checksum now
                     * that we know it needs to be
                     * byteswapped.
                     */
                    fletcher_4_incremental_byteswap(drr,
                                                    sizeof (dmu_replay_record_t), &zc);
                }
            } else if (drrb->drr_magic != DMU_BACKUP_MAGIC) {
                (void) fprintf(stderr, "Invalid stream "
                               "(bad magic number)\n");
                exit(1);
            }
            first = B_FALSE;
        }
        if (do_byteswap) {
            drr->drr_type = BSWAP_32(drr->drr_type);
            drr->drr_payloadlen =
                BSWAP_32(drr->drr_payloadlen);
        }

        /*
         * 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.
         */
        if (drr->drr_type >= DRR_NUMTYPES) {
            (void) printf("INVALID record found: type 0x%x\n",
                          drr->drr_type);
            (void) printf("Aborting.\n");
            exit(1);
        }

        drr_record_count[drr->drr_type]++;

        switch (drr->drr_type) {
        case DRR_BEGIN:
            if (do_byteswap) {
                drrb->drr_magic = BSWAP_64(drrb->drr_magic);
                drrb->drr_versioninfo =
                    BSWAP_64(drrb->drr_versioninfo);
                drrb->drr_creation_time =
                    BSWAP_64(drrb->drr_creation_time);
                drrb->drr_type = BSWAP_32(drrb->drr_type);
                drrb->drr_flags = BSWAP_32(drrb->drr_flags);
                drrb->drr_toguid = BSWAP_64(drrb->drr_toguid);
                drrb->drr_fromguid =
                    BSWAP_64(drrb->drr_fromguid);
            }

            (void) printf("BEGIN record\n");
            (void) printf("\thdrtype = %lld\n",
                          DMU_GET_STREAM_HDRTYPE(drrb->drr_versioninfo));
            (void) printf("\tfeatures = %llx\n",
                          DMU_GET_FEATUREFLAGS(drrb->drr_versioninfo));
            (void) printf("\tmagic = %llx\n",
                          (u_longlong_t)drrb->drr_magic);
            (void) printf("\tcreation_time = %llx\n",
                          (u_longlong_t)drrb->drr_creation_time);
            (void) printf("\ttype = %u\n", drrb->drr_type);
            (void) printf("\tflags = 0x%x\n", drrb->drr_flags);
            (void) printf("\ttoguid = %llx\n",
                          (u_longlong_t)drrb->drr_toguid);
            (void) printf("\tfromguid = %llx\n",
                          (u_longlong_t)drrb->drr_fromguid);
            (void) printf("\ttoname = %s\n", drrb->drr_toname);
            if (verbose)
                (void) printf("\n");

            if ((DMU_GET_STREAM_HDRTYPE(drrb->drr_versioninfo) ==
                    DMU_COMPOUNDSTREAM) && drr->drr_payloadlen != 0) {
                nvlist_t *nv;
                int sz = drr->drr_payloadlen;

                if (sz > 1<<20) {
                    free(buf);
                    buf = malloc(sz);
                }
                (void) ssread(buf, sz, &zc);
                if (ferror(send_stream))
                    perror("fread");
                err = nvlist_unpack(buf, sz, &nv, 0);
                if (err)
                    perror(strerror(err));
                nvlist_print(stdout, nv);
                nvlist_free(nv);
            }
            break;

        case DRR_END:
            if (do_byteswap) {
                drre->drr_checksum.zc_word[0] =
                    BSWAP_64(drre->drr_checksum.zc_word[0]);
                drre->drr_checksum.zc_word[1] =
                    BSWAP_64(drre->drr_checksum.zc_word[1]);
                drre->drr_checksum.zc_word[2] =
                    BSWAP_64(drre->drr_checksum.zc_word[2]);
                drre->drr_checksum.zc_word[3] =
                    BSWAP_64(drre->drr_checksum.zc_word[3]);
            }
            /*
             * We compare against the *previous* checksum
             * value, because the stored checksum is of
             * everything before the DRR_END record.
             */
            if (do_cksum && !ZIO_CHECKSUM_EQUAL(drre->drr_checksum,
                                                pcksum)) {
                (void) printf("Expected checksum differs from "
                              "checksum in stream.\n");
                (void) printf("Expected checksum = %"
                              FX64 "/%" FX64 "/%" FX64 "/%" FX64 "\n",
                              pcksum.zc_word[0],
                              pcksum.zc_word[1],
                              pcksum.zc_word[2],
                              pcksum.zc_word[3]);
            }
            (void) printf("END checksum = %" FX64 "/%" FX64 "/%" FX64 "/%" FX64 "\n",
                          drre->drr_checksum.zc_word[0],
                          drre->drr_checksum.zc_word[1],
                          drre->drr_checksum.zc_word[2],
                          drre->drr_checksum.zc_word[3]);

            ZIO_SET_CHECKSUM(&zc, 0, 0, 0, 0);
            break;

        case DRR_OBJECT:
            if (do_byteswap) {
                drro->drr_object = BSWAP_64(drro->drr_object);
                drro->drr_type = BSWAP_32(drro->drr_type);
                drro->drr_bonustype =
                    BSWAP_32(drro->drr_bonustype);
                drro->drr_blksz = BSWAP_32(drro->drr_blksz);
                drro->drr_bonuslen =
                    BSWAP_32(drro->drr_bonuslen);
                drro->drr_toguid = BSWAP_64(drro->drr_toguid);
            }
            if (verbose) {
                (void) printf("OBJECT object = %llu type = %u "
                              "bonustype = %u blksz = %u bonuslen = %u\n",
                              (u_longlong_t)drro->drr_object,
                              drro->drr_type,
                              drro->drr_bonustype,
                              drro->drr_blksz,
                              drro->drr_bonuslen);
            }
            if (drro->drr_bonuslen > 0) {
                (void) ssread(buf, P2ROUNDUP(drro->drr_bonuslen,
                                             8), &zc);
            }
            break;

        case DRR_FREEOBJECTS:
            if (do_byteswap) {
                drrfo->drr_firstobj =
                    BSWAP_64(drrfo->drr_firstobj);
                drrfo->drr_numobjs =
                    BSWAP_64(drrfo->drr_numobjs);
                drrfo->drr_toguid = BSWAP_64(drrfo->drr_toguid);
            }
            if (verbose) {
                (void) printf("FREEOBJECTS firstobj = %llu "
                              "numobjs = %llu\n",
                              (u_longlong_t)drrfo->drr_firstobj,
                              (u_longlong_t)drrfo->drr_numobjs);
            }
            break;

        case DRR_WRITE:
            if (do_byteswap) {
                drrw->drr_object = BSWAP_64(drrw->drr_object);
                drrw->drr_type = BSWAP_32(drrw->drr_type);
                drrw->drr_offset = BSWAP_64(drrw->drr_offset);
                drrw->drr_length = BSWAP_64(drrw->drr_length);
                drrw->drr_toguid = BSWAP_64(drrw->drr_toguid);
                drrw->drr_key.ddk_prop =
                    BSWAP_64(drrw->drr_key.ddk_prop);
            }
            if (verbose) {
                (void) printf("WRITE object = %llu type = %u "
                              "checksum type = %u\n"
                              "offset = %llu length = %llu "
                              "props = %llx\n",
                              (u_longlong_t)drrw->drr_object,
                              drrw->drr_type,
                              drrw->drr_checksumtype,
                              (u_longlong_t)drrw->drr_offset,
                              (u_longlong_t)drrw->drr_length,
                              (u_longlong_t)drrw->drr_key.ddk_prop);
            }
            (void) ssread(buf, drrw->drr_length, &zc);
            total_write_size += drrw->drr_length;
            break;

        case DRR_WRITE_BYREF:
            if (do_byteswap) {
                drrwbr->drr_object =
                    BSWAP_64(drrwbr->drr_object);
                drrwbr->drr_offset =
                    BSWAP_64(drrwbr->drr_offset);
                drrwbr->drr_length =
                    BSWAP_64(drrwbr->drr_length);
                drrwbr->drr_toguid =
                    BSWAP_64(drrwbr->drr_toguid);
                drrwbr->drr_refguid =
                    BSWAP_64(drrwbr->drr_refguid);
                drrwbr->drr_refobject =
                    BSWAP_64(drrwbr->drr_refobject);
                drrwbr->drr_refoffset =
                    BSWAP_64(drrwbr->drr_refoffset);
                drrwbr->drr_key.ddk_prop =
                    BSWAP_64(drrwbr->drr_key.ddk_prop);
            }
            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",
                              (u_longlong_t)drrwbr->drr_object,
                              drrwbr->drr_checksumtype,
                              (u_longlong_t)drrwbr->drr_key.ddk_prop,
                              (u_longlong_t)drrwbr->drr_offset,
                              (u_longlong_t)drrwbr->drr_length,
                              (u_longlong_t)drrwbr->drr_toguid,
                              (u_longlong_t)drrwbr->drr_refguid,
                              (u_longlong_t)drrwbr->drr_refobject,
                              (u_longlong_t)drrwbr->drr_refoffset);
            }
            break;

        case DRR_FREE:
            if (do_byteswap) {
                drrf->drr_object = BSWAP_64(drrf->drr_object);
                drrf->drr_offset = BSWAP_64(drrf->drr_offset);
                drrf->drr_length = BSWAP_64(drrf->drr_length);
            }
            if (verbose) {
                (void) printf("FREE object = %llu "
                              "offset = %llu length = %lld\n",
                              (u_longlong_t)drrf->drr_object,
                              (u_longlong_t)drrf->drr_offset,
                              (longlong_t)drrf->drr_length);
            }
            break;
        case DRR_SPILL:
            if (do_byteswap) {
                drrs->drr_object = BSWAP_64(drrs->drr_object);
                drrs->drr_length = BSWAP_64(drrs->drr_length);
            }
            if (verbose) {
                (void) printf("SPILL block for object = %" FU64
                              "length = %" FU64 "\n", drrs->drr_object,
                              drrs->drr_length);
            }
            (void) ssread(buf, drrs->drr_length, &zc);
            break;
        }
        pcksum = zc;
    }
    free(buf);

    /* Print final summary */

    (void) printf("SUMMARY:\n");
    (void) printf("\tTotal DRR_BEGIN records = %lld\n",
                  (u_longlong_t)drr_record_count[DRR_BEGIN]);
    (void) printf("\tTotal DRR_END records = %lld\n",
                  (u_longlong_t)drr_record_count[DRR_END]);
    (void) printf("\tTotal DRR_OBJECT records = %lld\n",
                  (u_longlong_t)drr_record_count[DRR_OBJECT]);
    (void) printf("\tTotal DRR_FREEOBJECTS records = %lld\n",
                  (u_longlong_t)drr_record_count[DRR_FREEOBJECTS]);
    (void) printf("\tTotal DRR_WRITE records = %lld\n",
                  (u_longlong_t)drr_record_count[DRR_WRITE]);
    (void) printf("\tTotal DRR_FREE records = %lld\n",
                  (u_longlong_t)drr_record_count[DRR_FREE]);
    (void) printf("\tTotal DRR_SPILL records = %lld\n",
                  (u_longlong_t)drr_record_count[DRR_SPILL]);
    (void) printf("\tTotal records = %lld\n",
                  (u_longlong_t)(drr_record_count[DRR_BEGIN] +
                                 drr_record_count[DRR_OBJECT] +
                                 drr_record_count[DRR_FREEOBJECTS] +
                                 drr_record_count[DRR_WRITE] +
                                 drr_record_count[DRR_FREE] +
                                 drr_record_count[DRR_SPILL] +
                                 drr_record_count[DRR_END]));
    (void) printf("\tTotal write size = %lld (0x%llx)\n",
                  (u_longlong_t)total_write_size, (u_longlong_t)total_write_size);
    (void) printf("\tTotal stream length = %lld (0x%llx)\n",
                  (u_longlong_t)total_stream_len, (u_longlong_t)total_stream_len);
    return (0);
}
Exemplo n.º 18
0
Arquivo: zfs_vfsops.c Projeto: nwf/zfs
static int
zfs_space_delta_cb(dmu_object_type_t bonustype, void *data,
    uint64_t *userp, uint64_t *groupp)
{
	/*
	 * Is it a valid type of object to track?
	 */
	if (bonustype != DMU_OT_ZNODE && bonustype != DMU_OT_SA)
		return (SET_ERROR(ENOENT));

	/*
	 * If we have a NULL data pointer
	 * then assume the id's aren't changing and
	 * return EEXIST to the dmu to let it know to
	 * use the same ids
	 */
	if (data == NULL)
		return (SET_ERROR(EEXIST));

	if (bonustype == DMU_OT_ZNODE) {
		znode_phys_t *znp = data;
		*userp = znp->zp_uid;
		*groupp = znp->zp_gid;
	} else {
		int hdrsize;
		sa_hdr_phys_t *sap = data;
		sa_hdr_phys_t sa = *sap;
		boolean_t swap = B_FALSE;

		ASSERT(bonustype == DMU_OT_SA);

		if (sa.sa_magic == 0) {
			/*
			 * This should only happen for newly created
			 * files that haven't had the znode data filled
			 * in yet.
			 */
			*userp = 0;
			*groupp = 0;
			return (0);
		}
		if (sa.sa_magic == BSWAP_32(SA_MAGIC)) {
			sa.sa_magic = SA_MAGIC;
			sa.sa_layout_info = BSWAP_16(sa.sa_layout_info);
			swap = B_TRUE;
		} else {
			VERIFY3U(sa.sa_magic, ==, SA_MAGIC);
		}

		hdrsize = sa_hdrsize(&sa);
		VERIFY3U(hdrsize, >=, sizeof (sa_hdr_phys_t));
		*userp = *((uint64_t *)((uintptr_t)data + hdrsize +
		    SA_UID_OFFSET));
		*groupp = *((uint64_t *)((uintptr_t)data + hdrsize +
		    SA_GID_OFFSET));
		if (swap) {
			*userp = BSWAP_64(*userp);
			*groupp = BSWAP_64(*groupp);
		}
	}
	return (0);
}
Exemplo n.º 19
0
int
zio_checksum_error_impl(spa_t *spa, blkptr_t *bp, enum zio_checksum checksum,
    abd_t *abd, uint64_t size, uint64_t offset, zio_bad_cksum_t *info)
{
	zio_checksum_info_t *ci = &zio_checksum_table[checksum];
	int byteswap;
	zio_cksum_t actual_cksum, expected_cksum;

	if (checksum >= ZIO_CHECKSUM_FUNCTIONS || ci->ci_func[0] == NULL)
		return (SET_ERROR(EINVAL));

	zio_checksum_template_init(checksum, spa);

	if (ci->ci_flags & ZCHECKSUM_FLAG_EMBEDDED) {
		zio_eck_t *eck;
		zio_cksum_t verifier;
		size_t eck_offset;
		uint64_t data_size = size;
		void *data = abd_borrow_buf_copy(abd, data_size);

		if (checksum == ZIO_CHECKSUM_ZILOG2) {
			zil_chain_t *zilc = data;
			uint64_t nused;

			eck = &zilc->zc_eck;
			if (eck->zec_magic == ZEC_MAGIC) {
				nused = zilc->zc_nused;
			} else if (eck->zec_magic == BSWAP_64(ZEC_MAGIC)) {
				nused = BSWAP_64(zilc->zc_nused);
			} else {
				abd_return_buf(abd, data, data_size);
				return (SET_ERROR(ECKSUM));
			}

			if (nused > data_size) {
				abd_return_buf(abd, data, data_size);
				return (SET_ERROR(ECKSUM));
			}

			size = P2ROUNDUP_TYPED(nused, ZIL_MIN_BLKSZ, uint64_t);
		} else {
			eck = (zio_eck_t *)((char *)data + data_size) - 1;
		}

		if (checksum == ZIO_CHECKSUM_GANG_HEADER)
			zio_checksum_gang_verifier(&verifier, bp);
		else if (checksum == ZIO_CHECKSUM_LABEL)
			zio_checksum_label_verifier(&verifier, offset);
		else
			verifier = bp->blk_cksum;

		byteswap = (eck->zec_magic == BSWAP_64(ZEC_MAGIC));

		if (byteswap)
			byteswap_uint64_array(&verifier, sizeof (zio_cksum_t));

		eck_offset = (size_t)(&eck->zec_cksum) - (size_t)data;
		expected_cksum = eck->zec_cksum;
		eck->zec_cksum = verifier;
		abd_return_buf_copy(abd, data, data_size);

		ci->ci_func[byteswap](abd, size,
		    spa->spa_cksum_tmpls[checksum], &actual_cksum);
		abd_copy_from_buf_off(abd, &expected_cksum,
		    eck_offset, sizeof (zio_cksum_t));

		if (byteswap) {
			byteswap_uint64_array(&expected_cksum,
			    sizeof (zio_cksum_t));
		}
	} else {
		byteswap = BP_SHOULD_BYTESWAP(bp);
		expected_cksum = bp->blk_cksum;
		ci->ci_func[byteswap](abd, size,
		    spa->spa_cksum_tmpls[checksum], &actual_cksum);
	}

	if (info != NULL) {
		info->zbc_expected = expected_cksum;
		info->zbc_actual = actual_cksum;
		info->zbc_checksum_name = ci->ci_name;
		info->zbc_byteswapped = byteswap;
		info->zbc_injected = 0;
		info->zbc_has_cksum = 1;
	}

	if (!ZIO_CHECKSUM_EQUAL(actual_cksum, expected_cksum))
		return (SET_ERROR(ECKSUM));

	return (0);
}
Exemplo n.º 20
0
/*
 * swap ace_t and ace_oject_t
 */
void
zfs_ace_byteswap(void *buf, size_t size, boolean_t zfs_layout)
{
	caddr_t end;
	caddr_t ptr;
	zfs_ace_t *zacep;
	ace_t *acep;
	uint16_t entry_type;
	size_t entry_size;
	int ace_type;

	end = (caddr_t)buf + size;
	ptr = buf;

	while (ptr < end) {
		if (zfs_layout) {
			/*
			 * Avoid overrun.  Embedded aces can have one
			 * of several sizes.  We don't know exactly
			 * how many our present, only the size of the
			 * buffer containing them.  That size may be
			 * larger than needed to hold the aces
			 * present.  As long as we do not do any
			 * swapping beyond the end of our block we are
			 * okay.  It it safe to swap any non-ace data
			 * within the block since it is just zeros.
			 */
			if (ptr + sizeof (zfs_ace_hdr_t) > end) {
				break;
			}
			zacep = (zfs_ace_t *)ptr;
			zacep->z_hdr.z_access_mask =
			    BSWAP_32(zacep->z_hdr.z_access_mask);
			zacep->z_hdr.z_flags = BSWAP_16(zacep->z_hdr.z_flags);
			ace_type = zacep->z_hdr.z_type =
			    BSWAP_16(zacep->z_hdr.z_type);
			entry_type = zacep->z_hdr.z_flags & ACE_TYPE_FLAGS;
		} else {
			/* Overrun avoidance */
			if (ptr + sizeof (ace_t) > end) {
				break;
			}
			acep = (ace_t *)ptr;
			acep->a_access_mask = BSWAP_32(acep->a_access_mask);
			acep->a_flags = BSWAP_16(acep->a_flags);
			ace_type = acep->a_type = BSWAP_16(acep->a_type);
			acep->a_who = BSWAP_32(acep->a_who);
			entry_type = acep->a_flags & ACE_TYPE_FLAGS;
		}
		switch (entry_type) {
		case ACE_OWNER:
		case ACE_EVERYONE:
		case (ACE_IDENTIFIER_GROUP | ACE_GROUP):
			entry_size = zfs_layout ?
			    sizeof (zfs_ace_hdr_t) : sizeof (ace_t);
			break;
		case ACE_IDENTIFIER_GROUP:
		default:
			/* Overrun avoidance */
			if (zfs_layout) {
				if (ptr + sizeof (zfs_ace_t) <= end) {
					zacep->z_fuid = BSWAP_64(zacep->z_fuid);
				} else {
					entry_size = sizeof (zfs_ace_t);
					break;
				}
			}
			switch (ace_type) {
			case ACE_ACCESS_ALLOWED_OBJECT_ACE_TYPE:
			case ACE_ACCESS_DENIED_OBJECT_ACE_TYPE:
			case ACE_SYSTEM_AUDIT_OBJECT_ACE_TYPE:
			case ACE_SYSTEM_ALARM_OBJECT_ACE_TYPE:
				entry_size = zfs_layout ?
				    sizeof (zfs_object_ace_t) :
				    sizeof (ace_object_t);
				break;
			default:
				entry_size = zfs_layout ? sizeof (zfs_ace_t) :
				    sizeof (ace_t);
				break;
			}
		}
		ptr = ptr + entry_size;
	}
}
Exemplo n.º 21
0
int
zio_checksum_error_impl(spa_t *spa, const blkptr_t *bp,
    enum zio_checksum checksum, abd_t *abd, uint64_t size, uint64_t offset,
    zio_bad_cksum_t *info)
{
	zio_checksum_info_t *ci = &zio_checksum_table[checksum];
	zio_cksum_t actual_cksum, expected_cksum;
	zio_eck_t eck;
	int byteswap;

	if (checksum >= ZIO_CHECKSUM_FUNCTIONS || ci->ci_func[0] == NULL)
		return (SET_ERROR(EINVAL));

	zio_checksum_template_init(checksum, spa);

	if (ci->ci_flags & ZCHECKSUM_FLAG_EMBEDDED) {
		zio_cksum_t verifier;
		size_t eck_offset;

		if (checksum == ZIO_CHECKSUM_ZILOG2) {
			zil_chain_t zilc;
			uint64_t nused;

			abd_copy_to_buf(&zilc, abd, sizeof (zil_chain_t));

			eck = zilc.zc_eck;
			eck_offset = offsetof(zil_chain_t, zc_eck) +
			    offsetof(zio_eck_t, zec_cksum);

			if (eck.zec_magic == ZEC_MAGIC) {
				nused = zilc.zc_nused;
			} else if (eck.zec_magic == BSWAP_64(ZEC_MAGIC)) {
				nused = BSWAP_64(zilc.zc_nused);
			} else {
				return (SET_ERROR(ECKSUM));
			}

			if (nused > size) {
				return (SET_ERROR(ECKSUM));
			}

			size = P2ROUNDUP_TYPED(nused, ZIL_MIN_BLKSZ, uint64_t);
		} else {
			eck_offset = size - sizeof (zio_eck_t);
			abd_copy_to_buf_off(&eck, abd, eck_offset,
			    sizeof (zio_eck_t));
			eck_offset += offsetof(zio_eck_t, zec_cksum);
		}

		if (checksum == ZIO_CHECKSUM_GANG_HEADER)
			zio_checksum_gang_verifier(&verifier, bp);
		else if (checksum == ZIO_CHECKSUM_LABEL)
			zio_checksum_label_verifier(&verifier, offset);
		else
			verifier = bp->blk_cksum;

		byteswap = (eck.zec_magic == BSWAP_64(ZEC_MAGIC));

		if (byteswap)
			byteswap_uint64_array(&verifier, sizeof (zio_cksum_t));

		expected_cksum = eck.zec_cksum;

		abd_copy_from_buf_off(abd, &verifier, eck_offset,
		    sizeof (zio_cksum_t));

		ci->ci_func[byteswap](abd, size,
		    spa->spa_cksum_tmpls[checksum], &actual_cksum);

		abd_copy_from_buf_off(abd, &expected_cksum, eck_offset,
		    sizeof (zio_cksum_t));

		if (byteswap) {
			byteswap_uint64_array(&expected_cksum,
			    sizeof (zio_cksum_t));
		}
	} else {
		byteswap = BP_SHOULD_BYTESWAP(bp);
		expected_cksum = bp->blk_cksum;
		ci->ci_func[byteswap](abd, size,
		    spa->spa_cksum_tmpls[checksum], &actual_cksum);
	}

	/*
	 * MAC checksums are a special case since half of this checksum will
	 * actually be the encryption MAC. This will be verified by the
	 * decryption process, so we just check the truncated checksum now.
	 * Objset blocks use embedded MACs so we don't truncate the checksum
	 * for them.
	 */
	if (bp != NULL && BP_USES_CRYPT(bp) &&
	    BP_GET_TYPE(bp) != DMU_OT_OBJSET) {
		if (!(ci->ci_flags & ZCHECKSUM_FLAG_DEDUP)) {
			actual_cksum.zc_word[0] ^= actual_cksum.zc_word[2];
			actual_cksum.zc_word[1] ^= actual_cksum.zc_word[3];
		}

		actual_cksum.zc_word[2] = 0;
		actual_cksum.zc_word[3] = 0;
		expected_cksum.zc_word[2] = 0;
		expected_cksum.zc_word[3] = 0;
	}

	if (info != NULL) {
		info->zbc_expected = expected_cksum;
		info->zbc_actual = actual_cksum;
		info->zbc_checksum_name = ci->ci_name;
		info->zbc_byteswapped = byteswap;
		info->zbc_injected = 0;
		info->zbc_has_cksum = 1;
	}

	if (!ZIO_CHECKSUM_EQUAL(actual_cksum, expected_cksum))
		return (SET_ERROR(ECKSUM));

	return (0);
}
Exemplo n.º 22
0
int
zio_checksum_error(zio_t *zio, zio_bad_cksum_t *info)
{
	blkptr_t *bp = zio->io_bp;
	uint_t checksum = (bp == NULL ? zio->io_prop.zp_checksum :
	    (BP_IS_GANG(bp) ? ZIO_CHECKSUM_GANG_HEADER : BP_GET_CHECKSUM(bp)));
	int byteswap;
	int error;
	uint64_t size = (bp == NULL ? zio->io_size :
	    (BP_IS_GANG(bp) ? SPA_GANGBLOCKSIZE : BP_GET_PSIZE(bp)));
	uint64_t offset = zio->io_offset;
	void *data = zio->io_data;
	zio_checksum_info_t *ci = &zio_checksum_table[checksum];
	zio_cksum_t actual_cksum, expected_cksum, verifier;

	if (checksum >= ZIO_CHECKSUM_FUNCTIONS || ci->ci_func[0] == NULL)
		return (SET_ERROR(EINVAL));

	if (ci->ci_eck) {
		zio_eck_t *eck;

		if (checksum == ZIO_CHECKSUM_ZILOG2) {
			zil_chain_t *zilc = data;
			uint64_t nused;

			eck = &zilc->zc_eck;
			if (eck->zec_magic == ZEC_MAGIC)
				nused = zilc->zc_nused;
			else if (eck->zec_magic == BSWAP_64(ZEC_MAGIC))
				nused = BSWAP_64(zilc->zc_nused);
			else
				return (SET_ERROR(ECKSUM));

			if (nused > size)
				return (SET_ERROR(ECKSUM));

			size = P2ROUNDUP_TYPED(nused, ZIL_MIN_BLKSZ, uint64_t);
		} else {
			eck = (zio_eck_t *)((char *)data + size) - 1;
		}

		if (checksum == ZIO_CHECKSUM_GANG_HEADER)
			zio_checksum_gang_verifier(&verifier, bp);
		else if (checksum == ZIO_CHECKSUM_LABEL)
			zio_checksum_label_verifier(&verifier, offset);
		else
			verifier = bp->blk_cksum;

		byteswap = (eck->zec_magic == BSWAP_64(ZEC_MAGIC));

		if (byteswap)
			byteswap_uint64_array(&verifier, sizeof (zio_cksum_t));

		expected_cksum = eck->zec_cksum;
		eck->zec_cksum = verifier;
		ci->ci_func[byteswap](data, size, &actual_cksum);
		eck->zec_cksum = expected_cksum;

		if (byteswap)
			byteswap_uint64_array(&expected_cksum,
			    sizeof (zio_cksum_t));
	} else {
		ASSERT(!BP_IS_GANG(bp));
		byteswap = BP_SHOULD_BYTESWAP(bp);
		expected_cksum = bp->blk_cksum;
		ci->ci_func[byteswap](data, size, &actual_cksum);
	}

	info->zbc_expected = expected_cksum;
	info->zbc_actual = actual_cksum;
	info->zbc_checksum_name = ci->ci_name;
	info->zbc_byteswapped = byteswap;
	info->zbc_injected = 0;
	info->zbc_has_cksum = 1;

	/*
	 * Special case for truncated checksums with crypto MAC
	 * This may not be the best place to deal with this but it is here now.
	 *
	 * Words 0 and 1 and 32 bits of word 2 of the checksum are the
	 * first 160 bytes of SHA256 hash.
	 * The rest of words 2 and all of word 3 are the crypto MAC so
	 * ignore those because we can't check them until we do the decryption
	 * later, nor could we do them if the key wasn't present
	 */
	if (ci->ci_trunc) {
	  if (!(0 == (
		      (actual_cksum.zc_word[0] - expected_cksum.zc_word[0]) |
		      (actual_cksum.zc_word[1] - expected_cksum.zc_word[1]) |
		      (BF64_GET(actual_cksum.zc_word[2], 0, 32) -
		       BF64_GET(expected_cksum.zc_word[2], 0, 32))))) {
            return (ECKSUM);
	  }
	} else if (!ZIO_CHECKSUM_EQUAL(actual_cksum, expected_cksum)) {
		return (SET_ERROR(ECKSUM));
	}

	if (zio_injection_enabled && !zio->io_error &&
	    (error = zio_handle_fault_injection(zio, ECKSUM)) != 0) {

		info->zbc_injected = 1;
		return (error);
	}

	return (0);
}