#include <sys/param.h>
#include <sys/utfconv.h>
#include <sys/stat.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <libkern/libkern.h>
#include "../headers/FileMgrInternal.h"
#include "../headers/BTreesInternal.h"
HFSCatalogNodeID threadParentID;
u_int16_t tempSize;
FSBufferDescriptor btRecord;
- BTreeIterator searchIterator;
+ struct BTreeIterator *searchIterator;
FCB *fcb;
- bzero(&searchIterator, sizeof(searchIterator));
+ MALLOC (searchIterator, struct BTreeIterator*, sizeof(struct BTreeIterator), M_TEMP, M_WAITOK);
+ if (searchIterator == NULL) {
+ return memFullErr; // translates to ENOMEM
+ }
+
+ bzero(searchIterator, sizeof(*searchIterator));
fcb = GetFileControlBlock(volume->catalogRefNum);
btRecord.itemCount = 1;
btRecord.itemSize = sizeof(CatalogRecord);
- searchIterator.hint.nodeNum = hint;
+ searchIterator->hint.nodeNum = hint;
- bcopy(keyPtr, &searchIterator.key, sizeof(CatalogKey));
+ bcopy(keyPtr, &searchIterator->key, sizeof(CatalogKey));
- result = BTSearchRecord( fcb, &searchIterator, &btRecord, &tempSize, &searchIterator );
+ result = BTSearchRecord( fcb, searchIterator, &btRecord, &tempSize, searchIterator );
if (result == noErr)
{
- *newHint = searchIterator.hint.nodeNum;
+ *newHint = searchIterator->hint.nodeNum;
- BlockMoveData(&searchIterator.key, keyPtr, sizeof(CatalogKey));
+ BlockMoveData(&searchIterator->key, keyPtr, sizeof(CatalogKey));
}
- if (result == btNotFound)
- result = cmNotFound;
- ReturnIfError(result);
+ if (result == btNotFound) {
+ result = cmNotFound;
+ }
+
+ if (result) {
+ FREE(searchIterator, M_TEMP);
+ return result;
+ }
// if we got a thread record, then go look up real record
switch ( dataPtr->recordType )
{
+
+#if CONFIG_HFS_STD
case kHFSFileThreadRecord:
case kHFSFolderThreadRecord:
threadParentID = dataPtr->hfsThread.parentID;
nodeName = (CatalogName *) &dataPtr->hfsThread.nodeName;
break;
+#endif
case kHFSPlusFileThreadRecord:
case kHFSPlusFolderThreadRecord:
if ( threadParentID ) // found a thread
result = LocateCatalogRecord(volume, threadParentID, nodeName, kNoHint, keyPtr, dataPtr, newHint);
+ FREE (searchIterator, M_TEMP);
return result;
}
OSErr result;
uint16_t tempSize;
FSBufferDescriptor btRecord;
- BTreeIterator searchIterator;
+ struct BTreeIterator *searchIterator = NULL;
FCB *fcb;
BTreeControlBlock *btcb;
- bzero(&searchIterator, sizeof(searchIterator));
+ MALLOC (searchIterator, struct BTreeIterator*, sizeof(struct BTreeIterator), M_TEMP, M_WAITOK);
+ if (searchIterator == NULL) {
+ return memFullErr; // translates to ENOMEM
+ }
+
+ bzero(searchIterator, sizeof(*searchIterator));
+
fcb = GetFileControlBlock(volume->catalogRefNum);
btcb = (BTreeControlBlock *)fcb->fcbBTCBPtr;
btRecord.itemCount = 1;
btRecord.itemSize = sizeof(CatalogRecord);
- BuildCatalogKey(folderID, name, (volume->vcbSigWord == kHFSPlusSigWord), (CatalogKey *)&searchIterator.key);
+ BuildCatalogKey(folderID, name, (volume->vcbSigWord == kHFSPlusSigWord), (CatalogKey *)&searchIterator->key);
- result = BTSearchRecord(fcb, &searchIterator, &btRecord, &tempSize, &searchIterator);
+ result = BTSearchRecord(fcb, searchIterator, &btRecord, &tempSize, searchIterator);
if (result == noErr) {
- *newHint = searchIterator.hint.nodeNum;
- BlockMoveData(&searchIterator.key, keyPtr, CalcKeySize(btcb, &searchIterator.key));
+ *newHint = searchIterator->hint.nodeNum;
+ BlockMoveData(&searchIterator->key, keyPtr, CalcKeySize(btcb, &searchIterator->key));
}
+ FREE (searchIterator, M_TEMP);
return (result == btNotFound ? cmNotFound : result);
}
key->hfsPlus.keyLength += sizeof(UniChar) * cName->ustr.length; // add CName size to key length
}
}
+#if CONFIG_HFS_STD
else
{
key->hfs.keyLength = kHFSCatalogKeyMinimumLength; // initial key length (1 + 4 + 1)
key->hfs.keyLength += key->hfs.nodeName[0]; // add CName size to key length
}
}
+#endif
+
}
OSErr
*textEncoding = hfs_pickencoding(key->hfsPlus.nodeName.unicode,
key->hfsPlus.nodeName.length);
}
+#if CONFIG_HFS_STD
else {
key->hfs.keyLength = kHFSCatalogKeyMinimumLength; // initial key length (1 + 4 + 1)
key->hfs.reserved = 0; // clear unused byte
if (textEncoding)
*textEncoding = 0;
}
+#endif
if (err) {
if (err == ENAMETOOLONG)
{
FCB * fcb;
OSErr result;
+ struct hfsmount *hfsmp = VCBTOHFS (volume);
fcb = GetFileControlBlock(volume->catalogRefNum);
result = BTFlushPath(fcb);
{
//--- check if catalog's fcb is dirty...
- if ( 0 /*fcb->fcbFlags & fcbModifiedMask*/ )
+ if ( (0) /*fcb->fcbFlags & fcbModifiedMask*/ )
{
- HFS_MOUNT_LOCK(volume, TRUE);
+ hfs_lock_mount (hfsmp);
MarkVCBDirty(volume); // Mark the VCB dirty
volume->vcbLsMod = GetTimeUTC(); // update last modified date
- HFS_MOUNT_UNLOCK(volume, TRUE);
+ hfs_unlock_mount (hfsmp);
// result = FlushVolumeControlBlock(volume);
}
//_______________________________________________________________________
void
-CopyCatalogName(const CatalogName *srcName, CatalogName *dstName, Boolean isHFSPLus)
+CopyCatalogName(const CatalogName *srcName, CatalogName *dstName, Boolean isHFSPlus)
{
- u_int32_t length;
+ u_int32_t length = 0;
if ( srcName == NULL )
{
return;
}
- if (isHFSPLus)
+ if (isHFSPlus) {
length = sizeof(UniChar) * (srcName->ustr.length + 1);
- else
+ }
+#if CONFIG_HFS_STD
+ else {
length = sizeof(u_int8_t) + srcName->pstr[0];
+ }
+#endif
if ( length > 1 )
BlockMoveData(srcName, dstName, length);