150476Speter/*- 215353Swosch * Copyright (c) 2015 Allan Jude <allanjude@FreeBSD.org> 318566Sbde * All rights reserved. 431859Sbde * 515353Swosch * Redistribution and use in source and binary forms, with or without 615353Swosch * modification, are permitted provided that the following conditions 715353Swosch * are met: 833815Sbde * 1. Redistributions of source code must retain the above copyright 915948Swosch * notice, this list of conditions and the following disclaimer. 1033815Sbde * 2. Redistributions in binary form must reproduce the above copyright 1133815Sbde * notice, this list of conditions and the following disclaimer in the 12139761Skrion * documentation and/or other materials provided with the distribution. 1399202Sru * 1499202Sru * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 1518566Sbde * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1615353Swosch * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1718566Sbde * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 1818566Sbde * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1918566Sbde * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2099202Sru * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2199202Sru * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2218566Sbde * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2318566Sbde * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2418340Sswallace * SUCH DAMAGE. 2515948Swosch */ 26139103Sru 2718566Sbde#include <sys/cdefs.h> 2815353Swosch#include <sys/disk.h> 2915353Swosch#include <sys/types.h> 3015353Swosch#include <stdio.h> 3115353Swosch#include <stdlib.h> 3233815Sbde#include <string.h> 3315353Swosch 3415353Swosch#include <geom/eli/g_eli.h> 3516663Sjkh 3615353Swosch#include "fstyp.h" 3715353Swosch 3816663Sjkhint 3915353Swoschfstyp_geli(FILE *fp, char *label __unused, size_t labelsize __unused) 4014801Swosch{ 4194940Sru int error; 4294940Sru off_t mediasize; 4394940Sru u_int sectorsize; 4494940Sru struct g_eli_metadata md; 4564784Ssheldonh u_char *buf; 4618340Sswallace 4718340Sswallace error = ioctl(fileno(fp), DIOCGMEDIASIZE, &mediasize); 4818340Sswallace if (error != 0) 4918340Sswallace return (1); 5014801Swosch error = ioctl(fileno(fp), DIOCGSECTORSIZE, §orsize); 5118340Sswallace if (error != 0) 5276896Sru return (1); 5318340Sswallace buf = (u_char *)read_buf(fp, mediasize - sectorsize, sectorsize); 5476896Sru if (buf == NULL) 5576896Sru goto gelierr; 5676896Sru error = eli_metadata_decode(buf, &md); 5776896Sru if (error) 5876896Sru goto gelierr; 5976896Sru 6076896Sru if (strcmp(md.md_magic, G_ELI_MAGIC) == 0) { 6176896Sru free(buf); 6276896Sru return (0); 6376896Sru } 6476896Sru 6576896Srugelierr: 6676896Sru free(buf); 6718340Sswallace 68139103Sru return (1); 6976896Sru} 7076896Sru