/// <summary> /// Fetch a directory to build the internal index (recursive) /// </summary> private void AddDirectoryToIndex(DataTrackIndexEntry indexDirectoryEntry) { DirectoryEntry entry; DataTrackIndexEntry indexEntry; long lba = indexDirectoryEntry.DirectoryEntry.ExtentLba; long size = indexDirectoryEntry.DirectoryEntry.ExtentSize; int sectorsCount = (int)(size / GetSectorDataSize(_defaultSectorMode)); var stream = new CBinaryReader(ReadSectors(lba, sectorsCount, _defaultSectorMode)); // First directory entry of a directory entry is the directory itself, so let's skip it ReadDirectoryEntry(stream); // Second directory entry is the parent directory entry. // As we parse the data from root to children, it has already been handled, so let's skip it too ReadDirectoryEntry(stream); while (stream.Position < size) { short b = stream.TestByte(); if (b == 0) { // DirectoryEntry cannot be "splitted" on two sectors int dataSize = GetSectorDataSize(_defaultSectorMode); stream.Position = (((stream.Position / dataSize) + 1) * dataSize); b = stream.TestByte(); } if (b <= 0) { break; } else { entry = ReadDirectoryEntry(stream); indexEntry = new DataTrackIndexEntry(indexDirectoryEntry, entry); _index.AddToIndex(indexEntry); if (indexEntry.IsDirectory) { AddDirectoryToIndex(indexEntry); } } } stream.CloseAndDispose(); }