File indexing completed on 2024-04-28 05:45:55
0001 /* 0002 SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de> 0003 SPDX-FileCopyrightText: 2014-2017 Andrius Štikonas <andrius@stikonas.eu> 0004 SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org> 0005 0006 SPDX-License-Identifier: GPL-3.0-or-later 0007 */ 0008 0009 #include "jobs/shredfilesystemjob.h" 0010 0011 #include "core/partition.h" 0012 #include "core/device.h" 0013 #include "core/copysourceshred.h" 0014 #include "core/copytargetdevice.h" 0015 0016 #include "fs/filesystem.h" 0017 #include "fs/filesystemfactory.h" 0018 0019 #include "util/report.h" 0020 0021 #include <QDebug> 0022 0023 #include <KLocalizedString> 0024 0025 /** Creates a new ShredFileSystemJob 0026 @param d the Device the FileSystem is on 0027 @param p the Partition the FileSystem is in 0028 */ 0029 ShredFileSystemJob::ShredFileSystemJob(Device& d, Partition& p, bool randomShred) : 0030 Job(), 0031 m_Device(d), 0032 m_Partition(p), 0033 m_RandomShred(randomShred) 0034 { 0035 } 0036 0037 qint32 ShredFileSystemJob::numSteps() const 0038 { 0039 return 100; 0040 } 0041 0042 bool ShredFileSystemJob::run(Report& parent) 0043 { 0044 Q_ASSERT(device().deviceNode() == partition().devicePath()); 0045 0046 if (device().deviceNode() != partition().devicePath()) { 0047 qWarning() << "deviceNode: " << device().deviceNode() << ", partition path: " << partition().devicePath(); 0048 return false; 0049 } 0050 0051 bool rval = false; 0052 0053 Report* report = jobStarted(parent); 0054 0055 // Again, a scope for copyTarget and copySource. See MoveFileSystemJob::run() 0056 { 0057 CopyTargetDevice copyTarget(device(), partition().fileSystem().firstByte(), partition().fileSystem().lastByte()); 0058 CopySourceShred copySource(partition().capacity(), m_RandomShred); 0059 0060 if (!copySource.open()) 0061 report->line() << xi18nc("@info:progress", "Could not open random data source to overwrite file system."); 0062 else if (!copyTarget.open()) 0063 report->line() << xi18nc("@info:progress", "Could not open target partition <filename>%1</filename> to restore to.", partition().deviceNode()); 0064 else { 0065 rval = copyBlocks(*report, copyTarget, copySource); 0066 report->line() << i18nc("@info:progress", "Closing device. This may take a few seconds."); 0067 } 0068 } 0069 0070 jobFinished(*report, rval); 0071 0072 return rval; 0073 } 0074 0075 QString ShredFileSystemJob::description() const 0076 { 0077 return xi18nc("@info:progress", "Shred the file system on <filename>%1</filename>", partition().deviceNode()); 0078 }