#ifndef __FILEMGRINTERNAL__
#define __FILEMGRINTERNAL__
#include <sys/param.h>
#include <sys/vnode.h>
#include "../../hfs.h"
#include "../../hfs_macos_defs.h"
#include "../../hfs_format.h"
#if PRAGMA_ONCE
#pragma once
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if PRAGMA_IMPORT
#pragma import on
#endif
#if PRAGMA_STRUCT_ALIGN
#pragma options align=mac68k
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(push, 2)
#elif PRAGMA_STRUCT_PACK
#pragma pack(2)
#endif
typedef UInt32 HFSCatalogNodeID;
#if TARGET_API_MACOS_X
#define ERR_BASE -32767
#else
#define ERR_BASE 0
#endif
enum {
fxRangeErr = ERR_BASE + 16,
fxOvFlErr = ERR_BASE + 17,
uniTooLongErr = ERR_BASE + 24,
uniBufferTooSmallErr = ERR_BASE + 25,
uniNotMappableErr = ERR_BASE + 26,
btNotFound = ERR_BASE + 32,
btExists = ERR_BASE + 33,
btNoSpaceAvail = ERR_BASE + 34,
btNoFit = ERR_BASE + 35,
btBadNode = ERR_BASE + 36,
btBadHdr = ERR_BASE + 37,
dsBadRotate = ERR_BASE + 64,
cmNotFound = ERR_BASE + 48,
cmExists = ERR_BASE + 49,
cmNotEmpty = ERR_BASE + 50,
cmRootCN = ERR_BASE + 51,
cmBadNews = ERR_BASE + 52,
cmFThdDirErr = ERR_BASE + 53,
cmFThdGone = ERR_BASE + 54,
cmParentNotFound = ERR_BASE + 55,
fsDSIntErr = -127
};
enum {
kEFContigBit = 1,
kEFContigMask = 0x02,
kEFAllBit = 0,
kEFAllMask = 0x01,
kTFTrunExtBit = 0,
kTFTrunExtMask = 1
};
enum {
kUndefinedStrLen = 0,
kNoHint = 0,
kNumExtentsToCache = 4
};
enum {
kInvalidMRUCacheKey = -1L,
kDefaultNumMRUCacheBlocks = 16
};
union ExtentKey {
HFSExtentKey hfs;
HFSPlusExtentKey hfsPlus;
};
typedef union ExtentKey ExtentKey;
union ExtentDescriptor {
HFSExtentDescriptor hfs;
HFSPlusExtentDescriptor hfsPlus;
};
typedef union ExtentDescriptor ExtentDescriptor;
union ExtentRecord {
HFSExtentRecord hfs;
HFSPlusExtentRecord hfsPlus;
};
typedef union ExtentRecord ExtentRecord;
union CatalogKey {
HFSCatalogKey hfs;
HFSPlusCatalogKey hfsPlus;
};
typedef union CatalogKey CatalogKey;
union CatalogRecord {
SInt16 recordType;
HFSCatalogFolder hfsFolder;
HFSCatalogFile hfsFile;
HFSCatalogThread hfsThread;
HFSPlusCatalogFolder hfsPlusFolder;
HFSPlusCatalogFile hfsPlusFile;
HFSPlusCatalogThread hfsPlusThread;
};
typedef union CatalogRecord CatalogRecord;
enum {
CMMaxCName = kHFSMaxFileNameChars
};
enum {
vcbMaxNam = 27,
vcbManualEjectMask = 0x0001,
vcbFlushCriticalInfoMask = 0x0002,
kDefaultVolumeMask = 0x0020,
kFilesOpenMask = 0x0040
};
union CatalogName {
Str31 pstr;
HFSUniStr255 ustr;
};
typedef union CatalogName CatalogName;
#define GetFileControlBlock(fref) ((FCB *)((fref)->v_data))
#define GetFileRefNumFromFCB(filePtr) ((filePtr)->h_vp)
EXTERN_API_C( void )
MarkVCBDirty (ExtendedVCB *vcb);
EXTERN_API_C( void )
MarkVCBClean (ExtendedVCB *vcb);
EXTERN_API_C( Boolean )
IsVCBDirty (ExtendedVCB *vcb);
#define VCB_LOCK_INIT(vcb) simple_lock_init(&vcb->vcbSimpleLock)
#define VCB_LOCK(vcb) simple_lock(&vcb->vcbSimpleLock)
#define VCB_UNLOCK(vcb) simple_unlock(&vcb->vcbSimpleLock)
#define MarkVCBDirty(vcb) { VCB_LOCK((vcb)); ((vcb)->vcbFlags |= 0xFF00); VCB_UNLOCK((vcb)); }
#define MarkVCBClean(vcb) { VCB_LOCK((vcb)); ((vcb)->vcbFlags &= 0x00FF); VCB_UNLOCK((vcb)); }
#define IsVCBDirty(vcb) ((Boolean) ((vcb->vcbFlags & 0xFF00) != 0))
EXTERN_API_C( void )
ReturnIfError (OSErr result);
#define ReturnIfError(result) if ( (result) != noErr ) return (result); else ;
EXTERN_API_C( void )
ReturnErrorIf (Boolean condition,
OSErr result);
#define ReturnErrorIf(condition, error) if ( (condition) ) return( (error) );
EXTERN_API_C( void )
ExitOnError (OSErr result);
#define ExitOnError( result ) if ( ( result ) != noErr ) goto ErrorExit; else ;
EXTERN_API_C( OSErr )
CreateCatalogNode (ExtendedVCB * volume,
HFSCatalogNodeID parentID,
ConstUTF8Param name,
UInt32 nodeType,
HFSCatalogNodeID * catalogNodeID,
UInt32 * catalogHint,
UInt32 teHint);
EXTERN_API_C( OSErr )
DeleteCatalogNode (ExtendedVCB * volume,
HFSCatalogNodeID parentID,
ConstUTF8Param name,
UInt32 hint);
EXTERN_API_C( OSErr )
GetCatalogNode (ExtendedVCB * volume,
HFSCatalogNodeID parentID,
ConstUTF8Param name,
UInt32 length,
UInt32 hint,
CatalogNodeData * nodeData,
UInt32 * newHint);
EXTERN_API_C( OSErr )
GetCatalogOffspring (ExtendedVCB * volume,
HFSCatalogNodeID folderID,
UInt16 index,
CatalogNodeData * nodeData,
HFSCatalogNodeID * nodeID,
SInt16 * nodeType);
EXTERN_API_C( OSErr )
MoveRenameCatalogNode (ExtendedVCB * volume,
HFSCatalogNodeID srcParentID,
ConstUTF8Param srcName,
UInt32 srcHint,
HFSCatalogNodeID dstParentID,
ConstUTF8Param dstName,
UInt32 * newHint,
UInt32 teHint);
EXTERN_API_C( OSErr )
UpdateCatalogNode (ExtendedVCB * volume,
HFSCatalogNodeID parentID,
ConstUTF8Param name,
UInt32 catalogHint,
const CatalogNodeData * nodeData);
EXTERN_API_C( OSErr )
CreateFileIDRef (ExtendedVCB * volume,
HFSCatalogNodeID parentID,
ConstUTF8Param name,
UInt32 hint,
HFSCatalogNodeID * threadID);
EXTERN_API_C( OSErr )
ExchangeFileIDs (ExtendedVCB * volume,
ConstUTF8Param srcName,
ConstUTF8Param destName,
HFSCatalogNodeID srcID,
HFSCatalogNodeID destID,
UInt32 srcHint,
UInt32 destHint );
EXTERN_API_C( OSErr )
LinkCatalogNode (ExtendedVCB * volume,
HFSCatalogNodeID parentID,
ConstUTF8Param name,
HFSCatalogNodeID linkParentID,
ConstUTF8Param linkName);
EXTERN_API_C( SInt32 )
CompareCatalogKeys (HFSCatalogKey * searchKey,
HFSCatalogKey * trialKey);
EXTERN_API_C( SInt32 )
CompareExtendedCatalogKeys (HFSPlusCatalogKey * searchKey,
HFSPlusCatalogKey * trialKey);
EXTERN_API_C( OSErr )
InitCatalogCache (void);
EXTERN_API_C( void )
InvalidateCatalogCache (ExtendedVCB * volume);
EXTERN_API_C( OSErr )
InitMRUCache (UInt32 bufferSize,
UInt32 numCacheBlocks,
Ptr * cachePtr);
EXTERN_API_C( OSErr )
DisposeMRUCache (Ptr cachePtr);
EXTERN_API_C( void )
TrashMRUCache (Ptr cachePtr);
EXTERN_API_C( OSErr )
GetMRUCacheBlock (UInt32 key,
Ptr cachePtr,
Ptr * buffer);
EXTERN_API_C( void )
InvalidateMRUCacheBlock (Ptr cachePtr,
Ptr buffer);
EXTERN_API_C( void )
InsertMRUCacheBlock (Ptr cachePtr,
UInt32 key,
Ptr buffer);
typedef CALLBACK_API_C( SInt32 , KeyCompareProcPtr )(void *a, void *b);
EXTERN_API_C( OSErr )
SearchBTreeRecord (FileReference refNum,
const void * key,
UInt32 hint,
void * foundKey,
void * data,
UInt16 * dataSize,
UInt32 * newHint);
EXTERN_API_C( OSErr )
InsertBTreeRecord (FileReference refNum,
void * key,
void * data,
UInt16 dataSize,
UInt32 * newHint);
EXTERN_API_C( OSErr )
DeleteBTreeRecord (FileReference refNum,
void * key);
EXTERN_API_C( OSErr )
ReplaceBTreeRecord (FileReference refNum,
const void * key,
UInt32 hint,
void * newData,
UInt16 dataSize,
UInt32 * newHint);
EXTERN_API_C( OSErr )
GetBlock_glue (UInt16 flags,
UInt32 nodeNumber,
Ptr * nodeBuffer,
FileReference refNum,
ExtendedVCB * vcb);
EXTERN_API_C( OSErr )
RelBlock_glue (Ptr nodeBuffer,
UInt16 flags);
EXTERN_API_C( OSErr )
BlockAllocate (ExtendedVCB * vcb,
UInt32 startingBlock,
SInt64 bytesRequested,
SInt64 bytesMaximum,
Boolean forceContiguous,
UInt32 * startBlock,
UInt32 * actualBlocks);
EXTERN_API_C( OSErr )
BlockDeallocate (ExtendedVCB * vcb,
UInt32 firstBlock,
UInt32 numBlocks);
EXTERN_API_C( UInt32 )
FileBytesToBlocks (SInt64 numerator,
UInt32 denominator);
EXTERN_API_C( OSErr )
FlushExtentFile (ExtendedVCB * vcb);
EXTERN_API_C( SInt32 )
CompareExtentKeys (const HFSExtentKey * searchKey,
const HFSExtentKey * trialKey);
EXTERN_API_C( SInt32 )
CompareExtentKeysPlus (const HFSPlusExtentKey *searchKey,
const HFSPlusExtentKey *trialKey);
EXTERN_API_C( OSErr )
DeleteFile (ExtendedVCB * vcb,
HFSCatalogNodeID parDirID,
ConstUTF8Param catalogName,
UInt32 catalogHint);
EXTERN_API_C( OSErr )
TruncateFileC (ExtendedVCB * vcb,
FCB * fcb,
SInt64 peof,
Boolean truncateToExtent);
EXTERN_API_C( OSErr )
ExtendFileC (ExtendedVCB * vcb,
FCB * fcb,
SInt64 bytesToAdd,
UInt32 blockHint,
UInt32 flags,
SInt64 * actualBytesAdded);
EXTERN_API_C( OSErr )
MapFileBlockC (ExtendedVCB * vcb,
FCB * fcb,
size_t numberOfBytes,
off_t offset,
daddr_t * startBlock,
size_t * availableBytes);
#if TARGET_API_MACOS_X
EXTERN_API_C( Boolean )
NodesAreContiguous (ExtendedVCB * vcb,
FCB * fcb,
UInt32 nodeSize);
#endif
EXTERN_API_C( void )
ClearMemory (void * start,
UInt32 length);
EXTERN_API_C( OSErr )
VolumeWritable (ExtendedVCB * vcb);
EXTERN_API_C( UInt32 )
GetTimeUTC (void);
EXTERN_API_C( UInt32 )
GetTimeLocal (Boolean forHFS);
EXTERN_API_C( UInt32 )
LocalToUTC (UInt32 localTime);
EXTERN_API_C( UInt32 )
UTCToLocal (UInt32 utcTime);
EXTERN_API_C( OSErr )
FlushVolumeControlBlock (ExtendedVCB * vcb);
EXTERN_API_C( OSErr )
ValidVolumeHeader (HFSPlusVolumeHeader * volumeHeader);
#if PRAGMA_STRUCT_ALIGN
#pragma options align=reset
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(pop)
#elif PRAGMA_STRUCT_PACK
#pragma pack()
#endif
#ifdef PRAGMA_IMPORT_OFF
#pragma import off
#elif PRAGMA_IMPORT
#pragma import reset
#endif
#ifdef __cplusplus
}
#endif
#endif