public HFSPlusCatalogFile getCatalogFileWithKey(HFSPlusCatalogKey recordKeyID) { HFSPlusCatalogFile result; byte[] nodeRawData = new byte[this.nodeSize]; uint currentNodeNumber = this.header.headerInfo.rootNode; fs.Seek(currentNodeNumber * this.nodeSize, SeekOrigin.Begin); fs.Read(nodeRawData, 0, this.nodeSize); absNode.nodeType currentNodeType = getNodeType(currentNodeNumber); uint leafNodeNumber = getLeafNodeContainingRecord(recordKeyID); fs.Seek(leafNodeNumber * this.nodeSize, SeekOrigin.Begin); fs.Read(nodeRawData, 0, this.nodeSize); catalogLeafNode leafNode = new catalogLeafNode(ref nodeRawData); foreach (HFSPlusCatalogFile leafRecord in leafNode.fileRecords) { if (dataOperations.keyCompareResult.equalsTrialKey == catalogKeyCompare(leafRecord.key, recordKeyID, this.header.headerInfo.keyCompareType == 0xBC)) { result = leafRecord; return(result); } } throw new Exception("The specified search key was not found."); }
public extentsOverflowLeafNode.extentsOverflowLeafRecord getExtentRecordWithKey(HFSPlusExtentKey recordKeyID) { extentsOverflowLeafNode.extentsOverflowLeafRecord result; byte[] nodeRawData = new byte[this.nodeSize]; uint currentNodeNumber = this.header.headerInfo.rootNode; absNode.nodeType currentNodeType = getNodeType(currentNodeNumber); // until a leaf node is found while (currentNodeType != absNode.nodeType.leaf) { fs.Seek(currentNodeNumber * this.nodeSize, SeekOrigin.Begin); fs.Read(nodeRawData, 0, this.nodeSize); extentsOverflowIndexNode currentNode = new extentsOverflowIndexNode(ref nodeRawData); extentsOverflowIndexNode.extentsOverflowIndexRecord perhapsThisRecord = currentNode.records[0]; // finds the subtree that contains the desired record and follows it foreach (extentsOverflowIndexNode.extentsOverflowIndexRecord record in currentNode.records) { bool equalsSearch = extentsOverflowKeyCompare(record.extentKey, recordKeyID) == dataOperations.keyCompareResult.equalsTrialKey; bool lessThanSearch = extentsOverflowKeyCompare(record.extentKey, recordKeyID) == dataOperations.keyCompareResult.greaterThanTrialKey; bool greaterThanOrEqualToBestKnown = extentsOverflowKeyCompare(record.extentKey, perhapsThisRecord.extentKey) == dataOperations.keyCompareResult.lessThanTrialKey || extentsOverflowKeyCompare(record.extentKey, perhapsThisRecord.extentKey) == dataOperations.keyCompareResult.equalsTrialKey; if (lessThanSearch && greaterThanOrEqualToBestKnown || equalsSearch) { perhapsThisRecord = record; } } currentNodeNumber = perhapsThisRecord.pointer; currentNodeType = (absNode.nodeType)getNodeType(currentNodeNumber); } // once the leaf node is found, compile the data from it and return that node fs.Seek(currentNodeNumber * this.nodeSize, SeekOrigin.Begin); fs.Read(nodeRawData, 0, this.nodeSize); extentsOverflowLeafNode leafNode = new extentsOverflowLeafNode(ref nodeRawData); foreach (extentsOverflowLeafNode.extentsOverflowLeafRecord leafRecord in leafNode.records) { if (dataOperations.keyCompareResult.equalsTrialKey == extentsOverflowKeyCompare(leafRecord.key, recordKeyID)) { result = leafRecord; return(result); } } throw new Exception("The specified search key was not found."); }
public attributesLeafNode.HFSPlusAttrInlineData getAttriInlineDataWithKey(HFSPlusAttrKey recordKeyID, bool caseSensitiveCompare = false) { byte[] nodeRawData = new byte[this.nodeSize]; attributesLeafNode.HFSPlusAttrInlineData result = new attributesLeafNode.HFSPlusAttrInlineData(); // find the root node uint currentNodeNumber = this.header.headerInfo.rootNode; fs.Seek(currentNodeNumber * this.nodeSize, SeekOrigin.Begin); fs.Read(nodeRawData, 0, this.nodeSize); absNode.nodeType currentNodeType = getNodeType(currentNodeNumber); bool found = false; // get the leaf if (this.header.headerInfo.rootNode > 0) { uint leafRecordNumber = getLeafNodeContainingRecord(recordKeyID); fs.Seek(leafRecordNumber * this.nodeSize, SeekOrigin.Begin); fs.Read(nodeRawData, 0, this.nodeSize); attributesLeafNode leafNode = new attributesLeafNode(ref nodeRawData); foreach (attributesLeafNode.HFSPlusAttrInlineData leafRecord in leafNode.inlineRecords) { if (dataOperations.keyCompareResult.equalsTrialKey == attrKeyCompare(leafRecord.key, recordKeyID, caseSensitiveCompare) && found == false) { result = leafRecord; found = true; } } } if (found) { return(result); } else { throw new KeyNotFoundException(); } }
private uint getLeafNodeContainingRecord(HFSPlusAttrKey recordKeyID) { byte[] nodeRawData = new byte[this.nodeSize]; uint currentNodeNumber = this.header.headerInfo.rootNode; absNode.nodeType currentNodeType = getNodeType(currentNodeNumber); // why is currentNodeType showing as 255 when it should be -1? while (currentNodeType != absNode.nodeType.leaf) { fs.Seek(currentNodeNumber * this.nodeSize, SeekOrigin.Begin); fs.Read(nodeRawData, 0, this.nodeSize); attributesIndexNode currentNode = new attributesIndexNode(ref nodeRawData); attributesIndexNode.attrIndexRecord perhapsThisRecord = currentNode.records[0]; foreach (attributesIndexNode.attrIndexRecord record in currentNode.records) { bool equalsSearch = attrKeyCompare(record.attrKey, recordKeyID, this.header.headerInfo.keyCompareType == 0xBC) == dataOperations.keyCompareResult.equalsTrialKey; bool lessThanSearch = attrKeyCompare(record.attrKey, recordKeyID, this.header.headerInfo.keyCompareType == 0xBC) == dataOperations.keyCompareResult.greaterThanTrialKey; bool greaterThanOrEqualToBestKnown = attrKeyCompare(record.attrKey, perhapsThisRecord.attrKey, this.header.headerInfo.keyCompareType == 0xBC) == dataOperations.keyCompareResult.lessThanTrialKey || attrKeyCompare(record.attrKey, perhapsThisRecord.attrKey, this.header.headerInfo.keyCompareType == 0xBC) == dataOperations.keyCompareResult.equalsTrialKey; if (equalsSearch) { return(record.pointer); } else if (lessThanSearch && greaterThanOrEqualToBestKnown) { perhapsThisRecord = record; } } currentNodeNumber = perhapsThisRecord.pointer; currentNodeType = (absNode.nodeType)getNodeType(currentNodeNumber); } return(currentNodeNumber); }
private uint getLeafNodeContainingRecord(HFSPlusCatalogKey recordKeyID) { byte[] nodeRawData = new byte[this.nodeSize]; uint currentNodeNumber = this.header.headerInfo.rootNode; absNode.nodeType currentNodeType = getNodeType(currentNodeNumber); while (currentNodeType != absNode.nodeType.leaf) { fs.Seek(currentNodeNumber * this.nodeSize, SeekOrigin.Begin); fs.Read(nodeRawData, 0, this.nodeSize); catalogIndexNode currentNode = new catalogIndexNode(ref nodeRawData); catalogIndexNode.catalogIndexRecord perhapsThisRecord = currentNode.records[0]; // find out which pointer to follow foreach (catalogIndexNode.catalogIndexRecord record in currentNode.records) { bool equalsSearch = catalogKeyCompare(record.catalogKey, recordKeyID, this.header.headerInfo.keyCompareType == 0xBC) == dataOperations.keyCompareResult.equalsTrialKey; bool lessThanSearch = catalogKeyCompare(record.catalogKey, recordKeyID, this.header.headerInfo.keyCompareType == 0xBC) == dataOperations.keyCompareResult.greaterThanTrialKey; bool greaterThanOrEqualToBestKnown = catalogKeyCompare(record.catalogKey, perhapsThisRecord.catalogKey, this.header.headerInfo.keyCompareType == 0xBC) == dataOperations.keyCompareResult.lessThanTrialKey || catalogKeyCompare(record.catalogKey, perhapsThisRecord.catalogKey, this.header.headerInfo.keyCompareType == 0xBC) == dataOperations.keyCompareResult.equalsTrialKey; if (lessThanSearch && greaterThanOrEqualToBestKnown || equalsSearch) { perhapsThisRecord = record; } } currentNodeNumber = perhapsThisRecord.pointer; currentNodeType = (absNode.nodeType)getNodeType(currentNodeNumber); } // send back pointer return(currentNodeNumber); }
public attributesLeafNode.attributesDataForFile getAttrFileDataWithKey(HFSPlusAttrKey recordKeyID, bool caseSensitiveCompare = false) { byte[] nodeRawData = new byte[this.nodeSize]; attributesLeafNode.attributesDataForFile allAttributes = new attributesLeafNode.attributesDataForFile(); allAttributes.inline = new List <attributesLeafNode.HFSPlusAttrInlineData>(); allAttributes.forks = new List <attributesLeafNode.HFSPlusAttrForkData>(); // find the root node uint currentNodeNumber = this.header.headerInfo.rootNode; fs.Seek(currentNodeNumber * this.nodeSize, SeekOrigin.Begin); fs.Read(nodeRawData, 0, this.nodeSize); absNode.nodeType currentNodeType = getNodeType(currentNodeNumber); // find the leaf where records matching this key start if (this.header.headerInfo.rootNode > 0) { uint leafRecordNumber = getLeafNodeContainingRecord(recordKeyID); fs.Seek(leafRecordNumber * this.nodeSize, SeekOrigin.Begin); fs.Read(nodeRawData, 0, this.nodeSize); attributesLeafNode leafNode = new attributesLeafNode(ref nodeRawData); bool allDataFound = false; while (!allDataFound) { int recordsAdded = 0; foreach (attributesLeafNode.HFSPlusAttrForkData leafRecord in leafNode.forkDataRecords) { if (dataOperations.keyCompareResult.equalsTrialKey == attrKeyCompare(leafRecord.key, recordKeyID, caseSensitiveCompare)) { allAttributes.forks.Add(leafRecord); recordsAdded++; } } foreach (attributesLeafNode.HFSPlusAttrExtents leafRecord in leafNode.extentsRecords) { if (dataOperations.keyCompareResult.equalsTrialKey == attrKeyCompare(leafRecord.key, recordKeyID, caseSensitiveCompare)) { // find out which forkdata record to add the extent to foreach (attributesLeafNode.HFSPlusAttrForkData fork in allAttributes.forks) { if (fork.key.fileID == leafRecord.key.fileID && fork.key.attrName == leafRecord.key.attrName) { // then add all the extents in the record for (int i = 0; i < leafRecord.extents.Count(); i++) { fork.theFork.forkDataValues.extents.Add(leafRecord.extents[i]); } } } recordsAdded++; } } foreach (attributesLeafNode.HFSPlusAttrInlineData leafRecord in leafNode.inlineRecords) { if (dataOperations.keyCompareResult.equalsTrialKey == attrKeyCompare(leafRecord.key, recordKeyID, caseSensitiveCompare)) { allAttributes.inline.Add(leafRecord); recordsAdded++; } } // if the last record in the node matches the search key, there may be more matching records in the next node // if the node is the last leaf node, its flink will be 0 if (attrKeyCompare(buildAttrTrialKey(leafNode.rawRecords[leafNode.rawRecords.Count() - 1]), recordKeyID, caseSensitiveCompare) == dataOperations.keyCompareResult.equalsTrialKey && leafNode.BTNodeDescriptor.fLink > 0) { uint nextNode = leafNode.BTNodeDescriptor.fLink; fs.Seek(nextNode * this.nodeSize, SeekOrigin.Begin); fs.Read(nodeRawData, 0, this.nodeSize); leafNode = new attributesLeafNode(ref nodeRawData); } else { allDataFound = true; } //if (!allDataFound && recordsAdded == 0) //{ // throw new Exception("The specified search key was not found."); //} } } return(allAttributes); }