private ExtentBlock LoadExtentBlock(ExtentIndex idxEntry) { uint blockSize = _context.SuperBlock.BlockSize; _context.RawStream.Position = idxEntry.LeafPhysicalBlock * blockSize; byte[] buffer = Utilities.ReadFully(_context.RawStream, (int)blockSize); ExtentBlock subBlock = Utilities.ToStruct <ExtentBlock>(buffer, 0); return(subBlock); }
private Extent FindExtent(ExtentBlock node, uint logicalBlock) { if (node.Index != null) { ExtentIndex idxEntry = null; if (node.Index.Length == 0) { return(null); } else if (node.Index[0].FirstLogicalBlock >= logicalBlock) { idxEntry = node.Index[0]; } else { for (int i = 0; i < node.Index.Length; ++i) { if (node.Index[i].FirstLogicalBlock > logicalBlock) { idxEntry = node.Index[i - 1]; break; } } } if (idxEntry == null) { idxEntry = node.Index[node.Index.Length - 1]; } ExtentBlock subBlock = LoadExtentBlock(idxEntry); return(FindExtent(subBlock, logicalBlock)); } else if (node.Extents != null) { Extent entry = null; if (node.Extents.Length == 0) { return(null); } else if (node.Extents[0].FirstLogicalBlock >= logicalBlock) { return(node.Extents[0]); } else { for (int i = 0; i < node.Extents.Length; ++i) { if (node.Extents[i].FirstLogicalBlock > logicalBlock) { entry = node.Extents[i - 1]; break; } } } if (entry == null) { entry = node.Extents[node.Extents.Length - 1]; } return(entry); } else { return(null); } }