File indexing completed on 2024-04-28 05:45:53
0001 /* 0002 SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de> 0003 SPDX-FileCopyrightText: 2014-2020 Andrius Štikonas <andrius@stikonas.eu> 0004 SPDX-FileCopyrightText: 2016 Chantara Tith <tith.chantara@gmail.com> 0005 SPDX-FileCopyrightText: 2018 Caio Jordão Carvalho <caiojcarvalho@gmail.com> 0006 0007 SPDX-License-Identifier: GPL-3.0-or-later 0008 */ 0009 0010 #include "jobs/createpartitiontablejob.h" 0011 0012 #include "backend/corebackendmanager.h" 0013 #include "backend/corebackenddevice.h" 0014 #include "backend/corebackend.h" 0015 0016 #include "core/device.h" 0017 #include "core/partitiontable.h" 0018 0019 #include "util/report.h" 0020 0021 #include <KLocalizedString> 0022 0023 /** Creates a new CreatePartitionTableJob 0024 @param d the Device a new PartitionTable is to be created on 0025 */ 0026 CreatePartitionTableJob::CreatePartitionTableJob(Device& d) : 0027 Job(), 0028 m_Device(d) 0029 { 0030 } 0031 0032 bool CreatePartitionTableJob::run(Report& parent) 0033 { 0034 bool rval = false; 0035 0036 Report* report = jobStarted(parent); 0037 0038 if (device().partitionTable()->type() == PartitionTable::TableType::none) 0039 return true; 0040 0041 if (device().type() == Device::Type::Disk_Device || device().type() == Device::Type::SoftwareRAID_Device) { 0042 std::unique_ptr<CoreBackendDevice> backendDevice = CoreBackendManager::self()->backend()->openDevice(device()); 0043 0044 if (backendDevice != nullptr) { 0045 Q_ASSERT(device().partitionTable()); 0046 0047 rval = backendDevice->createPartitionTable(*report, *device().partitionTable()); 0048 } else 0049 report->line() << xi18nc("@info:progress", "Creating partition table failed: Could not open device <filename>%1</filename>.", device().deviceNode()); 0050 } else if (device().type() == Device::Type::LVM_Device) { 0051 //TODO: figure what to do with LVM partitionTable 0052 } 0053 0054 jobFinished(*report, rval); 0055 0056 return rval; 0057 } 0058 0059 QString CreatePartitionTableJob::description() const 0060 { 0061 return xi18nc("@info:progress", "Create new partition table on device <filename>%1</filename>", device().deviceNode()); 0062 }