private void GetDiskSections() { _sections = new List <PhysicalDiskSection>(); try { _masterBootRecord = new MasterBootRecord(this); _sections.Add(_masterBootRecord); ulong offset = MasterBootRecord.MBR_SIZE; foreach (MasterBootRecord.PartitionEntry pEntry in _masterBootRecord.PartitionEntries) { if (pEntry.PartitionOffset > offset) { _sections.Add(new UnallocatedDiskArea(this, offset, pEntry.PartitionOffset - offset)); } if (offset > pEntry.PartitionOffset) { throw new Exception("Something went wrong!"); } _sections.Add(new PhysicalDiskPartition(this, pEntry)); offset = pEntry.PartitionOffset + pEntry.PartitionLength; } if (StreamLength > offset) { _sections.Add(new UnallocatedDiskArea(this, offset, StreamLength - offset)); } } catch (Exception) { } }
public PhysicalDiskPartition(WinPhysicalDisk disk, MasterBootRecord.PartitionEntry pEntry) { PhysicalDisk = disk; Offset = pEntry.PartitionOffset; Length = pEntry.PartitionLength; ManagementScope ms = new ManagementScope(); ObjectQuery oq = new ObjectQuery( string.Format("SELECT * FROM Win32_DiskPartition WHERE DiskIndex = {0} AND Index = {1}", disk.Attributes.Index, pEntry.Index)); ManagementObjectSearcher mos = new ManagementObjectSearcher(ms, oq); ManagementObjectCollection moc = mos.Get(); if (moc.Count != 1) { throw new Exception("Unable to get partition data from WMI"); } foreach (ManagementObject mo in moc) { Attributes = new PhysicalDiskPartitionAttributes(mo, disk); break; } Attributes.PartitionType = pEntry.PartitionType; _fileSystem = FileSystem.TryLoad(this as IFileSystemStore); }
private void GetDiskSections() { _sections = new List<PhysicalDiskSection>(); try { _masterBootRecord = new MasterBootRecord(this); _sections.Add(_masterBootRecord); ulong offset = MasterBootRecord.MBR_SIZE; foreach (MasterBootRecord.PartitionEntry pEntry in _masterBootRecord.PartitionEntries) { if (pEntry.PartitionOffset > offset) { _sections.Add(new UnallocatedDiskArea(this, offset, pEntry.PartitionOffset - offset)); } if (offset > pEntry.PartitionOffset) { throw new Exception("Something went wrong!"); } _sections.Add(new PhysicalDiskPartition(this, pEntry)); offset = pEntry.PartitionOffset + pEntry.PartitionLength; } if (StreamLength > offset) { _sections.Add(new UnallocatedDiskArea(this, offset, StreamLength - offset)); } } catch (Exception) { } }