]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/hfs/hfs_endian.c
xnu-792.tar.gz
[apple/xnu.git] / bsd / hfs / hfs_endian.c
index d01635c4eb752fab4db916de103404e025d11730..0341f15db049c4a559f7e8ab734030e6236661f0 100644 (file)
@@ -50,9 +50,6 @@ hfs_swap_HFSPlusForkData (
 {
     int i;
 
-    DBG_FUNC_NAME("hfs_swap_HFSPlusForkData");
-    DBG_PRINT_FUNC_NAME();
-
        src->logicalSize                = SWAP_BE64 (src->logicalSize);
 
        src->clumpSize                  = SWAP_BE32 (src->clumpSize);
@@ -84,8 +81,6 @@ hfs_swap_BTNode (
     UInt32 i;
     int error = 0;
 
-    DBG_FUNC_NAME("hfs_swap_BTNode");
-    DBG_PRINT_FUNC_NAME();
 
 #ifdef ENDIAN_DEBUG
     if (unswap == 0) {
@@ -218,9 +213,6 @@ hfs_swap_HFSPlusBTInternalNode (
     UInt32 i;
     UInt32 j;
 
-    DBG_FUNC_NAME("hfs_swap_HFSPlusBTInternalNode");
-    DBG_PRINT_FUNC_NAME();
-
     if (fileID == kHFSExtentsFileID) {
         HFSPlusExtentKey *srcKey;
         HFSPlusExtentDescriptor *srcRec;
@@ -363,10 +355,81 @@ hfs_swap_HFSPlusBTInternalNode (
             if (unswap) srcPtr[0] = SWAP_BE16 (srcPtr[0]);
         }
         
+    } else if (fileID == kHFSAttributesFileID) {
+       HFSPlusAttrKey *srcKey;
+       HFSPlusAttrRecord *srcRec;
+       
+       for (i = 0; i < srcDesc->numRecords; i++) {
+               srcKey = (HFSPlusAttrKey *)((char *)src->buffer + srcOffs[i]);
+               
+               if (!unswap) srcKey->keyLength = SWAP_BE16(srcKey->keyLength);
+               srcRec = (HFSPlusAttrRecord *)((char *)srcKey + srcKey->keyLength + 2);
+               if (unswap) srcKey->keyLength = SWAP_BE16(srcKey->keyLength);
+               
+               srcKey->fileID = SWAP_BE32(srcKey->fileID);
+               srcKey->startBlock = SWAP_BE32(srcKey->startBlock);
+               
+               if (!unswap) srcKey->attrNameLen = SWAP_BE16(srcKey->attrNameLen);
+               for (j = 0; j < srcKey->attrNameLen; j++)
+                       srcKey->attrName[j] = SWAP_BE16(srcKey->attrName[j]);
+               if (unswap) srcKey->attrNameLen = SWAP_BE16(srcKey->attrNameLen);
+               
+               /* If this is an index node, just swap the child node number */
+            if (srcDesc->kind == kBTIndexNode) {
+                *((UInt32 *)srcRec) = SWAP_BE32 (*((UInt32 *)srcRec));
+                continue;
+            }
+            
+            /* Swap the data record */
+            if (!unswap) srcRec->recordType = SWAP_BE32(srcRec->recordType);
+            switch (srcRec->recordType) {
+               case kHFSPlusAttrInlineData:
+                       /* We're not swapping the reserved fields */
+                       srcRec->attrData.attrSize = SWAP_BE32(srcRec->attrData.attrSize);
+                       /* Not swapping the attrData */
+                       break;
+               case kHFSPlusAttrForkData:
+                       /* We're not swapping the reserved field */
+                       hfs_swap_HFSPlusForkData(&srcRec->forkData.theFork);
+                       break;
+               case kHFSPlusAttrExtents:
+                       /* We're not swapping the reserved field */
+                       for (j = 0; j < kHFSPlusExtentDensity; j++) {
+                               srcRec->overflowExtents.extents[j].startBlock =
+                                       SWAP_BE32(srcRec->overflowExtents.extents[j].startBlock);
+                               srcRec->overflowExtents.extents[j].blockCount =
+                                       SWAP_BE32(srcRec->overflowExtents.extents[j].blockCount);
+                       }
+                       break;
+            }
+            if (unswap) srcRec->recordType = SWAP_BE32(srcRec->recordType);
+       }
+    } else if (fileID > kHFSFirstUserCatalogNodeID) {
+               HotFileKey *srcKey;
+               UInt32 *srcRec;
+        
+               for (i = 0; i < srcDesc->numRecords; i++) {
+                       srcKey = (HotFileKey *)((char *)src->buffer + srcOffs[i]);
+
+                       if (!unswap)
+                               srcKey->keyLength = SWAP_BE16 (srcKey->keyLength);
+                       srcRec = (u_int32_t *)((char *)srcKey + srcKey->keyLength + 2);
+                       if (unswap)
+                               srcKey->keyLength = SWAP_BE16 (srcKey->keyLength);
+
+                       /* Don't swap srcKey->forkType */
+                       /* Don't swap srcKey->pad */
+
+                       srcKey->temperature = SWAP_BE32 (srcKey->temperature);
+                       srcKey->fileID = SWAP_BE32 (srcKey->fileID);
+             
+                       *((UInt32 *)srcRec) = SWAP_BE32 (*((UInt32 *)srcRec));
+               }
     } else {
         panic ("%s unrecognized B-Tree type", "hfs_swap_BTNode:");
     }
 
+
     return (0);
 }
 
@@ -383,9 +446,6 @@ hfs_swap_HFSBTInternalNode (
     UInt32 i;
     UInt32 j;
 
-    DBG_FUNC_NAME("hfs_swap_HFSBTInternalNode");
-    DBG_PRINT_FUNC_NAME();
-
     if (fileID == kHFSExtentsFileID) {
         HFSExtentKey *srcKey;
         HFSExtentDescriptor *srcRec;