1/* 2 * Copyright (c) 1999-2014 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24#include <CoreFoundation/CFBase.h> 25 26/* 27 * Mac OS Finder flags 28 */ 29enum { 30 kHasBeenInited = 0x0100, /* Files only */ 31 /* Clear if the file contains desktop database */ 32 /* bit 0x0200 was the letter bit for AOCE, but is now reserved for future use */ 33 kHasCustomIcon = 0x0400, /* Files and folders */ 34 kIsStationery = 0x0800, /* Files only */ 35 kNameLocked = 0x1000, /* Files and folders */ 36 kHasBundle = 0x2000, /* Files only */ 37 kIsInvisible = 0x4000, /* Files and folders */ 38 kIsAlias = 0x8000 /* Files only */ 39}; 40 41 42/* Finder types (mostly opaque in our usage) */ 43struct FInfo { 44 uint32_t fileType; /* The type of the file */ 45 uint32_t fileCreator; /* The file's creator */ 46 UInt16 finderFlags; /* ex: kHasBundle, kIsInvisible... */ 47 UInt8 opaque[6]; /* If set to {0, 0}, the Finder will place the item automatically */ 48}; 49typedef struct FInfo FInfo; 50 51struct FXInfo { 52 UInt8 opaque[16]; 53}; 54typedef struct FXInfo FXInfo; 55 56struct DInfo { 57 UInt8 opaque[16]; 58}; 59typedef struct DInfo DInfo; 60 61struct DXInfo { 62 UInt8 opaque[16]; 63}; 64typedef struct DXInfo DXInfo; 65 66 67enum { 68 kMinHFSPlusVolumeSize = (512 * 1024), 69 70 kBytesPerSector = 512, 71 kBitsPerSector = 4096, 72 kBTreeHeaderUserBytes = 128, 73 kLog2SectorSize = 9, 74 kHFSNodeSize = 512, 75 kHFSMaxAllocationBlks = 65536, 76 77 kHFSPlusDataClumpFactor = 16, 78 kHFSPlusRsrcClumpFactor = 16, 79 80 kWriteSeqNum = 2, 81 kHeaderBlocks = 3, 82 kTailBlocks = 2, 83 kMDBStart = 2, 84 kVolBitMapStart = kHeaderBlocks, 85 86 /* Desktop DB, Desktop DF, Finder, System, ReadMe */ 87 kWapperFileCount = 5, 88 /* Maximum wrapper size is 32MB */ 89 kMaxWrapperSize = 1024 * 1024 * 32, 90 /* Maximum volume that can be wrapped is 256GB */ 91 kMaxWrapableSectors = (kMaxWrapperSize/8) * (65536/512) 92}; 93 94/* B-tree key descriptor */ 95#define KD_SKIP 0 96#define KD_BYTE 1 97#define KD_SIGNBYTE 2 98#define KD_STRING 3 99#define KD_WORD 4 100#define KD_SIGNWORD 5 101#define KD_LONG 6 102#define KD_SIGNLONG 7 103#define KD_FIXLENSTR 8 104#define KD_DTDBSTR 9 105#define KD_USEPROC 10 106 107 108enum { 109 kTextEncodingMacRoman = 0L, 110 kTextEncodingMacJapanese = 1 111}; 112 113 114/* 115 * The following constant sets the default block size. 116 * This constant must be a power of 2 and meet the following constraints: 117 * MINBSIZE <= DFL_BLKSIZE <= MAXBSIZE 118 * sectorsize <= DFL_BLKSIZE 119 */ 120#define HFSOPTIMALBLKSIZE 4096 121#define HFSMINBSIZE 512 122#define HFSMAXBSIZE 2147483648U 123#define DFL_BLKSIZE HFSOPTIMALBLKSIZE 124 125 126#define kDTDF_FileID 16 127#define kDTDF_Name "Desktop DF" 128#define kDTDF_Chars 10 129#define kDTDF_Type 'DTFL' 130#define kDTDF_Creator 'DMGR' 131 132#define kDTDB_FileID 17 133#define kDTDB_Name "Desktop DB" 134#define kDTDB_Chars 10 135#define kDTDB_Type 'BTFL' 136#define kDTDB_Creator 'DMGR' 137#define kDTDB_Size 1024 138 139#define kReadMe_FileID 18 140#define kReadMe_Name "ReadMe" 141#define kReadMe_Chars 6 142#define kReadMe_Type 'ttro' 143#define kReadMe_Creator 'ttxt' 144 145#define kFinder_FileID 19 146#define kFinder_Name "Finder" 147#define kFinder_Chars 6 148#define kFinder_Type 'FNDR' 149#define kFinder_Creator 'MACS' 150 151#define kSystem_FileID 20 152#define kSystem_Name "System" 153#define kSystem_Chars 6 154#define kSystem_Type 'zsys' 155#define kSystem_Creator 'MACS' 156 157 158 159#if !defined(FALSE) && !defined(TRUE) 160enum { 161 FALSE = 0, 162 TRUE = 1 163}; 164#endif 165 166 167#define kDefaultVolumeNameStr "untitled" 168 169/* 170 * This is the straight GMT conversion constant: 171 * 172 * 00:00:00 January 1, 1970 - 00:00:00 January 1, 1904 173 * (3600 * 24 * ((365 * (1970 - 1904)) + (((1970 - 1904) / 4) + 1))) 174 */ 175#define MAC_GMT_FACTOR 2082844800UL 176 177/* 178 * Maximum number of bytes in an HFS+ filename. 179 * It's 255 characters; a UTF16 character may translate 180 * to 3 bytes. Plus one for NUL. 181 */ 182 183#define kHFSPlusMaxFileNameBytes (3 * 255 + 1) 184 185/* sectorSize = kBytesPerSector = 512 186 sectorOffset and totalSectors are in terms of 512-byte sector size. 187*/ 188struct DriveInfo { 189 int fd; 190 uint32_t sectorSize; 191 uint32_t sectorOffset; 192 uint64_t totalSectors; 193 194 /* actual device info. physSectorSize is necessary to de-block 195 * while using the raw device. 196 */ 197 uint32_t physSectorSize; 198 uint64_t physSectorsPerIO; 199 uint64_t physTotalSectors; 200}; 201typedef struct DriveInfo DriveInfo; 202 203enum { 204 kMakeHFSWrapper = 0x01, 205 kMakeMaxHFSBitmap = 0x02, 206 kMakeStandardHFS = 0x04, 207 kMakeCaseSensitive = 0x08, 208 kUseAccessPerms = 0x10, 209 kMakeContentProtect= 0x20, 210}; 211 212 213struct hfsparams { 214 uint32_t flags; /* kMakeHFSWrapper, ... */ 215 uint32_t blockSize; 216 uint32_t rsrcClumpSize; 217 uint32_t dataClumpSize; 218 uint32_t nextFreeFileID; 219 220 uint32_t catalogClumpSize; 221 uint32_t catalogNodeSize; 222 uint32_t catalogExtsCount; 223 uint32_t catalogStartBlock; 224 225 uint32_t extentsClumpSize; 226 uint32_t extentsNodeSize; 227 uint32_t extentsExtsCount; 228 uint32_t extentsStartBlock; 229 230 uint32_t attributesClumpSize; 231 uint32_t attributesNodeSize; 232 uint32_t attributesExtsCount; 233 uint32_t attributesStartBlock; 234 235 uint32_t allocationClumpSize; 236 uint32_t allocationExtsCount; 237 uint32_t allocationStartBlock; 238 239 uint32_t createDate; /* in UTC */ 240 uint32_t hfsAlignment; 241 unsigned char *volumeName; /* In UTF8, but we need to allocate space for it. */ 242 uint32_t encodingHint; 243 uint32_t journaledHFS; 244 uint32_t journalSize; 245 uint32_t journalInfoBlock; 246 uint32_t journalBlock; 247 char *journalDevice; 248 uid_t owner; 249 gid_t group; 250 mode_t mask; 251#ifdef DEBUG_BUILD 252 uint16_t protectlevel; 253#endif 254 uint32_t fsStartBlock; /* allocation block offset where the btree allocaiton should start */ 255 uint32_t nextAllocBlock; /* Set VH nextAllocationBlock */ 256}; 257typedef struct hfsparams hfsparams_t; 258 259extern int make_hfsplus(const DriveInfo *driveInfo, hfsparams_t *defaults); 260 261 262#if __STDC__ 263void fatal(const char *fmt, ...); 264#else 265void fatal(); 266#endif 267