Changeset 1873
- Timestamp:
- 3/1/2010 9:52:43 AM (2 years ago)
- Location:
- trunk/eraser6/Eraser.Util
- Files:
-
- 2 edited
-
NtfsApi.cs (modified) (3 diffs)
-
VolumeInfo.cs (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser6/Eraser.Util/NtfsApi.cs
r1859 r1873 38 38 public static long GetMftValidSize(VolumeInfo volume) 39 39 { 40 return GetNtfsVolumeData(volume).MftValidDataLength; 40 NativeMethods.NTFS_VOLUME_DATA_BUFFER? volumeData = GetNtfsVolumeData(volume); 41 if (volumeData == null) 42 throw Win32ErrorCode.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); 43 44 return volumeData.Value.MftValidDataLength; 41 45 } 42 46 … … 48 52 public static long GetMftRecordSegmentSize(VolumeInfo volume) 49 53 { 50 try 51 { 52 return GetNtfsVolumeData(volume).BytesPerFileRecordSegment; 53 } 54 catch (UnauthorizedAccessException) 55 { 54 NativeMethods.NTFS_VOLUME_DATA_BUFFER? volumeData = GetNtfsVolumeData(volume); 55 if (volumeData == null) 56 56 return Math.Min(volume.ClusterSize, 1024); 57 } 57 58 return volumeData.Value.BytesPerFileRecordSegment; 58 59 } 59 60 … … 64 65 /// <param name="volume">The volume to query.</param> 65 66 /// <returns>The NTFS_VOLUME_DATA_BUFFER structure representing the data 66 /// file systme structures for the volume.</returns> 67 /// <exception cref="UnauthorizedAccessException">Thrown when the current user 68 /// does not have the permissions required to obtain the volume information.</exception> 69 internal static NativeMethods.NTFS_VOLUME_DATA_BUFFER GetNtfsVolumeData(VolumeInfo volume) 67 /// file system structures for the volume, or null if the data could not be 68 /// retrieved.</returns> 69 internal static NativeMethods.NTFS_VOLUME_DATA_BUFFER? GetNtfsVolumeData(VolumeInfo volume) 70 70 { 71 71 using (SafeFileHandle volumeHandle = volume.OpenHandle( 72 72 FileAccess.Read, FileShare.ReadWrite, FileOptions.None)) 73 73 { 74 if (volumeHandle.IsInvalid) 75 return null; 76 74 77 uint resultSize = 0; 75 78 NativeMethods.NTFS_VOLUME_DATA_BUFFER volumeData = -
trunk/eraser6/Eraser.Util/VolumeInfo.cs
r1867 r1873 620 620 //Check that the handle is valid 621 621 if (handle.IsInvalid) 622 throw Win32ErrorCode.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); 622 { 623 int errorCode = Marshal.GetLastWin32Error(); 624 handle.Close(); 625 throw Win32ErrorCode.GetExceptionForWin32Error(errorCode); 626 } 623 627 624 628 //Return the FileStream … … 660 664 if (openPath.Length > 0 && openPath[openPath.Length - 1] == '\\') 661 665 openPath = openPath.Remove(openPath.Length - 1); 662 SafeFileHandle result = NativeMethods.CreateFile(openPath, access, 663 (uint)share, IntPtr.Zero, (uint)FileMode.Open, (uint)options, IntPtr.Zero); 664 if (result.IsInvalid) 665 { 666 int errorCode = Marshal.GetLastWin32Error(); 667 result.Close(); 668 throw Win32ErrorCode.GetExceptionForWin32Error(errorCode); 669 } 670 671 return result; 666 return NativeMethods.CreateFile(openPath, access, (uint)share, IntPtr.Zero, 667 (uint)FileMode.Open, (uint)options, IntPtr.Zero); 672 668 } 673 669
Note: See TracChangeset
for help on using the changeset viewer.
