/*1* CDDL HEADER START2*3* This file and its contents are supplied under the terms of the4* Common Development and Distribution License ("CDDL"), version 1.0.5* You may only use this file in accordance with the terms of version6* 1.0 of the CDDL.7*8* A full copy of the text of the CDDL should have accompanied this9* source. A copy of the CDDL is also available via the Internet at10* http://www.illumos.org/license/CDDL.11*12* CDDL HEADER END13*/1415/*16* Copyright (c) 2013 by Delphix. All rights reserved.17*/1819/*20* Embedded-data Block Pointers21*22* Normally, block pointers point (via their DVAs) to a block which holds data.23* If the data that we need to store is very small, this is an inefficient24* use of space, because a block must be at minimum 1 sector (typically 51225* bytes or 4KB). Additionally, reading these small blocks tends to generate26* more random reads.27*28* Embedded-data Block Pointers allow small pieces of data (the "payload",29* up to 112 bytes) to be stored in the block pointer itself, instead of30* being pointed to. The "Pointer" part of this name is a bit of a31* misnomer, as nothing is pointed to.32*33* BP_EMBEDDED_TYPE_DATA block pointers allow highly-compressible data to34* be embedded in the block pointer. The logic for this is handled in35* the SPA, by the zio pipeline. Therefore most code outside the zio36* pipeline doesn't need special-cases to handle these block pointers.37*38* See spa.h for details on the exact layout of embedded block pointers.39*/4041/*42* buf must be at least BPE_GET_PSIZE(bp) bytes long (which will never be43* more than BPE_PAYLOAD_SIZE bytes).44*/45void46decode_embedded_bp_compressed(const blkptr_t *bp, void *buf)47{48int psize;49uint8_t *buf8 = buf;50uint64_t w = 0;51const uint64_t *bp64 = (const uint64_t *)bp;5253ASSERT(BP_IS_EMBEDDED(bp));5455psize = BPE_GET_PSIZE(bp);5657/*58* Decode the words of the block pointer into the byte array.59* Low bits of first word are the first byte (little endian).60*/61for (int i = 0; i < psize; i++) {62if (i % sizeof (w) == 0) {63/* beginning of a word */64ASSERT3P(bp64, <, bp + 1);65w = *bp64;66bp64++;67if (!BPE_IS_PAYLOADWORD(bp, bp64))68bp64++;69}70buf8[i] = BF64_GET(w, (i % sizeof (w)) * NBBY, NBBY);71}72}737475