-
-//*******************************************************************************
-// Routine: AdjustVolumeCounts
-//
-// Function: Adjusts the folder and file counts in the VCB
-//
-//*******************************************************************************
-
-void
-AdjustVolumeCounts(ExtendedVCB *volume, SInt16 type, SInt16 delta)
-{
- //\80\80 also update extended VCB fields...
-
- VCB_LOCK(volume);
-
- if (type == kHFSFolderRecord || type == kHFSPlusFolderRecord)
- volume->vcbDirCnt += delta; // adjust volume folder count, \80\80 worry about overflow?
- else
- volume->vcbFilCnt += delta; // adjust volume file count
-
- volume->vcbFlags |= 0xFF00; // Mark the VCB dirty
- volume->vcbLsMod = GetTimeUTC(); // update last modified date
-
- VCB_UNLOCK(volume);
-}
-
-
-//*******************************************************************************
-
-void
-UpdateVolumeEncodings(ExtendedVCB *volume, TextEncoding encoding)
-{
- UInt32 index;
-
- encoding &= 0x7F;
-
- index = MapEncodingToIndex(encoding);
-
- VCB_LOCK(volume);
-
- volume->encodingsBitmap |= (1 << index);
-
- VCB_UNLOCK(volume);
-
- // vcb should already be marked dirty
-}
-
-
-//*******************************************************************************
-
-OSErr
-UpdateFolderCount( ExtendedVCB *volume, HFSCatalogNodeID parentID, const CatalogName *name, SInt16 newType,
- UInt32 hint, SInt16 valenceDelta)
-{
- CatalogKey tempKey; // 518 bytes
- CatalogRecord tempData; // 520 bytes
- UInt32 tempHint;
- HFSCatalogNodeID folderID;
- UInt16 recordSize;
- OSErr result;
-
-#if 0
- result = SearchBTreeRecord(volume->catalogRefNum, parentKey, hint,
- &tempKey, &tempData, &recordSize, &tempHint);
- if (result)
- return (result == btNotFound ? cmNotFound : result);
-#else
-
- result = LocateCatalogNode(volume, parentID, name, hint, &tempKey, &tempData, &tempHint);
- ReturnIfError(result);
-#endif
-
- if ( volume->vcbSigWord == kHFSPlusSigWord ) // HFS Plus
- {
- UInt32 timeStamp;
-
- if ( DEBUG_BUILD && tempData.recordType != kHFSPlusFolderRecord )
- DebugStr("\p UpdateFolder: found HFS folder on HFS+ volume!");
-
- timeStamp = GetTimeUTC();
- /* adjust valence, but don't go negative */
- if (valenceDelta > 0)
- tempData.hfsPlusFolder.valence += valenceDelta;
- else if (tempData.hfsPlusFolder.valence != 0)
- tempData.hfsPlusFolder.valence += valenceDelta;
- else
- volume->vcbFlags |= kHFS_DamagedVolume;
- tempData.hfsPlusFolder.contentModDate = timeStamp; // set date/time last modified
- folderID = tempData.hfsPlusFolder.folderID;
- recordSize = sizeof(tempData.hfsPlusFolder);
- }
- else // classic HFS
- {
- if ( DEBUG_BUILD && tempData.recordType != kHFSFolderRecord )
- DebugStr("\p UpdateFolder: found HFS+ folder on HFS volume!");
-
- /* adjust valence, but don't go negative */
- if (valenceDelta > 0)
- tempData.hfsFolder.valence += valenceDelta;
- else if (tempData.hfsFolder.valence != 0)
- tempData.hfsFolder.valence += valenceDelta;
- else
- volume->vcbFlags |= kHFS_DamagedVolume;
- tempData.hfsFolder.modifyDate = GetTimeLocal(true); // set date/time last modified
- folderID = tempData.hfsFolder.folderID;
- recordSize = sizeof(tempData.hfsFolder);
- }
-
- result = ReplaceBTreeRecord(volume->catalogRefNum, &tempKey, tempHint,
- &tempData, recordSize, &tempHint);
- ReturnIfError(result);
-
- if ( folderID == kHFSRootFolderID )
- {
- if (newType == kHFSFolderRecord || newType == kHFSPlusFolderRecord)
- {
- VCB_LOCK(volume);
- volume->vcbNmRtDirs += valenceDelta; // adjust root folder count (undefined for HFS Plus)
- VCB_UNLOCK(volume);
- }
- else
- {
- VCB_LOCK(volume);
- volume->vcbNmFls += valenceDelta; // adjust root file count (used by GetVolInfo)
- VCB_UNLOCK(volume);
- }
- }
-
- //XXX also update extended VCB fields...
-
- return result;
-}
-
-
-//*******************************************************************************
-
-UInt16
-GetCatalogRecordSize(const CatalogRecord *dataRecord)
-{
- switch (dataRecord->recordType)
- {
- case kHFSFileRecord:
- return sizeof(HFSCatalogFile);
-
- case kHFSFolderRecord:
- return sizeof(HFSCatalogFolder);
-
- case kHFSPlusFileRecord:
- return sizeof(HFSPlusCatalogFile);
-
- case kHFSPlusFolderRecord:
- return sizeof(HFSPlusCatalogFolder);
-
- case kHFSFolderThreadRecord:
- case kHFSFileThreadRecord:
- return sizeof(HFSCatalogThread);
-
- case kHFSPlusFolderThreadRecord:
- case kHFSPlusFileThreadRecord:
- return sizeof(HFSPlusCatalogThread);
-
- default:
- return 0;
- }
-}
-
-
-//*******************************************************************************
-
-void
-CopyCatalogNodeData(const ExtendedVCB *volume, const CatalogRecord *dataPtr, CatalogNodeData *nodeData)
-{
- /* convert classic hfs records to hfs plus format */
-
- if (dataPtr->recordType == kHFSFolderRecord) {
- nodeData->cnd_type = kCatalogFolderNode;
- nodeData->cnd_flags = dataPtr->hfsFolder.flags;
- nodeData->cnd_nodeID = dataPtr->hfsFolder.folderID;
- nodeData->cnd_createDate = LocalToUTC(dataPtr->hfsFolder.createDate);
- nodeData->cnd_contentModDate = LocalToUTC(dataPtr->hfsFolder.modifyDate);
- nodeData->cnd_backupDate = LocalToUTC(dataPtr->hfsFolder.backupDate);
- nodeData->cnd_valence = dataPtr->hfsFolder.valence;
-
- BlockMoveData(&dataPtr->hfsFolder.userInfo, &nodeData->cnd_finderInfo, 32);
- } else if (dataPtr->recordType == kHFSFileRecord) {
- UInt32 i;
-
- nodeData->cnd_type = kCatalogFileNode;
- nodeData->cnd_flags = dataPtr->hfsFile.flags;
- nodeData->cnd_nodeID = dataPtr->hfsFile.fileID;
- nodeData->cnd_createDate = LocalToUTC(dataPtr->hfsFile.createDate);
- nodeData->cnd_contentModDate = LocalToUTC(dataPtr->hfsFile.modifyDate);
- nodeData->cnd_backupDate = LocalToUTC(dataPtr->hfsFile.backupDate);
- nodeData->cnd_linkCount = 0;
-
- BlockMoveData(&dataPtr->hfsFile.userInfo, &nodeData->cnd_finderInfo, 16);
- BlockMoveData(&dataPtr->hfsFile.finderInfo, (void*)((UInt32)&nodeData->cnd_finderInfo + 16), 16);
-
- nodeData->cnd_datafork.logicalSize = dataPtr->hfsFile.dataLogicalSize;
- nodeData->cnd_datafork.totalBlocks =
- dataPtr->hfsFile.dataPhysicalSize / volume->blockSize;
-
- nodeData->cnd_rsrcfork.logicalSize = dataPtr->hfsFile.rsrcLogicalSize;
- nodeData->cnd_rsrcfork.totalBlocks =
- dataPtr->hfsFile.rsrcPhysicalSize / volume->blockSize;
-
- for (i = 0; i < kHFSExtentDensity; ++i) {
- nodeData->cnd_datafork.extents[i].startBlock =
- (UInt32) (dataPtr->hfsFile.dataExtents[i].startBlock);
-
- nodeData->cnd_datafork.extents[i].blockCount =
- (UInt32) (dataPtr->hfsFile.dataExtents[i].blockCount);
-
- nodeData->cnd_rsrcfork.extents[i].startBlock =
- (UInt32) (dataPtr->hfsFile.rsrcExtents[i].startBlock);
-
- nodeData->cnd_rsrcfork.extents[i].blockCount =
- (UInt32) (dataPtr->hfsFile.rsrcExtents[i].blockCount);
- }
- for (i = kHFSExtentDensity; i < kHFSPlusExtentDensity; ++i) {
- nodeData->cnd_datafork.extents[i].startBlock = 0;
- nodeData->cnd_datafork.extents[i].blockCount = 0;
- nodeData->cnd_rsrcfork.extents[i].startBlock = 0;
- nodeData->cnd_rsrcfork.extents[i].blockCount = 0;
- }
- } else {
- nodeData->cnd_type = 0;
- }
-}
-
-