[48674] | 1 | /* $Id: fsw_hfs.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * fsw_hfs.h - HFS file system driver header.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2010-2023 Oracle and/or its affiliates.
|
---|
[48674] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
[48674] | 11 | *
|
---|
[96407] | 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
[48674] | 25 | * The contents of this file may alternatively be used under the terms
|
---|
| 26 | * of the Common Development and Distribution License Version 1.0
|
---|
[96407] | 27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
| 28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
[48674] | 29 | * CDDL are applicable instead of those of the GPL.
|
---|
| 30 | *
|
---|
| 31 | * You may elect to license modified versions of this file under the
|
---|
| 32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
[96407] | 33 | *
|
---|
| 34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
[48674] | 35 | */
|
---|
| 36 |
|
---|
| 37 | #ifndef _FSW_HFS_H_
|
---|
| 38 | #define _FSW_HFS_H_
|
---|
| 39 |
|
---|
| 40 | #define VOLSTRUCTNAME fsw_hfs_volume
|
---|
| 41 | #define DNODESTRUCTNAME fsw_hfs_dnode
|
---|
| 42 |
|
---|
| 43 | #include "fsw_core.h"
|
---|
| 44 |
|
---|
| 45 | #define IN_RING0
|
---|
| 46 | #if !defined(ARCH_BITS) || !defined(HC_ARCH_BITS)
|
---|
| 47 | # error "please add right bitness"
|
---|
| 48 | #endif
|
---|
| 49 | #include "iprt/formats/hfs.h"
|
---|
| 50 | #include "iprt/asm.h" /* endian conversion */
|
---|
| 51 |
|
---|
[82381] | 52 | #ifndef HOST_POSIX
|
---|
[81717] | 53 | #include <Library/BaseLib.h>
|
---|
[82381] | 54 | #endif
|
---|
[48674] | 55 |
|
---|
| 56 | //! Block size for HFS volumes.
|
---|
| 57 | #define HFS_BLOCKSIZE 512
|
---|
| 58 |
|
---|
| 59 | //! Block number where the HFS superblock resides.
|
---|
| 60 | #define HFS_SUPERBLOCK_BLOCKNO 2
|
---|
| 61 |
|
---|
| 62 | #ifdef _MSC_VER
|
---|
| 63 | /* vasily: disable warning for non-standard anonymous struct/union
|
---|
| 64 | * declarations
|
---|
| 65 | */
|
---|
| 66 | # pragma warning (disable:4201)
|
---|
| 67 | #endif
|
---|
| 68 |
|
---|
| 69 | struct hfs_dirrec {
|
---|
| 70 | fsw_u8 _dummy;
|
---|
| 71 | };
|
---|
| 72 |
|
---|
| 73 | #pragma pack(1)
|
---|
| 74 | struct fsw_hfs_key
|
---|
| 75 | {
|
---|
| 76 | union
|
---|
| 77 | {
|
---|
| 78 | struct HFSPlusExtentKey ext_key;
|
---|
| 79 | struct HFSPlusCatalogKey cat_key;
|
---|
| 80 | fsw_u16 key_len; /* Length is at the beginning of all keys */
|
---|
| 81 | };
|
---|
| 82 | };
|
---|
| 83 | #pragma pack()
|
---|
| 84 |
|
---|
| 85 | typedef enum {
|
---|
| 86 | /* Regular HFS */
|
---|
| 87 | FSW_HFS_PLAIN = 0,
|
---|
| 88 | /* HFS+ */
|
---|
| 89 | FSW_HFS_PLUS,
|
---|
| 90 | /* HFS+ embedded to HFS */
|
---|
| 91 | FSW_HFS_PLUS_EMB
|
---|
| 92 | } fsw_hfs_kind;
|
---|
| 93 |
|
---|
| 94 | /**
|
---|
| 95 | * HFS: Dnode structure with HFS-specific data.
|
---|
| 96 | */
|
---|
| 97 | struct fsw_hfs_dnode
|
---|
| 98 | {
|
---|
| 99 | struct fsw_dnode g; //!< Generic dnode structure
|
---|
| 100 | HFSPlusExtentRecord extents;
|
---|
| 101 | fsw_u32 ctime;
|
---|
| 102 | fsw_u32 mtime;
|
---|
| 103 | fsw_u64 used_bytes;
|
---|
[59146] | 104 | fsw_u32 node_num;
|
---|
[48674] | 105 | };
|
---|
| 106 |
|
---|
| 107 | /**
|
---|
| 108 | * HFS: In-memory B-tree structure.
|
---|
| 109 | */
|
---|
| 110 | struct fsw_hfs_btree
|
---|
| 111 | {
|
---|
| 112 | fsw_u32 root_node;
|
---|
| 113 | fsw_u32 node_size;
|
---|
| 114 | struct fsw_hfs_dnode* file;
|
---|
| 115 | };
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 | /**
|
---|
| 119 | * HFS: In-memory volume structure with HFS-specific data.
|
---|
| 120 | */
|
---|
| 121 |
|
---|
| 122 | struct fsw_hfs_volume
|
---|
| 123 | {
|
---|
| 124 | struct fsw_volume g; //!< Generic volume structure
|
---|
| 125 |
|
---|
| 126 | struct HFSPlusVolumeHeader *primary_voldesc; //!< Volume Descriptor
|
---|
| 127 | struct fsw_hfs_btree catalog_tree; // Catalog tree
|
---|
| 128 | struct fsw_hfs_btree extents_tree; // Extents overflow tree
|
---|
| 129 | struct fsw_hfs_dnode root_file;
|
---|
| 130 | int case_sensitive;
|
---|
| 131 | fsw_u32 block_size_shift;
|
---|
| 132 | fsw_hfs_kind hfs_kind;
|
---|
| 133 | fsw_u32 emb_block_off;
|
---|
| 134 | };
|
---|
| 135 |
|
---|
| 136 | /* Endianess swappers. */
|
---|
| 137 | DECLINLINE(fsw_u16)
|
---|
| 138 | be16_to_cpu(fsw_u16 x)
|
---|
| 139 | {
|
---|
| 140 | return RT_BE2H_U16(x);
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | DECLINLINE(fsw_u16)
|
---|
| 144 | cpu_to_be16(fsw_u16 x)
|
---|
| 145 | {
|
---|
| 146 | return RT_H2BE_U16(x);
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 |
|
---|
| 150 | DECLINLINE(fsw_u32)
|
---|
| 151 | cpu_to_be32(fsw_u32 x)
|
---|
| 152 | {
|
---|
| 153 | return RT_H2BE_U32(x);
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | DECLINLINE(fsw_u32)
|
---|
| 157 | be32_to_cpu(fsw_u32 x)
|
---|
| 158 | {
|
---|
| 159 | return RT_BE2H_U32(x);
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | DECLINLINE(fsw_u64)
|
---|
| 163 | be64_to_cpu(fsw_u64 x)
|
---|
| 164 | {
|
---|
[81717] | 165 | #ifdef RT_LITTLE_ENDIAN
|
---|
[82381] | 166 | #ifdef HOST_POSIX
|
---|
| 167 | return RT_BE2H_U64(x);
|
---|
| 168 | #else
|
---|
[81717] | 169 | return SwapBytes64(x);
|
---|
[82381] | 170 | #endif
|
---|
[81717] | 171 | #else
|
---|
| 172 | return x;
|
---|
| 173 | #endif
|
---|
[48674] | 174 | }
|
---|
| 175 |
|
---|
| 176 | #endif
|
---|
| 177 |
|
---|