1 /*- 2 * Copyright (c) 2002 McAfee, Inc. 3 * All rights reserved. 4 * 5 * This software was developed for the FreeBSD Project by Marshall 6 * Kirk McKusick and McAfee Research,, the Security Research Division of 7 * McAfee, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as 8 * part of the DARPA CHATS research program 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 */ 31 /* 32 * CDDL HEADER START 33 * 34 * The contents of this file are subject to the terms of the 35 * Common Development and Distribution License (the "License"). 36 * You may not use this file except in compliance with the License. 37 * 38 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 39 * or http://www.opensolaris.org/os/licensing. 40 * See the License for the specific language governing permissions 41 * and limitations under the License. 42 * 43 * When distributing Covered Code, include this CDDL HEADER in each 44 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 45 * If applicable, add the following below this CDDL HEADER, with the 46 * fields enclosed by brackets "[]" replaced with your own identifying 47 * information: Portions Copyright [yyyy] [name of copyright owner] 48 * 49 * CDDL HEADER END 50 */ 51 /* 52 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 53 * Use is subject to license terms. 54 */ 55 /* 56 * Copyright 2013 by Saso Kiselkov. All rights reserved. 57 */ 58 /* 59 * Copyright (c) 2013 by Delphix. All rights reserved. 60 */ 61 62 #define MAXNAMELEN 256 63 64 #define _NOTE(s) 65 66 typedef enum { B_FALSE, B_TRUE } boolean_t; 67 68 /* CRC64 table */ 69 #define ZFS_CRC64_POLY 0xC96C5795D7870F42ULL /* ECMA-182, reflected form */ 70 71 /* 72 * Macros for various sorts of alignment and rounding when the alignment 73 * is known to be a power of 2. 74 */ 75 #define P2ALIGN(x, align) ((x) & -(align)) 76 #define P2PHASE(x, align) ((x) & ((align) - 1)) 77 #define P2NPHASE(x, align) (-(x) & ((align) - 1)) 78 #define P2ROUNDUP(x, align) (-(-(x) & -(align))) 79 #define P2END(x, align) (-(~(x) & -(align))) 80 #define P2PHASEUP(x, align, phase) ((phase) - (((phase) - (x)) & -(align))) 81 #define P2BOUNDARY(off, len, align) (((off) ^ ((off) + (len) - 1)) > (align) - 1) 82 83 /* 84 * General-purpose 32-bit and 64-bit bitfield encodings. 85 */ 86 #define BF32_DECODE(x, low, len) P2PHASE((x) >> (low), 1U << (len)) 87 #define BF64_DECODE(x, low, len) P2PHASE((x) >> (low), 1ULL << (len)) 88 #define BF32_ENCODE(x, low, len) (P2PHASE((x), 1U << (len)) << (low)) 89 #define BF64_ENCODE(x, low, len) (P2PHASE((x), 1ULL << (len)) << (low)) 90 91 #define BF32_GET(x, low, len) BF32_DECODE(x, low, len) 92 #define BF64_GET(x, low, len) BF64_DECODE(x, low, len) 93 94 #define BF32_SET(x, low, len, val) \ 95 ((x) ^= BF32_ENCODE((x >> low) ^ (val), low, len)) 96 #define BF64_SET(x, low, len, val) \ 97 ((x) ^= BF64_ENCODE((x >> low) ^ (val), low, len)) 98 99 #define BF32_GET_SB(x, low, len, shift, bias) \ 100 ((BF32_GET(x, low, len) + (bias)) << (shift)) 101 #define BF64_GET_SB(x, low, len, shift, bias) \ 102 ((BF64_GET(x, low, len) + (bias)) << (shift)) 103 104 #define BF32_SET_SB(x, low, len, shift, bias, val) \ 105 BF32_SET(x, low, len, ((val) >> (shift)) - (bias)) 106 #define BF64_SET_SB(x, low, len, shift, bias, val) \ 107 BF64_SET(x, low, len, ((val) >> (shift)) - (bias)) 108 109 /* 110 * Macros to reverse byte order 111 */ 112 #define BSWAP_8(x) ((x) & 0xff) 113 #define BSWAP_16(x) ((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8)) 114 #define BSWAP_32(x) ((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16)) 115 #define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32)) 116 117 /* 118 * Note: the boot loader can't actually read blocks larger than 128KB, 119 * due to lack of memory. Therefore its SPA_MAXBLOCKSIZE is still 128KB. 120 */ 121 #define SPA_MINBLOCKSHIFT 9 122 #define SPA_MAXBLOCKSHIFT 17 123 #define SPA_MINBLOCKSIZE (1ULL << SPA_MINBLOCKSHIFT) 124 #define SPA_MAXBLOCKSIZE (1ULL << SPA_MAXBLOCKSHIFT) 125 126 /* 127 * The DVA size encodings for LSIZE and PSIZE support blocks up to 32MB. 128 * The ASIZE encoding should be at least 64 times larger (6 more bits) 129 * to support up to 4-way RAID-Z mirror mode with worst-case gang block 130 * overhead, three DVAs per bp, plus one more bit in case we do anything 131 * else that expands the ASIZE. 132 */ 133 #define SPA_LSIZEBITS 16 /* LSIZE up to 32M (2^16 * 512) */ 134 #define SPA_PSIZEBITS 16 /* PSIZE up to 32M (2^16 * 512) */ 135 #define SPA_ASIZEBITS 24 /* ASIZE up to 64 times larger */ 136 137 /* 138 * All SPA data is represented by 128-bit data virtual addresses (DVAs). 139 * The members of the dva_t should be considered opaque outside the SPA. 140 */ 141 typedef struct dva { 142 uint64_t dva_word[2]; 143 } dva_t; 144 145 /* 146 * Each block has a 256-bit checksum -- strong enough for cryptographic hashes. 147 */ 148 typedef struct zio_cksum { 149 uint64_t zc_word[4]; 150 } zio_cksum_t; 151 152 /* 153 * Each block is described by its DVAs, time of birth, checksum, etc. 154 * The word-by-word, bit-by-bit layout of the blkptr is as follows: 155 * 156 * 64 56 48 40 32 24 16 8 0 157 * +-------+-------+-------+-------+-------+-------+-------+-------+ 158 * 0 | vdev1 | GRID | ASIZE | 159 * +-------+-------+-------+-------+-------+-------+-------+-------+ 160 * 1 |G| offset1 | 161 * +-------+-------+-------+-------+-------+-------+-------+-------+ 162 * 2 | vdev2 | GRID | ASIZE | 163 * +-------+-------+-------+-------+-------+-------+-------+-------+ 164 * 3 |G| offset2 | 165 * +-------+-------+-------+-------+-------+-------+-------+-------+ 166 * 4 | vdev3 | GRID | ASIZE | 167 * +-------+-------+-------+-------+-------+-------+-------+-------+ 168 * 5 |G| offset3 | 169 * +-------+-------+-------+-------+-------+-------+-------+-------+ 170 * 6 |BDX|lvl| type | cksum |E| comp| PSIZE | LSIZE | 171 * +-------+-------+-------+-------+-------+-------+-------+-------+ 172 * 7 | padding | 173 * +-------+-------+-------+-------+-------+-------+-------+-------+ 174 * 8 | padding | 175 * +-------+-------+-------+-------+-------+-------+-------+-------+ 176 * 9 | physical birth txg | 177 * +-------+-------+-------+-------+-------+-------+-------+-------+ 178 * a | logical birth txg | 179 * +-------+-------+-------+-------+-------+-------+-------+-------+ 180 * b | fill count | 181 * +-------+-------+-------+-------+-------+-------+-------+-------+ 182 * c | checksum[0] | 183 * +-------+-------+-------+-------+-------+-------+-------+-------+ 184 * d | checksum[1] | 185 * +-------+-------+-------+-------+-------+-------+-------+-------+ 186 * e | checksum[2] | 187 * +-------+-------+-------+-------+-------+-------+-------+-------+ 188 * f | checksum[3] | 189 * +-------+-------+-------+-------+-------+-------+-------+-------+ 190 * 191 * Legend: 192 * 193 * vdev virtual device ID 194 * offset offset into virtual device 195 * LSIZE logical size 196 * PSIZE physical size (after compression) 197 * ASIZE allocated size (including RAID-Z parity and gang block headers) 198 * GRID RAID-Z layout information (reserved for future use) 199 * cksum checksum function 200 * comp compression function 201 * G gang block indicator 202 * B byteorder (endianness) 203 * D dedup 204 * X encryption (on version 30, which is not supported) 205 * E blkptr_t contains embedded data (see below) 206 * lvl level of indirection 207 * type DMU object type 208 * phys birth txg of block allocation; zero if same as logical birth txg 209 * log. birth transaction group in which the block was logically born 210 * fill count number of non-zero blocks under this bp 211 * checksum[4] 256-bit checksum of the data this bp describes 212 */ 213 214 /* 215 * "Embedded" blkptr_t's don't actually point to a block, instead they 216 * have a data payload embedded in the blkptr_t itself. See the comment 217 * in blkptr.c for more details. 218 * 219 * The blkptr_t is laid out as follows: 220 * 221 * 64 56 48 40 32 24 16 8 0 222 * +-------+-------+-------+-------+-------+-------+-------+-------+ 223 * 0 | payload | 224 * 1 | payload | 225 * 2 | payload | 226 * 3 | payload | 227 * 4 | payload | 228 * 5 | payload | 229 * +-------+-------+-------+-------+-------+-------+-------+-------+ 230 * 6 |BDX|lvl| type | etype |E| comp| PSIZE| LSIZE | 231 * +-------+-------+-------+-------+-------+-------+-------+-------+ 232 * 7 | payload | 233 * 8 | payload | 234 * 9 | payload | 235 * +-------+-------+-------+-------+-------+-------+-------+-------+ 236 * a | logical birth txg | 237 * +-------+-------+-------+-------+-------+-------+-------+-------+ 238 * b | payload | 239 * c | payload | 240 * d | payload | 241 * e | payload | 242 * f | payload | 243 * +-------+-------+-------+-------+-------+-------+-------+-------+ 244 * 245 * Legend: 246 * 247 * payload contains the embedded data 248 * B (byteorder) byteorder (endianness) 249 * D (dedup) padding (set to zero) 250 * X encryption (set to zero; see above) 251 * E (embedded) set to one 252 * lvl indirection level 253 * type DMU object type 254 * etype how to interpret embedded data (BP_EMBEDDED_TYPE_*) 255 * comp compression function of payload 256 * PSIZE size of payload after compression, in bytes 257 * LSIZE logical size of payload, in bytes 258 * note that 25 bits is enough to store the largest 259 * "normal" BP's LSIZE (2^16 * 2^9) in bytes 260 * log. birth transaction group in which the block was logically born 261 * 262 * Note that LSIZE and PSIZE are stored in bytes, whereas for non-embedded 263 * bp's they are stored in units of SPA_MINBLOCKSHIFT. 264 * Generally, the generic BP_GET_*() macros can be used on embedded BP's. 265 * The B, D, X, lvl, type, and comp fields are stored the same as with normal 266 * BP's so the BP_SET_* macros can be used with them. etype, PSIZE, LSIZE must 267 * be set with the BPE_SET_* macros. BP_SET_EMBEDDED() should be called before 268 * other macros, as they assert that they are only used on BP's of the correct 269 * "embedded-ness". 270 */ 271 272 #define BPE_GET_ETYPE(bp) \ 273 (ASSERT(BP_IS_EMBEDDED(bp)), \ 274 BF64_GET((bp)->blk_prop, 40, 8)) 275 #define BPE_SET_ETYPE(bp, t) do { \ 276 ASSERT(BP_IS_EMBEDDED(bp)); \ 277 BF64_SET((bp)->blk_prop, 40, 8, t); \ 278 _NOTE(CONSTCOND) } while (0) 279 280 #define BPE_GET_LSIZE(bp) \ 281 (ASSERT(BP_IS_EMBEDDED(bp)), \ 282 BF64_GET_SB((bp)->blk_prop, 0, 25, 0, 1)) 283 #define BPE_SET_LSIZE(bp, x) do { \ 284 ASSERT(BP_IS_EMBEDDED(bp)); \ 285 BF64_SET_SB((bp)->blk_prop, 0, 25, 0, 1, x); \ 286 _NOTE(CONSTCOND) } while (0) 287 288 #define BPE_GET_PSIZE(bp) \ 289 (ASSERT(BP_IS_EMBEDDED(bp)), \ 290 BF64_GET_SB((bp)->blk_prop, 25, 7, 0, 1)) 291 #define BPE_SET_PSIZE(bp, x) do { \ 292 ASSERT(BP_IS_EMBEDDED(bp)); \ 293 BF64_SET_SB((bp)->blk_prop, 25, 7, 0, 1, x); \ 294 _NOTE(CONSTCOND) } while (0) 295 296 typedef enum bp_embedded_type { 297 BP_EMBEDDED_TYPE_DATA, 298 BP_EMBEDDED_TYPE_RESERVED, /* Reserved for an unintegrated feature. */ 299 NUM_BP_EMBEDDED_TYPES = BP_EMBEDDED_TYPE_RESERVED 300 } bp_embedded_type_t; 301 302 #define BPE_NUM_WORDS 14 303 #define BPE_PAYLOAD_SIZE (BPE_NUM_WORDS * sizeof (uint64_t)) 304 #define BPE_IS_PAYLOADWORD(bp, wp) \ 305 ((wp) != &(bp)->blk_prop && (wp) != &(bp)->blk_birth) 306 307 #define SPA_BLKPTRSHIFT 7 /* blkptr_t is 128 bytes */ 308 #define SPA_DVAS_PER_BP 3 /* Number of DVAs in a bp */ 309 310 typedef struct blkptr { 311 dva_t blk_dva[SPA_DVAS_PER_BP]; /* Data Virtual Addresses */ 312 uint64_t blk_prop; /* size, compression, type, etc */ 313 uint64_t blk_pad[2]; /* Extra space for the future */ 314 uint64_t blk_phys_birth; /* txg when block was allocated */ 315 uint64_t blk_birth; /* transaction group at birth */ 316 uint64_t blk_fill; /* fill count */ 317 zio_cksum_t blk_cksum; /* 256-bit checksum */ 318 } blkptr_t; 319 320 /* 321 * Macros to get and set fields in a bp or DVA. 322 */ 323 #define DVA_GET_ASIZE(dva) \ 324 BF64_GET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, SPA_MINBLOCKSHIFT, 0) 325 #define DVA_SET_ASIZE(dva, x) \ 326 BF64_SET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, \ 327 SPA_MINBLOCKSHIFT, 0, x) 328 329 #define DVA_GET_GRID(dva) BF64_GET((dva)->dva_word[0], 24, 8) 330 #define DVA_SET_GRID(dva, x) BF64_SET((dva)->dva_word[0], 24, 8, x) 331 332 #define DVA_GET_VDEV(dva) BF64_GET((dva)->dva_word[0], 32, 32) 333 #define DVA_SET_VDEV(dva, x) BF64_SET((dva)->dva_word[0], 32, 32, x) 334 335 #define DVA_GET_OFFSET(dva) \ 336 BF64_GET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0) 337 #define DVA_SET_OFFSET(dva, x) \ 338 BF64_SET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0, x) 339 340 #define DVA_GET_GANG(dva) BF64_GET((dva)->dva_word[1], 63, 1) 341 #define DVA_SET_GANG(dva, x) BF64_SET((dva)->dva_word[1], 63, 1, x) 342 343 #define BP_GET_LSIZE(bp) \ 344 (BP_IS_EMBEDDED(bp) ? \ 345 (BPE_GET_ETYPE(bp) == BP_EMBEDDED_TYPE_DATA ? BPE_GET_LSIZE(bp) : 0): \ 346 BF64_GET_SB((bp)->blk_prop, 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1)) 347 #define BP_SET_LSIZE(bp, x) do { \ 348 ASSERT(!BP_IS_EMBEDDED(bp)); \ 349 BF64_SET_SB((bp)->blk_prop, \ 350 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1, x); \ 351 _NOTE(CONSTCOND) } while (0) 352 353 #define BP_GET_PSIZE(bp) \ 354 BF64_GET_SB((bp)->blk_prop, 16, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1) 355 #define BP_SET_PSIZE(bp, x) \ 356 BF64_SET_SB((bp)->blk_prop, 16, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1, x) 357 358 #define BP_GET_COMPRESS(bp) BF64_GET((bp)->blk_prop, 32, 7) 359 #define BP_SET_COMPRESS(bp, x) BF64_SET((bp)->blk_prop, 32, 7, x) 360 361 #define BP_GET_CHECKSUM(bp) BF64_GET((bp)->blk_prop, 40, 8) 362 #define BP_SET_CHECKSUM(bp, x) BF64_SET((bp)->blk_prop, 40, 8, x) 363 364 #define BP_GET_TYPE(bp) BF64_GET((bp)->blk_prop, 48, 8) 365 #define BP_SET_TYPE(bp, x) BF64_SET((bp)->blk_prop, 48, 8, x) 366 367 #define BP_GET_LEVEL(bp) BF64_GET((bp)->blk_prop, 56, 5) 368 #define BP_SET_LEVEL(bp, x) BF64_SET((bp)->blk_prop, 56, 5, x) 369 370 #define BP_IS_EMBEDDED(bp) BF64_GET((bp)->blk_prop, 39, 1) 371 372 #define BP_GET_DEDUP(bp) BF64_GET((bp)->blk_prop, 62, 1) 373 #define BP_SET_DEDUP(bp, x) BF64_SET((bp)->blk_prop, 62, 1, x) 374 375 #define BP_GET_BYTEORDER(bp) BF64_GET((bp)->blk_prop, 63, 1) 376 #define BP_SET_BYTEORDER(bp, x) BF64_SET((bp)->blk_prop, 63, 1, x) 377 378 #define BP_PHYSICAL_BIRTH(bp) \ 379 ((bp)->blk_phys_birth ? (bp)->blk_phys_birth : (bp)->blk_birth) 380 381 #define BP_GET_ASIZE(bp) \ 382 (DVA_GET_ASIZE(&(bp)->blk_dva[0]) + DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \ 383 DVA_GET_ASIZE(&(bp)->blk_dva[2])) 384 385 #define BP_GET_UCSIZE(bp) \ 386 ((BP_GET_LEVEL(bp) > 0 || dmu_ot[BP_GET_TYPE(bp)].ot_metadata) ? \ 387 BP_GET_PSIZE(bp) : BP_GET_LSIZE(bp)); 388 389 #define BP_GET_NDVAS(bp) \ 390 (!!DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \ 391 !!DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \ 392 !!DVA_GET_ASIZE(&(bp)->blk_dva[2])) 393 394 #define DVA_EQUAL(dva1, dva2) \ 395 ((dva1)->dva_word[1] == (dva2)->dva_word[1] && \ 396 (dva1)->dva_word[0] == (dva2)->dva_word[0]) 397 398 #define ZIO_CHECKSUM_EQUAL(zc1, zc2) \ 399 (0 == (((zc1).zc_word[0] - (zc2).zc_word[0]) | \ 400 ((zc1).zc_word[1] - (zc2).zc_word[1]) | \ 401 ((zc1).zc_word[2] - (zc2).zc_word[2]) | \ 402 ((zc1).zc_word[3] - (zc2).zc_word[3]))) 403 404 405 #define DVA_IS_VALID(dva) (DVA_GET_ASIZE(dva) != 0) 406 407 #define ZIO_SET_CHECKSUM(zcp, w0, w1, w2, w3) \ 408 { \ 409 (zcp)->zc_word[0] = w0; \ 410 (zcp)->zc_word[1] = w1; \ 411 (zcp)->zc_word[2] = w2; \ 412 (zcp)->zc_word[3] = w3; \ 413 } 414 415 #define BP_IDENTITY(bp) (&(bp)->blk_dva[0]) 416 #define BP_IS_GANG(bp) DVA_GET_GANG(BP_IDENTITY(bp)) 417 #define DVA_IS_EMPTY(dva) ((dva)->dva_word[0] == 0ULL && \ 418 (dva)->dva_word[1] == 0ULL) 419 #define BP_IS_HOLE(bp) DVA_IS_EMPTY(BP_IDENTITY(bp)) 420 #define BP_IS_OLDER(bp, txg) (!BP_IS_HOLE(bp) && (bp)->blk_birth < (txg)) 421 422 #define BP_ZERO(bp) \ 423 { \ 424 (bp)->blk_dva[0].dva_word[0] = 0; \ 425 (bp)->blk_dva[0].dva_word[1] = 0; \ 426 (bp)->blk_dva[1].dva_word[0] = 0; \ 427 (bp)->blk_dva[1].dva_word[1] = 0; \ 428 (bp)->blk_dva[2].dva_word[0] = 0; \ 429 (bp)->blk_dva[2].dva_word[1] = 0; \ 430 (bp)->blk_prop = 0; \ 431 (bp)->blk_pad[0] = 0; \ 432 (bp)->blk_pad[1] = 0; \ 433 (bp)->blk_phys_birth = 0; \ 434 (bp)->blk_birth = 0; \ 435 (bp)->blk_fill = 0; \ 436 ZIO_SET_CHECKSUM(&(bp)->blk_cksum, 0, 0, 0, 0); \ 437 } 438 439 #define BPE_NUM_WORDS 14 440 #define BPE_PAYLOAD_SIZE (BPE_NUM_WORDS * sizeof (uint64_t)) 441 #define BPE_IS_PAYLOADWORD(bp, wp) \ 442 ((wp) != &(bp)->blk_prop && (wp) != &(bp)->blk_birth) 443 444 /* 445 * Embedded checksum 446 */ 447 #define ZEC_MAGIC 0x210da7ab10c7a11ULL 448 449 typedef struct zio_eck { 450 uint64_t zec_magic; /* for validation, endianness */ 451 zio_cksum_t zec_cksum; /* 256-bit checksum */ 452 } zio_eck_t; 453 454 /* 455 * Gang block headers are self-checksumming and contain an array 456 * of block pointers. 457 */ 458 #define SPA_GANGBLOCKSIZE SPA_MINBLOCKSIZE 459 #define SPA_GBH_NBLKPTRS ((SPA_GANGBLOCKSIZE - \ 460 sizeof (zio_eck_t)) / sizeof (blkptr_t)) 461 #define SPA_GBH_FILLER ((SPA_GANGBLOCKSIZE - \ 462 sizeof (zio_eck_t) - \ 463 (SPA_GBH_NBLKPTRS * sizeof (blkptr_t))) /\ 464 sizeof (uint64_t)) 465 466 typedef struct zio_gbh { 467 blkptr_t zg_blkptr[SPA_GBH_NBLKPTRS]; 468 uint64_t zg_filler[SPA_GBH_FILLER]; 469 zio_eck_t zg_tail; 470 } zio_gbh_phys_t; 471 472 #define VDEV_RAIDZ_MAXPARITY 3 473 474 #define VDEV_PAD_SIZE (8 << 10) 475 /* 2 padding areas (vl_pad1 and vl_pad2) to skip */ 476 #define VDEV_SKIP_SIZE VDEV_PAD_SIZE * 2 477 #define VDEV_PHYS_SIZE (112 << 10) 478 #define VDEV_UBERBLOCK_RING (128 << 10) 479 480 #define VDEV_UBERBLOCK_SHIFT(vd) \ 481 MAX((vd)->v_top->v_ashift, UBERBLOCK_SHIFT) 482 #define VDEV_UBERBLOCK_COUNT(vd) \ 483 (VDEV_UBERBLOCK_RING >> VDEV_UBERBLOCK_SHIFT(vd)) 484 #define VDEV_UBERBLOCK_OFFSET(vd, n) \ 485 offsetof(vdev_label_t, vl_uberblock[(n) << VDEV_UBERBLOCK_SHIFT(vd)]) 486 #define VDEV_UBERBLOCK_SIZE(vd) (1ULL << VDEV_UBERBLOCK_SHIFT(vd)) 487 488 typedef struct vdev_phys { 489 char vp_nvlist[VDEV_PHYS_SIZE - sizeof (zio_eck_t)]; 490 zio_eck_t vp_zbt; 491 } vdev_phys_t; 492 493 typedef struct vdev_label { 494 char vl_pad1[VDEV_PAD_SIZE]; /* 8K */ 495 char vl_pad2[VDEV_PAD_SIZE]; /* 8K */ 496 vdev_phys_t vl_vdev_phys; /* 112K */ 497 char vl_uberblock[VDEV_UBERBLOCK_RING]; /* 128K */ 498 } vdev_label_t; /* 256K total */ 499 500 /* 501 * vdev_dirty() flags 502 */ 503 #define VDD_METASLAB 0x01 504 #define VDD_DTL 0x02 505 506 /* 507 * Size and offset of embedded boot loader region on each label. 508 * The total size of the first two labels plus the boot area is 4MB. 509 */ 510 #define VDEV_BOOT_OFFSET (2 * sizeof (vdev_label_t)) 511 #define VDEV_BOOT_SIZE (7ULL << 19) /* 3.5M */ 512 513 /* 514 * Size of label regions at the start and end of each leaf device. 515 */ 516 #define VDEV_LABEL_START_SIZE (2 * sizeof (vdev_label_t) + VDEV_BOOT_SIZE) 517 #define VDEV_LABEL_END_SIZE (2 * sizeof (vdev_label_t)) 518 #define VDEV_LABELS 4 519 520 enum zio_checksum { 521 ZIO_CHECKSUM_INHERIT = 0, 522 ZIO_CHECKSUM_ON, 523 ZIO_CHECKSUM_OFF, 524 ZIO_CHECKSUM_LABEL, 525 ZIO_CHECKSUM_GANG_HEADER, 526 ZIO_CHECKSUM_ZILOG, 527 ZIO_CHECKSUM_FLETCHER_2, 528 ZIO_CHECKSUM_FLETCHER_4, 529 ZIO_CHECKSUM_SHA256, 530 ZIO_CHECKSUM_ZILOG2, 531 ZIO_CHECKSUM_FUNCTIONS 532 }; 533 534 #define ZIO_CHECKSUM_ON_VALUE ZIO_CHECKSUM_FLETCHER_4 535 #define ZIO_CHECKSUM_DEFAULT ZIO_CHECKSUM_ON 536 537 enum zio_compress { 538 ZIO_COMPRESS_INHERIT = 0, 539 ZIO_COMPRESS_ON, 540 ZIO_COMPRESS_OFF, 541 ZIO_COMPRESS_LZJB, 542 ZIO_COMPRESS_EMPTY, 543 ZIO_COMPRESS_GZIP_1, 544 ZIO_COMPRESS_GZIP_2, 545 ZIO_COMPRESS_GZIP_3, 546 ZIO_COMPRESS_GZIP_4, 547 ZIO_COMPRESS_GZIP_5, 548 ZIO_COMPRESS_GZIP_6, 549 ZIO_COMPRESS_GZIP_7, 550 ZIO_COMPRESS_GZIP_8, 551 ZIO_COMPRESS_GZIP_9, 552 ZIO_COMPRESS_ZLE, 553 ZIO_COMPRESS_LZ4, 554 ZIO_COMPRESS_FUNCTIONS 555 }; 556 557 #define ZIO_COMPRESS_ON_VALUE ZIO_COMPRESS_LZJB 558 #define ZIO_COMPRESS_DEFAULT ZIO_COMPRESS_OFF 559 560 /* nvlist pack encoding */ 561 #define NV_ENCODE_NATIVE 0 562 #define NV_ENCODE_XDR 1 563 564 typedef enum { 565 DATA_TYPE_UNKNOWN = 0, 566 DATA_TYPE_BOOLEAN, 567 DATA_TYPE_BYTE, 568 DATA_TYPE_INT16, 569 DATA_TYPE_UINT16, 570 DATA_TYPE_INT32, 571 DATA_TYPE_UINT32, 572 DATA_TYPE_INT64, 573 DATA_TYPE_UINT64, 574 DATA_TYPE_STRING, 575 DATA_TYPE_BYTE_ARRAY, 576 DATA_TYPE_INT16_ARRAY, 577 DATA_TYPE_UINT16_ARRAY, 578 DATA_TYPE_INT32_ARRAY, 579 DATA_TYPE_UINT32_ARRAY, 580 DATA_TYPE_INT64_ARRAY, 581 DATA_TYPE_UINT64_ARRAY, 582 DATA_TYPE_STRING_ARRAY, 583 DATA_TYPE_HRTIME, 584 DATA_TYPE_NVLIST, 585 DATA_TYPE_NVLIST_ARRAY, 586 DATA_TYPE_BOOLEAN_VALUE, 587 DATA_TYPE_INT8, 588 DATA_TYPE_UINT8, 589 DATA_TYPE_BOOLEAN_ARRAY, 590 DATA_TYPE_INT8_ARRAY, 591 DATA_TYPE_UINT8_ARRAY 592 } data_type_t; 593 594 /* 595 * On-disk version number. 596 */ 597 #define SPA_VERSION_1 1ULL 598 #define SPA_VERSION_2 2ULL 599 #define SPA_VERSION_3 3ULL 600 #define SPA_VERSION_4 4ULL 601 #define SPA_VERSION_5 5ULL 602 #define SPA_VERSION_6 6ULL 603 #define SPA_VERSION_7 7ULL 604 #define SPA_VERSION_8 8ULL 605 #define SPA_VERSION_9 9ULL 606 #define SPA_VERSION_10 10ULL 607 #define SPA_VERSION_11 11ULL 608 #define SPA_VERSION_12 12ULL 609 #define SPA_VERSION_13 13ULL 610 #define SPA_VERSION_14 14ULL 611 #define SPA_VERSION_15 15ULL 612 #define SPA_VERSION_16 16ULL 613 #define SPA_VERSION_17 17ULL 614 #define SPA_VERSION_18 18ULL 615 #define SPA_VERSION_19 19ULL 616 #define SPA_VERSION_20 20ULL 617 #define SPA_VERSION_21 21ULL 618 #define SPA_VERSION_22 22ULL 619 #define SPA_VERSION_23 23ULL 620 #define SPA_VERSION_24 24ULL 621 #define SPA_VERSION_25 25ULL 622 #define SPA_VERSION_26 26ULL 623 #define SPA_VERSION_27 27ULL 624 #define SPA_VERSION_28 28ULL 625 #define SPA_VERSION_5000 5000ULL 626 627 /* 628 * When bumping up SPA_VERSION, make sure GRUB ZFS understands the on-disk 629 * format change. Go to usr/src/grub/grub-0.97/stage2/{zfs-include/, fsys_zfs*}, 630 * and do the appropriate changes. Also bump the version number in 631 * usr/src/grub/capability. 632 */ 633 #define SPA_VERSION SPA_VERSION_5000 634 #define SPA_VERSION_STRING "5000" 635 636 /* 637 * Symbolic names for the changes that caused a SPA_VERSION switch. 638 * Used in the code when checking for presence or absence of a feature. 639 * Feel free to define multiple symbolic names for each version if there 640 * were multiple changes to on-disk structures during that version. 641 * 642 * NOTE: When checking the current SPA_VERSION in your code, be sure 643 * to use spa_version() since it reports the version of the 644 * last synced uberblock. Checking the in-flight version can 645 * be dangerous in some cases. 646 */ 647 #define SPA_VERSION_INITIAL SPA_VERSION_1 648 #define SPA_VERSION_DITTO_BLOCKS SPA_VERSION_2 649 #define SPA_VERSION_SPARES SPA_VERSION_3 650 #define SPA_VERSION_RAID6 SPA_VERSION_3 651 #define SPA_VERSION_BPLIST_ACCOUNT SPA_VERSION_3 652 #define SPA_VERSION_RAIDZ_DEFLATE SPA_VERSION_3 653 #define SPA_VERSION_DNODE_BYTES SPA_VERSION_3 654 #define SPA_VERSION_ZPOOL_HISTORY SPA_VERSION_4 655 #define SPA_VERSION_GZIP_COMPRESSION SPA_VERSION_5 656 #define SPA_VERSION_BOOTFS SPA_VERSION_6 657 #define SPA_VERSION_SLOGS SPA_VERSION_7 658 #define SPA_VERSION_DELEGATED_PERMS SPA_VERSION_8 659 #define SPA_VERSION_FUID SPA_VERSION_9 660 #define SPA_VERSION_REFRESERVATION SPA_VERSION_9 661 #define SPA_VERSION_REFQUOTA SPA_VERSION_9 662 #define SPA_VERSION_UNIQUE_ACCURATE SPA_VERSION_9 663 #define SPA_VERSION_L2CACHE SPA_VERSION_10 664 #define SPA_VERSION_NEXT_CLONES SPA_VERSION_11 665 #define SPA_VERSION_ORIGIN SPA_VERSION_11 666 #define SPA_VERSION_DSL_SCRUB SPA_VERSION_11 667 #define SPA_VERSION_SNAP_PROPS SPA_VERSION_12 668 #define SPA_VERSION_USED_BREAKDOWN SPA_VERSION_13 669 #define SPA_VERSION_PASSTHROUGH_X SPA_VERSION_14 670 #define SPA_VERSION_USERSPACE SPA_VERSION_15 671 #define SPA_VERSION_STMF_PROP SPA_VERSION_16 672 #define SPA_VERSION_RAIDZ3 SPA_VERSION_17 673 #define SPA_VERSION_USERREFS SPA_VERSION_18 674 #define SPA_VERSION_HOLES SPA_VERSION_19 675 #define SPA_VERSION_ZLE_COMPRESSION SPA_VERSION_20 676 #define SPA_VERSION_DEDUP SPA_VERSION_21 677 #define SPA_VERSION_RECVD_PROPS SPA_VERSION_22 678 #define SPA_VERSION_SLIM_ZIL SPA_VERSION_23 679 #define SPA_VERSION_SA SPA_VERSION_24 680 #define SPA_VERSION_SCAN SPA_VERSION_25 681 #define SPA_VERSION_DIR_CLONES SPA_VERSION_26 682 #define SPA_VERSION_DEADLISTS SPA_VERSION_26 683 #define SPA_VERSION_FAST_SNAP SPA_VERSION_27 684 #define SPA_VERSION_MULTI_REPLACE SPA_VERSION_28 685 #define SPA_VERSION_BEFORE_FEATURES SPA_VERSION_28 686 #define SPA_VERSION_FEATURES SPA_VERSION_5000 687 688 #define SPA_VERSION_IS_SUPPORTED(v) \ 689 (((v) >= SPA_VERSION_INITIAL && (v) <= SPA_VERSION_BEFORE_FEATURES) || \ 690 ((v) >= SPA_VERSION_FEATURES && (v) <= SPA_VERSION)) 691 692 /* 693 * The following are configuration names used in the nvlist describing a pool's 694 * configuration. 695 */ 696 #define ZPOOL_CONFIG_VERSION "version" 697 #define ZPOOL_CONFIG_POOL_NAME "name" 698 #define ZPOOL_CONFIG_POOL_STATE "state" 699 #define ZPOOL_CONFIG_POOL_TXG "txg" 700 #define ZPOOL_CONFIG_POOL_GUID "pool_guid" 701 #define ZPOOL_CONFIG_CREATE_TXG "create_txg" 702 #define ZPOOL_CONFIG_TOP_GUID "top_guid" 703 #define ZPOOL_CONFIG_VDEV_TREE "vdev_tree" 704 #define ZPOOL_CONFIG_TYPE "type" 705 #define ZPOOL_CONFIG_CHILDREN "children" 706 #define ZPOOL_CONFIG_ID "id" 707 #define ZPOOL_CONFIG_GUID "guid" 708 #define ZPOOL_CONFIG_PATH "path" 709 #define ZPOOL_CONFIG_DEVID "devid" 710 #define ZPOOL_CONFIG_METASLAB_ARRAY "metaslab_array" 711 #define ZPOOL_CONFIG_METASLAB_SHIFT "metaslab_shift" 712 #define ZPOOL_CONFIG_ASHIFT "ashift" 713 #define ZPOOL_CONFIG_ASIZE "asize" 714 #define ZPOOL_CONFIG_DTL "DTL" 715 #define ZPOOL_CONFIG_STATS "stats" 716 #define ZPOOL_CONFIG_WHOLE_DISK "whole_disk" 717 #define ZPOOL_CONFIG_ERRCOUNT "error_count" 718 #define ZPOOL_CONFIG_NOT_PRESENT "not_present" 719 #define ZPOOL_CONFIG_SPARES "spares" 720 #define ZPOOL_CONFIG_IS_SPARE "is_spare" 721 #define ZPOOL_CONFIG_NPARITY "nparity" 722 #define ZPOOL_CONFIG_HOSTID "hostid" 723 #define ZPOOL_CONFIG_HOSTNAME "hostname" 724 #define ZPOOL_CONFIG_IS_LOG "is_log" 725 #define ZPOOL_CONFIG_TIMESTAMP "timestamp" /* not stored on disk */ 726 #define ZPOOL_CONFIG_FEATURES_FOR_READ "features_for_read" 727 728 /* 729 * The persistent vdev state is stored as separate values rather than a single 730 * 'vdev_state' entry. This is because a device can be in multiple states, such 731 * as offline and degraded. 732 */ 733 #define ZPOOL_CONFIG_OFFLINE "offline" 734 #define ZPOOL_CONFIG_FAULTED "faulted" 735 #define ZPOOL_CONFIG_DEGRADED "degraded" 736 #define ZPOOL_CONFIG_REMOVED "removed" 737 #define ZPOOL_CONFIG_FRU "fru" 738 #define ZPOOL_CONFIG_AUX_STATE "aux_state" 739 740 #define VDEV_TYPE_ROOT "root" 741 #define VDEV_TYPE_MIRROR "mirror" 742 #define VDEV_TYPE_REPLACING "replacing" 743 #define VDEV_TYPE_RAIDZ "raidz" 744 #define VDEV_TYPE_DISK "disk" 745 #define VDEV_TYPE_FILE "file" 746 #define VDEV_TYPE_MISSING "missing" 747 #define VDEV_TYPE_HOLE "hole" 748 #define VDEV_TYPE_SPARE "spare" 749 #define VDEV_TYPE_LOG "log" 750 #define VDEV_TYPE_L2CACHE "l2cache" 751 752 /* 753 * This is needed in userland to report the minimum necessary device size. 754 */ 755 #define SPA_MINDEVSIZE (64ULL << 20) 756 757 /* 758 * The location of the pool configuration repository, shared between kernel and 759 * userland. 760 */ 761 #define ZPOOL_CACHE "/boot/zfs/zpool.cache" 762 763 /* 764 * vdev states are ordered from least to most healthy. 765 * A vdev that's CANT_OPEN or below is considered unusable. 766 */ 767 typedef enum vdev_state { 768 VDEV_STATE_UNKNOWN = 0, /* Uninitialized vdev */ 769 VDEV_STATE_CLOSED, /* Not currently open */ 770 VDEV_STATE_OFFLINE, /* Not allowed to open */ 771 VDEV_STATE_REMOVED, /* Explicitly removed from system */ 772 VDEV_STATE_CANT_OPEN, /* Tried to open, but failed */ 773 VDEV_STATE_FAULTED, /* External request to fault device */ 774 VDEV_STATE_DEGRADED, /* Replicated vdev with unhealthy kids */ 775 VDEV_STATE_HEALTHY /* Presumed good */ 776 } vdev_state_t; 777 778 /* 779 * vdev aux states. When a vdev is in the CANT_OPEN state, the aux field 780 * of the vdev stats structure uses these constants to distinguish why. 781 */ 782 typedef enum vdev_aux { 783 VDEV_AUX_NONE, /* no error */ 784 VDEV_AUX_OPEN_FAILED, /* ldi_open_*() or vn_open() failed */ 785 VDEV_AUX_CORRUPT_DATA, /* bad label or disk contents */ 786 VDEV_AUX_NO_REPLICAS, /* insufficient number of replicas */ 787 VDEV_AUX_BAD_GUID_SUM, /* vdev guid sum doesn't match */ 788 VDEV_AUX_TOO_SMALL, /* vdev size is too small */ 789 VDEV_AUX_BAD_LABEL, /* the label is OK but invalid */ 790 VDEV_AUX_VERSION_NEWER, /* on-disk version is too new */ 791 VDEV_AUX_VERSION_OLDER, /* on-disk version is too old */ 792 VDEV_AUX_SPARED /* hot spare used in another pool */ 793 } vdev_aux_t; 794 795 /* 796 * pool state. The following states are written to disk as part of the normal 797 * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE. The remaining states are 798 * software abstractions used at various levels to communicate pool state. 799 */ 800 typedef enum pool_state { 801 POOL_STATE_ACTIVE = 0, /* In active use */ 802 POOL_STATE_EXPORTED, /* Explicitly exported */ 803 POOL_STATE_DESTROYED, /* Explicitly destroyed */ 804 POOL_STATE_SPARE, /* Reserved for hot spare use */ 805 POOL_STATE_UNINITIALIZED, /* Internal spa_t state */ 806 POOL_STATE_UNAVAIL, /* Internal libzfs state */ 807 POOL_STATE_POTENTIALLY_ACTIVE /* Internal libzfs state */ 808 } pool_state_t; 809 810 /* 811 * The uberblock version is incremented whenever an incompatible on-disk 812 * format change is made to the SPA, DMU, or ZAP. 813 * 814 * Note: the first two fields should never be moved. When a storage pool 815 * is opened, the uberblock must be read off the disk before the version 816 * can be checked. If the ub_version field is moved, we may not detect 817 * version mismatch. If the ub_magic field is moved, applications that 818 * expect the magic number in the first word won't work. 819 */ 820 #define UBERBLOCK_MAGIC 0x00bab10c /* oo-ba-bloc! */ 821 #define UBERBLOCK_SHIFT 10 /* up to 1K */ 822 823 struct uberblock { 824 uint64_t ub_magic; /* UBERBLOCK_MAGIC */ 825 uint64_t ub_version; /* SPA_VERSION */ 826 uint64_t ub_txg; /* txg of last sync */ 827 uint64_t ub_guid_sum; /* sum of all vdev guids */ 828 uint64_t ub_timestamp; /* UTC time of last sync */ 829 blkptr_t ub_rootbp; /* MOS objset_phys_t */ 830 }; 831 832 /* 833 * Flags. 834 */ 835 #define DNODE_MUST_BE_ALLOCATED 1 836 #define DNODE_MUST_BE_FREE 2 837 838 /* 839 * Fixed constants. 840 */ 841 #define DNODE_SHIFT 9 /* 512 bytes */ 842 #define DN_MIN_INDBLKSHIFT 12 /* 4k */ 843 #define DN_MAX_INDBLKSHIFT 14 /* 16k */ 844 #define DNODE_BLOCK_SHIFT 14 /* 16k */ 845 #define DNODE_CORE_SIZE 64 /* 64 bytes for dnode sans blkptrs */ 846 #define DN_MAX_OBJECT_SHIFT 48 /* 256 trillion (zfs_fid_t limit) */ 847 #define DN_MAX_OFFSET_SHIFT 64 /* 2^64 bytes in a dnode */ 848 849 /* 850 * Derived constants. 851 */ 852 #define DNODE_SIZE (1 << DNODE_SHIFT) 853 #define DN_MAX_NBLKPTR ((DNODE_SIZE - DNODE_CORE_SIZE) >> SPA_BLKPTRSHIFT) 854 #define DN_MAX_BONUSLEN (DNODE_SIZE - DNODE_CORE_SIZE - (1 << SPA_BLKPTRSHIFT)) 855 #define DN_MAX_OBJECT (1ULL << DN_MAX_OBJECT_SHIFT) 856 857 #define DNODES_PER_BLOCK_SHIFT (DNODE_BLOCK_SHIFT - DNODE_SHIFT) 858 #define DNODES_PER_BLOCK (1ULL << DNODES_PER_BLOCK_SHIFT) 859 #define DNODES_PER_LEVEL_SHIFT (DN_MAX_INDBLKSHIFT - SPA_BLKPTRSHIFT) 860 861 /* The +2 here is a cheesy way to round up */ 862 #define DN_MAX_LEVELS (2 + ((DN_MAX_OFFSET_SHIFT - SPA_MINBLOCKSHIFT) / \ 863 (DN_MIN_INDBLKSHIFT - SPA_BLKPTRSHIFT))) 864 865 #define DN_BONUS(dnp) ((void*)((dnp)->dn_bonus + \ 866 (((dnp)->dn_nblkptr - 1) * sizeof (blkptr_t)))) 867 868 #define DN_USED_BYTES(dnp) (((dnp)->dn_flags & DNODE_FLAG_USED_BYTES) ? \ 869 (dnp)->dn_used : (dnp)->dn_used << SPA_MINBLOCKSHIFT) 870 871 #define EPB(blkshift, typeshift) (1 << (blkshift - typeshift)) 872 873 /* Is dn_used in bytes? if not, it's in multiples of SPA_MINBLOCKSIZE */ 874 #define DNODE_FLAG_USED_BYTES (1<<0) 875 #define DNODE_FLAG_USERUSED_ACCOUNTED (1<<1) 876 877 /* Does dnode have a SA spill blkptr in bonus? */ 878 #define DNODE_FLAG_SPILL_BLKPTR (1<<2) 879 880 typedef struct dnode_phys { 881 uint8_t dn_type; /* dmu_object_type_t */ 882 uint8_t dn_indblkshift; /* ln2(indirect block size) */ 883 uint8_t dn_nlevels; /* 1=dn_blkptr->data blocks */ 884 uint8_t dn_nblkptr; /* length of dn_blkptr */ 885 uint8_t dn_bonustype; /* type of data in bonus buffer */ 886 uint8_t dn_checksum; /* ZIO_CHECKSUM type */ 887 uint8_t dn_compress; /* ZIO_COMPRESS type */ 888 uint8_t dn_flags; /* DNODE_FLAG_* */ 889 uint16_t dn_datablkszsec; /* data block size in 512b sectors */ 890 uint16_t dn_bonuslen; /* length of dn_bonus */ 891 uint8_t dn_pad2[4]; 892 893 /* accounting is protected by dn_dirty_mtx */ 894 uint64_t dn_maxblkid; /* largest allocated block ID */ 895 uint64_t dn_used; /* bytes (or sectors) of disk space */ 896 897 uint64_t dn_pad3[4]; 898 899 blkptr_t dn_blkptr[1]; 900 uint8_t dn_bonus[DN_MAX_BONUSLEN - sizeof (blkptr_t)]; 901 blkptr_t dn_spill; 902 } dnode_phys_t; 903 904 typedef enum dmu_object_byteswap { 905 DMU_BSWAP_UINT8, 906 DMU_BSWAP_UINT16, 907 DMU_BSWAP_UINT32, 908 DMU_BSWAP_UINT64, 909 DMU_BSWAP_ZAP, 910 DMU_BSWAP_DNODE, 911 DMU_BSWAP_OBJSET, 912 DMU_BSWAP_ZNODE, 913 DMU_BSWAP_OLDACL, 914 DMU_BSWAP_ACL, 915 /* 916 * Allocating a new byteswap type number makes the on-disk format 917 * incompatible with any other format that uses the same number. 918 * 919 * Data can usually be structured to work with one of the 920 * DMU_BSWAP_UINT* or DMU_BSWAP_ZAP types. 921 */ 922 DMU_BSWAP_NUMFUNCS 923 } dmu_object_byteswap_t; 924 925 #define DMU_OT_NEWTYPE 0x80 926 #define DMU_OT_METADATA 0x40 927 #define DMU_OT_BYTESWAP_MASK 0x3f 928 929 /* 930 * Defines a uint8_t object type. Object types specify if the data 931 * in the object is metadata (boolean) and how to byteswap the data 932 * (dmu_object_byteswap_t). 933 */ 934 #define DMU_OT(byteswap, metadata) \ 935 (DMU_OT_NEWTYPE | \ 936 ((metadata) ? DMU_OT_METADATA : 0) | \ 937 ((byteswap) & DMU_OT_BYTESWAP_MASK)) 938 939 typedef enum dmu_object_type { 940 DMU_OT_NONE, 941 /* general: */ 942 DMU_OT_OBJECT_DIRECTORY, /* ZAP */ 943 DMU_OT_OBJECT_ARRAY, /* UINT64 */ 944 DMU_OT_PACKED_NVLIST, /* UINT8 (XDR by nvlist_pack/unpack) */ 945 DMU_OT_PACKED_NVLIST_SIZE, /* UINT64 */ 946 DMU_OT_BPLIST, /* UINT64 */ 947 DMU_OT_BPLIST_HDR, /* UINT64 */ 948 /* spa: */ 949 DMU_OT_SPACE_MAP_HEADER, /* UINT64 */ 950 DMU_OT_SPACE_MAP, /* UINT64 */ 951 /* zil: */ 952 DMU_OT_INTENT_LOG, /* UINT64 */ 953 /* dmu: */ 954 DMU_OT_DNODE, /* DNODE */ 955 DMU_OT_OBJSET, /* OBJSET */ 956 /* dsl: */ 957 DMU_OT_DSL_DIR, /* UINT64 */ 958 DMU_OT_DSL_DIR_CHILD_MAP, /* ZAP */ 959 DMU_OT_DSL_DS_SNAP_MAP, /* ZAP */ 960 DMU_OT_DSL_PROPS, /* ZAP */ 961 DMU_OT_DSL_DATASET, /* UINT64 */ 962 /* zpl: */ 963 DMU_OT_ZNODE, /* ZNODE */ 964 DMU_OT_OLDACL, /* Old ACL */ 965 DMU_OT_PLAIN_FILE_CONTENTS, /* UINT8 */ 966 DMU_OT_DIRECTORY_CONTENTS, /* ZAP */ 967 DMU_OT_MASTER_NODE, /* ZAP */ 968 DMU_OT_UNLINKED_SET, /* ZAP */ 969 /* zvol: */ 970 DMU_OT_ZVOL, /* UINT8 */ 971 DMU_OT_ZVOL_PROP, /* ZAP */ 972 /* other; for testing only! */ 973 DMU_OT_PLAIN_OTHER, /* UINT8 */ 974 DMU_OT_UINT64_OTHER, /* UINT64 */ 975 DMU_OT_ZAP_OTHER, /* ZAP */ 976 /* new object types: */ 977 DMU_OT_ERROR_LOG, /* ZAP */ 978 DMU_OT_SPA_HISTORY, /* UINT8 */ 979 DMU_OT_SPA_HISTORY_OFFSETS, /* spa_his_phys_t */ 980 DMU_OT_POOL_PROPS, /* ZAP */ 981 DMU_OT_DSL_PERMS, /* ZAP */ 982 DMU_OT_ACL, /* ACL */ 983 DMU_OT_SYSACL, /* SYSACL */ 984 DMU_OT_FUID, /* FUID table (Packed NVLIST UINT8) */ 985 DMU_OT_FUID_SIZE, /* FUID table size UINT64 */ 986 DMU_OT_NEXT_CLONES, /* ZAP */ 987 DMU_OT_SCAN_QUEUE, /* ZAP */ 988 DMU_OT_USERGROUP_USED, /* ZAP */ 989 DMU_OT_USERGROUP_QUOTA, /* ZAP */ 990 DMU_OT_USERREFS, /* ZAP */ 991 DMU_OT_DDT_ZAP, /* ZAP */ 992 DMU_OT_DDT_STATS, /* ZAP */ 993 DMU_OT_SA, /* System attr */ 994 DMU_OT_SA_MASTER_NODE, /* ZAP */ 995 DMU_OT_SA_ATTR_REGISTRATION, /* ZAP */ 996 DMU_OT_SA_ATTR_LAYOUTS, /* ZAP */ 997 DMU_OT_SCAN_XLATE, /* ZAP */ 998 DMU_OT_DEDUP, /* fake dedup BP from ddt_bp_create() */ 999 DMU_OT_NUMTYPES, 1000 1001 /* 1002 * Names for valid types declared with DMU_OT(). 1003 */ 1004 DMU_OTN_UINT8_DATA = DMU_OT(DMU_BSWAP_UINT8, B_FALSE), 1005 DMU_OTN_UINT8_METADATA = DMU_OT(DMU_BSWAP_UINT8, B_TRUE), 1006 DMU_OTN_UINT16_DATA = DMU_OT(DMU_BSWAP_UINT16, B_FALSE), 1007 DMU_OTN_UINT16_METADATA = DMU_OT(DMU_BSWAP_UINT16, B_TRUE), 1008 DMU_OTN_UINT32_DATA = DMU_OT(DMU_BSWAP_UINT32, B_FALSE), 1009 DMU_OTN_UINT32_METADATA = DMU_OT(DMU_BSWAP_UINT32, B_TRUE), 1010 DMU_OTN_UINT64_DATA = DMU_OT(DMU_BSWAP_UINT64, B_FALSE), 1011 DMU_OTN_UINT64_METADATA = DMU_OT(DMU_BSWAP_UINT64, B_TRUE), 1012 DMU_OTN_ZAP_DATA = DMU_OT(DMU_BSWAP_ZAP, B_FALSE), 1013 DMU_OTN_ZAP_METADATA = DMU_OT(DMU_BSWAP_ZAP, B_TRUE) 1014 } dmu_object_type_t; 1015 1016 typedef enum dmu_objset_type { 1017 DMU_OST_NONE, 1018 DMU_OST_META, 1019 DMU_OST_ZFS, 1020 DMU_OST_ZVOL, 1021 DMU_OST_OTHER, /* For testing only! */ 1022 DMU_OST_ANY, /* Be careful! */ 1023 DMU_OST_NUMTYPES 1024 } dmu_objset_type_t; 1025 1026 /* 1027 * header for all bonus and spill buffers. 1028 * The header has a fixed portion with a variable number 1029 * of "lengths" depending on the number of variable sized 1030 * attribues which are determined by the "layout number" 1031 */ 1032 1033 #define SA_MAGIC 0x2F505A /* ZFS SA */ 1034 typedef struct sa_hdr_phys { 1035 uint32_t sa_magic; 1036 uint16_t sa_layout_info; /* Encoded with hdrsize and layout number */ 1037 uint16_t sa_lengths[1]; /* optional sizes for variable length attrs */ 1038 /* ... Data follows the lengths. */ 1039 } sa_hdr_phys_t; 1040 1041 /* 1042 * sa_hdr_phys -> sa_layout_info 1043 * 1044 * 16 10 0 1045 * +--------+-------+ 1046 * | hdrsz |layout | 1047 * +--------+-------+ 1048 * 1049 * Bits 0-10 are the layout number 1050 * Bits 11-16 are the size of the header. 1051 * The hdrsize is the number * 8 1052 * 1053 * For example. 1054 * hdrsz of 1 ==> 8 byte header 1055 * 2 ==> 16 byte header 1056 * 1057 */ 1058 1059 #define SA_HDR_LAYOUT_NUM(hdr) BF32_GET(hdr->sa_layout_info, 0, 10) 1060 #define SA_HDR_SIZE(hdr) BF32_GET_SB(hdr->sa_layout_info, 10, 16, 3, 0) 1061 #define SA_HDR_LAYOUT_INFO_ENCODE(x, num, size) \ 1062 { \ 1063 BF32_SET_SB(x, 10, 6, 3, 0, size); \ 1064 BF32_SET(x, 0, 10, num); \ 1065 } 1066 1067 #define SA_MODE_OFFSET 0 1068 #define SA_SIZE_OFFSET 8 1069 #define SA_GEN_OFFSET 16 1070 #define SA_UID_OFFSET 24 1071 #define SA_GID_OFFSET 32 1072 #define SA_PARENT_OFFSET 40 1073 1074 /* 1075 * Intent log header - this on disk structure holds fields to manage 1076 * the log. All fields are 64 bit to easily handle cross architectures. 1077 */ 1078 typedef struct zil_header { 1079 uint64_t zh_claim_txg; /* txg in which log blocks were claimed */ 1080 uint64_t zh_replay_seq; /* highest replayed sequence number */ 1081 blkptr_t zh_log; /* log chain */ 1082 uint64_t zh_claim_seq; /* highest claimed sequence number */ 1083 uint64_t zh_pad[5]; 1084 } zil_header_t; 1085 1086 #define OBJSET_PHYS_SIZE 2048 1087 1088 typedef struct objset_phys { 1089 dnode_phys_t os_meta_dnode; 1090 zil_header_t os_zil_header; 1091 uint64_t os_type; 1092 uint64_t os_flags; 1093 char os_pad[OBJSET_PHYS_SIZE - sizeof (dnode_phys_t)*3 - 1094 sizeof (zil_header_t) - sizeof (uint64_t)*2]; 1095 dnode_phys_t os_userused_dnode; 1096 dnode_phys_t os_groupused_dnode; 1097 } objset_phys_t; 1098 1099 typedef struct dsl_dir_phys { 1100 uint64_t dd_creation_time; /* not actually used */ 1101 uint64_t dd_head_dataset_obj; 1102 uint64_t dd_parent_obj; 1103 uint64_t dd_clone_parent_obj; 1104 uint64_t dd_child_dir_zapobj; 1105 /* 1106 * how much space our children are accounting for; for leaf 1107 * datasets, == physical space used by fs + snaps 1108 */ 1109 uint64_t dd_used_bytes; 1110 uint64_t dd_compressed_bytes; 1111 uint64_t dd_uncompressed_bytes; 1112 /* Administrative quota setting */ 1113 uint64_t dd_quota; 1114 /* Administrative reservation setting */ 1115 uint64_t dd_reserved; 1116 uint64_t dd_props_zapobj; 1117 uint64_t dd_pad[21]; /* pad out to 256 bytes for good measure */ 1118 } dsl_dir_phys_t; 1119 1120 typedef struct dsl_dataset_phys { 1121 uint64_t ds_dir_obj; 1122 uint64_t ds_prev_snap_obj; 1123 uint64_t ds_prev_snap_txg; 1124 uint64_t ds_next_snap_obj; 1125 uint64_t ds_snapnames_zapobj; /* zap obj of snaps; ==0 for snaps */ 1126 uint64_t ds_num_children; /* clone/snap children; ==0 for head */ 1127 uint64_t ds_creation_time; /* seconds since 1970 */ 1128 uint64_t ds_creation_txg; 1129 uint64_t ds_deadlist_obj; 1130 uint64_t ds_used_bytes; 1131 uint64_t ds_compressed_bytes; 1132 uint64_t ds_uncompressed_bytes; 1133 uint64_t ds_unique_bytes; /* only relevant to snapshots */ 1134 /* 1135 * The ds_fsid_guid is a 56-bit ID that can change to avoid 1136 * collisions. The ds_guid is a 64-bit ID that will never 1137 * change, so there is a small probability that it will collide. 1138 */ 1139 uint64_t ds_fsid_guid; 1140 uint64_t ds_guid; 1141 uint64_t ds_flags; 1142 blkptr_t ds_bp; 1143 uint64_t ds_pad[8]; /* pad out to 320 bytes for good measure */ 1144 } dsl_dataset_phys_t; 1145 1146 /* 1147 * The names of zap entries in the DIRECTORY_OBJECT of the MOS. 1148 */ 1149 #define DMU_POOL_DIRECTORY_OBJECT 1 1150 #define DMU_POOL_CONFIG "config" 1151 #define DMU_POOL_FEATURES_FOR_READ "features_for_read" 1152 #define DMU_POOL_ROOT_DATASET "root_dataset" 1153 #define DMU_POOL_SYNC_BPLIST "sync_bplist" 1154 #define DMU_POOL_ERRLOG_SCRUB "errlog_scrub" 1155 #define DMU_POOL_ERRLOG_LAST "errlog_last" 1156 #define DMU_POOL_SPARES "spares" 1157 #define DMU_POOL_DEFLATE "deflate" 1158 #define DMU_POOL_HISTORY "history" 1159 #define DMU_POOL_PROPS "pool_props" 1160 1161 #define ZAP_MAGIC 0x2F52AB2ABULL 1162 1163 #define FZAP_BLOCK_SHIFT(zap) ((zap)->zap_block_shift) 1164 1165 #define ZAP_MAXCD (uint32_t)(-1) 1166 #define ZAP_HASHBITS 28 1167 #define MZAP_ENT_LEN 64 1168 #define MZAP_NAME_LEN (MZAP_ENT_LEN - 8 - 4 - 2) 1169 #define MZAP_MAX_BLKSHIFT SPA_MAXBLOCKSHIFT 1170 #define MZAP_MAX_BLKSZ (1 << MZAP_MAX_BLKSHIFT) 1171 1172 typedef struct mzap_ent_phys { 1173 uint64_t mze_value; 1174 uint32_t mze_cd; 1175 uint16_t mze_pad; /* in case we want to chain them someday */ 1176 char mze_name[MZAP_NAME_LEN]; 1177 } mzap_ent_phys_t; 1178 1179 typedef struct mzap_phys { 1180 uint64_t mz_block_type; /* ZBT_MICRO */ 1181 uint64_t mz_salt; 1182 uint64_t mz_pad[6]; 1183 mzap_ent_phys_t mz_chunk[1]; 1184 /* actually variable size depending on block size */ 1185 } mzap_phys_t; 1186 1187 /* 1188 * The (fat) zap is stored in one object. It is an array of 1189 * 1<<FZAP_BLOCK_SHIFT byte blocks. The layout looks like one of: 1190 * 1191 * ptrtbl fits in first block: 1192 * [zap_phys_t zap_ptrtbl_shift < 6] [zap_leaf_t] ... 1193 * 1194 * ptrtbl too big for first block: 1195 * [zap_phys_t zap_ptrtbl_shift >= 6] [zap_leaf_t] [ptrtbl] ... 1196 * 1197 */ 1198 1199 #define ZBT_LEAF ((1ULL << 63) + 0) 1200 #define ZBT_HEADER ((1ULL << 63) + 1) 1201 #define ZBT_MICRO ((1ULL << 63) + 3) 1202 /* any other values are ptrtbl blocks */ 1203 1204 /* 1205 * the embedded pointer table takes up half a block: 1206 * block size / entry size (2^3) / 2 1207 */ 1208 #define ZAP_EMBEDDED_PTRTBL_SHIFT(zap) (FZAP_BLOCK_SHIFT(zap) - 3 - 1) 1209 1210 /* 1211 * The embedded pointer table starts half-way through the block. Since 1212 * the pointer table itself is half the block, it starts at (64-bit) 1213 * word number (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap)). 1214 */ 1215 #define ZAP_EMBEDDED_PTRTBL_ENT(zap, idx) \ 1216 ((uint64_t *)(zap)->zap_phys) \ 1217 [(idx) + (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap))] 1218 1219 /* 1220 * TAKE NOTE: 1221 * If zap_phys_t is modified, zap_byteswap() must be modified. 1222 */ 1223 typedef struct zap_phys { 1224 uint64_t zap_block_type; /* ZBT_HEADER */ 1225 uint64_t zap_magic; /* ZAP_MAGIC */ 1226 1227 struct zap_table_phys { 1228 uint64_t zt_blk; /* starting block number */ 1229 uint64_t zt_numblks; /* number of blocks */ 1230 uint64_t zt_shift; /* bits to index it */ 1231 uint64_t zt_nextblk; /* next (larger) copy start block */ 1232 uint64_t zt_blks_copied; /* number source blocks copied */ 1233 } zap_ptrtbl; 1234 1235 uint64_t zap_freeblk; /* the next free block */ 1236 uint64_t zap_num_leafs; /* number of leafs */ 1237 uint64_t zap_num_entries; /* number of entries */ 1238 uint64_t zap_salt; /* salt to stir into hash function */ 1239 /* 1240 * This structure is followed by padding, and then the embedded 1241 * pointer table. The embedded pointer table takes up second 1242 * half of the block. It is accessed using the 1243 * ZAP_EMBEDDED_PTRTBL_ENT() macro. 1244 */ 1245 } zap_phys_t; 1246 1247 typedef struct zap_table_phys zap_table_phys_t; 1248 1249 typedef struct fat_zap { 1250 int zap_block_shift; /* block size shift */ 1251 zap_phys_t *zap_phys; 1252 } fat_zap_t; 1253 1254 #define ZAP_LEAF_MAGIC 0x2AB1EAF 1255 1256 /* chunk size = 24 bytes */ 1257 #define ZAP_LEAF_CHUNKSIZE 24 1258 1259 /* 1260 * The amount of space available for chunks is: 1261 * block size (1<<l->l_bs) - hash entry size (2) * number of hash 1262 * entries - header space (2*chunksize) 1263 */ 1264 #define ZAP_LEAF_NUMCHUNKS(l) \ 1265 (((1<<(l)->l_bs) - 2*ZAP_LEAF_HASH_NUMENTRIES(l)) / \ 1266 ZAP_LEAF_CHUNKSIZE - 2) 1267 1268 /* 1269 * The amount of space within the chunk available for the array is: 1270 * chunk size - space for type (1) - space for next pointer (2) 1271 */ 1272 #define ZAP_LEAF_ARRAY_BYTES (ZAP_LEAF_CHUNKSIZE - 3) 1273 1274 #define ZAP_LEAF_ARRAY_NCHUNKS(bytes) \ 1275 (((bytes)+ZAP_LEAF_ARRAY_BYTES-1)/ZAP_LEAF_ARRAY_BYTES) 1276 1277 /* 1278 * Low water mark: when there are only this many chunks free, start 1279 * growing the ptrtbl. Ideally, this should be larger than a 1280 * "reasonably-sized" entry. 20 chunks is more than enough for the 1281 * largest directory entry (MAXNAMELEN (256) byte name, 8-byte value), 1282 * while still being only around 3% for 16k blocks. 1283 */ 1284 #define ZAP_LEAF_LOW_WATER (20) 1285 1286 /* 1287 * The leaf hash table has block size / 2^5 (32) number of entries, 1288 * which should be more than enough for the maximum number of entries, 1289 * which is less than block size / CHUNKSIZE (24) / minimum number of 1290 * chunks per entry (3). 1291 */ 1292 #define ZAP_LEAF_HASH_SHIFT(l) ((l)->l_bs - 5) 1293 #define ZAP_LEAF_HASH_NUMENTRIES(l) (1 << ZAP_LEAF_HASH_SHIFT(l)) 1294 1295 /* 1296 * The chunks start immediately after the hash table. The end of the 1297 * hash table is at l_hash + HASH_NUMENTRIES, which we simply cast to a 1298 * chunk_t. 1299 */ 1300 #define ZAP_LEAF_CHUNK(l, idx) \ 1301 ((zap_leaf_chunk_t *) \ 1302 ((l)->l_phys->l_hash + ZAP_LEAF_HASH_NUMENTRIES(l)))[idx] 1303 #define ZAP_LEAF_ENTRY(l, idx) (&ZAP_LEAF_CHUNK(l, idx).l_entry) 1304 1305 typedef enum zap_chunk_type { 1306 ZAP_CHUNK_FREE = 253, 1307 ZAP_CHUNK_ENTRY = 252, 1308 ZAP_CHUNK_ARRAY = 251, 1309 ZAP_CHUNK_TYPE_MAX = 250 1310 } zap_chunk_type_t; 1311 1312 /* 1313 * TAKE NOTE: 1314 * If zap_leaf_phys_t is modified, zap_leaf_byteswap() must be modified. 1315 */ 1316 typedef struct zap_leaf_phys { 1317 struct zap_leaf_header { 1318 uint64_t lh_block_type; /* ZBT_LEAF */ 1319 uint64_t lh_pad1; 1320 uint64_t lh_prefix; /* hash prefix of this leaf */ 1321 uint32_t lh_magic; /* ZAP_LEAF_MAGIC */ 1322 uint16_t lh_nfree; /* number free chunks */ 1323 uint16_t lh_nentries; /* number of entries */ 1324 uint16_t lh_prefix_len; /* num bits used to id this */ 1325 1326 /* above is accessable to zap, below is zap_leaf private */ 1327 1328 uint16_t lh_freelist; /* chunk head of free list */ 1329 uint8_t lh_pad2[12]; 1330 } l_hdr; /* 2 24-byte chunks */ 1331 1332 /* 1333 * The header is followed by a hash table with 1334 * ZAP_LEAF_HASH_NUMENTRIES(zap) entries. The hash table is 1335 * followed by an array of ZAP_LEAF_NUMCHUNKS(zap) 1336 * zap_leaf_chunk structures. These structures are accessed 1337 * with the ZAP_LEAF_CHUNK() macro. 1338 */ 1339 1340 uint16_t l_hash[1]; 1341 } zap_leaf_phys_t; 1342 1343 typedef union zap_leaf_chunk { 1344 struct zap_leaf_entry { 1345 uint8_t le_type; /* always ZAP_CHUNK_ENTRY */ 1346 uint8_t le_value_intlen; /* size of ints */ 1347 uint16_t le_next; /* next entry in hash chain */ 1348 uint16_t le_name_chunk; /* first chunk of the name */ 1349 uint16_t le_name_numints; /* bytes in name, incl null */ 1350 uint16_t le_value_chunk; /* first chunk of the value */ 1351 uint16_t le_value_numints; /* value length in ints */ 1352 uint32_t le_cd; /* collision differentiator */ 1353 uint64_t le_hash; /* hash value of the name */ 1354 } l_entry; 1355 struct zap_leaf_array { 1356 uint8_t la_type; /* always ZAP_CHUNK_ARRAY */ 1357 uint8_t la_array[ZAP_LEAF_ARRAY_BYTES]; 1358 uint16_t la_next; /* next blk or CHAIN_END */ 1359 } l_array; 1360 struct zap_leaf_free { 1361 uint8_t lf_type; /* always ZAP_CHUNK_FREE */ 1362 uint8_t lf_pad[ZAP_LEAF_ARRAY_BYTES]; 1363 uint16_t lf_next; /* next in free list, or CHAIN_END */ 1364 } l_free; 1365 } zap_leaf_chunk_t; 1366 1367 typedef struct zap_leaf { 1368 int l_bs; /* block size shift */ 1369 zap_leaf_phys_t *l_phys; 1370 } zap_leaf_t; 1371 1372 /* 1373 * Define special zfs pflags 1374 */ 1375 #define ZFS_XATTR 0x1 /* is an extended attribute */ 1376 #define ZFS_INHERIT_ACE 0x2 /* ace has inheritable ACEs */ 1377 #define ZFS_ACL_TRIVIAL 0x4 /* files ACL is trivial */ 1378 1379 #define MASTER_NODE_OBJ 1 1380 1381 /* 1382 * special attributes for master node. 1383 */ 1384 1385 #define ZFS_FSID "FSID" 1386 #define ZFS_UNLINKED_SET "DELETE_QUEUE" 1387 #define ZFS_ROOT_OBJ "ROOT" 1388 #define ZPL_VERSION_OBJ "VERSION" 1389 #define ZFS_PROP_BLOCKPERPAGE "BLOCKPERPAGE" 1390 #define ZFS_PROP_NOGROWBLOCKS "NOGROWBLOCKS" 1391 1392 #define ZFS_FLAG_BLOCKPERPAGE 0x1 1393 #define ZFS_FLAG_NOGROWBLOCKS 0x2 1394 1395 /* 1396 * ZPL version - rev'd whenever an incompatible on-disk format change 1397 * occurs. Independent of SPA/DMU/ZAP versioning. 1398 */ 1399 1400 #define ZPL_VERSION 1ULL 1401 1402 /* 1403 * The directory entry has the type (currently unused on Solaris) in the 1404 * top 4 bits, and the object number in the low 48 bits. The "middle" 1405 * 12 bits are unused. 1406 */ 1407 #define ZFS_DIRENT_TYPE(de) BF64_GET(de, 60, 4) 1408 #define ZFS_DIRENT_OBJ(de) BF64_GET(de, 0, 48) 1409 #define ZFS_DIRENT_MAKE(type, obj) (((uint64_t)type << 60) | obj) 1410 1411 typedef struct ace { 1412 uid_t a_who; /* uid or gid */ 1413 uint32_t a_access_mask; /* read,write,... */ 1414 uint16_t a_flags; /* see below */ 1415 uint16_t a_type; /* allow or deny */ 1416 } ace_t; 1417 1418 #define ACE_SLOT_CNT 6 1419 1420 typedef struct zfs_znode_acl { 1421 uint64_t z_acl_extern_obj; /* ext acl pieces */ 1422 uint32_t z_acl_count; /* Number of ACEs */ 1423 uint16_t z_acl_version; /* acl version */ 1424 uint16_t z_acl_pad; /* pad */ 1425 ace_t z_ace_data[ACE_SLOT_CNT]; /* 6 standard ACEs */ 1426 } zfs_znode_acl_t; 1427 1428 /* 1429 * This is the persistent portion of the znode. It is stored 1430 * in the "bonus buffer" of the file. Short symbolic links 1431 * are also stored in the bonus buffer. 1432 */ 1433 typedef struct znode_phys { 1434 uint64_t zp_atime[2]; /* 0 - last file access time */ 1435 uint64_t zp_mtime[2]; /* 16 - last file modification time */ 1436 uint64_t zp_ctime[2]; /* 32 - last file change time */ 1437 uint64_t zp_crtime[2]; /* 48 - creation time */ 1438 uint64_t zp_gen; /* 64 - generation (txg of creation) */ 1439 uint64_t zp_mode; /* 72 - file mode bits */ 1440 uint64_t zp_size; /* 80 - size of file */ 1441 uint64_t zp_parent; /* 88 - directory parent (`..') */ 1442 uint64_t zp_links; /* 96 - number of links to file */ 1443 uint64_t zp_xattr; /* 104 - DMU object for xattrs */ 1444 uint64_t zp_rdev; /* 112 - dev_t for VBLK & VCHR files */ 1445 uint64_t zp_flags; /* 120 - persistent flags */ 1446 uint64_t zp_uid; /* 128 - file owner */ 1447 uint64_t zp_gid; /* 136 - owning group */ 1448 uint64_t zp_pad[4]; /* 144 - future */ 1449 zfs_znode_acl_t zp_acl; /* 176 - 263 ACL */ 1450 /* 1451 * Data may pad out any remaining bytes in the znode buffer, eg: 1452 * 1453 * |<---------------------- dnode_phys (512) ------------------------>| 1454 * |<-- dnode (192) --->|<----------- "bonus" buffer (320) ---------->| 1455 * |<---- znode (264) ---->|<---- data (56) ---->| 1456 * 1457 * At present, we only use this space to store symbolic links. 1458 */ 1459 } znode_phys_t; 1460 1461 /* 1462 * In-core vdev representation. 1463 */ 1464 struct vdev; 1465 typedef int vdev_phys_read_t(struct vdev *vdev, void *priv, 1466 off_t offset, void *buf, size_t bytes); 1467 typedef int vdev_read_t(struct vdev *vdev, const blkptr_t *bp, 1468 void *buf, off_t offset, size_t bytes); 1469 1470 typedef STAILQ_HEAD(vdev_list, vdev) vdev_list_t; 1471 1472 typedef struct vdev { 1473 STAILQ_ENTRY(vdev) v_childlink; /* link in parent's child list */ 1474 STAILQ_ENTRY(vdev) v_alllink; /* link in global vdev list */ 1475 vdev_list_t v_children; /* children of this vdev */ 1476 const char *v_name; /* vdev name */ 1477 uint64_t v_guid; /* vdev guid */ 1478 int v_id; /* index in parent */ 1479 int v_ashift; /* offset to block shift */ 1480 int v_nparity; /* # parity for raidz */ 1481 struct vdev *v_top; /* parent vdev */ 1482 int v_nchildren; /* # children */ 1483 vdev_state_t v_state; /* current state */ 1484 vdev_phys_read_t *v_phys_read; /* read from raw leaf vdev */ 1485 vdev_read_t *v_read; /* read from vdev */ 1486 void *v_read_priv; /* private data for read function */ 1487 } vdev_t; 1488 1489 /* 1490 * In-core pool representation. 1491 */ 1492 typedef STAILQ_HEAD(spa_list, spa) spa_list_t; 1493 1494 typedef struct spa { 1495 STAILQ_ENTRY(spa) spa_link; /* link in global pool list */ 1496 char *spa_name; /* pool name */ 1497 uint64_t spa_guid; /* pool guid */ 1498 uint64_t spa_txg; /* most recent transaction */ 1499 struct uberblock spa_uberblock; /* best uberblock so far */ 1500 vdev_list_t spa_vdevs; /* list of all toplevel vdevs */ 1501 objset_phys_t spa_mos; /* MOS for this pool */ 1502 int spa_inited; /* initialized */ 1503 } spa_t; 1504 1505 static void decode_embedded_bp_compressed(const blkptr_t *, void *); 1506