1284589Sallanjude/*- 2284589Sallanjude * Copyright (c) 2015 Allan Jude <allanjude@FreeBSD.org> 3293776Sallanjude * 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> 32293776Sallanjude#include <cddl/compat/opensolaris/sys/types.h> 33293776Sallanjude#include <sys/time.h> 34293776Sallanjude#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{ 49293776Sallanjude vdev_label_t *vdev_label = NULL; 50293776Sallanjude vdev_phys_t *vdev_phys; 51284589Sallanjude char *zpool_name = NULL; 52284589Sallanjude nvlist_t *config = NULL; 53293776Sallanjude int err = 0; 54284589Sallanjude 55293776Sallanjude /* 56293776Sallanjude * Read in the first ZFS vdev label ("L0"), located at the beginning 57293776Sallanjude * of the vdev and extract the pool name from it. 58293776Sallanjude * 59293776Sallanjude * TODO: the checksum of label should be validated. 60293776Sallanjude */ 61293776Sallanjude vdev_label = (vdev_label_t *)read_buf(fp, 0, sizeof(*vdev_label)); 62293776Sallanjude if (vdev_label == NULL) 63284589Sallanjude return (1); 64284589Sallanjude 65293776Sallanjude vdev_phys = &(vdev_label->vl_vdev_phys); 66293776Sallanjude 67293776Sallanjude if ((nvlist_unpack(vdev_phys->vp_nvlist, sizeof(vdev_phys->vp_nvlist), 68293776Sallanjude &config, 0)) == 0 && 69293776Sallanjude (nvlist_lookup_string(config, "name", &zpool_name) == 0)) { 70293776Sallanjude strlcpy(label, zpool_name, labelsize); 71293776Sallanjude } else 72293776Sallanjude err = 1; 73293776Sallanjude 74284589Sallanjude nvlist_free(config); 75293776Sallanjude free(vdev_label); 76284589Sallanjude 77293776Sallanjude return (err); 78284589Sallanjude} 79