protected override List<Disk> LoadDisksInternal() { List<Disk> res = new List<Disk>(); try { ManagementScope ms = new ManagementScope(); ObjectQuery oq = new ObjectQuery("SELECT * FROM Win32_DiskDrive"); ManagementObjectSearcher mos = new ManagementObjectSearcher(ms, oq); ManagementObjectCollection moc = mos.Get(); foreach (ManagementObject mo in moc) { WinPhysicalDisk disk = new WinPhysicalDisk(mo); res.Add(disk); } } catch (Exception e) { Console.Error.WriteLine(e); } return res; }
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); }
public PhysicalDiskPartitionAttributes(ManagementObject mo, WinPhysicalDisk disk) { BytesPerSector = disk.Attributes.BytesPerSector; Access = GetProperty <Access>(mo, "Access", Access.Unknown); Availability = GetProperty <Availability>(mo, "Availability", Availability.Unknown); BlockSize = GetProperty <ulong>(mo, "BlockSize", 0); Bootable = GetProperty <bool>(mo, "Bootable", false); BootPartition = GetProperty <bool>(mo, "BootPartition", false); Caption = GetProperty <string>(mo, "Caption", ""); ConfigManagerErrorCode = GetProperty <uint>(mo, "ConfigManagerErrorCode", 0); ConfigManagerUserConfig = GetProperty <bool>(mo, "ConfigManagerUserConfig", false); CreationClassName = GetProperty <string>(mo, "CreationClassName", ""); Description = GetProperty <string>(mo, "Description", ""); DeviceID = GetProperty <string>(mo, "DeviceID", ""); DiskIndex = GetProperty <uint>(mo, "DiskIndex", 0); ErrorCleared = GetProperty <bool>(mo, "ErrorCleared", false); ErrorDescription = GetProperty <string>(mo, "ErrorDescription", ""); ErrorMethodology = GetProperty <string>(mo, "ErrorMethodology", ""); HiddenSectors = GetProperty <uint>(mo, "HiddenSectors", 0); Index = GetProperty <uint>(mo, "Index", 0); InstallDate = GetProperty <DateTime>(mo, "InstallDate", DateTime.MinValue); LastErrorCode = GetProperty <uint>(mo, "LastErrorCode", 0); Name = GetProperty <string>(mo, "Name", ""); NumberOfBlocks = GetProperty <ulong>(mo, "NumberOfBlocks", 0); PNPDeviceID = GetProperty <string>(mo, "PNPDeviceID", ""); PowerManagementCapabilities = GetArray <PowerManagementCapability>(mo, "PowerManagementCapabilities", new PowerManagementCapability[0]); PowerManagementSupported = GetProperty <bool>(mo, "PowerManagementSupported", false); PrimaryPartition = GetProperty <bool>(mo, "PrimaryPartition", false); Purpose = GetProperty <string>(mo, "Purpose", ""); RewritePartition = GetProperty <bool>(mo, "RewritePartition", false); Size = GetProperty <ulong>(mo, "Size", 0); StartingOffset = GetProperty <ulong>(mo, "StartingOffset", 0); Status = GetProperty <string>(mo, "Status", ""); StatusInfo = GetProperty <StatusInfo>(mo, "StatusInfo", 0); SystemCreationClassName = GetProperty <string>(mo, "SystemCreationClassName", ""); SystemName = GetProperty <string>(mo, "SystemName", ""); Type = GetProperty <string>(mo, "Type", ""); }
public PhysicalDiskPartitionAttributes(ManagementObject mo, WinPhysicalDisk disk) { BytesPerSector = disk.Attributes.BytesPerSector; Access = GetProperty<Access>(mo, "Access", Access.Unknown); Availability = GetProperty<Availability>(mo, "Availability", Availability.Unknown); BlockSize = GetProperty<ulong>(mo, "BlockSize", 0); Bootable = GetProperty<bool>(mo, "Bootable", false); BootPartition = GetProperty<bool>(mo, "BootPartition", false); Caption = GetProperty<string>(mo, "Caption", ""); ConfigManagerErrorCode = GetProperty<uint>(mo, "ConfigManagerErrorCode", 0); ConfigManagerUserConfig = GetProperty<bool>(mo, "ConfigManagerUserConfig", false); CreationClassName = GetProperty<string>(mo, "CreationClassName", ""); Description = GetProperty<string>(mo, "Description", ""); DeviceID = GetProperty<string>(mo, "DeviceID", ""); DiskIndex = GetProperty<uint>(mo, "DiskIndex", 0); ErrorCleared = GetProperty<bool>(mo, "ErrorCleared", false); ErrorDescription = GetProperty<string>(mo, "ErrorDescription", ""); ErrorMethodology = GetProperty<string>(mo, "ErrorMethodology", ""); HiddenSectors = GetProperty<uint>(mo, "HiddenSectors", 0); Index = GetProperty<uint>(mo, "Index", 0); InstallDate = GetProperty<DateTime>(mo, "InstallDate", DateTime.MinValue); LastErrorCode = GetProperty<uint>(mo, "LastErrorCode", 0); Name = GetProperty<string>(mo, "Name", ""); NumberOfBlocks = GetProperty<ulong>(mo, "NumberOfBlocks", 0); PNPDeviceID = GetProperty<string>(mo, "PNPDeviceID", ""); PowerManagementCapabilities = GetArray<PowerManagementCapability>(mo, "PowerManagementCapabilities", new PowerManagementCapability[0]); PowerManagementSupported = GetProperty<bool>(mo, "PowerManagementSupported", false); PrimaryPartition = GetProperty<bool>(mo, "PrimaryPartition", false); Purpose = GetProperty<string>(mo, "Purpose", ""); RewritePartition = GetProperty<bool>(mo, "RewritePartition", false); Size = GetProperty<ulong>(mo, "Size", 0); StartingOffset = GetProperty<ulong>(mo, "StartingOffset", 0); Status = GetProperty<string>(mo, "Status", ""); StatusInfo = GetProperty<StatusInfo>(mo, "StatusInfo", 0); SystemCreationClassName = GetProperty<string>(mo, "SystemCreationClassName", ""); SystemName = GetProperty<string>(mo, "SystemName", ""); Type = GetProperty<string>(mo, "Type", ""); }
public MasterBootRecord(WinPhysicalDisk disk) { PhysicalDisk = disk; Offset = 0; Length = MBR_SIZE; _partitionEntries = new List<PartitionEntry>(); try { _data = disk.GetBytes(0, MBR_SIZE); } catch (Exception e) { throw new Exception("Failed to load the Master Boot Record!", e); } for (int i = 0; i < MAX_PARTITIONS; i++) { int offset = 0x1BE + 16 * i; if (PartitionEntryExistsAt(offset, 16)) { _partitionEntries.Add(new PartitionEntry(_data, offset, (int)disk.Attributes.BytesPerSector, i)); } } _partitionEntries.Sort(new Comparison<PartitionEntry>(delegate(PartitionEntry a, PartitionEntry b) { return a.PartitionOffset.CompareTo(b.PartitionOffset); })); }