Changeset 1859


Ignore:
Timestamp:
3/1/2010 2:57:41 AM (5 years ago)
Author:
lowjoel
Message:

For NTFS MFT Record lengths we need volume (data) read access so instead catch unauthorized access exceptions (i.e. when running under a split user token in 7) and return using the heuristic of one of volume cluster size and 1024 bytes, whichever is smaller

Location:
trunk/eraser6
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser6/Eraser.DefaultPlugins/FileSystems/Ntfs.cs

    r1802 r1859  
    165165            //TODO: any more deterministic way of finding out? 
    166166            VolumeInfo volume = VolumeInfo.FromMountPoint(info.DirectoryName); 
    167             if (info.Length < Math.Max(volume.ClusterSize, 1024)) 
     167            if (info.Length < NtfsApi.GetMftRecordSegmentSize(volume)) 
    168168            { 
    169169                //Yes it does, erase exactly to the file length 
  • trunk/eraser6/Eraser.Util/NativeMethods/Kernel.cs

    r1841 r1859  
    383383        } 
    384384 
    385         [DllImport("Kernel32.dll", CharSet = CharSet.Unicode)] 
     385        [DllImport("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] 
    386386        [return: MarshalAs(UnmanagedType.Bool)] 
    387387        public static extern bool DeviceIoControl(SafeFileHandle hDevice, 
  • trunk/eraser6/Eraser.Util/NtfsApi.cs

    r1843 r1859  
    4848        public static long GetMftRecordSegmentSize(VolumeInfo volume) 
    4949        { 
    50             return GetNtfsVolumeData(volume).BytesPerFileRecordSegment; 
     50            try 
     51            { 
     52                return GetNtfsVolumeData(volume).BytesPerFileRecordSegment; 
     53            } 
     54            catch (UnauthorizedAccessException) 
     55            { 
     56                return Math.Min(volume.ClusterSize, 1024); 
     57            } 
    5158        } 
    5259 
     
    5865        /// <returns>The NTFS_VOLUME_DATA_BUFFER structure representing the data 
    5966        /// 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> 
    6069        internal static NativeMethods.NTFS_VOLUME_DATA_BUFFER GetNtfsVolumeData(VolumeInfo volume) 
    6170        { 
    6271            using (SafeFileHandle volumeHandle = volume.OpenHandle( 
    63                 NativeMethods.FILE_READ_ATTRIBUTES, FileShare.ReadWrite, FileOptions.None)) 
     72                FileAccess.Read, FileShare.ReadWrite, FileOptions.None)) 
    6473            { 
    6574                uint resultSize = 0; 
Note: See TracChangeset for help on using the changeset viewer.