2 * Copyright (c) 1999, 2005-2011 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
30 #include <sys/types.h>
36 #include <hfs/hfs_format.h>
40 #include <MacMemory.h>
41 #include <HFSVolumes.h>
47 /* Classic Mac OS Types */
49 typedef int16_t SInt16
;
50 typedef int32_t SInt32
;
51 typedef int64_t SInt64
;
53 typedef u_int8_t UInt8
;
54 typedef u_int16_t UInt16
;
55 typedef u_int32_t UInt32
;
56 typedef u_int64_t UInt64
;
58 typedef void * LogicalAddress
;
61 typedef u_int8_t Byte
;
63 typedef unsigned char Boolean
;
64 typedef u_int32_t ItemCount
;
65 typedef u_int32_t ByteCount
;
66 typedef u_int32_t OptionBits
;
68 typedef int16_t OSErr
;
69 typedef int32_t OSStatus
;
71 typedef u_int32_t OSType
;
72 typedef u_int32_t ResType
;
74 typedef u_int16_t UniChar
;
75 typedef u_int32_t UniCharCount
;
76 typedef UniChar
* UniCharArrayPtr
;
77 typedef const UniChar
* ConstUniCharArrayPtr
;
78 typedef u_int32_t TextEncoding
;
80 typedef unsigned char * StringPtr
;
81 typedef unsigned char Str27
[28];
82 typedef unsigned char Str31
[32];
83 typedef unsigned char Str63
[64];
84 typedef unsigned char Str255
[256];
86 typedef const unsigned char * ConstStr31Param
;
87 typedef const unsigned char * ConstStr63Param
;
88 typedef const unsigned char * ConstStr255Param
;
90 typedef u_int32_t HFSCatalogNodeID
;
111 fileBoundsErr
= -1309,
119 kHasBeenInited
= 0x0100,
120 kHasCustomIcon
= 0x0400,
121 kIsStationery
= 0x0800,
122 kNameLocked
= 0x1000,
124 kIsInvisible
= 0x4000,
128 #define EXTERN_API(_type) extern _type
129 #define EXTERN_API_C(_type) extern _type
134 DebugStr(ConstStr255Param debuggerMsg
);
136 typedef void * QElemPtr
;
137 typedef void * DrvQElPtr
;
146 kVCBFlagsIdleFlushBit
= 3, /* Set if volume should be flushed at idle time */
147 kVCBFlagsIdleFlushMask
= 0x0008,
148 kVCBFlagsHFSPlusAPIsBit
= 4, /* Set if volume implements HFS Plus APIs itself (not via emu\
150 kVCBFlagsHFSPlusAPIsMask
= 0x0010,
151 kVCBFlagsHardwareGoneBit
= 5, /* Set if disk driver returned a hardwareGoneErr to Read or W\
153 kVCBFlagsHardwareGoneMask
= 0x0020,
154 kVCBFlagsVolumeDirtyBit
= 15, /* Set if volume information has changed since the last Flush\
156 kVCBFlagsVolumeDirtyMask
= 0x8000
160 /* Disk Cache constants */
165 gbDefault
= 0, /* default value - read if not found */
167 gbReadBit
= 0, /* read block from disk (forced read) */
169 gbExistBit
= 1, /* get existing cache block */
170 gbExistMask
= 0x0002,
171 gbNoReadBit
= 2, /* don't read block from disk if not found in cache */
172 gbNoReadMask
= 0x0004,
173 gbReleaseBit
= 3, /* release block immediately after GetBlock */
174 gbReleaseMask
= 0x0008
179 * UTReleaseBlock options
182 rbDefault
= 0, /* default value - just mark the buffer not in-use */
184 rbWriteBit
= 0, /* force write buffer to disk */
185 rbWriteMask
= 0x0001,
186 rbTrashBit
= 1, /* trash buffer contents after release */
187 rbTrashMask
= 0x0002,
188 rbDirtyBit
= 2, /* mark buffer dirty */
189 rbDirtyMask
= 0x0004,
190 rbFreeBit
= 3, /* free the buffer (save in the hash) */
191 rbFreeMask
= 0x000A /* rbFreeMask (rbFreeBit + rbTrashBit) works as rbTrash on < System 7.0 RamCache; on >= System 7.0, rbfreeMask overrides rbTrash */
196 * UTFlushCache options
199 fcDefault
= 0, /* default value - pass this fcOption to just flush any dirty buffers */
201 fcTrashBit
= 0, /* (don't pass this as fcOption, use only for testing bit) */
202 fcTrashMask
= 0x0001, /* pass this fcOption value to flush and trash cache blocks */
203 fcFreeBit
= 1, /* (don't pass this as fcOption, use only for testing bit) */
204 fcFreeMask
= 0x0003 /* pass this fcOption to flush and free cache blocks (Note: both fcTrash and fcFree bits are set) */
209 * UTCacheReadIP and UTCacheWriteIP cacheOption bits and masks are the ioPosMode
210 * bits and masks in Files.x
214 * Cache routine internal error codes
217 chNoBuf
= 1, /* no free cache buffers (all in use) */
218 chInUse
= 2, /* requested block in use */
219 chnotfound
= 3, /* requested block not found */
220 chNotInUse
= 4 /* block being released was not in use */
225 * FCBRec.fcbFlags bits
228 fcbWriteBit
= 0, /* Data can be written to this file */
230 fcbResourceBit
= 1, /* This file is a resource fork */
231 fcbResourceMask
= 0x02,
232 fcbWriteLockedBit
= 2, /* File has a locked byte range */
233 fcbWriteLockedMask
= 0x04,
234 fcbSharedWriteBit
= 4, /* File is open for shared write access */
235 fcbSharedWriteMask
= 0x10,
236 fcbFileLockedBit
= 5, /* File is locked (write-protected) */
237 fcbFileLockedMask
= 0x20,
238 fcbOwnClumpBit
= 6, /* File has clump size specified in FCB */
239 fcbOwnClumpMask
= 0x40,
240 fcbModifiedBit
= 7, /* File has changed since it was last flushed */
241 fcbModifiedMask
= 0x80
245 fcbLargeFileBit
= 3, /* File may grow beyond 2GB; cache uses file blocks, not bytes */
246 fcbLargeFileMask
= 0x08
249 #define kSectorShift 9 /* log2(kSectorSize); used for bit shifts */
252 Fork Level Access Method Block get options
255 kGetBlock
= 0x00000000,
256 kForceReadBlock
= 0x00000002,
257 kGetEmptyBlock
= 0x00000008,
258 kSkipEndianSwap
= 0x00000010
260 typedef OptionBits GetBlockOptions
;
263 Fork Level Access Method Block release options
266 kReleaseBlock
= 0x00000000,
267 kForceWriteBlock
= 0x00000001,
268 kMarkBlockDirty
= 0x00000002,
269 kTrashBlock
= 0x00000004
271 typedef OptionBits ReleaseBlockOptions
;
273 struct BlockDescriptor
{
278 Boolean blockReadFromDisk
;
281 typedef struct BlockDescriptor BlockDescriptor
;
282 typedef BlockDescriptor
*BlockDescPtr
;
291 UInt32 vcbAttributes
;
292 UInt32 vcbLastMountedVersion
;
294 UInt32 vcbCreateDate
;
295 UInt32 vcbModifyDate
;
296 UInt32 vcbBackupDate
;
297 UInt32 vcbCheckedDate
;
299 UInt32 vcbFolderCount
;
301 UInt32 vcbTotalBlocks
;
302 UInt32 vcbFreeBlocks
;
303 UInt32 vcbNextAllocation
;
304 UInt32 vcbRsrcClumpSize
;
305 UInt32 vcbDataClumpSize
;
306 UInt32 vcbNextCatalogID
;
307 UInt32 vcbWriteCount
;
308 UInt64 vcbEncodingsBitmap
;
309 UInt8 vcbFinderInfo
[32];
311 /* MDB-specific fields... */
312 SInt16 vcbNmFls
; /* number of files in root folder */
313 SInt16 vcbNmRtDirs
; /* number of directories in root folder */
314 UInt16 vcbVBMSt
; /* first sector of HFS volume bitmap */
315 UInt16 vcbAlBlSt
; /* first allocation block in HFS volume */
316 UInt16 vcbVSeqNum
; /* volume backup sequence number */
318 Str27 vcbVN
; /* HFS volume name */
320 /* runtime fields... */
321 struct SFCB
* vcbAllocationFile
;
322 struct SFCB
* vcbExtentsFile
;
323 struct SFCB
* vcbCatalogFile
;
324 struct SFCB
* vcbAttributesFile
;
325 struct SFCB
* vcbStartupFile
;
327 UInt32 vcbEmbeddedOffset
; /* Byte offset where HFS+ starts */
329 SInt16 vcbDriveNumber
;
330 SInt16 vcbDriverReadRef
;
331 SInt16 vcbDriverWriteRef
;
333 void * vcbBlockCache
;
335 struct SGlob
* vcbGPtr
;
337 /* deprecated fields... */
340 typedef struct SVCB SVCB
;
346 struct SVCB
* fcbVolume
;
348 HFSExtentRecord fcbExtents16
;
349 HFSPlusExtentRecord fcbExtents32
;
350 UInt32 fcbCatalogHint
;
352 UInt64 fcbLogicalSize
;
353 UInt64 fcbPhysicalSize
;
356 typedef struct SFCB SFCB
;
359 extern OSErr
GetDeviceSize(int driveRefNum
, UInt64
*numBlocks
, UInt32
*blockSize
);
361 extern OSErr
DeviceRead(int device
, int drive
, void* buffer
, SInt64 offset
, UInt32 reqBytes
, UInt32
*actBytes
);
363 extern OSErr
DeviceWrite(int device
, int drive
, void* buffer
, SInt64 offset
, UInt32 reqBytes
, UInt32
*actBytes
);
367 * Block Cache Interface
369 extern void InitBlockCache(SVCB
*volume
);
371 extern OSStatus
GetVolumeBlock (SVCB
*volume
, UInt64 blockNum
, GetBlockOptions options
,
372 BlockDescriptor
*block
);
374 extern OSStatus
ReleaseVolumeBlock (SVCB
*volume
, BlockDescriptor
*block
,
375 ReleaseBlockOptions options
);
377 extern OSStatus
GetFileBlock (SFCB
*file
, UInt32 blockNum
, GetBlockOptions options
,
378 BlockDescriptor
*block
);
380 extern OSStatus
ReleaseFileBlock (SFCB
*file
, BlockDescriptor
*block
,
381 ReleaseBlockOptions options
);
383 extern OSStatus
SetFileBlockSize (SFCB
*file
, ByteCount blockSize
);
389 #define AllocateMemory(size) malloc((size_t)(size))
390 #define AllocateClearMemory(size) calloc(1,(size_t)(size))
391 #define ReallocateMemory(ptr,newSize) SetPtrSize((void*)(ptr),(size_t)(newSize))
392 #define MemorySize(ptr) malloc_size((void*)(ptr))
393 #define DisposeMemory(ptr) free((void *)(ptr))
394 #define CopyMemory(src,dst,len) bcopy((void*)(src),(void*)(dst),(size_t)(len))
395 #define ClearMemory(start,len) bzero((void*)(start),(size_t)(len))
397 extern UInt32
TickCount();
398 extern OSErr
MemError(void);
399 extern Handle
NewHandleClear(Size byteCount
);
400 extern Handle
NewHandle(Size byteCount
);
401 extern void DisposeHandle(Handle h
);
402 extern Size
GetHandleSize(Handle h
);
403 extern void SetHandleSize(Handle h
, Size newSize
);
404 extern OSErr
PtrAndHand(const void *ptr1
, Handle hand2
, long size
);
408 #define AllocateMemory(size) NewPtr((Size)(size))
409 #define AllocateClearMemory(size) NewPtrClear((Size)(size))
410 #define ReallocateMemory(ptr,newSize) SetPtrSize((Ptr)(ptr),(Size)(newSize))
411 #define MemorySize(ptr) GetPtrSize((Ptr)(ptr))
412 #define DisposeMemory(ptr) DisposePtr((Ptr)(ptr))
413 #define CopyMemory(src,dst,len) BlockMoveData((void *)(src),(void *)(dst),(Size)(len))
414 void ClearMemory(void* start
, long len
);
418 #endif /* __SRUNTIME__ */