File indexing completed on 2024-04-28 05:45:53
0001 /* 0002 SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de> 0003 SPDX-FileCopyrightText: 2012-2018 Andrius Štikonas <andrius@stikonas.eu> 0004 SPDX-FileCopyrightText: 2016 Chantara Tith <tith.chantara@gmail.com> 0005 0006 SPDX-License-Identifier: GPL-3.0-or-later 0007 */ 0008 0009 #include "jobs/deletefilesystemjob.h" 0010 0011 #include "backend/corebackend.h" 0012 #include "backend/corebackendmanager.h" 0013 #include "backend/corebackenddevice.h" 0014 #include "backend/corebackendpartitiontable.h" 0015 0016 #include "core/partition.h" 0017 #include "core/device.h" 0018 0019 #include "util/helpers.h" 0020 #include "util/report.h" 0021 0022 #include <QDebug> 0023 0024 #include <KLocalizedString> 0025 0026 /** Creates a new DeleteFileSystemJob 0027 @param d the Device the FileSystem to delete is on 0028 @param p the Partition the FileSystem to delete is on 0029 */ 0030 DeleteFileSystemJob::DeleteFileSystemJob(Device& d, Partition& p) : 0031 Job(), 0032 m_Device(d), 0033 m_Partition(p) 0034 { 0035 } 0036 0037 bool DeleteFileSystemJob::run(Report& parent) 0038 { 0039 Q_ASSERT(device().deviceNode() == partition().devicePath()); 0040 0041 if (device().deviceNode() != partition().devicePath()) { 0042 qWarning() << "deviceNode: " << device().deviceNode() << ", partition path: " << partition().devicePath(); 0043 return false; 0044 } 0045 0046 bool rval = false; 0047 0048 Report* report = jobStarted(parent); 0049 0050 if (isMounted(partition().partitionPath())) { 0051 report->line() << xi18nc("@info:progress", "Could not delete file system: file system on <filename>%1</filename> is mounted.", partition().deviceNode()); 0052 jobFinished(*report, rval); 0053 return false; 0054 } 0055 0056 if (partition().roles().has(PartitionRole::Extended)) { 0057 rval = true; 0058 } else if (device().type() == Device::Type::LVM_Device) { 0059 rval = true; 0060 } 0061 else { 0062 if (!partition().fileSystem().remove(*report, partition().deviceNode())) { 0063 jobFinished(*report, rval); 0064 return false; 0065 } 0066 0067 std::unique_ptr<CoreBackendDevice> backendDevice = CoreBackendManager::self()->backend()->openDevice(device()); 0068 0069 if (backendDevice) { 0070 std::unique_ptr<CoreBackendPartitionTable> backendPartitionTable = backendDevice->openPartitionTable(); 0071 0072 if (backendPartitionTable) { 0073 rval = backendPartitionTable->clobberFileSystem(*report, partition()); 0074 0075 if (!rval) 0076 report->line() << xi18nc("@info:progress", "Could not delete file system on <filename>%1</filename>.", partition().deviceNode()); 0077 else 0078 backendPartitionTable->commit(); 0079 } else 0080 report->line() << xi18nc("@info:progress", "Could not open partition table on device <filename>%1</filename> to delete file system on <filename>%2</filename>.", device().deviceNode(), partition().deviceNode()); 0081 0082 } else 0083 report->line() << xi18nc("@info:progress", "Could not delete file system signature for partition <filename>%1</filename>: Failed to open device <filename>%2</filename>.", partition().deviceNode(), device().deviceNode()); 0084 } 0085 0086 jobFinished(*report, rval); 0087 0088 return rval; 0089 } 0090 0091 QString DeleteFileSystemJob::description() const 0092 { 0093 return xi18nc("@info:progress", "Delete file system on <filename>%1</filename>", partition().deviceNode()); 0094 }