rename copysourcerandom to copysourceshred because that is what it's used for

let the user configure if he wants to shred with zeros (i.e. fast) or with
random data (i.e. secure)

svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1106963
This commit is contained in:
Volker Lanz 2010-03-24 10:42:30 +00:00
parent 27fe63b20d
commit ab945358cf
5 changed files with 82 additions and 28 deletions

View File

@ -88,5 +88,12 @@
<entry key="preferredUnit" type="Int">
<default>Capacity::MiB</default>
</entry>
<entry key="shredSource" type="Enum">
<choices>
<choice name="random"/>
<choice name="zeros"/>
</choices>
<default>random</default>
</entry>
</group>
</kcfg>

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>459</width>
<height>389</height>
<width>473</width>
<height>575</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
@ -198,9 +198,54 @@
</layout>
</widget>
</item>
<item>
<widget class="KButtonGroup" name="kcfg_shredSource">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Shredding</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Overwrite with:</string>
</property>
<property name="buddy">
<cstring>m_ComboBackend</cstring>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton">
<property name="text">
<string>Random data</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_2">
<property name="text">
<string>Zeros</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KButtonGroup</class>
<extends>QGroupBox</extends>
<header>kbuttongroup.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KComboBox</class>
<extends>QComboBox</extends>

View File

@ -17,47 +17,49 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#include "core/copysourcerandom.h"
#include "core/copysourceshred.h"
#include <kdebug.h>
/** Constructs a CopySourceRandom with the given @p size
#include <config.h>
/** Constructs a CopySourceShred with the given @p size
@param s the size the copy source will (pretend to) have
@param sectorsize the sectorsize the copy source will (pretend to) have
*/
CopySourceRandom::CopySourceRandom (qint64 s, qint32 sectorsize) :
CopySourceShred::CopySourceShred (qint64 s, qint32 sectorsize) :
CopySource(),
m_Size(s),
m_SectorSize(sectorsize),
m_Random("/dev/urandom")
m_SourceFile(Config::shredSource == static_cast<int>(Config::EnumShredSource::random) ? "/dev/urandom" : "/dev/zero")
{
}
/** Opens the random source.
/** Opens the shred source.
@return true on success
*/
bool CopySourceRandom::open()
bool CopySourceShred::open()
{
return random().open(QIODevice::ReadOnly);
return sourceFile().open(QIODevice::ReadOnly);
}
/** Returns the length of the random source in sectors.
/** Returns the length of the source in sectors.
@return length of the source in sectors.
*/
qint64 CopySourceRandom::length() const
qint64 CopySourceShred::length() const
{
return size() / sectorSize();
}
/** Reads the given number of sectors from the random source into the given buffer.
/** Reads the given number of sectors from the source into the given buffer.
@param buffer buffer to store the sectors read in
@param readOffset offset where to begin reading (unused)
@param numSectors number of sectors to read
@return true on success
*/
bool CopySourceRandom::readSectors(void* buffer, qint64 readOffset, qint64 numSectors)
bool CopySourceShred::readSectors(void* buffer, qint64 readOffset, qint64 numSectors)
{
Q_UNUSED(readOffset);
return random().read(static_cast<char*>(buffer), numSectors * sectorSize()) == numSectors * sectorSize();
return sourceFile().read(static_cast<char*>(buffer), numSectors * sectorSize()) == numSectors * sectorSize();
}

View File

@ -17,9 +17,9 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
#if !defined(COPYSOURCERANDOM__H)
#if !defined(COPYSOURCESHRED__H)
#define COPYSOURCERANDOM__H
#define COPYSOURCESHRED__H
#include "core/copysource.h"
@ -27,16 +27,16 @@
class CopyTarget;
/** @brief A source of random data to copy from.
/** @brief A source for securely overwriting a partition (shredding).
Represents a random date source to copy from. Used to securely overwrite data on disk.
Represents a source of data (random or zeros) to copy from. Used to securely overwrite data on disk.
@author vl@fidra.de
*/
class CopySourceRandom : public CopySource
class CopySourceShred : public CopySource
{
public:
CopySourceRandom(qint64 size, qint32 sectorsize);
CopySourceShred(qint64 size, qint32 sectorsize);
public:
virtual bool open();
@ -44,19 +44,19 @@ class CopySourceRandom : public CopySource
virtual qint64 length() const;
virtual qint32 sectorSize() const { return m_SectorSize; } /**< @return the file's sector size */
virtual bool overlaps(const CopyTarget&) const { return false; } /**< @return false for random source */
virtual qint64 firstSector() const { return 0; } /**< @return 0 for random source */
virtual qint64 lastSector() const { return length(); } /**< @return equal to length for random source. @see length() */
virtual bool overlaps(const CopyTarget&) const { return false; } /**< @return false for shred source */
virtual qint64 firstSector() const { return 0; } /**< @return 0 for shred source */
virtual qint64 lastSector() const { return length(); } /**< @return equal to length for shred source. @see length() */
protected:
QFile& random() { return m_Random; }
const QFile& random() const { return m_Random; }
QFile& sourceFile() { return m_SourceFile; }
const QFile& sourceFile() const { return m_SourceFile; }
qint32 size() const { return m_Size; }
private:
qint64 m_Size;
qint32 m_SectorSize;
QFile m_Random;
QFile m_SourceFile;
};
#endif

View File

@ -21,7 +21,7 @@
#include "core/partition.h"
#include "core/device.h"
#include "core/copysourcerandom.h"
#include "core/copysourceshred.h"
#include "core/copytargetdevice.h"
#include "fs/filesystem.h"
@ -65,7 +65,7 @@ bool ShredFileSystemJob::run(Report& parent)
// Again, a scope for copyTarget and copySource. See MoveFileSystemJob::run()
{
CopyTargetDevice copyTarget(device(), partition().fileSystem().firstSector(), partition().fileSystem().lastSector());
CopySourceRandom copySource(partition().capacity(), copyTarget.sectorSize());
CopySourceShred copySource(partition().capacity(), copyTarget.sectorSize());
if (!copySource.open())
report->line() << i18nc("@info/plain", "Could not open random data source to overwrite file system.");