Changeset 2180 for trunk/eraser/Eraser.Util/PhysicalDriveInfo.cs
- Timestamp:
- 6/18/2010 9:33:10 AM (2 years ago)
- File:
-
- 1 edited
-
trunk/eraser/Eraser.Util/PhysicalDriveInfo.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser/Eraser.Util/PhysicalDriveInfo.cs
r2174 r2180 127 127 get 128 128 { 129 //Get all registered DOS Device names. 130 string[] dosDevices = NativeMethods.QueryDosDevices(); 129 List<VolumeInfo> result = new List<VolumeInfo>(); 131 130 132 //Get a list of Win32 device names, and map it to DOS Devices. 133 ComLib.Collections.DictionaryMultiValue<string, string> devices = 134 new ComLib.Collections.DictionaryMultiValue<string, string>(); 135 foreach (string dosDevice in dosDevices) 131 //Check every partition index on this drive. 132 for (int i = 1; ; ++i) 136 133 { 137 string win32Device = NativeMethods.QueryDosDevice(dosDevice); 138 if (win32Device != null) 139 devices.Add(win32Device, dosDevice); 140 } 134 string path = string.Format(CultureInfo.InvariantCulture, 135 "\\Device\\Harddisk{0}\\Partition{1}", Index, i); 136 using (SafeFileHandle handle = OpenWin32Device(path)) 137 { 138 if (handle.IsInvalid) 139 break; 140 } 141 141 142 List<VolumeInfo> result = new List<VolumeInfo>(); 143 foreach (VolumeInfo info in VolumeInfo.Volumes) 144 { 145 if (info.VolumeId.Substring(0, 4) == "\\\\?\\") 142 //This partition index is valid. Check which VolumeInfo this maps to. 143 foreach (VolumeInfo info in VolumeInfo.Volumes) 146 144 { 147 string win32Device = NativeMethods.QueryDosDevice( 148 info.VolumeId.Substring(4, info.VolumeId.Length - 5)); 149 foreach (string dosDevice in devices.Get(win32Device)) 145 //Only check local drives 146 if (info.VolumeId.Substring(0, 4) == "\\\\?\\") 150 147 { 151 Match match = HarddiskPartitionRegex.Match(dosDevice); 152 if (!match.Success) 153 continue; 154 155 //Check the HardDisk ID: if it is the same as our index, it is our partition. 156 if (Convert.ToInt32(match.Groups[1].Value) == Index) 148 //Check whether the DOS Device maps to the target of the symbolic link 149 if (NativeMethods.NtQuerySymbolicLink(path) == 150 NativeMethods.QueryDosDevice(info.VolumeId.Substring( 151 4, info.VolumeId.Length - 5))) 157 152 { 158 int partition = Convert.ToInt32(match.Groups[2].Value) - 1; 159 while (partition >= result.Count) 160 result.Add(null); 161 162 result[partition] = info; 153 //Yes, this volume belongs to this disk 154 result.Add(info); 155 break; 163 156 } 164 157 }
Note: See TracChangeset
for help on using the changeset viewer.
