1284589Sallanjude/*- 2284589Sallanjude * Copyright (c) 2015 Allan Jude <allanjude@FreeBSD.org> 3287937Sdelphij * Copyright (c) 2015 Xin LI <delphij@FreeBSD.org> 4284589Sallanjude * All rights reserved. 5284589Sallanjude * 6284589Sallanjude * Redistribution and use in source and binary forms, with or without 7284589Sallanjude * modification, are permitted provided that the following conditions 8284589Sallanjude * are met: 9284589Sallanjude * 1. Redistributions of source code must retain the above copyright 10284589Sallanjude * notice, this list of conditions and the following disclaimer. 11284589Sallanjude * 2. Redistributions in binary form must reproduce the above copyright 12284589Sallanjude * notice, this list of conditions and the following disclaimer in the 13284589Sallanjude * documentation and/or other materials provided with the distribution. 14284589Sallanjude * 15284589Sallanjude * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 16284589Sallanjude * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17284589Sallanjude * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18284589Sallanjude * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 19284589Sallanjude * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20284589Sallanjude * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21284589Sallanjude * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22284589Sallanjude * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23284589Sallanjude * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24284589Sallanjude * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25284589Sallanjude * SUCH DAMAGE. 26284589Sallanjude */ 27284589Sallanjude 28284589Sallanjude#include <sys/cdefs.h> 29284589Sallanjude__FBSDID("$FreeBSD$"); 30284589Sallanjude 31284589Sallanjude#include <sys/types.h> 32292757Sallanjude#include <cddl/compat/opensolaris/sys/types.h> 33292757Sallanjude#include <sys/time.h> 34292757Sallanjude#include <cddl/compat/opensolaris/sys/time.h> 35284589Sallanjude#include <stdint.h> 36284589Sallanjude#include <stdio.h> 37284589Sallanjude#include <stdlib.h> 38284589Sallanjude#include <string.h> 39284589Sallanjude#include <unistd.h> 40284589Sallanjude 41284589Sallanjude#include <libnvpair.h> 42284589Sallanjude#include <sys/vdev_impl.h> 43284589Sallanjude 44284589Sallanjude#include "fstyp.h" 45284589Sallanjude 46284589Sallanjudeint 47284589Sallanjudefstyp_zfs(FILE *fp, char *label, size_t labelsize) 48284589Sallanjude{ 49287937Sdelphij vdev_label_t *vdev_label = NULL; 50287937Sdelphij vdev_phys_t *vdev_phys; 51284589Sallanjude char *zpool_name = NULL; 52284589Sallanjude nvlist_t *config = NULL; 53287937Sdelphij int err = 0; 54284589Sallanjude 55287937Sdelphij /* 56287937Sdelphij * Read in the first ZFS vdev label ("L0"), located at the beginning 57287937Sdelphij * of the vdev and extract the pool name from it. 58287937Sdelphij * 59287937Sdelphij * TODO: the checksum of label should be validated. 60287937Sdelphij */ 61287937Sdelphij vdev_label = (vdev_label_t *)read_buf(fp, 0, sizeof(*vdev_label)); 62287937Sdelphij if (vdev_label == NULL) 63284589Sallanjude return (1); 64284589Sallanjude 65287937Sdelphij vdev_phys = &(vdev_label->vl_vdev_phys); 66287937Sdelphij 67287937Sdelphij if ((nvlist_unpack(vdev_phys->vp_nvlist, sizeof(vdev_phys->vp_nvlist), 68287937Sdelphij &config, 0)) == 0 && 69287937Sdelphij (nvlist_lookup_string(config, "name", &zpool_name) == 0)) { 70287937Sdelphij strlcpy(label, zpool_name, labelsize); 71287937Sdelphij } else 72287937Sdelphij err = 1; 73287937Sdelphij 74284589Sallanjude nvlist_free(config); 75287937Sdelphij free(vdev_label); 76284589Sallanjude 77287937Sdelphij return (err); 78284589Sallanjude} 79