199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2007 Doug Rabson
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Stand-alone ZFS file reader.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * List of all vdevs, chained through v_alllink.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * List of ZFS features supported for read
199767f8919635c4928607450d9e0abb932109ceToomas Soome "org.illumos:lz4_compress",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "com.delphix:hole_birth",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "com.delphix:extensible_dataset",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "com.delphix:embedded_data",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "org.open-zfs:large_blocks",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "org.illumos:sha512",
199767f8919635c4928607450d9e0abb932109ceToomas Soome * List of all pools, chained through spa_link.
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic char *zfs_temp_buf, *zfs_temp_end, *zfs_temp_ptr;
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int zio_read(const spa_t *spa, const blkptr_t *bp, void *buf);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int zfs_get_root(const spa_t *spa, uint64_t *objid);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int zfs_rlookup(const spa_t *spa, uint64_t objnum, char *result);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void *
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: out of temporary buffer space\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: zfs_alloc()/zfs_free() mismatch\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soomexdr_uint64_t(const unsigned char **xdr, uint64_t *lp)
199767f8919635c4928607450d9e0abb932109ceToomas Soomenvlist_find(const unsigned char *nvlist, const char *name, int type,
199767f8919635c4928607450d9e0abb932109ceToomas Soome pairname = (const char*) p;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!memcmp(name, pairname, namelen) && type == pairtype) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome (*(const char**) valuep) = (const char*) p;
199767f8919635c4928607450d9e0abb932109ceToomas Soome (*(const unsigned char**) valuep) =
199767f8919635c4928607450d9e0abb932109ceToomas Soome (const unsigned char*) p;
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Not the pair we are looking for, skip to the next one.
199767f8919635c4928607450d9e0abb932109ceToomas Soomenvlist_check_features_for_read(const unsigned char *nvlist)
199767f8919635c4928607450d9e0abb932109ceToomas Soome pairname = (const char*) p;
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; features_for_read[i] != NULL; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!memcmp(pairname, features_for_read[i], namelen)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: unsupported feature: %s\n", pairname);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Return the next nvlist in an nvlist array.
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic const unsigned char *
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic const unsigned char *
199767f8919635c4928607450d9e0abb932109ceToomas Soomenvlist_print(const unsigned char *nvlist, unsigned int indent)
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_UNKNOWN",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_BOOLEAN",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_BYTE",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_INT16",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_UINT16",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_INT32",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_UINT32",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_INT64",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_UINT64",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_STRING",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_BYTE_ARRAY",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_INT16_ARRAY",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_UINT16_ARRAY",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_INT32_ARRAY",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_UINT32_ARRAY",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_INT64_ARRAY",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_UINT64_ARRAY",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_STRING_ARRAY",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_HRTIME",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_NVLIST",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_NVLIST_ARRAY",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_BOOLEAN_VALUE",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_INT8",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_UINT8",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_BOOLEAN_ARRAY",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_INT8_ARRAY",
199767f8919635c4928607450d9e0abb932109ceToomas Soome "DATA_TYPE_UINT8_ARRAY"
199767f8919635c4928607450d9e0abb932109ceToomas Soome unsigned int i, j;
199767f8919635c4928607450d9e0abb932109ceToomas Soome pairname = (const char*) p;
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < indent; i++)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("%s %s", typenames[pairtype], pairname);
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (j = 0; j < elements; j++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < indent; i++)
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("%s %s", typenames[pairtype], pairname);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevdev_read_phys(vdev_t *vdev, const blkptr_t *bp, void *buf,
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*printf("ZFS: reading %d bytes at 0x%jx to %p\n", psize, (uintmax_t)offset, buf);*/
199767f8919635c4928607450d9e0abb932109ceToomas Soome rc = vdev->v_phys_read(vdev, vdev->v_read_priv, offset, buf, psize);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevdev_disk_read(vdev_t *vdev, const blkptr_t *bp, void *buf,
199767f8919635c4928607450d9e0abb932109ceToomas Soomevdev_mirror_read(vdev_t *vdev, const blkptr_t *bp, void *buf,
199767f8919635c4928607450d9e0abb932109ceToomas Soome STAILQ_FOREACH(kid, &vdev->v_children, v_childlink) {
199767f8919635c4928607450d9e0abb932109ceToomas Soomevdev_replacing_read(vdev_t *vdev, const blkptr_t *bp, void *buf,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Here we should have two kids:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * First one which is the one we are replacing and we can trust
199767f8919635c4928607450d9e0abb932109ceToomas Soome * only this one to have valid data, but it might not be present.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Second one is that one we are replacing with. It is most likely
199767f8919635c4928607450d9e0abb932109ceToomas Soome * healthy, but we can't trust it has needed data, so we won't use it.
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (kid->v_read(kid, bp, buf, offset, bytes));
199767f8919635c4928607450d9e0abb932109ceToomas Soomevdev_create(uint64_t guid, vdev_read_t *vdev_read)
199767f8919635c4928607450d9e0abb932109ceToomas Soome STAILQ_INSERT_TAIL(&zfs_vdevs, vdev, v_alllink);
199767f8919635c4928607450d9e0abb932109ceToomas Soomevdev_init_from_nvlist(const unsigned char *nvlist, vdev_t *pvdev,
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t is_offline, is_faulted, is_degraded, is_removed, isnt_present;
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: can only boot from disk, mirror, raidz1, raidz2 and raidz3 vdevs\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome is_offline = is_removed = is_faulted = is_degraded = isnt_present = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome nvlist_find(nvlist, ZPOOL_CONFIG_OFFLINE, DATA_TYPE_UINT64, 0,
199767f8919635c4928607450d9e0abb932109ceToomas Soome nvlist_find(nvlist, ZPOOL_CONFIG_REMOVED, DATA_TYPE_UINT64, 0,
199767f8919635c4928607450d9e0abb932109ceToomas Soome nvlist_find(nvlist, ZPOOL_CONFIG_FAULTED, DATA_TYPE_UINT64, 0,
199767f8919635c4928607450d9e0abb932109ceToomas Soome nvlist_find(nvlist, ZPOOL_CONFIG_DEGRADED, DATA_TYPE_UINT64, 0,
199767f8919635c4928607450d9e0abb932109ceToomas Soome nvlist_find(nvlist, ZPOOL_CONFIG_NOT_PRESENT, DATA_TYPE_UINT64, 0,
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (nvlist_find(nvlist, ZPOOL_CONFIG_PHYS_PATH,
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: can only boot from disk, mirror, raidz1, raidz2 and raidz3 vdevs\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This is either new vdev or we've already seen this vdev,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * but from an older vdev label, so let's refresh its state
199767f8919635c4928607450d9e0abb932109ceToomas Soome * from the newer label.
199767f8919635c4928607450d9e0abb932109ceToomas Soome rc = nvlist_find(nvlist, ZPOOL_CONFIG_CHILDREN,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Its ok if we don't have any kids.
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < nkids; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome rc = vdev_init_from_nvlist(kids, vdev, &kid, is_newer);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * A mirror or raidz is healthy if all its kids are healthy. A
199767f8919635c4928607450d9e0abb932109ceToomas Soome * mirror is degraded if any of its kids is healthy; a raidz
199767f8919635c4928607450d9e0abb932109ceToomas Soome * is degraded if at most nparity kids are offline.
199767f8919635c4928607450d9e0abb932109ceToomas Soome STAILQ_FOREACH(kid, &vdev->v_children, v_childlink) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (kid = STAILQ_FIRST(&vdev->v_children); kid != NULL;
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic const char *
199767f8919635c4928607450d9e0abb932109ceToomas Soome "CANT_OPEN",
199767f8919635c4928607450d9e0abb932109ceToomas Soomeprint_state(int indent, const char *name, vdev_state_t state)
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < indent; i++)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (pager_printf(STATUS_FORMAT, buf, state_name(state)));
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret = print_state(indent, vdev->v_name, vdev->v_state);
199767f8919635c4928607450d9e0abb932109ceToomas Soome STAILQ_FOREACH(kid, &vdev->v_children, v_childlink) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret = pager_printf(" pool: %s\n", spa->spa_name);
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret = pager_printf("bootfs: %s\n", spa->spa_name);
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret = pager_printf("bootfs: %s/%s\n", spa->spa_name,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ret = pager_printf(STATUS_FORMAT, "NAME", "STATE");
199767f8919635c4928607450d9e0abb932109ceToomas Soome STAILQ_FOREACH(vdev, &spa->spa_vdevs, v_childlink) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (good_kids > 0 && (degraded_kids + bad_kids) == 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome STAILQ_FOREACH(vdev, &spa->spa_vdevs, v_childlink) {
199767f8919635c4928607450d9e0abb932109ceToomas Soomevdev_probe(vdev_phys_read_t *phys_read, void *read_priv, spa_t **spap)
199767f8919635c4928607450d9e0abb932109ceToomas Soome vdev_phys_t *vdev_label = (vdev_phys_t *) zap_scratch;
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Load the vdev label and figure out which
199767f8919635c4928607450d9e0abb932109ceToomas Soome * uberblock is most current.
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (vdev_read_phys(&vtmp, &bp, vdev_label, off, 0))
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (vdev_label->vp_nvlist[0] != NV_ENCODE_XDR) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome nvlist = (const unsigned char *) vdev_label->vp_nvlist + 4;
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: unsupported ZFS version %u (should be %u)\n",
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Check ZFS features for read */
199767f8919635c4928607450d9e0abb932109ceToomas Soome && nvlist_check_features_for_read(features) != 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* We don't boot only from destroyed pools. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Cache and spare devices end up here - just ignore
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*printf("ZFS: can't find pool details\n");*/
199767f8919635c4928607450d9e0abb932109ceToomas Soome (void) nvlist_find(nvlist, ZPOOL_CONFIG_IS_LOG, DATA_TYPE_UINT64, 0,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Create the pool if this is the first time we've seen it.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Get the vdev tree and create our in-core copy of it.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * If we already have a vdev with this guid, this must
199767f8919635c4928607450d9e0abb932109ceToomas Soome * be some kind of alias (overlapping slices, dangerously dedicated
199767f8919635c4928607450d9e0abb932109ceToomas Soome * disks etc).
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (vdev && vdev->v_phys_read) /* Has this vdev already been inited? */
199767f8919635c4928607450d9e0abb932109ceToomas Soome rc = vdev_init_from_nvlist(vdevs, NULL, &top_vdev, is_newer);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Add the toplevel vdev to the pool if its not already there.
199767f8919635c4928607450d9e0abb932109ceToomas Soome STAILQ_FOREACH(pool_vdev, &spa->spa_vdevs, v_childlink)
199767f8919635c4928607450d9e0abb932109ceToomas Soome STAILQ_INSERT_TAIL(&spa->spa_vdevs, top_vdev, v_childlink);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * We should already have created an incomplete vdev for this
199767f8919635c4928607450d9e0abb932109ceToomas Soome * vdev. Find it and initialise it with our read proc.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Re-evaluate top-level vdev state.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Ok, we are happy with the pool so far. Lets find
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the best uberblock and then we can actually access
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the contents of the pool.
199767f8919635c4928607450d9e0abb932109ceToomas Soome } else if (up->ub_txg == spa->spa_uberblock.ub_txg) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (up->ub_timestamp > spa->spa_uberblock.ub_timestamp)
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (v = 0; v < 32; v++)
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (n == (1 << v))
199767f8919635c4928607450d9e0abb932109ceToomas Soomezio_read_gang(const spa_t *spa, const blkptr_t *bp, void *buf)
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Artificial BP for gang block header. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome BP_SET_CHECKSUM(&gbh_bp, ZIO_CHECKSUM_GANG_HEADER);
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < SPA_DVAS_PER_BP; i++)
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Read gang header block using the artificial BP. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < SPA_GBH_NBLKPTRS; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soomezio_read(const spa_t *spa, const blkptr_t *bp, void *buf)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Process data embedded in block pointer
199767f8919635c4928607450d9e0abb932109ceToomas Soome ASSERT(BPE_GET_ETYPE(bp) == BP_EMBEDDED_TYPE_DATA);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: i/o error - unable to decompress block pointer data, error %d\n",
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < SPA_DVAS_PER_BP; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome STAILQ_FOREACH(vdev, &spa->spa_vdevs, v_childlink) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (size != BP_GET_PSIZE(bp) || cpfunc != ZIO_COMPRESS_OFF)
199767f8919635c4928607450d9e0abb932109ceToomas Soome error = vdev->v_read(vdev, bp, pbuf, offset, size);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: i/o error - all block copies unavailable\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soomednode_read(const spa_t *spa, const dnode_phys_t *dnode, off_t offset, void *buf, size_t buflen)
199767f8919635c4928607450d9e0abb932109ceToomas Soome int ibshift = dnode->dn_indblkshift - SPA_BLKPTRSHIFT;
199767f8919635c4928607450d9e0abb932109ceToomas Soome int bsize = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT;
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: I/O error - blocks larger than %llu are not "
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Note: bsize may not be a power of two here so we need to do an
199767f8919635c4928607450d9e0abb932109ceToomas Soome * actual divide rather than a bitshift.
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (buflen > 0) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("warning: zfs bug: bn %llx > dn_maxblkid %llx\n",
199767f8919635c4928607450d9e0abb932109ceToomas Soome (unsigned long long)bn,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * zfs bug, will not return error
199767f8919635c4928607450d9e0abb932109ceToomas Soome * return (EIO);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (dnode == dnode_cache_obj && bn == dnode_cache_bn)
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < nlevels; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copy the bp from the indirect array so that
199767f8919635c4928607450d9e0abb932109ceToomas Soome * we can re-use the scratch buffer for multi-level
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The buffer contains our data block. Copy what we
199767f8919635c4928607450d9e0abb932109ceToomas Soome * need from it and loop.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Lookup a value in a microzap directory. Assumes that the zap
199767f8919635c4928607450d9e0abb932109ceToomas Soome * scratch buffer contains the directory contents.
199767f8919635c4928607450d9e0abb932109ceToomas Soomemzap_lookup(const dnode_phys_t *dnode, const char *name, uint64_t *value)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Microzap objects use exactly one block. Read the whole
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < chunks; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Compare a name with a zap leaf entry. Return non-zero if the name
199767f8919635c4928607450d9e0abb932109ceToomas Soomefzap_name_equal(const zap_leaf_t *zl, const zap_leaf_chunk_t *zc, const char *name)
199767f8919635c4928607450d9e0abb932109ceToomas Soome const char *p;
199767f8919635c4928607450d9e0abb932109ceToomas Soome nc = &ZAP_LEAF_CHUNK(zl, zc->l_entry.le_name_chunk);
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (namelen > 0) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Extract a uint64_t value from a zap leaf entry.
199767f8919635c4928607450d9e0abb932109ceToomas Soomefzap_leaf_value(const zap_leaf_t *zl, const zap_leaf_chunk_t *zc)
199767f8919635c4928607450d9e0abb932109ceToomas Soome vc = &ZAP_LEAF_CHUNK(zl, zc->l_entry.le_value_chunk);
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0, value = 0, p = vc->l_array.la_array; i < 8; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Lookup a value in a fatzap directory. Assumes that the zap scratch
199767f8919635c4928607450d9e0abb932109ceToomas Soome * buffer contains the directory header.
199767f8919635c4928607450d9e0abb932109ceToomas Soomefzap_lookup(const spa_t *spa, const dnode_phys_t *dnode, const char *name, uint64_t *value)
199767f8919635c4928607450d9e0abb932109ceToomas Soome int bsize = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT;
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Figure out where the pointer table is and read it in if necessary.
199767f8919635c4928607450d9e0abb932109ceToomas Soome rc = dnode_read(spa, dnode, zh.zap_ptrtbl.zt_blk * bsize,
199767f8919635c4928607450d9e0abb932109ceToomas Soome off_t off = ptrtbl[hash >> (64 - zh.zap_ptrtbl.zt_shift)] << zl.l_bs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome rc = dnode_read(spa, dnode, off, zap_scratch, bsize);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Make sure this chunk matches our hash.
199767f8919635c4928607450d9e0abb932109ceToomas Soome != hash >> (64 - zl.l_phys->l_hdr.lh_prefix_len))
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Hash within the chunk to find our entry.
199767f8919635c4928607450d9e0abb932109ceToomas Soome int shift = (64 - ZAP_LEAF_HASH_SHIFT(&zl) - zl.l_phys->l_hdr.lh_prefix_len);
199767f8919635c4928607450d9e0abb932109ceToomas Soome int h = (hash >> shift) & ((1 << ZAP_LEAF_HASH_SHIFT(&zl)) - 1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (h == 0xffff)
199767f8919635c4928607450d9e0abb932109ceToomas Soome zc = &ZAP_LEAF_CHUNK(&zl, zc->l_entry.le_next);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (zc->l_entry.le_value_intlen * zc->l_entry.le_value_numints > 8)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Lookup a name in a zap object and return its value as a uint64_t.
199767f8919635c4928607450d9e0abb932109ceToomas Soomezap_lookup(const spa_t *spa, const dnode_phys_t *dnode, const char *name, uint64_t *value)
199767f8919635c4928607450d9e0abb932109ceToomas Soome size_t size = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT;
199767f8919635c4928607450d9e0abb932109ceToomas Soome rc = dnode_read(spa, dnode, 0, zap_scratch, size);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: invalid zap_type=%d\n", (int)zap_type);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * List a microzap directory. Assumes that the zap scratch buffer contains
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the directory contents.
199767f8919635c4928607450d9e0abb932109ceToomas Soomemzap_list(const dnode_phys_t *dnode, int (*callback)(const char *, uint64_t))
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Microzap objects use exactly one block. Read the whole
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < chunks; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome * List a fatzap directory. Assumes that the zap scratch buffer contains
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the directory header.
199767f8919635c4928607450d9e0abb932109ceToomas Soomefzap_list(const spa_t *spa, const dnode_phys_t *dnode, int (*callback)(const char *, uint64_t))
199767f8919635c4928607450d9e0abb932109ceToomas Soome int bsize = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT;
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This assumes that the leaf blocks start at block 1. The
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation isn't exactly clear on this.
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (dnode_read(spa, dnode, off, zap_scratch, bsize))
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (j = 0; j < ZAP_LEAF_NUMCHUNKS(&zl); j++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Paste the name back together.
199767f8919635c4928607450d9e0abb932109ceToomas Soome nc = &ZAP_LEAF_CHUNK(&zl, zc->l_entry.le_name_chunk);
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (namelen > 0) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome nc = &ZAP_LEAF_CHUNK(&zl, nc->l_array.la_next);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Assume the first eight bytes of the value are
199767f8919635c4928607450d9e0abb932109ceToomas Soome * a uint64_t.
199767f8919635c4928607450d9e0abb932109ceToomas Soome //printf("%s 0x%jx\n", name, (uintmax_t)value);
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic int zfs_printf(const char *name, uint64_t value __unused)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * List a zap directory.
199767f8919635c4928607450d9e0abb932109ceToomas Soomezap_list(const spa_t *spa, const dnode_phys_t *dnode)
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (dnode_read(spa, dnode, 0, zap_scratch, size))
199767f8919635c4928607450d9e0abb932109ceToomas Soomeobjset_get_dnode(const spa_t *spa, const objset_phys_t *os, uint64_t objnum, dnode_phys_t *dnode)
199767f8919635c4928607450d9e0abb932109ceToomas Soome return dnode_read(spa, &os->os_meta_dnode, offset,
199767f8919635c4928607450d9e0abb932109ceToomas Soomemzap_rlookup(const spa_t *spa, const dnode_phys_t *dnode, char *name, uint64_t value)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Microzap objects use exactly one block. Read the whole
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; i < chunks; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soomefzap_name_copy(const zap_leaf_t *zl, const zap_leaf_chunk_t *zc, char *name)
199767f8919635c4928607450d9e0abb932109ceToomas Soome nc = &ZAP_LEAF_CHUNK(zl, zc->l_entry.le_name_chunk);
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (namelen > 0) {
199767f8919635c4928607450d9e0abb932109ceToomas Soomefzap_rlookup(const spa_t *spa, const dnode_phys_t *dnode, char *name, uint64_t value)
199767f8919635c4928607450d9e0abb932109ceToomas Soome int bsize = dnode->dn_datablkszsec << SPA_MINBLOCKSHIFT;
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This assumes that the leaf blocks start at block 1. The
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation isn't exactly clear on this.
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (dnode_read(spa, dnode, off, zap_scratch, bsize))
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (j = 0; j < ZAP_LEAF_NUMCHUNKS(&zl); j++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soomezap_rlookup(const spa_t *spa, const dnode_phys_t *dnode, char *name, uint64_t value)
199767f8919635c4928607450d9e0abb932109ceToomas Soome rc = dnode_read(spa, dnode, 0, zap_scratch, size);
199767f8919635c4928607450d9e0abb932109ceToomas Soomezfs_rlookup(const spa_t *spa, uint64_t objnum, char *result)
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t dir_obj, parent_obj, child_dir_zapobj;
199767f8919635c4928607450d9e0abb932109ceToomas Soome dnode_phys_t child_dir_zap, dataset, dir, parent;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (objset_get_dnode(spa, &spa->spa_mos, objnum, &dataset)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: can't find dataset %ju\n", (uintmax_t)objnum);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (objset_get_dnode(spa, &spa->spa_mos, dir_obj, &dir) != 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Actual loop condition. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (objset_get_dnode(spa, &spa->spa_mos, parent_obj, &parent) != 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (objset_get_dnode(spa, &spa->spa_mos, child_dir_zapobj, &child_dir_zap) != 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (zap_rlookup(spa, &child_dir_zap, component, dir_obj) != 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Actual loop iteration. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (*p != '\0')
199767f8919635c4928607450d9e0abb932109ceToomas Soomezfs_lookup_dataset(const spa_t *spa, const char *name, uint64_t *objnum)
199767f8919635c4928607450d9e0abb932109ceToomas Soome const char *p, *q;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (objset_get_dnode(spa, &spa->spa_mos, DMU_POOL_DIRECTORY_OBJECT, &dir))
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (zap_lookup(spa, &dir, DMU_POOL_ROOT_DATASET, &dir_obj))
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (objset_get_dnode(spa, &spa->spa_mos, dir_obj, &dir))
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (*p == '/')
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Actual loop condition #1. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (*p == '\0')
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (objset_get_dnode(spa, &spa->spa_mos, child_dir_zapobj, &child_dir_zap) != 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Actual loop condition #2. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (zap_lookup(spa, &child_dir_zap, element, &dir_obj) != 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#pragma GCC diagnostic ignored "-Wstrict-aliasing"
199767f8919635c4928607450d9e0abb932109ceToomas Soomezfs_list_dataset(const spa_t *spa, uint64_t objnum/*, int pos, char *entry*/)
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (objset_get_dnode(spa, &spa->spa_mos, objnum, &dataset)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: can't find dataset %ju\n", (uintmax_t)objnum);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (objset_get_dnode(spa, &spa->spa_mos, dir_obj, &dir)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: can't find dirobj %ju\n", (uintmax_t)dir_obj);
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (objset_get_dnode(spa, &spa->spa_mos, child_dir_zapobj, &child_dir_zap) != 0) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: can't find child zap %ju\n", (uintmax_t)dir_obj);
199767f8919635c4928607450d9e0abb932109ceToomas Soomezfs_callback_dataset(const spa_t *spa, uint64_t objnum, int (*callback)(const char *, uint64_t))
199767f8919635c4928607450d9e0abb932109ceToomas Soome err = objset_get_dnode(spa, &spa->spa_mos, objnum, &dataset);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: can't find dataset %ju\n", (uintmax_t)objnum);
199767f8919635c4928607450d9e0abb932109ceToomas Soome err = objset_get_dnode(spa, &spa->spa_mos, dir_obj, &dir);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: can't find dirobj %ju\n", (uintmax_t)dir_obj);
199767f8919635c4928607450d9e0abb932109ceToomas Soome err = objset_get_dnode(spa, &spa->spa_mos, child_dir_zapobj, &child_dir_zap);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: can't find child zap %ju\n", (uintmax_t)dir_obj);
199767f8919635c4928607450d9e0abb932109ceToomas Soome err = dnode_read(spa, &child_dir_zap, 0, zap_scratch, child_dir_zap.dn_datablkszsec * 512);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return fzap_list(spa, &child_dir_zap, callback);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Find the object set given the object number of its dataset object
199767f8919635c4928607450d9e0abb932109ceToomas Soome * and return its details in *objset
199767f8919635c4928607450d9e0abb932109ceToomas Soomezfs_mount_dataset(const spa_t *spa, uint64_t objnum, objset_phys_t *objset)
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (objset_get_dnode(spa, &spa->spa_mos, objnum, &dataset)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: can't find dataset %ju\n", (uintmax_t)objnum);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: can't read object set for dataset %ju\n",
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Find the object set pointed to by the BOOTFS property or the root
199767f8919635c4928607450d9e0abb932109ceToomas Soome * dataset if there is none and return its details in *objset
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Start with the MOS directory object.
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (objset_get_dnode(spa, &spa->spa_mos, DMU_POOL_DIRECTORY_OBJECT, &dir)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: can't read MOS object directory\n");
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Lookup the pool_props and see if we can find a bootfs.
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (zap_lookup(spa, &dir, DMU_POOL_PROPS, &props) == 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome && objset_get_dnode(spa, &spa->spa_mos, props, &propdir) == 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome && zap_lookup(spa, &propdir, "bootfs", &bootfs) == 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Lookup the root dataset directory
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (zap_lookup(spa, &dir, DMU_POOL_ROOT_DATASET, &root)
199767f8919635c4928607450d9e0abb932109ceToomas Soome || objset_get_dnode(spa, &spa->spa_mos, root, &dir)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Use the information from the dataset directory's bonus buffer
199767f8919635c4928607450d9e0abb932109ceToomas Soome * to find the dataset object and from that the object set itself.
199767f8919635c4928607450d9e0abb932109ceToomas Soome dsl_dir_phys_t *dd = (dsl_dir_phys_t *) &dir.dn_bonus;
199767f8919635c4928607450d9e0abb932109ceToomas Soomezfs_mount(const spa_t *spa, uint64_t rootobj, struct zfsmount *mnt)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Find the root object set if not explicitly provided
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (rootobj == 0 && zfs_get_root(spa, &rootobj)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (zfs_mount_dataset(spa, rootobj, &mnt->objset)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome * callback function for feature name checks.
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (i = 0; features_for_read[i] != NULL; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: unsupported feature: %s\n", name);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Checks whether the MOS features that are active are supported.
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((rc = objset_get_dnode(spa, &spa->spa_mos, DMU_OT_OBJECT_DIRECTORY,
5e069aaf824cc0abc9835809924db4929507ee32Toomas Soome if ((rc = zap_lookup(spa, &dir, DMU_POOL_FEATURES_FOR_READ,
5e069aaf824cc0abc9835809924db4929507ee32Toomas Soome * It is older pool without features. As we have already
5e069aaf824cc0abc9835809924db4929507ee32Toomas Soome * tested the label, just return without raising the error.
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((rc = objset_get_dnode(spa, &spa->spa_mos, objnum, &dir)) != 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (dnode_read(spa, &dir, 0, zap_scratch, size))
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (zio_read(spa, &spa->spa_uberblock.ub_rootbp, &spa->spa_mos)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: can't read MOS of pool %s\n", spa->spa_name);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: corrupted MOS of pool %s\n", spa->spa_name);
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: pool %s is not supported\n", spa->spa_name);
199767f8919635c4928607450d9e0abb932109ceToomas Soomezfs_dnode_stat(const spa_t *spa, dnode_phys_t *dn, struct stat *sb)
199767f8919635c4928607450d9e0abb932109ceToomas Soome znode_phys_t *zp = (znode_phys_t *)dn->dn_bonus;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if ((dn->dn_flags & DNODE_FLAG_SPILL_BLKPTR) != 0) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome sb->st_mode = *(uint64_t *)((char *)sahdrp + hdrsize +
199767f8919635c4928607450d9e0abb932109ceToomas Soome sb->st_uid = *(uint64_t *)((char *)sahdrp + hdrsize +
199767f8919635c4928607450d9e0abb932109ceToomas Soome sb->st_gid = *(uint64_t *)((char *)sahdrp + hdrsize +
199767f8919635c4928607450d9e0abb932109ceToomas Soome sb->st_size = *(uint64_t *)((char *)sahdrp + hdrsize +
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Lookup a file and return its dnode.
199767f8919635c4928607450d9e0abb932109ceToomas Soomezfs_lookup(const struct zfsmount *mnt, const char *upath, dnode_phys_t *dnode)
199767f8919635c4928607450d9e0abb932109ceToomas Soome const char *p, *q;
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("ZFS: unexpected object set type %ju\n",
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Get the root directory dnode.
199767f8919635c4928607450d9e0abb932109ceToomas Soome rc = objset_get_dnode(spa, &mnt->objset, MASTER_NODE_OBJ, &dn);
199767f8919635c4928607450d9e0abb932109ceToomas Soome rc = zap_lookup(spa, &dn, ZFS_ROOT_OBJ, &rootnum);
199767f8919635c4928607450d9e0abb932109ceToomas Soome rc = objset_get_dnode(spa, &mnt->objset, rootnum, &dn);
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (p && *p) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome while (*p == '/')
199767f8919635c4928607450d9e0abb932109ceToomas Soome rc = objset_get_dnode(spa, &mnt->objset, objnum, &dn);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Check for symlink.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Read the link value and copy the tail of our
199767f8919635c4928607450d9e0abb932109ceToomas Soome * current path onto the end.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Second test is purely to silence bogus compiler
199767f8919635c4928607450d9e0abb932109ceToomas Soome * warning about accessing past the end of dn_bonus.
199767f8919635c4928607450d9e0abb932109ceToomas Soome memcpy(path, &dn.dn_bonus[sizeof(znode_phys_t)],
199767f8919635c4928607450d9e0abb932109ceToomas Soome rc = dnode_read(spa, &dn, 0, path, sb.st_size);
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Restart with the new path, starting either at
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the root or at the parent depending whether or
199767f8919635c4928607450d9e0abb932109ceToomas Soome * not the link is relative.
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (*p == '/')