1*0e92585cSPiotr Pawel Stefaniak /*- 2*0e92585cSPiotr Pawel Stefaniak * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3*0e92585cSPiotr Pawel Stefaniak * 4*0e92585cSPiotr Pawel Stefaniak * Copyright (c) 2021 Miguel Gocobachi 5*0e92585cSPiotr Pawel Stefaniak * 6*0e92585cSPiotr Pawel Stefaniak * Redistribution and use in source and binary forms, with or without 7*0e92585cSPiotr Pawel Stefaniak * modification, are permitted provided that the following conditions 8*0e92585cSPiotr Pawel Stefaniak * are met: 9*0e92585cSPiotr Pawel Stefaniak * 10*0e92585cSPiotr Pawel Stefaniak * 1. Redistributions of source code must retain the above copyright 11*0e92585cSPiotr Pawel Stefaniak * notice, this list of conditions and the following disclaimer. 12*0e92585cSPiotr Pawel Stefaniak * 2. Redistributions in binary form must reproduce the above copyright 13*0e92585cSPiotr Pawel Stefaniak * notice, this list of conditions and the following disclaimer in the 14*0e92585cSPiotr Pawel Stefaniak * documentation and/or other materials provided with the distribution. 15*0e92585cSPiotr Pawel Stefaniak * 16*0e92585cSPiotr Pawel Stefaniak * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17*0e92585cSPiotr Pawel Stefaniak * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*0e92585cSPiotr Pawel Stefaniak * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*0e92585cSPiotr Pawel Stefaniak * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20*0e92585cSPiotr Pawel Stefaniak * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*0e92585cSPiotr Pawel Stefaniak * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*0e92585cSPiotr Pawel Stefaniak * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*0e92585cSPiotr Pawel Stefaniak * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*0e92585cSPiotr Pawel Stefaniak * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*0e92585cSPiotr Pawel Stefaniak * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*0e92585cSPiotr Pawel Stefaniak * SUCH DAMAGE. 27*0e92585cSPiotr Pawel Stefaniak * 28*0e92585cSPiotr Pawel Stefaniak */ 29*0e92585cSPiotr Pawel Stefaniak 30*0e92585cSPiotr Pawel Stefaniak #include <sys/cdefs.h> 31*0e92585cSPiotr Pawel Stefaniak __FBSDID("$FreeBSD$"); 32*0e92585cSPiotr Pawel Stefaniak 33*0e92585cSPiotr Pawel Stefaniak #include <stdint.h> 34*0e92585cSPiotr Pawel Stefaniak #include <stdio.h> 35*0e92585cSPiotr Pawel Stefaniak #include <stdlib.h> 36*0e92585cSPiotr Pawel Stefaniak #include <string.h> 37*0e92585cSPiotr Pawel Stefaniak 38*0e92585cSPiotr Pawel Stefaniak #include "fstyp.h" 39*0e92585cSPiotr Pawel Stefaniak 40*0e92585cSPiotr Pawel Stefaniak #define B_OS_NAME_LENGTH 32 41*0e92585cSPiotr Pawel Stefaniak #define BEFS_BLOCK_OFFSET 512 42*0e92585cSPiotr Pawel Stefaniak #define BEFS_SUPER_BLOCK_MAGIC1 0x42465331 43*0e92585cSPiotr Pawel Stefaniak 44*0e92585cSPiotr Pawel Stefaniak struct disk_super_block { 45*0e92585cSPiotr Pawel Stefaniak char name[B_OS_NAME_LENGTH]; 46*0e92585cSPiotr Pawel Stefaniak int32_t magic1; 47*0e92585cSPiotr Pawel Stefaniak }; 48*0e92585cSPiotr Pawel Stefaniak 49*0e92585cSPiotr Pawel Stefaniak int 50*0e92585cSPiotr Pawel Stefaniak fstyp_befs(FILE *fp, char *label, size_t size) 51*0e92585cSPiotr Pawel Stefaniak { 52*0e92585cSPiotr Pawel Stefaniak struct disk_super_block *volume; 53*0e92585cSPiotr Pawel Stefaniak 54*0e92585cSPiotr Pawel Stefaniak volume = read_buf(fp, BEFS_BLOCK_OFFSET, sizeof(*volume)); 55*0e92585cSPiotr Pawel Stefaniak 56*0e92585cSPiotr Pawel Stefaniak if (volume == NULL) { 57*0e92585cSPiotr Pawel Stefaniak return (1); 58*0e92585cSPiotr Pawel Stefaniak } 59*0e92585cSPiotr Pawel Stefaniak 60*0e92585cSPiotr Pawel Stefaniak if (volume->magic1 == BEFS_SUPER_BLOCK_MAGIC1) { 61*0e92585cSPiotr Pawel Stefaniak strlcpy(label, volume->name, size); 62*0e92585cSPiotr Pawel Stefaniak free(volume); 63*0e92585cSPiotr Pawel Stefaniak 64*0e92585cSPiotr Pawel Stefaniak return (0); 65*0e92585cSPiotr Pawel Stefaniak } 66*0e92585cSPiotr Pawel Stefaniak 67*0e92585cSPiotr Pawel Stefaniak free(volume); 68*0e92585cSPiotr Pawel Stefaniak 69*0e92585cSPiotr Pawel Stefaniak return (1); 70*0e92585cSPiotr Pawel Stefaniak } 71