2020-09-29 23:55:11 +01:00
|
|
|
/*
|
|
|
|
SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de>
|
|
|
|
SPDX-FileCopyrightText: 2014-2017 Andrius Štikonas <andrius@stikonas.eu>
|
|
|
|
SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
2015-06-04 01:29:22 +01:00
|
|
|
|
|
|
|
#include "jobs/shredfilesystemjob.h"
|
|
|
|
|
|
|
|
#include "core/partition.h"
|
|
|
|
#include "core/device.h"
|
|
|
|
#include "core/copysourceshred.h"
|
|
|
|
#include "core/copytargetdevice.h"
|
|
|
|
|
|
|
|
#include "fs/filesystem.h"
|
|
|
|
#include "fs/filesystemfactory.h"
|
|
|
|
|
|
|
|
#include "util/report.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
#include <KLocalizedString>
|
|
|
|
|
|
|
|
/** Creates a new ShredFileSystemJob
|
2015-07-13 15:16:36 +01:00
|
|
|
@param d the Device the FileSystem is on
|
|
|
|
@param p the Partition the FileSystem is in
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
2015-07-10 14:56:12 +01:00
|
|
|
ShredFileSystemJob::ShredFileSystemJob(Device& d, Partition& p, bool randomShred) :
|
2015-07-13 15:16:36 +01:00
|
|
|
Job(),
|
|
|
|
m_Device(d),
|
2015-07-10 14:56:12 +01:00
|
|
|
m_Partition(p),
|
|
|
|
m_RandomShred(randomShred)
|
2015-06-04 01:29:22 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
qint32 ShredFileSystemJob::numSteps() const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
return 100;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ShredFileSystemJob::run(Report& parent)
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
Q_ASSERT(device().deviceNode() == partition().devicePath());
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
if (device().deviceNode() != partition().devicePath()) {
|
|
|
|
qWarning() << "deviceNode: " << device().deviceNode() << ", partition path: " << partition().devicePath();
|
|
|
|
return false;
|
|
|
|
}
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
bool rval = false;
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
Report* report = jobStarted(parent);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
// Again, a scope for copyTarget and copySource. See MoveFileSystemJob::run()
|
|
|
|
{
|
2017-10-26 16:20:21 +01:00
|
|
|
CopyTargetDevice copyTarget(device(), partition().fileSystem().firstByte(), partition().fileSystem().lastByte());
|
|
|
|
CopySourceShred copySource(partition().capacity(), m_RandomShred);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
if (!copySource.open())
|
2016-07-17 23:41:00 +01:00
|
|
|
report->line() << xi18nc("@info:progress", "Could not open random data source to overwrite file system.");
|
2015-07-13 15:16:36 +01:00
|
|
|
else if (!copyTarget.open())
|
2016-07-17 23:41:00 +01:00
|
|
|
report->line() << xi18nc("@info:progress", "Could not open target partition <filename>%1</filename> to restore to.", partition().deviceNode());
|
2015-07-13 15:16:36 +01:00
|
|
|
else {
|
|
|
|
rval = copyBlocks(*report, copyTarget, copySource);
|
2016-07-17 23:41:00 +01:00
|
|
|
report->line() << i18nc("@info:progress", "Closing device. This may take a few seconds.");
|
2015-07-13 15:16:36 +01:00
|
|
|
}
|
|
|
|
}
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
jobFinished(*report, rval);
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return rval;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
QString ShredFileSystemJob::description() const
|
|
|
|
{
|
2016-07-17 23:41:00 +01:00
|
|
|
return xi18nc("@info:progress", "Shred the file system on <filename>%1</filename>", partition().deviceNode());
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|