2 * Copyright (c) 2007 Doug Rabson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
31 * Stand-alone ZFS file reader.
35 #include <sys/stdint.h>
48 * List of all vdevs, chained through v_alllink.
50 static vdev_list_t zfs_vdevs;
53 * List of all pools, chained through spa_link.
55 static spa_list_t zfs_pools;
57 static uint64_t zfs_crc64_table[256];
58 static const dnode_phys_t *dnode_cache_obj = 0;
59 static uint64_t dnode_cache_bn;
60 static char *dnode_cache_buf;
61 static char *zap_scratch;
62 static char *zfs_temp_buf, *zfs_temp_end, *zfs_temp_ptr;
64 #define TEMP_SIZE (1024 * 1024)
66 static int zio_read(const spa_t *spa, const blkptr_t *bp, void *buf);
71 STAILQ_INIT(&zfs_vdevs);
72 STAILQ_INIT(&zfs_pools);
74 zfs_temp_buf = malloc(TEMP_SIZE);
75 zfs_temp_end = zfs_temp_buf + TEMP_SIZE;
76 zfs_temp_ptr = zfs_temp_buf;
77 dnode_cache_buf = malloc(SPA_MAXBLOCKSIZE);
78 zap_scratch = malloc(SPA_MAXBLOCKSIZE);
84 zfs_alloc(size_t size)
88 if (zfs_temp_ptr + size > zfs_temp_end) {
89 printf("ZFS: out of temporary buffer space\n");
99 zfs_free(void *ptr, size_t size)
102 zfs_temp_ptr -= size;
103 if (zfs_temp_ptr != ptr) {
104 printf("ZFS: zfs_alloc()/zfs_free() mismatch\n");
110 xdr_int(const unsigned char **xdr, int *ip)
112 *ip = ((*xdr)[0] << 24)
121 xdr_u_int(const unsigned char **xdr, u_int *ip)
123 *ip = ((*xdr)[0] << 24)
132 xdr_uint64_t(const unsigned char **xdr, uint64_t *lp)
138 *lp = (((uint64_t) hi) << 32) | lo;
143 nvlist_find(const unsigned char *nvlist, const char *name, int type,
144 int* elementsp, void *valuep)
146 const unsigned char *p, *pair;
148 int encoded_size, decoded_size;
155 xdr_int(&p, &encoded_size);
156 xdr_int(&p, &decoded_size);
157 while (encoded_size && decoded_size) {
158 int namelen, pairtype, elements;
159 const char *pairname;
161 xdr_int(&p, &namelen);
162 pairname = (const char*) p;
163 p += roundup(namelen, 4);
164 xdr_int(&p, &pairtype);
166 if (!memcmp(name, pairname, namelen) && type == pairtype) {
167 xdr_int(&p, &elements);
169 *elementsp = elements;
170 if (type == DATA_TYPE_UINT64) {
171 xdr_uint64_t(&p, (uint64_t *) valuep);
173 } else if (type == DATA_TYPE_STRING) {
176 (*(const char**) valuep) = (const char*) p;
178 } else if (type == DATA_TYPE_NVLIST
179 || type == DATA_TYPE_NVLIST_ARRAY) {
180 (*(const unsigned char**) valuep) =
181 (const unsigned char*) p;
188 * Not the pair we are looking for, skip to the next one.
190 p = pair + encoded_size;
194 xdr_int(&p, &encoded_size);
195 xdr_int(&p, &decoded_size);
202 * Return the next nvlist in an nvlist array.
204 static const unsigned char *
205 nvlist_next(const unsigned char *nvlist)
207 const unsigned char *p, *pair;
209 int encoded_size, decoded_size;
216 xdr_int(&p, &encoded_size);
217 xdr_int(&p, &decoded_size);
218 while (encoded_size && decoded_size) {
219 p = pair + encoded_size;
222 xdr_int(&p, &encoded_size);
223 xdr_int(&p, &decoded_size);
231 static const unsigned char *
232 nvlist_print(const unsigned char *nvlist, unsigned int indent)
234 static const char* typenames[] = {
245 "DATA_TYPE_BYTE_ARRAY",
246 "DATA_TYPE_INT16_ARRAY",
247 "DATA_TYPE_UINT16_ARRAY",
248 "DATA_TYPE_INT32_ARRAY",
249 "DATA_TYPE_UINT32_ARRAY",
250 "DATA_TYPE_INT64_ARRAY",
251 "DATA_TYPE_UINT64_ARRAY",
252 "DATA_TYPE_STRING_ARRAY",
255 "DATA_TYPE_NVLIST_ARRAY",
256 "DATA_TYPE_BOOLEAN_VALUE",
259 "DATA_TYPE_BOOLEAN_ARRAY",
260 "DATA_TYPE_INT8_ARRAY",
261 "DATA_TYPE_UINT8_ARRAY"
265 const unsigned char *p, *pair;
267 int encoded_size, decoded_size;
274 xdr_int(&p, &encoded_size);
275 xdr_int(&p, &decoded_size);
276 while (encoded_size && decoded_size) {
277 int namelen, pairtype, elements;
278 const char *pairname;
280 xdr_int(&p, &namelen);
281 pairname = (const char*) p;
282 p += roundup(namelen, 4);
283 xdr_int(&p, &pairtype);
285 for (i = 0; i < indent; i++)
287 printf("%s %s", typenames[pairtype], pairname);
289 xdr_int(&p, &elements);
291 case DATA_TYPE_UINT64: {
293 xdr_uint64_t(&p, &val);
294 printf(" = 0x%jx\n", (uintmax_t)val);
298 case DATA_TYPE_STRING: {
301 printf(" = \"%s\"\n", p);
305 case DATA_TYPE_NVLIST:
307 nvlist_print(p, indent + 1);
310 case DATA_TYPE_NVLIST_ARRAY:
311 for (j = 0; j < elements; j++) {
313 p = nvlist_print(p, indent + 1);
314 if (j != elements - 1) {
315 for (i = 0; i < indent; i++)
317 printf("%s %s", typenames[pairtype], pairname);
326 p = pair + encoded_size;
329 xdr_int(&p, &encoded_size);
330 xdr_int(&p, &decoded_size);
339 vdev_read_phys(vdev_t *vdev, const blkptr_t *bp, void *buf,
340 off_t offset, size_t size)
345 if (!vdev->v_phys_read)
349 psize = BP_GET_PSIZE(bp);
354 /*printf("ZFS: reading %d bytes at 0x%jx to %p\n", psize, (uintmax_t)offset, buf);*/
355 rc = vdev->v_phys_read(vdev, vdev->v_read_priv, offset, buf, psize);
358 if (bp && zio_checksum_verify(bp, buf))
365 vdev_disk_read(vdev_t *vdev, const blkptr_t *bp, void *buf,
366 off_t offset, size_t bytes)
369 return (vdev_read_phys(vdev, bp, buf,
370 offset + VDEV_LABEL_START_SIZE, bytes));
375 vdev_mirror_read(vdev_t *vdev, const blkptr_t *bp, void *buf,
376 off_t offset, size_t bytes)
382 STAILQ_FOREACH(kid, &vdev->v_children, v_childlink) {
383 if (kid->v_state != VDEV_STATE_HEALTHY)
385 rc = kid->v_read(kid, bp, buf, offset, bytes);
394 vdev_replacing_read(vdev_t *vdev, const blkptr_t *bp, void *buf,
395 off_t offset, size_t bytes)
400 * Here we should have two kids:
401 * First one which is the one we are replacing and we can trust
402 * only this one to have valid data, but it might not be present.
403 * Second one is that one we are replacing with. It is most likely
404 * healthy, but we can't trust it has needed data, so we won't use it.
406 kid = STAILQ_FIRST(&vdev->v_children);
409 if (kid->v_state != VDEV_STATE_HEALTHY)
411 return (kid->v_read(kid, bp, buf, offset, bytes));
415 vdev_find(uint64_t guid)
419 STAILQ_FOREACH(vdev, &zfs_vdevs, v_alllink)
420 if (vdev->v_guid == guid)
427 vdev_create(uint64_t guid, vdev_read_t *read)
431 vdev = malloc(sizeof(vdev_t));
432 memset(vdev, 0, sizeof(vdev_t));
433 STAILQ_INIT(&vdev->v_children);
435 vdev->v_state = VDEV_STATE_OFFLINE;
437 vdev->v_phys_read = 0;
438 vdev->v_read_priv = 0;
439 STAILQ_INSERT_TAIL(&zfs_vdevs, vdev, v_alllink);
445 vdev_init_from_nvlist(const unsigned char *nvlist, vdev_t *pvdev,
446 vdev_t **vdevp, int is_newer)
449 uint64_t guid, id, ashift, nparity;
453 const unsigned char *kids;
454 int nkids, i, is_new;
455 uint64_t is_offline, is_faulted, is_degraded, is_removed, isnt_present;
457 if (nvlist_find(nvlist, ZPOOL_CONFIG_GUID,
458 DATA_TYPE_UINT64, 0, &guid)
459 || nvlist_find(nvlist, ZPOOL_CONFIG_ID,
460 DATA_TYPE_UINT64, 0, &id)
461 || nvlist_find(nvlist, ZPOOL_CONFIG_TYPE,
462 DATA_TYPE_STRING, 0, &type)) {
463 printf("ZFS: can't find vdev details\n");
467 if (strcmp(type, VDEV_TYPE_MIRROR)
468 && strcmp(type, VDEV_TYPE_DISK)
470 && strcmp(type, VDEV_TYPE_FILE)
472 && strcmp(type, VDEV_TYPE_RAIDZ)
473 && strcmp(type, VDEV_TYPE_REPLACING)) {
474 printf("ZFS: can only boot from disk, mirror, raidz1, raidz2 and raidz3 vdevs\n");
478 is_offline = is_removed = is_faulted = is_degraded = isnt_present = 0;
480 nvlist_find(nvlist, ZPOOL_CONFIG_OFFLINE, DATA_TYPE_UINT64, 0,
482 nvlist_find(nvlist, ZPOOL_CONFIG_REMOVED, DATA_TYPE_UINT64, 0,
484 nvlist_find(nvlist, ZPOOL_CONFIG_FAULTED, DATA_TYPE_UINT64, 0,
486 nvlist_find(nvlist, ZPOOL_CONFIG_DEGRADED, DATA_TYPE_UINT64, 0,
488 nvlist_find(nvlist, ZPOOL_CONFIG_NOT_PRESENT, DATA_TYPE_UINT64, 0,
491 vdev = vdev_find(guid);
495 if (!strcmp(type, VDEV_TYPE_MIRROR))
496 vdev = vdev_create(guid, vdev_mirror_read);
497 else if (!strcmp(type, VDEV_TYPE_RAIDZ))
498 vdev = vdev_create(guid, vdev_raidz_read);
499 else if (!strcmp(type, VDEV_TYPE_REPLACING))
500 vdev = vdev_create(guid, vdev_replacing_read);
502 vdev = vdev_create(guid, vdev_disk_read);
505 vdev->v_top = pvdev != NULL ? pvdev : vdev;
506 if (nvlist_find(nvlist, ZPOOL_CONFIG_ASHIFT,
507 DATA_TYPE_UINT64, 0, &ashift) == 0)
508 vdev->v_ashift = ashift;
511 if (nvlist_find(nvlist, ZPOOL_CONFIG_NPARITY,
512 DATA_TYPE_UINT64, 0, &nparity) == 0)
513 vdev->v_nparity = nparity;
516 if (nvlist_find(nvlist, ZPOOL_CONFIG_PATH,
517 DATA_TYPE_STRING, 0, &path) == 0) {
518 if (strncmp(path, "/dev/", 5) == 0)
520 vdev->v_name = strdup(path);
522 if (!strcmp(type, "raidz")) {
523 if (vdev->v_nparity == 1)
524 vdev->v_name = "raidz1";
525 else if (vdev->v_nparity == 2)
526 vdev->v_name = "raidz2";
527 else if (vdev->v_nparity == 3)
528 vdev->v_name = "raidz3";
530 printf("ZFS: can only boot from disk, mirror, raidz1, raidz2 and raidz3 vdevs\n");
534 vdev->v_name = strdup(type);
541 if (is_new || is_newer) {
543 * This is either new vdev or we've already seen this vdev,
544 * but from an older vdev label, so let's refresh its state
545 * from the newer label.
548 vdev->v_state = VDEV_STATE_OFFLINE;
550 vdev->v_state = VDEV_STATE_REMOVED;
552 vdev->v_state = VDEV_STATE_FAULTED;
553 else if (is_degraded)
554 vdev->v_state = VDEV_STATE_DEGRADED;
555 else if (isnt_present)
556 vdev->v_state = VDEV_STATE_CANT_OPEN;
559 rc = nvlist_find(nvlist, ZPOOL_CONFIG_CHILDREN,
560 DATA_TYPE_NVLIST_ARRAY, &nkids, &kids);
562 * Its ok if we don't have any kids.
565 vdev->v_nchildren = nkids;
566 for (i = 0; i < nkids; i++) {
567 rc = vdev_init_from_nvlist(kids, vdev, &kid, is_newer);
571 STAILQ_INSERT_TAIL(&vdev->v_children, kid,
573 kids = nvlist_next(kids);
576 vdev->v_nchildren = 0;
585 vdev_set_state(vdev_t *vdev)
592 * A mirror or raidz is healthy if all its kids are healthy. A
593 * mirror is degraded if any of its kids is healthy; a raidz
594 * is degraded if at most nparity kids are offline.
596 if (STAILQ_FIRST(&vdev->v_children)) {
599 STAILQ_FOREACH(kid, &vdev->v_children, v_childlink) {
600 if (kid->v_state == VDEV_STATE_HEALTHY)
606 vdev->v_state = VDEV_STATE_HEALTHY;
608 if (vdev->v_read == vdev_mirror_read) {
610 vdev->v_state = VDEV_STATE_DEGRADED;
612 vdev->v_state = VDEV_STATE_OFFLINE;
614 } else if (vdev->v_read == vdev_raidz_read) {
615 if (bad_kids > vdev->v_nparity) {
616 vdev->v_state = VDEV_STATE_OFFLINE;
618 vdev->v_state = VDEV_STATE_DEGRADED;
626 spa_find_by_guid(uint64_t guid)
630 STAILQ_FOREACH(spa, &zfs_pools, spa_link)
631 if (spa->spa_guid == guid)
638 spa_find_by_name(const char *name)
642 STAILQ_FOREACH(spa, &zfs_pools, spa_link)
643 if (!strcmp(spa->spa_name, name))
650 spa_create(uint64_t guid)
654 spa = malloc(sizeof(spa_t));
655 memset(spa, 0, sizeof(spa_t));
656 STAILQ_INIT(&spa->spa_vdevs);
657 spa->spa_guid = guid;
658 STAILQ_INSERT_TAIL(&zfs_pools, spa, spa_link);
664 state_name(vdev_state_t state)
666 static const char* names[] = {
681 #define pager_printf printf
686 pager_printf(const char *fmt, ...)
692 vsprintf(line, fmt, args);
699 #define STATUS_FORMAT " %s %s\n"
702 print_state(int indent, const char *name, vdev_state_t state)
708 for (i = 0; i < indent; i++)
711 pager_printf(STATUS_FORMAT, buf, state_name(state));
716 vdev_status(vdev_t *vdev, int indent)
719 print_state(indent, vdev->v_name, vdev->v_state);
721 STAILQ_FOREACH(kid, &vdev->v_children, v_childlink) {
722 vdev_status(kid, indent + 1);
727 spa_status(spa_t *spa)
730 int good_kids, bad_kids, degraded_kids;
733 pager_printf(" pool: %s\n", spa->spa_name);
734 pager_printf("config:\n\n");
735 pager_printf(STATUS_FORMAT, "NAME", "STATE");
740 STAILQ_FOREACH(vdev, &spa->spa_vdevs, v_childlink) {
741 if (vdev->v_state == VDEV_STATE_HEALTHY)
743 else if (vdev->v_state == VDEV_STATE_DEGRADED)
749 state = VDEV_STATE_CLOSED;
750 if (good_kids > 0 && (degraded_kids + bad_kids) == 0)
751 state = VDEV_STATE_HEALTHY;
752 else if ((good_kids + degraded_kids) > 0)
753 state = VDEV_STATE_DEGRADED;
755 print_state(0, spa->spa_name, state);
756 STAILQ_FOREACH(vdev, &spa->spa_vdevs, v_childlink) {
757 vdev_status(vdev, 1);
767 STAILQ_FOREACH(spa, &zfs_pools, spa_link) {
776 vdev_probe(vdev_phys_read_t *read, void *read_priv, spa_t **spap)
779 vdev_phys_t *vdev_label = (vdev_phys_t *) zap_scratch;
781 vdev_t *vdev, *top_vdev, *pool_vdev;
784 const unsigned char *nvlist;
787 uint64_t pool_txg, pool_guid;
789 const char *pool_name;
790 const unsigned char *vdevs;
793 const struct uberblock *up;
796 * Load the vdev label and figure out which
797 * uberblock is most current.
799 memset(&vtmp, 0, sizeof(vtmp));
800 vtmp.v_phys_read = read;
801 vtmp.v_read_priv = read_priv;
802 off = offsetof(vdev_label_t, vl_vdev_phys);
804 BP_SET_LSIZE(&bp, sizeof(vdev_phys_t));
805 BP_SET_PSIZE(&bp, sizeof(vdev_phys_t));
806 BP_SET_CHECKSUM(&bp, ZIO_CHECKSUM_LABEL);
807 BP_SET_COMPRESS(&bp, ZIO_COMPRESS_OFF);
808 DVA_SET_OFFSET(BP_IDENTITY(&bp), off);
809 ZIO_SET_CHECKSUM(&bp.blk_cksum, off, 0, 0, 0);
810 if (vdev_read_phys(&vtmp, &bp, vdev_label, off, 0))
813 if (vdev_label->vp_nvlist[0] != NV_ENCODE_XDR) {
817 nvlist = (const unsigned char *) vdev_label->vp_nvlist + 4;
819 if (nvlist_find(nvlist,
820 ZPOOL_CONFIG_VERSION,
821 DATA_TYPE_UINT64, 0, &val)) {
825 if (val > SPA_VERSION) {
826 printf("ZFS: unsupported ZFS version %u (should be %u)\n",
827 (unsigned) val, (unsigned) SPA_VERSION);
831 if (nvlist_find(nvlist,
832 ZPOOL_CONFIG_POOL_STATE,
833 DATA_TYPE_UINT64, 0, &val)) {
837 if (val == POOL_STATE_DESTROYED) {
838 /* We don't boot only from destroyed pools. */
842 if (nvlist_find(nvlist,
843 ZPOOL_CONFIG_POOL_TXG,
844 DATA_TYPE_UINT64, 0, &pool_txg)
845 || nvlist_find(nvlist,
846 ZPOOL_CONFIG_POOL_GUID,
847 DATA_TYPE_UINT64, 0, &pool_guid)
848 || nvlist_find(nvlist,
849 ZPOOL_CONFIG_POOL_NAME,
850 DATA_TYPE_STRING, 0, &pool_name)) {
852 * Cache and spare devices end up here - just ignore
855 /*printf("ZFS: can't find pool details\n");*/
860 (void) nvlist_find(nvlist, ZPOOL_CONFIG_IS_LOG, DATA_TYPE_UINT64, 0,
866 * Create the pool if this is the first time we've seen it.
868 spa = spa_find_by_guid(pool_guid);
870 spa = spa_create(pool_guid);
871 spa->spa_name = strdup(pool_name);
873 if (pool_txg > spa->spa_txg) {
874 spa->spa_txg = pool_txg;
880 * Get the vdev tree and create our in-core copy of it.
881 * If we already have a vdev with this guid, this must
882 * be some kind of alias (overlapping slices, dangerously dedicated
885 if (nvlist_find(nvlist,
887 DATA_TYPE_UINT64, 0, &guid)) {
890 vdev = vdev_find(guid);
891 if (vdev && vdev->v_phys_read) /* Has this vdev already been inited? */
894 if (nvlist_find(nvlist,
895 ZPOOL_CONFIG_VDEV_TREE,
896 DATA_TYPE_NVLIST, 0, &vdevs)) {
900 rc = vdev_init_from_nvlist(vdevs, NULL, &top_vdev, is_newer);
905 * Add the toplevel vdev to the pool if its not already there.
907 STAILQ_FOREACH(pool_vdev, &spa->spa_vdevs, v_childlink)
908 if (top_vdev == pool_vdev)
910 if (!pool_vdev && top_vdev)
911 STAILQ_INSERT_TAIL(&spa->spa_vdevs, top_vdev, v_childlink);
914 * We should already have created an incomplete vdev for this
915 * vdev. Find it and initialise it with our read proc.
917 vdev = vdev_find(guid);
919 vdev->v_phys_read = read;
920 vdev->v_read_priv = read_priv;
921 vdev->v_state = VDEV_STATE_HEALTHY;
923 printf("ZFS: inconsistent nvlist contents\n");
928 * Re-evaluate top-level vdev state.
930 vdev_set_state(top_vdev);
933 * Ok, we are happy with the pool so far. Lets find
934 * the best uberblock and then we can actually access
935 * the contents of the pool.
937 upbuf = zfs_alloc(VDEV_UBERBLOCK_SIZE(vdev));
938 up = (const struct uberblock *)upbuf;
940 i < VDEV_UBERBLOCK_COUNT(vdev);
942 off = VDEV_UBERBLOCK_OFFSET(vdev, i);
944 DVA_SET_OFFSET(&bp.blk_dva[0], off);
945 BP_SET_LSIZE(&bp, VDEV_UBERBLOCK_SIZE(vdev));
946 BP_SET_PSIZE(&bp, VDEV_UBERBLOCK_SIZE(vdev));
947 BP_SET_CHECKSUM(&bp, ZIO_CHECKSUM_LABEL);
948 BP_SET_COMPRESS(&bp, ZIO_COMPRESS_OFF);
949 ZIO_SET_CHECKSUM(&bp.blk_cksum, off, 0, 0, 0);
951 if (vdev_read_phys(vdev, &bp, upbuf, off, 0))
954 if (up->ub_magic != UBERBLOCK_MAGIC)
956 if (up->ub_txg < spa->spa_txg)
958 if (up->ub_txg > spa->spa_uberblock.ub_txg) {
959 spa->spa_uberblock = *up;
960 } else if (up->ub_txg == spa->spa_uberblock.ub_txg) {
961 if (up->ub_timestamp > spa->spa_uberblock.ub_timestamp)
962 spa->spa_uberblock = *up;
965 zfs_free(upbuf, VDEV_UBERBLOCK_SIZE(vdev));
977 for (v = 0; v < 32; v++)
984 zio_read_gang(const spa_t *spa, const blkptr_t *bp, void *buf)
987 zio_gbh_phys_t zio_gb;
991 /* Artificial BP for gang block header. */
993 BP_SET_PSIZE(&gbh_bp, SPA_GANGBLOCKSIZE);
994 BP_SET_LSIZE(&gbh_bp, SPA_GANGBLOCKSIZE);
995 BP_SET_CHECKSUM(&gbh_bp, ZIO_CHECKSUM_GANG_HEADER);
996 BP_SET_COMPRESS(&gbh_bp, ZIO_COMPRESS_OFF);
997 for (i = 0; i < SPA_DVAS_PER_BP; i++)
998 DVA_SET_GANG(&gbh_bp.blk_dva[i], 0);
1000 /* Read gang header block using the artificial BP. */
1001 if (zio_read(spa, &gbh_bp, &zio_gb))
1005 for (i = 0; i < SPA_GBH_NBLKPTRS; i++) {
1006 blkptr_t *gbp = &zio_gb.zg_blkptr[i];
1008 if (BP_IS_HOLE(gbp))
1010 if (zio_read(spa, gbp, pbuf))
1012 pbuf += BP_GET_PSIZE(gbp);
1015 if (zio_checksum_verify(bp, buf))
1021 zio_read(const spa_t *spa, const blkptr_t *bp, void *buf)
1023 int cpfunc = BP_GET_COMPRESS(bp);
1024 uint64_t align, size;
1030 for (i = 0; i < SPA_DVAS_PER_BP; i++) {
1031 const dva_t *dva = &bp->blk_dva[i];
1036 if (!dva->dva_word[0] && !dva->dva_word[1])
1039 vdevid = DVA_GET_VDEV(dva);
1040 offset = DVA_GET_OFFSET(dva);
1041 STAILQ_FOREACH(vdev, &spa->spa_vdevs, v_childlink) {
1042 if (vdev->v_id == vdevid)
1045 if (!vdev || !vdev->v_read)
1048 size = BP_GET_PSIZE(bp);
1049 if (vdev->v_read == vdev_raidz_read) {
1050 align = 1ULL << vdev->v_top->v_ashift;
1051 if (P2PHASE(size, align) != 0)
1052 size = P2ROUNDUP(size, align);
1054 if (size != BP_GET_PSIZE(bp) || cpfunc != ZIO_COMPRESS_OFF)
1055 pbuf = zfs_alloc(size);
1059 if (DVA_GET_GANG(dva))
1060 error = zio_read_gang(spa, bp, pbuf);
1062 error = vdev->v_read(vdev, bp, pbuf, offset, size);
1064 if (cpfunc != ZIO_COMPRESS_OFF)
1065 error = zio_decompress_data(cpfunc, pbuf,
1066 BP_GET_PSIZE(bp), buf, BP_GET_LSIZE(bp));
1067 else if (size != BP_GET_PSIZE(bp))
1068 bcopy(pbuf, buf, BP_GET_PSIZE(bp));
1071 zfs_free(pbuf, size);
1076 printf("ZFS: i/o error - all block copies unavailable\n");
1081 dnode_read(const spa_t *spa, const dnode_phys_t *dnode, off_t offset, void *buf, size_t buflen)
1083 int ibshift = dnode->dn_indblkshift - SPA_BLKPTRSHIFT;
1084 int bsize = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT;
1085 int nlevels = dnode->dn_nlevels;
1089 * Note: bsize may not be a power of two here so we need to do an
1090 * actual divide rather than a bitshift.
1092 while (buflen > 0) {
1093 uint64_t bn = offset / bsize;
1094 int boff = offset % bsize;
1096 const blkptr_t *indbp;
1099 if (bn > dnode->dn_maxblkid)
1102 if (dnode == dnode_cache_obj && bn == dnode_cache_bn)
1105 indbp = dnode->dn_blkptr;
1106 for (i = 0; i < nlevels; i++) {
1108 * Copy the bp from the indirect array so that
1109 * we can re-use the scratch buffer for multi-level
1112 ibn = bn >> ((nlevels - i - 1) * ibshift);
1113 ibn &= ((1 << ibshift) - 1);
1115 rc = zio_read(spa, &bp, dnode_cache_buf);
1118 indbp = (const blkptr_t *) dnode_cache_buf;
1120 dnode_cache_obj = dnode;
1121 dnode_cache_bn = bn;
1125 * The buffer contains our data block. Copy what we
1126 * need from it and loop.
1129 if (i > buflen) i = buflen;
1130 memcpy(buf, &dnode_cache_buf[boff], i);
1131 buf = ((char*) buf) + i;
1140 * Lookup a value in a microzap directory. Assumes that the zap
1141 * scratch buffer contains the directory contents.
1144 mzap_lookup(const dnode_phys_t *dnode, const char *name, uint64_t *value)
1146 const mzap_phys_t *mz;
1147 const mzap_ent_phys_t *mze;
1152 * Microzap objects use exactly one block. Read the whole
1155 size = dnode->dn_datablkszsec * 512;
1157 mz = (const mzap_phys_t *) zap_scratch;
1158 chunks = size / MZAP_ENT_LEN - 1;
1160 for (i = 0; i < chunks; i++) {
1161 mze = &mz->mz_chunk[i];
1162 if (!strcmp(mze->mze_name, name)) {
1163 *value = mze->mze_value;
1172 * Compare a name with a zap leaf entry. Return non-zero if the name
1176 fzap_name_equal(const zap_leaf_t *zl, const zap_leaf_chunk_t *zc, const char *name)
1179 const zap_leaf_chunk_t *nc;
1182 namelen = zc->l_entry.le_name_numints;
1184 nc = &ZAP_LEAF_CHUNK(zl, zc->l_entry.le_name_chunk);
1186 while (namelen > 0) {
1189 if (len > ZAP_LEAF_ARRAY_BYTES)
1190 len = ZAP_LEAF_ARRAY_BYTES;
1191 if (memcmp(p, nc->l_array.la_array, len))
1195 nc = &ZAP_LEAF_CHUNK(zl, nc->l_array.la_next);
1202 * Extract a uint64_t value from a zap leaf entry.
1205 fzap_leaf_value(const zap_leaf_t *zl, const zap_leaf_chunk_t *zc)
1207 const zap_leaf_chunk_t *vc;
1212 vc = &ZAP_LEAF_CHUNK(zl, zc->l_entry.le_value_chunk);
1213 for (i = 0, value = 0, p = vc->l_array.la_array; i < 8; i++) {
1214 value = (value << 8) | p[i];
1221 * Lookup a value in a fatzap directory. Assumes that the zap scratch
1222 * buffer contains the directory header.
1225 fzap_lookup(const spa_t *spa, const dnode_phys_t *dnode, const char *name, uint64_t *value)
1227 int bsize = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT;
1228 zap_phys_t zh = *(zap_phys_t *) zap_scratch;
1234 if (zh.zap_magic != ZAP_MAGIC)
1237 z.zap_block_shift = ilog2(bsize);
1238 z.zap_phys = (zap_phys_t *) zap_scratch;
1241 * Figure out where the pointer table is and read it in if necessary.
1243 if (zh.zap_ptrtbl.zt_blk) {
1244 rc = dnode_read(spa, dnode, zh.zap_ptrtbl.zt_blk * bsize,
1245 zap_scratch, bsize);
1248 ptrtbl = (uint64_t *) zap_scratch;
1250 ptrtbl = &ZAP_EMBEDDED_PTRTBL_ENT(&z, 0);
1253 hash = zap_hash(zh.zap_salt, name);
1256 zl.l_bs = z.zap_block_shift;
1258 off_t off = ptrtbl[hash >> (64 - zh.zap_ptrtbl.zt_shift)] << zl.l_bs;
1259 zap_leaf_chunk_t *zc;
1261 rc = dnode_read(spa, dnode, off, zap_scratch, bsize);
1265 zl.l_phys = (zap_leaf_phys_t *) zap_scratch;
1268 * Make sure this chunk matches our hash.
1270 if (zl.l_phys->l_hdr.lh_prefix_len > 0
1271 && zl.l_phys->l_hdr.lh_prefix
1272 != hash >> (64 - zl.l_phys->l_hdr.lh_prefix_len))
1276 * Hash within the chunk to find our entry.
1278 int shift = (64 - ZAP_LEAF_HASH_SHIFT(&zl) - zl.l_phys->l_hdr.lh_prefix_len);
1279 int h = (hash >> shift) & ((1 << ZAP_LEAF_HASH_SHIFT(&zl)) - 1);
1280 h = zl.l_phys->l_hash[h];
1283 zc = &ZAP_LEAF_CHUNK(&zl, h);
1284 while (zc->l_entry.le_hash != hash) {
1285 if (zc->l_entry.le_next == 0xffff) {
1289 zc = &ZAP_LEAF_CHUNK(&zl, zc->l_entry.le_next);
1291 if (fzap_name_equal(&zl, zc, name)) {
1292 *value = fzap_leaf_value(&zl, zc);
1300 * Lookup a name in a zap object and return its value as a uint64_t.
1303 zap_lookup(const spa_t *spa, const dnode_phys_t *dnode, const char *name, uint64_t *value)
1307 size_t size = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT;
1309 rc = dnode_read(spa, dnode, 0, zap_scratch, size);
1313 zap_type = *(uint64_t *) zap_scratch;
1314 if (zap_type == ZBT_MICRO)
1315 return mzap_lookup(dnode, name, value);
1316 else if (zap_type == ZBT_HEADER)
1317 return fzap_lookup(spa, dnode, name, value);
1318 printf("ZFS: invalid zap_type=%d\n", (int)zap_type);
1325 * List a microzap directory. Assumes that the zap scratch buffer contains
1326 * the directory contents.
1329 mzap_list(const dnode_phys_t *dnode)
1331 const mzap_phys_t *mz;
1332 const mzap_ent_phys_t *mze;
1337 * Microzap objects use exactly one block. Read the whole
1340 size = dnode->dn_datablkszsec * 512;
1341 mz = (const mzap_phys_t *) zap_scratch;
1342 chunks = size / MZAP_ENT_LEN - 1;
1344 for (i = 0; i < chunks; i++) {
1345 mze = &mz->mz_chunk[i];
1346 if (mze->mze_name[0])
1347 //printf("%-32s 0x%jx\n", mze->mze_name, (uintmax_t)mze->mze_value);
1348 printf("%s\n", mze->mze_name);
1355 * List a fatzap directory. Assumes that the zap scratch buffer contains
1356 * the directory header.
1359 fzap_list(const spa_t *spa, const dnode_phys_t *dnode)
1361 int bsize = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT;
1362 zap_phys_t zh = *(zap_phys_t *) zap_scratch;
1366 if (zh.zap_magic != ZAP_MAGIC)
1369 z.zap_block_shift = ilog2(bsize);
1370 z.zap_phys = (zap_phys_t *) zap_scratch;
1373 * This assumes that the leaf blocks start at block 1. The
1374 * documentation isn't exactly clear on this.
1377 zl.l_bs = z.zap_block_shift;
1378 for (i = 0; i < zh.zap_num_leafs; i++) {
1379 off_t off = (i + 1) << zl.l_bs;
1383 if (dnode_read(spa, dnode, off, zap_scratch, bsize))
1386 zl.l_phys = (zap_leaf_phys_t *) zap_scratch;
1388 for (j = 0; j < ZAP_LEAF_NUMCHUNKS(&zl); j++) {
1389 zap_leaf_chunk_t *zc, *nc;
1392 zc = &ZAP_LEAF_CHUNK(&zl, j);
1393 if (zc->l_entry.le_type != ZAP_CHUNK_ENTRY)
1395 namelen = zc->l_entry.le_name_numints;
1396 if (namelen > sizeof(name))
1397 namelen = sizeof(name);
1400 * Paste the name back together.
1402 nc = &ZAP_LEAF_CHUNK(&zl, zc->l_entry.le_name_chunk);
1404 while (namelen > 0) {
1407 if (len > ZAP_LEAF_ARRAY_BYTES)
1408 len = ZAP_LEAF_ARRAY_BYTES;
1409 memcpy(p, nc->l_array.la_array, len);
1412 nc = &ZAP_LEAF_CHUNK(&zl, nc->l_array.la_next);
1416 * Assume the first eight bytes of the value are
1419 value = fzap_leaf_value(&zl, zc);
1421 //printf("%s 0x%jx\n", name, (uintmax_t)value);
1422 printf("%s\n", name);
1430 * List a zap directory.
1433 zap_list(const spa_t *spa, const dnode_phys_t *dnode)
1436 size_t size = dnode->dn_datablkszsec * 512;
1438 if (dnode_read(spa, dnode, 0, zap_scratch, size))
1441 zap_type = *(uint64_t *) zap_scratch;
1442 if (zap_type == ZBT_MICRO)
1443 return mzap_list(dnode);
1445 return fzap_list(spa, dnode);
1451 objset_get_dnode(const spa_t *spa, const objset_phys_t *os, uint64_t objnum, dnode_phys_t *dnode)
1455 offset = objnum * sizeof(dnode_phys_t);
1456 return dnode_read(spa, &os->os_meta_dnode, offset,
1457 dnode, sizeof(dnode_phys_t));
1461 mzap_rlookup(const spa_t *spa, const dnode_phys_t *dnode, char *name, uint64_t value)
1463 const mzap_phys_t *mz;
1464 const mzap_ent_phys_t *mze;
1469 * Microzap objects use exactly one block. Read the whole
1472 size = dnode->dn_datablkszsec * 512;
1474 mz = (const mzap_phys_t *) zap_scratch;
1475 chunks = size / MZAP_ENT_LEN - 1;
1477 for (i = 0; i < chunks; i++) {
1478 mze = &mz->mz_chunk[i];
1479 if (value == mze->mze_value) {
1480 strcpy(name, mze->mze_name);
1489 fzap_name_copy(const zap_leaf_t *zl, const zap_leaf_chunk_t *zc, char *name)
1492 const zap_leaf_chunk_t *nc;
1495 namelen = zc->l_entry.le_name_numints;
1497 nc = &ZAP_LEAF_CHUNK(zl, zc->l_entry.le_name_chunk);
1499 while (namelen > 0) {
1502 if (len > ZAP_LEAF_ARRAY_BYTES)
1503 len = ZAP_LEAF_ARRAY_BYTES;
1504 memcpy(p, nc->l_array.la_array, len);
1507 nc = &ZAP_LEAF_CHUNK(zl, nc->l_array.la_next);
1514 fzap_rlookup(const spa_t *spa, const dnode_phys_t *dnode, char *name, uint64_t value)
1516 int bsize = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT;
1517 zap_phys_t zh = *(zap_phys_t *) zap_scratch;
1521 if (zh.zap_magic != ZAP_MAGIC)
1524 z.zap_block_shift = ilog2(bsize);
1525 z.zap_phys = (zap_phys_t *) zap_scratch;
1528 * This assumes that the leaf blocks start at block 1. The
1529 * documentation isn't exactly clear on this.
1532 zl.l_bs = z.zap_block_shift;
1533 for (i = 0; i < zh.zap_num_leafs; i++) {
1534 off_t off = (i + 1) << zl.l_bs;
1536 if (dnode_read(spa, dnode, off, zap_scratch, bsize))
1539 zl.l_phys = (zap_leaf_phys_t *) zap_scratch;
1541 for (j = 0; j < ZAP_LEAF_NUMCHUNKS(&zl); j++) {
1542 zap_leaf_chunk_t *zc;
1544 zc = &ZAP_LEAF_CHUNK(&zl, j);
1545 if (zc->l_entry.le_type != ZAP_CHUNK_ENTRY)
1547 if (zc->l_entry.le_value_intlen != 8 ||
1548 zc->l_entry.le_value_numints != 1)
1551 if (fzap_leaf_value(&zl, zc) == value) {
1552 fzap_name_copy(&zl, zc, name);
1562 zap_rlookup(const spa_t *spa, const dnode_phys_t *dnode, char *name, uint64_t value)
1566 size_t size = dnode->dn_datablkszsec * 512;
1568 rc = dnode_read(spa, dnode, 0, zap_scratch, size);
1572 zap_type = *(uint64_t *) zap_scratch;
1573 if (zap_type == ZBT_MICRO)
1574 return mzap_rlookup(spa, dnode, name, value);
1576 return fzap_rlookup(spa, dnode, name, value);
1580 zfs_rlookup(const spa_t *spa, uint64_t objnum, char *result)
1583 char component[256];
1584 uint64_t dir_obj, parent_obj, child_dir_zapobj;
1585 dnode_phys_t child_dir_zap, dataset, dir, parent;
1587 dsl_dataset_phys_t *ds;
1591 p = &name[sizeof(name) - 1];
1594 if (objset_get_dnode(spa, &spa->spa_mos, objnum, &dataset)) {
1595 printf("ZFS: can't find dataset %ju\n", (uintmax_t)objnum);
1598 ds = (dsl_dataset_phys_t *)&dataset.dn_bonus;
1599 dir_obj = ds->ds_dir_obj;
1602 if (objset_get_dnode(spa, &spa->spa_mos, dir_obj, &dir) != 0)
1604 dd = (dsl_dir_phys_t *)&dir.dn_bonus;
1606 /* Actual loop condition. */
1607 parent_obj = dd->dd_parent_obj;
1608 if (parent_obj == 0)
1611 if (objset_get_dnode(spa, &spa->spa_mos, parent_obj, &parent) != 0)
1613 dd = (dsl_dir_phys_t *)&parent.dn_bonus;
1614 child_dir_zapobj = dd->dd_child_dir_zapobj;
1615 if (objset_get_dnode(spa, &spa->spa_mos, child_dir_zapobj, &child_dir_zap) != 0)
1617 if (zap_rlookup(spa, &child_dir_zap, component, dir_obj) != 0)
1620 len = strlen(component);
1622 memcpy(p, component, len);
1626 /* Actual loop iteration. */
1627 dir_obj = parent_obj;
1638 zfs_lookup_dataset(const spa_t *spa, const char *name, uint64_t *objnum)
1641 uint64_t dir_obj, child_dir_zapobj;
1642 dnode_phys_t child_dir_zap, dir;
1646 if (objset_get_dnode(spa, &spa->spa_mos, DMU_POOL_DIRECTORY_OBJECT, &dir))
1648 if (zap_lookup(spa, &dir, DMU_POOL_ROOT_DATASET, &dir_obj))
1653 if (objset_get_dnode(spa, &spa->spa_mos, dir_obj, &dir))
1655 dd = (dsl_dir_phys_t *)&dir.dn_bonus;
1659 /* Actual loop condition #1. */
1665 memcpy(element, p, q - p);
1666 element[q - p] = '\0';
1673 child_dir_zapobj = dd->dd_child_dir_zapobj;
1674 if (objset_get_dnode(spa, &spa->spa_mos, child_dir_zapobj, &child_dir_zap) != 0)
1677 /* Actual loop condition #2. */
1678 if (zap_lookup(spa, &child_dir_zap, element, &dir_obj) != 0)
1682 *objnum = dd->dd_head_dataset_obj;
1687 * Find the object set given the object number of its dataset object
1688 * and return its details in *objset
1691 zfs_mount_dataset(const spa_t *spa, uint64_t objnum, objset_phys_t *objset)
1693 dnode_phys_t dataset;
1694 dsl_dataset_phys_t *ds;
1696 if (objset_get_dnode(spa, &spa->spa_mos, objnum, &dataset)) {
1697 printf("ZFS: can't find dataset %ju\n", (uintmax_t)objnum);
1701 ds = (dsl_dataset_phys_t *) &dataset.dn_bonus;
1702 if (zio_read(spa, &ds->ds_bp, objset)) {
1703 printf("ZFS: can't read object set for dataset %ju\n",
1712 * Find the object set pointed to by the BOOTFS property or the root
1713 * dataset if there is none and return its details in *objset
1716 zfs_get_root(const spa_t *spa, uint64_t *objid)
1718 dnode_phys_t dir, propdir;
1719 uint64_t props, bootfs, root;
1724 * Start with the MOS directory object.
1726 if (objset_get_dnode(spa, &spa->spa_mos, DMU_POOL_DIRECTORY_OBJECT, &dir)) {
1727 printf("ZFS: can't read MOS object directory\n");
1732 * Lookup the pool_props and see if we can find a bootfs.
1734 if (zap_lookup(spa, &dir, DMU_POOL_PROPS, &props) == 0
1735 && objset_get_dnode(spa, &spa->spa_mos, props, &propdir) == 0
1736 && zap_lookup(spa, &propdir, "bootfs", &bootfs) == 0
1743 * Lookup the root dataset directory
1745 if (zap_lookup(spa, &dir, DMU_POOL_ROOT_DATASET, &root)
1746 || objset_get_dnode(spa, &spa->spa_mos, root, &dir)) {
1747 printf("ZFS: can't find root dsl_dir\n");
1752 * Use the information from the dataset directory's bonus buffer
1753 * to find the dataset object and from that the object set itself.
1755 dsl_dir_phys_t *dd = (dsl_dir_phys_t *) &dir.dn_bonus;
1756 *objid = dd->dd_head_dataset_obj;
1761 zfs_mount(const spa_t *spa, uint64_t rootobj, struct zfsmount *mount)
1767 * Find the root object set if not explicitly provided
1769 if (rootobj == 0 && zfs_get_root(spa, &rootobj)) {
1770 printf("ZFS: can't find root filesystem\n");
1774 if (zfs_mount_dataset(spa, rootobj, &mount->objset)) {
1775 printf("ZFS: can't open root filesystem\n");
1779 mount->rootobj = rootobj;
1785 zfs_spa_init(spa_t *spa)
1788 if (spa->spa_inited)
1790 if (zio_read(spa, &spa->spa_uberblock.ub_rootbp, &spa->spa_mos)) {
1791 printf("ZFS: can't read MOS of pool %s\n", spa->spa_name);
1794 spa->spa_inited = 1;
1799 zfs_dnode_stat(const spa_t *spa, dnode_phys_t *dn, struct stat *sb)
1802 if (dn->dn_bonustype != DMU_OT_SA) {
1803 znode_phys_t *zp = (znode_phys_t *)dn->dn_bonus;
1805 sb->st_mode = zp->zp_mode;
1806 sb->st_uid = zp->zp_uid;
1807 sb->st_gid = zp->zp_gid;
1808 sb->st_size = zp->zp_size;
1810 sa_hdr_phys_t *sahdrp;
1815 if (dn->dn_bonuslen != 0)
1816 sahdrp = (sa_hdr_phys_t *)DN_BONUS(dn);
1818 if ((dn->dn_flags & DNODE_FLAG_SPILL_BLKPTR) != 0) {
1819 blkptr_t *bp = &dn->dn_spill;
1822 size = BP_GET_LSIZE(bp);
1823 buf = zfs_alloc(size);
1824 error = zio_read(spa, bp, buf);
1826 zfs_free(buf, size);
1834 hdrsize = SA_HDR_SIZE(sahdrp);
1835 sb->st_mode = *(uint64_t *)((char *)sahdrp + hdrsize +
1837 sb->st_uid = *(uint64_t *)((char *)sahdrp + hdrsize +
1839 sb->st_gid = *(uint64_t *)((char *)sahdrp + hdrsize +
1841 sb->st_size = *(uint64_t *)((char *)sahdrp + hdrsize +
1844 zfs_free(buf, size);
1851 * Lookup a file and return its dnode.
1854 zfs_lookup(const struct zfsmount *mount, const char *upath, dnode_phys_t *dnode)
1857 uint64_t objnum, rootnum, parentnum;
1863 int symlinks_followed = 0;
1867 if (mount->objset.os_type != DMU_OST_ZFS) {
1868 printf("ZFS: unexpected object set type %ju\n",
1869 (uintmax_t)mount->objset.os_type);
1874 * Get the root directory dnode.
1876 rc = objset_get_dnode(spa, &mount->objset, MASTER_NODE_OBJ, &dn);
1880 rc = zap_lookup(spa, &dn, ZFS_ROOT_OBJ, &rootnum);
1884 rc = objset_get_dnode(spa, &mount->objset, rootnum, &dn);
1897 memcpy(element, p, q - p);
1905 rc = zfs_dnode_stat(spa, &dn, &sb);
1908 if (!S_ISDIR(sb.st_mode))
1912 rc = zap_lookup(spa, &dn, element, &objnum);
1915 objnum = ZFS_DIRENT_OBJ(objnum);
1917 rc = objset_get_dnode(spa, &mount->objset, objnum, &dn);
1922 * Check for symlink.
1924 rc = zfs_dnode_stat(spa, &dn, &sb);
1927 if (S_ISLNK(sb.st_mode)) {
1928 if (symlinks_followed > 10)
1930 symlinks_followed++;
1933 * Read the link value and copy the tail of our
1934 * current path onto the end.
1937 strcpy(&path[sb.st_size], p);
1939 path[sb.st_size] = 0;
1940 if (sb.st_size + sizeof(znode_phys_t) <= dn.dn_bonuslen) {
1941 memcpy(path, &dn.dn_bonus[sizeof(znode_phys_t)],
1944 rc = dnode_read(spa, &dn, 0, path, sb.st_size);
1950 * Restart with the new path, starting either at
1951 * the root or at the parent depending whether or
1952 * not the link is relative.
1959 objset_get_dnode(spa, &mount->objset, objnum, &dn);