Ignore:
Timestamp:
3/1/2010 9:52:43 AM (2 years ago)
Author:
lowjoel
Message:

Don't double error-handle in VolumeInfo?: The OpenHandle? and Open functions check for a valid file handle each, which is redundant. Since OpenHandle? is supposed to be called internally from the assembly, do no error checking and assume the calling function knows what it is doing. This can be seen in NtfsApi? where an exception has been replaced with an if-statement.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser6/Eraser.Util/NtfsApi.cs

    r1859 r1873  
    3838        public static long GetMftValidSize(VolumeInfo volume) 
    3939        { 
    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; 
    4145        } 
    4246 
     
    4852        public static long GetMftRecordSegmentSize(VolumeInfo volume) 
    4953        { 
    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) 
    5656                return Math.Min(volume.ClusterSize, 1024); 
    57             } 
     57 
     58            return volumeData.Value.BytesPerFileRecordSegment; 
    5859        } 
    5960 
     
    6465        /// <param name="volume">The volume to query.</param> 
    6566        /// <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) 
    7070        { 
    7171            using (SafeFileHandle volumeHandle = volume.OpenHandle( 
    7272                FileAccess.Read, FileShare.ReadWrite, FileOptions.None)) 
    7373            { 
     74                if (volumeHandle.IsInvalid) 
     75                    return null; 
     76 
    7477                uint resultSize = 0; 
    7578                NativeMethods.NTFS_VOLUME_DATA_BUFFER volumeData = 
Note: See TracChangeset for help on using the changeset viewer.