Changeset 2187 for trunk/eraser/Eraser.Util/PhysicalDriveInfo.cs
- Timestamp:
- 6/18/2010 11:33:59 AM (2 years ago)
- File:
-
- 1 edited
-
trunk/eraser/Eraser.Util/PhysicalDriveInfo.cs (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser/Eraser.Util/PhysicalDriveInfo.cs
r2186 r2187 65 65 for (int i = 0; ; ++i) 66 66 { 67 using (SafeFileHandle handle = OpenWin32Device(GetDiskPath(i))) 67 using (SafeFileHandle handle = OpenWin32Device(GetDiskPath(i), 68 NativeMethods.FILE_READ_ATTRIBUTES)) 68 69 { 69 70 if (handle.IsInvalid) … … 82 83 /// </summary> 83 84 /// <param name="deviceName">The name of the device to open.</param> 85 /// <param name="access">The access needed for the handle.</param> 84 86 /// <returns>A <see cref="SafeFileHandle"/> to the device.</returns> 85 private static SafeFileHandle OpenWin32Device(string deviceName )87 private static SafeFileHandle OpenWin32Device(string deviceName, uint access) 86 88 { 87 89 //Define the DOS device name for access … … 100 102 //Open the device handle. 101 103 return NativeMethods.CreateFile(string.Format(CultureInfo.InvariantCulture, 102 "\\\\.\\{0}", dosDeviceName), NativeMethods.FILE_READ_ATTRIBUTES,104 "\\\\.\\{0}", dosDeviceName), access, 103 105 NativeMethods.FILE_SHARE_READ | NativeMethods.FILE_SHARE_WRITE, IntPtr.Zero, 104 106 (int)FileMode.Open, (uint)FileAttributes.ReadOnly, IntPtr.Zero); … … 131 133 { 132 134 string path = GetPartitionPath(i); 133 using (SafeFileHandle handle = OpenWin32Device(path)) 135 using (SafeFileHandle handle = OpenWin32Device(path, 136 NativeMethods.FILE_READ_ATTRIBUTES)) 134 137 { 135 138 if (handle.IsInvalid) … … 161 164 162 165 /// <summary> 166 /// Gets the size of the disk, in bytes. 167 /// </summary> 168 public long Size 169 { 170 get 171 { 172 using (SafeFileHandle handle = OpenWin32Device(GetDiskPath(), 173 NativeMethods.GENERIC_READ)) 174 { 175 if (handle.IsInvalid) 176 throw Win32ErrorCode.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); 177 178 long result = 0; 179 uint returned = 0; 180 if (NativeMethods.DeviceIoControl(handle, NativeMethods.IOCTL_DISK_GET_LENGTH_INFO, 181 IntPtr.Zero, 0, out result, out returned, IntPtr.Zero)) 182 { 183 return result; 184 } 185 186 throw Win32ErrorCode.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); 187 } 188 } 189 } 190 191 /// <summary> 163 192 /// The format string for accessing partitions. 164 193 /// </summary>
Note: See TracChangeset
for help on using the changeset viewer.
