Changeset 2162


Ignore:
Timestamp:
6/13/2010 3:33:06 AM (2 years ago)
Author:
lowjoel
Message:

For erasing old file system table resident files:

  • Rewritten algorithm which is faster than the previous one
  • Reset all temporary files' times since they will be simply deleted during the free space erase

For erasing directory structures:

  • Reset all temporary files' times so that we can use the faster folder delete instead of the deep erase
File:
1 edited

Legend:

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

    r2157 r2162  
    5151            FileSystemEntriesEraseProgress callback) 
    5252        { 
     53            //Squeeze files smaller than one MFT record until the volume and the MFT is full. 
     54            long MFTRecordSize = NtfsApi.GetMftRecordSegmentSize(volume); 
     55            long lastFileSize = MFTRecordSize; 
     56 
    5357            try 
    5458            { 
    55                 //Squeeze one-byte files until the volume or the MFT is full. 
    56                 long oldMFTSize = NtfsApi.GetMftValidSize(volume); 
    57  
    5859                for ( ; ; ) 
    5960                { 
    6061                    //Open this stream 
    61                     using (FileStream strm = new FileStream( 
    62                         GenerateRandomFileName(tempDirectory, 18), FileMode.CreateNew, 
    63                         FileAccess.Write, FileShare.None, 8, FileOptions.WriteThrough)) 
    64                     { 
    65                         long streamSize = 0; 
    66                         try 
    67                         { 
    68                             while (true) 
    69                             { 
    70                                 //Stretch the file size to use up some of the resident space. 
    71                                 strm.SetLength(++streamSize); 
    72  
    73                                 //Then run the erase task 
    74                                 method.Erase(strm, long.MaxValue, 
    75                                     ManagerLibrary.Instance.PrngRegistrar[ManagerLibrary.Settings.ActivePrng], 
    76                                     null); 
    77  
    78                                 //Call the callback function if one is provided. We'll provide a dummy 
    79                                 //value since we really have no idea how much of the MFT we can clean. 
    80                                 if (callback != null) 
    81                                     callback(0, 1); 
    82                             } 
    83                         } 
    84                         catch (IOException) 
    85                         { 
    86                             if (streamSize == 1) 
    87                                 return; 
    88                         } 
    89                     } 
    90  
    91                     //We can stop when the MFT has grown. 
    92                     if (NtfsApi.GetMftValidSize(volume) > oldMFTSize) 
    93                         break; 
     62                    string fileName = GenerateRandomFileName(tempDirectory, 18); 
     63                    FileStream strm = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write, 
     64                        FileShare.None, 8, FileOptions.WriteThrough); 
     65                    try 
     66                    { 
     67                        //Stretch the file size to use up some of the resident space. 
     68                        strm.SetLength(lastFileSize); 
     69 
     70                        //Then run the erase task 
     71                        method.Erase(strm, long.MaxValue, ManagerLibrary.Instance.PrngRegistrar[ 
     72                                ManagerLibrary.Settings.ActivePrng], null); 
     73 
     74                        //Call the callback function if one is provided. We'll provide a dummy 
     75                        //value since we really have no idea how much of the MFT we can clean. 
     76                        if (callback != null) 
     77                            callback((int)(MFTRecordSize - lastFileSize), (int)MFTRecordSize); 
     78                    } 
     79                    catch (IOException) 
     80                    { 
     81                        if (lastFileSize-- == 0) 
     82                            break; 
     83                    } 
     84                    finally 
     85                    { 
     86                        //Close the stream handle 
     87                        strm.Close(); 
     88 
     89                        //Then reset the time the file was created. 
     90                        ResetFileTimes(new FileInfo(fileName)); 
     91                    } 
    9492                } 
    9593            } 
     
    120118                { 
    121119                    ++filesCreated; 
    122                     using (FileStream strm = new FileStream(FileSystem.GenerateRandomFileName( 
    123                         tempDir, 220), FileMode.CreateNew, FileAccess.Write)) 
    124                     { 
    125                     } 
     120                    string fileName = GenerateRandomFileName(tempDir, 220); 
     121                    File.Create(fileName).Close(); 
     122                    ResetFileTimes(new FileInfo(fileName)); 
    126123 
    127124                    if (filesCreated % pollingInterval == 0) 
     
    152149                    if (callback != null && i % 50 == 0) 
    153150                        callback(files.Length + i, files.Length * 2); 
    154                     DeleteFile(files[i]); 
     151                    files[i].Delete(); 
    155152                } 
    156153 
Note: See TracChangeset for help on using the changeset viewer.