From owner-svn-src-head@freebsd.org Mon Dec 23 05:43:02 2019 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 73D261E62DA; Mon, 23 Dec 2019 05:43:02 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47h7YL2BtVz4GP3; Mon, 23 Dec 2019 05:43:02 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 46B49B423; Mon, 23 Dec 2019 05:43:02 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xBN5h2kP003870; Mon, 23 Dec 2019 05:43:02 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xBN5h1iO003866; Mon, 23 Dec 2019 05:43:01 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201912230543.xBN5h1iO003866@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: Conrad Meyer Date: Mon, 23 Dec 2019 05:43:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r356033 - head/usr.sbin/fstyp X-SVN-Group: head X-SVN-Commit-Author: cem X-SVN-Commit-Paths: head/usr.sbin/fstyp X-SVN-Commit-Revision: 356033 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Dec 2019 05:43:02 -0000 Author: cem Date: Mon Dec 23 05:43:01 2019 New Revision: 356033 URL: https://svnweb.freebsd.org/changeset/base/356033 Log: fstyp(8): Detect HFS+ / HFSX volumes Added: head/usr.sbin/fstyp/hfsplus.c (contents, props changed) Modified: head/usr.sbin/fstyp/Makefile head/usr.sbin/fstyp/fstyp.c head/usr.sbin/fstyp/fstyp.h Modified: head/usr.sbin/fstyp/Makefile ============================================================================== --- head/usr.sbin/fstyp/Makefile Mon Dec 23 02:41:13 2019 (r356032) +++ head/usr.sbin/fstyp/Makefile Mon Dec 23 05:43:01 2019 (r356033) @@ -3,7 +3,7 @@ .include PROG= fstyp -SRCS= cd9660.c exfat.c ext2fs.c fstyp.c geli.c msdosfs.c ntfs.c ufs.c +SRCS= cd9660.c exfat.c ext2fs.c fstyp.c geli.c hfsplus.c msdosfs.c ntfs.c ufs.c .if ${MK_ZFS} != "no" SRCS += zfs.c Modified: head/usr.sbin/fstyp/fstyp.c ============================================================================== --- head/usr.sbin/fstyp/fstyp.c Mon Dec 23 02:41:13 2019 (r356032) +++ head/usr.sbin/fstyp/fstyp.c Mon Dec 23 05:43:01 2019 (r356033) @@ -66,6 +66,7 @@ static struct { { "exfat", &fstyp_exfat, false, EXFAT_ENC }, { "ext2fs", &fstyp_ext2fs, false, NULL }, { "geli", &fstyp_geli, true, NULL }, + { "hfs+", &fstyp_hfsp, false, NULL }, { "msdosfs", &fstyp_msdosfs, false, NULL }, { "ntfs", &fstyp_ntfs, false, NTFS_ENC }, { "ufs", &fstyp_ufs, false, NULL }, Modified: head/usr.sbin/fstyp/fstyp.h ============================================================================== --- head/usr.sbin/fstyp/fstyp.h Mon Dec 23 02:41:13 2019 (r356032) +++ head/usr.sbin/fstyp/fstyp.h Mon Dec 23 05:43:01 2019 (r356033) @@ -54,6 +54,7 @@ int fstyp_cd9660(FILE *fp, char *label, size_t size); int fstyp_exfat(FILE *fp, char *label, size_t size); int fstyp_ext2fs(FILE *fp, char *label, size_t size); int fstyp_geli(FILE *fp, char *label, size_t size); +int fstyp_hfsp(FILE *fp, char *label, size_t size); int fstyp_msdosfs(FILE *fp, char *label, size_t size); int fstyp_ntfs(FILE *fp, char *label, size_t size); int fstyp_ufs(FILE *fp, char *label, size_t size); Added: head/usr.sbin/fstyp/hfsplus.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.sbin/fstyp/hfsplus.c Mon Dec 23 05:43:01 2019 (r356033) @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2019 Conrad Meyer . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "fstyp.h" + +/* + * https://developer.apple.com/library/archive/technotes/tn/tn1150.html + */ + +#define VOL_HDR_OFF 1024 + +typedef uint32_t hfsp_cat_nodeid; + +typedef struct hfsp_ext_desc { + uint32_t ex_startBlock; + uint32_t ex_blockCount; +} hfsp_ext_desc; + +typedef struct hfsp_fork_data { + uint64_t fd_logicalSz; + uint32_t fd_clumpSz; + uint32_t fd_totalBlocks; + hfsp_ext_desc fd_extents[8]; +} hfsp_fork_data; + +struct hfsp_vol_hdr { + char hp_signature[2]; + uint16_t hp_version; + uint32_t hp_attributes; + uint32_t hp_lastMounted; + uint32_t hp_journalInfoBlock; + + /* Creation / etc dates. */ + uint32_t hp_create; + uint32_t hp_modify; + uint32_t hp_backup; + uint32_t hp_checked; + + /* Stats */ + uint32_t hp_files; + uint32_t hp_folders; + + /* Parameters */ + uint32_t hp_blockSize; + uint32_t hp_totalBlocks; + uint32_t hp_freeBlocks; + + uint32_t hp_nextAlloc; + uint32_t hp_rsrcClumpSz; + uint32_t hp_dataClumpSz; + + hfsp_cat_nodeid hp_nextCatID; + + uint32_t hp_writeCount; + uint64_t hp_encodingsBM; + + uint32_t hp_finderInfo[8]; + + hfsp_fork_data hp_allocationFile; + hfsp_fork_data hp_extentsFile; + hfsp_fork_data hp_catalogFile; + hfsp_fork_data hp_attributesFile; + hfsp_fork_data hp_startupFile; +}; +_Static_assert(sizeof(struct hfsp_vol_hdr) == 512, ""); + +int +fstyp_hfsp(FILE *fp, char *label, size_t size) +{ + struct hfsp_vol_hdr *hdr; + int retval; + + retval = 1; + hdr = read_buf(fp, VOL_HDR_OFF, sizeof(*hdr)); + if (hdr == NULL) + goto fail; + + if ((strncmp(hdr->hp_signature, "H+", 2) != 0 || hdr->hp_version != 4) + && + (strncmp(hdr->hp_signature, "HX", 2) != 0 || hdr->hp_version != 5)) + goto fail; + + /* This is an HFS+ volume. */ + retval = 0; + + /* No label support yet. */ + +fail: + free(hdr); + return (retval); +}