Changeset 2161
- Timestamp:
- 6/13/2010 3:30:16 AM (2 years ago)
- Location:
- trunk/eraser
- Files:
-
- 3 edited
-
Eraser.DefaultPlugins/ErasureTargets/UnusedSpaceErasureTarget.cs (modified) (2 diffs)
-
Eraser.DefaultPlugins/FileSystems/Windows.cs (modified) (2 diffs)
-
Eraser.Manager/FileSystem.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/eraser/Eraser.DefaultPlugins/ErasureTargets/UnusedSpaceErasureTarget.cs
r2092 r2161 231 231 Shell.LowDiskSpaceNotificationsEnabled = false; 232 232 233 ProgressManager mainProgress = new ProgressManager(); 234 Progress.Steps.Add(new SteppedProgressManagerStep(mainProgress, 235 EraseClusterTips ? 0.8f : 0.9f, S._("Erasing unused space..."))); 236 237 //Continue creating files while there is free space. 238 while (volInfo.AvailableFreeSpace > 0) 239 { 240 //Generate a non-existant file name 241 string currFile = FileSystem.GenerateRandomFileName(info, 18); 242 243 //Create the stream 244 using (FileStream stream = new FileStream(currFile, FileMode.CreateNew, 245 FileAccess.Write, FileShare.None, 8, FileOptions.WriteThrough)) 246 { 247 //Set the length of the file to be the amount of free space left 248 //or the maximum size of one of these dumps. 249 mainProgress.Total = mainProgress.Completed + 250 method.CalculateEraseDataSize(null, volInfo.AvailableFreeSpace); 251 long streamLength = Math.Min(ErasureMethod.FreeSpaceFileUnit, 252 volInfo.AvailableFreeSpace); 253 254 //Handle IO exceptions gracefully, because the filesystem 255 //may require more space than demanded by us for file allocation. 256 while (true) 257 try 258 { 259 stream.SetLength(streamLength); 260 break; 261 } 262 catch (IOException) 263 { 264 if (streamLength > volInfo.ClusterSize) 265 streamLength -= volInfo.ClusterSize; 266 else 267 throw; 268 } 269 270 //Then run the erase task 271 method.Erase(stream, long.MaxValue, 272 ManagerLibrary.Instance.PrngRegistrar[ManagerLibrary.Settings.ActivePrng], 273 delegate(long lastWritten, long totalData, int currentPass) 274 { 275 mainProgress.Completed += lastWritten; 276 OnProgressChanged(this, new ProgressChangedEventArgs(mainProgress, 277 new TaskProgressChangedEventArgs(Drive, currentPass, method.Passes))); 278 279 if (Task.Canceled) 280 throw new OperationCanceledException(S._("The task was cancelled.")); 281 } 282 ); 283 } 284 } 285 286 //Mark the main bulk of the progress as complete 287 mainProgress.MarkComplete(); 233 //Fill the disk 234 EraseUnusedSpace(volInfo, info, fsManager, method); 288 235 289 236 //Erase old resident file system table files … … 344 291 Progress = null; 345 292 } 293 294 private void EraseUnusedSpace(VolumeInfo volInfo, DirectoryInfo info, FileSystem fsInfo, 295 ErasureMethod method) 296 { 297 ProgressManager mainProgress = new ProgressManager(); 298 Progress.Steps.Add(new SteppedProgressManagerStep(mainProgress, 299 EraseClusterTips ? 0.8f : 0.9f, S._("Erasing unused space..."))); 300 301 //Continue creating files while there is free space. 302 while (volInfo.AvailableFreeSpace > 0) 303 { 304 //Generate a non-existant file name 305 string currFile = FileSystem.GenerateRandomFileName(info, 18); 306 307 //Create the stream 308 FileStream stream = new FileStream(currFile, FileMode.CreateNew, 309 FileAccess.Write, FileShare.None, 8, FileOptions.WriteThrough); 310 try 311 { 312 //Set the length of the file to be the amount of free space left 313 //or the maximum size of one of these dumps. 314 mainProgress.Total = mainProgress.Completed + 315 method.CalculateEraseDataSize(null, volInfo.AvailableFreeSpace); 316 long streamLength = Math.Min(ErasureMethod.FreeSpaceFileUnit, 317 volInfo.AvailableFreeSpace); 318 319 //Handle IO exceptions gracefully, because the filesystem 320 //may require more space than demanded by us for file allocation. 321 while (true) 322 try 323 { 324 stream.SetLength(streamLength); 325 break; 326 } 327 catch (IOException) 328 { 329 if (streamLength > volInfo.ClusterSize) 330 streamLength -= volInfo.ClusterSize; 331 else 332 throw; 333 } 334 335 //Then run the erase task 336 method.Erase(stream, long.MaxValue, 337 ManagerLibrary.Instance.PrngRegistrar[ManagerLibrary.Settings.ActivePrng], 338 delegate(long lastWritten, long totalData, int currentPass) 339 { 340 mainProgress.Completed += lastWritten; 341 OnProgressChanged(this, new ProgressChangedEventArgs(mainProgress, 342 new TaskProgressChangedEventArgs(Drive, currentPass, method.Passes))); 343 344 if (Task.Canceled) 345 throw new OperationCanceledException(S._("The task was cancelled.")); 346 } 347 ); 348 } 349 finally 350 { 351 stream.Close(); 352 fsInfo.ResetFileTimes(new FileInfo(currFile)); 353 } 354 } 355 356 //Mark the main bulk of the progress as complete 357 mainProgress.MarkComplete(); 358 } 346 359 } 347 360 } -
trunk/eraser/Eraser.DefaultPlugins/FileSystems/Windows.cs
r2159 r2161 38 38 public abstract class WindowsFileSystem : FileSystem 39 39 { 40 public override void ResetFileTimes(FileSystemInfo info) 41 { 42 //Reset the file access times: after every rename the file times may change. 43 info.SetTimes(MinTimestamp, MinTimestamp, MinTimestamp, MinTimestamp); 44 } 45 40 46 public override void DeleteFile(FileInfo info) 41 47 { … … 100 106 try 101 107 { 102 //Reset the file access times: after every rename the file times may change. 103 info.SetTimes(MinTimestamp, MinTimestamp, MinTimestamp, MinTimestamp); 108 ResetFileTimes(info); 104 109 105 110 //Try to rename the file. If it fails, it is probably due to another -
trunk/eraser/Eraser.Manager/FileSystem.cs
r2157 r2161 205 205 206 206 /// <summary> 207 /// Resets the created, modified, accessed and last update times for the given 208 /// <paramref name="info"/>. 209 /// </summary> 210 /// <param name="info">The file to reset times.</param> 211 public abstract void ResetFileTimes(FileSystemInfo info); 212 213 /// <summary> 207 214 /// Securely deletes the file reference from the directory structures 208 215 /// as well as resetting the Date Created, Date Accessed and Date Modified
Note: See TracChangeset
for help on using the changeset viewer.
