| 1 | /* |
|---|
| 2 | * $Id$ |
|---|
| 3 | * Copyright 2008-2013 The Eraser Project |
|---|
| 4 | * Original Author: Joel Low <lowjoel@users.sourceforge.net> |
|---|
| 5 | * Modified By: |
|---|
| 6 | * |
|---|
| 7 | * This file is part of Eraser. |
|---|
| 8 | * |
|---|
| 9 | * Eraser is free software: you can redistribute it and/or modify it under the |
|---|
| 10 | * terms of the GNU General Public License as published by the Free Software |
|---|
| 11 | * Foundation, either version 3 of the License, or (at your option) any later |
|---|
| 12 | * version. |
|---|
| 13 | * |
|---|
| 14 | * Eraser is distributed in the hope that it will be useful, but WITHOUT ANY |
|---|
| 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
|---|
| 16 | * A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
|---|
| 17 | * |
|---|
| 18 | * A copy of the GNU General Public License can be found at |
|---|
| 19 | * <http://www.gnu.org/licenses/>. |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | using System; |
|---|
| 23 | using System.Collections.Generic; |
|---|
| 24 | using System.Linq; |
|---|
| 25 | using System.Text; |
|---|
| 26 | |
|---|
| 27 | using System.IO; |
|---|
| 28 | using Eraser.Util; |
|---|
| 29 | |
|---|
| 30 | namespace Eraser.Plugins.ExtensionPoints |
|---|
| 31 | { |
|---|
| 32 | /// <summary> |
|---|
| 33 | /// An interface class representing the method for erasure. If classes only |
|---|
| 34 | /// inherit this class, then the method can only be used to erase abstract |
|---|
| 35 | /// streams, not drive space. |
|---|
| 36 | /// </summary> |
|---|
| 37 | public interface IErasureMethod : IRegisterable |
|---|
| 38 | { |
|---|
| 39 | /// <summary> |
|---|
| 40 | /// Returns a string that represents the current IErasureMethod. The suggested |
|---|
| 41 | /// template is {name} ({pass count} passes) |
|---|
| 42 | /// </summary> |
|---|
| 43 | /// <returns>The string that represents the current IErasureMethod.</returns> |
|---|
| 44 | string ToString(); |
|---|
| 45 | |
|---|
| 46 | /// <summary> |
|---|
| 47 | /// The name of this erase pass, used for display in the UI |
|---|
| 48 | /// </summary> |
|---|
| 49 | string Name |
|---|
| 50 | { |
|---|
| 51 | get; |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | /// <summary> |
|---|
| 55 | /// The number of erase passes for this erasure method. |
|---|
| 56 | /// </summary> |
|---|
| 57 | int Passes |
|---|
| 58 | { |
|---|
| 59 | get; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | /// <summary> |
|---|
| 63 | /// Calculates the total size of the erasure data that needs to be written. |
|---|
| 64 | /// This is mainly for use by the Manager to determine how much data needs |
|---|
| 65 | /// to be written to disk. |
|---|
| 66 | /// </summary> |
|---|
| 67 | /// <param name="paths">The list containing the file paths to erase. This |
|---|
| 68 | /// may be null if the list of paths are unknown.</param> |
|---|
| 69 | /// <param name="targetSize">The precomputed value of the total size of |
|---|
| 70 | /// the files to be erased.</param> |
|---|
| 71 | /// <returns>The total size of the files that need to be erased.</returns> |
|---|
| 72 | /// <remarks>This function MAY be slow. Most erasure methods can |
|---|
| 73 | /// calculate this amount fairly quickly as the number of files and the |
|---|
| 74 | /// total size of the files (the ones that take most computation time) |
|---|
| 75 | /// are already provided. However some exceptional cases may take a |
|---|
| 76 | /// long time if the data set is large.</remarks> |
|---|
| 77 | long CalculateEraseDataSize(ICollection<StreamInfo> paths, long targetSize); |
|---|
| 78 | |
|---|
| 79 | /// <summary> |
|---|
| 80 | /// The main bit of the class! This function is called whenever data has |
|---|
| 81 | /// to be erased. Erase the stream passed in, using the given PRNG for |
|---|
| 82 | /// randomness where necessary. |
|---|
| 83 | /// |
|---|
| 84 | /// This function should be implemented thread-safe as using the same |
|---|
| 85 | /// instance, this function may be called across different threads. |
|---|
| 86 | /// </summary> |
|---|
| 87 | /// <param name="stream">The stream which needs to be erased.</param> |
|---|
| 88 | /// <param name="erasureLength">The length of the stream to erase. If all |
|---|
| 89 | /// data in the stream should be overwritten, then pass in the maximum |
|---|
| 90 | /// value for long, the function will take the minimum.</param> |
|---|
| 91 | /// <param name="prng">The PRNG source for random data.</param> |
|---|
| 92 | /// <param name="callback">The progress callback function.</param> |
|---|
| 93 | void Erase(Stream stream, long erasureLength, IPrng prng, |
|---|
| 94 | ErasureMethodProgressFunction callback); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | /// <summary> |
|---|
| 98 | /// A simple callback for clients to retrieve progress information from |
|---|
| 99 | /// the erase method. |
|---|
| 100 | /// </summary> |
|---|
| 101 | /// <param name="lastWritten">The amount of data written to the stream since |
|---|
| 102 | /// the last call to the delegate.</param> |
|---|
| 103 | /// <param name="totalData">The total amount of data that must be written to |
|---|
| 104 | /// complete the erasure.</param> |
|---|
| 105 | /// <param name="currentPass">The current pass number. The total number |
|---|
| 106 | /// of passes can be found from the Passes property.</param> |
|---|
| 107 | public delegate void ErasureMethodProgressFunction(long lastWritten, |
|---|
| 108 | long totalData, int currentPass); |
|---|
| 109 | |
|---|
| 110 | /// <summary> |
|---|
| 111 | /// This class adds functionality to the ErasureMethod class to erase |
|---|
| 112 | /// drives (including unused space and for drive erasures) |
|---|
| 113 | /// </summary> |
|---|
| 114 | public interface IDriveErasureMethod : IErasureMethod |
|---|
| 115 | { |
|---|
| 116 | /// <summary> |
|---|
| 117 | /// This function will allow clients to erase a file in a set of files |
|---|
| 118 | /// used to fill the disk, thus achieving disk unused space erasure. |
|---|
| 119 | /// |
|---|
| 120 | /// By default, this function will simply call the Erase method inherited |
|---|
| 121 | /// from the ErasureMethod class. |
|---|
| 122 | /// |
|---|
| 123 | /// This function should be implemented thread-safe as using the same |
|---|
| 124 | /// instance, this function may be called across different threads. |
|---|
| 125 | /// </summary> |
|---|
| 126 | /// <param name="strm">The stream which needs to be erased.</param> |
|---|
| 127 | /// <param name="prng">The PRNG source for random data.</param> |
|---|
| 128 | /// <param name="callback">The progress callback function.</param> |
|---|
| 129 | void EraseDriveSpace(Stream stream, IPrng prng, ErasureMethodProgressFunction callback); |
|---|
| 130 | } |
|---|
| 131 | } |
|---|