2015-06-04 01:29:22 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* Copyright (C) 2010 by Volker Lanz <vl@fidra.de> *
|
2016-03-02 19:00:31 +00:00
|
|
|
* Copyright (C) 2016 by Andrius Štikonas <andrius@stikonas.eu> *
|
2015-06-04 01:29:22 +01:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#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
|
|
|
}
|