/* SPDX-FileCopyrightText: 2008-2011 Volker Lanz SPDX-FileCopyrightText: 2014-2018 Andrius Štikonas SPDX-FileCopyrightText: 2016 Chantara Tith SPDX-FileCopyrightText: 2018 Caio Jordão Carvalho SPDX-FileCopyrightText: 2020 Arnaud Ferraris SPDX-License-Identifier: GPL-3.0-or-later */ #include "jobs/createfilesystemjob.h" #include "backend/corebackend.h" #include "backend/corebackendmanager.h" #include "backend/corebackenddevice.h" #include "backend/corebackendpartitiontable.h" #include "core/device.h" #include "core/partition.h" #include "fs/filesystem.h" #include "util/report.h" #include /** Creates a new CreateFileSystemJob @param p the Partition the FileSystem to create is on */ CreateFileSystemJob::CreateFileSystemJob(Device& d, Partition& p, const QString& label) : Job(), m_Device(d), m_Partition(p), m_Label(label) { } bool CreateFileSystemJob::run(Report& parent) { bool rval = false; Report* report = jobStarted(parent); if (partition().fileSystem().type() == FileSystem::Type::Unformatted) return true; bool createResult; if (partition().fileSystem().supportCreate() == FileSystem::cmdSupportFileSystem) { if (partition().fileSystem().supportCreateWithLabel() == FileSystem::cmdSupportFileSystem) { createResult = partition().fileSystem().createWithLabel(*report, partition().deviceNode(), m_Label); } else { createResult = partition().fileSystem().create(*report, partition().deviceNode()); } if (createResult) { if (device().type() == Device::Type::Disk_Device || device().type() == Device::Type::SoftwareRAID_Device) { std::unique_ptr backendDevice = CoreBackendManager::self()->backend()->openDevice(device()); if (backendDevice) { std::unique_ptr backendPartitionTable = backendDevice->openPartitionTable(); if (backendPartitionTable) { if (backendPartitionTable->setPartitionSystemType(*report, partition())) { rval = true; backendPartitionTable->commit(); } else report->line() << xi18nc("@info:progress", "Failed to set the system type for the file system on partition %1.", partition().deviceNode()); } else report->line() << xi18nc("@info:progress", "Could not open partition table on device %1 to set the system type for partition %2.", device().deviceNode(), partition().deviceNode()); } else report->line() << xi18nc("@info:progress", "Could not open device %1 to set the system type for partition %2.", device().deviceNode(), partition().deviceNode()); } else if (device().type() == Device::Type::LVM_Device) { rval = true; } } } jobFinished(*report, rval); return rval; } QString CreateFileSystemJob::description() const { return xi18nc("@info:progress", "Create file system %1 on partition %2", partition().fileSystem().name(), partition().deviceNode()); }