diff --git a/src/backend/corebackendpartitiontable.h b/src/backend/corebackendpartitiontable.h index 5bc6082..cc21902 100644 --- a/src/backend/corebackendpartitiontable.h +++ b/src/backend/corebackendpartitiontable.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Volker Lanz * + * Copyright (C) 2008,2011 by Volker Lanz * * * * 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 * @@ -19,6 +19,12 @@ #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" @@ -30,8 +36,9 @@ /** Creates a new CreateFileSystemJob @param p the Partition the FileSystem to create is on */ -CreateFileSystemJob::CreateFileSystemJob(Partition& p) : +CreateFileSystemJob::CreateFileSystemJob(Device& d, Partition& p) : Job(), + m_Device(d), m_Partition(p) { } @@ -43,7 +50,36 @@ bool CreateFileSystemJob::run(Report& parent) Report* report = jobStarted(parent); if (partition().fileSystem().supportCreate() == FileSystem::cmdSupportFileSystem) - rval = partition().fileSystem().create(*report, partition().deviceNode()); + { + if (partition().fileSystem().create(*report, partition().deviceNode())) + { + CoreBackendDevice* backendDevice = CoreBackendManager::self()->backend()->openDevice(device().deviceNode()); + + if (backendDevice) + { + CoreBackendPartitionTable* backendPartitionTable = backendDevice->openPartitionTable(); + + if (backendPartitionTable) + { + if (backendPartitionTable->setPartitionSystemType(*report, partition())) + { + rval = true; + backendPartitionTable->commit(); + } + else + report->line() << i18nc("@info/plain", "Failed to set the system type for the file system on partition %1.", partition().deviceNode()); + + delete backendPartitionTable; + } + else + report->line() << i18nc("@info/plain", "Could not open partition table on device %1 to set the system type for partition %2.", device().deviceNode(), partition().deviceNode()); + + delete backendDevice; + } + else + report->line() << i18nc("@info/plain", "Could not open device %1 to set the system type for partition %2.", device().deviceNode(), partition().deviceNode()); + } + } jobFinished(*report, rval); diff --git a/src/jobs/createfilesystemjob.h b/src/jobs/createfilesystemjob.h index 80ab594..f5bce2f 100644 --- a/src/jobs/createfilesystemjob.h +++ b/src/jobs/createfilesystemjob.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2008 by Volker Lanz * + * Copyright (C) 2008,2011 by Volker Lanz * * * * 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 * @@ -23,6 +23,7 @@ #include "jobs/job.h" +class Device; class Partition; class Report; @@ -34,7 +35,7 @@ class QString; class CreateFileSystemJob : public Job { public: - CreateFileSystemJob(Partition& p); + CreateFileSystemJob(Device& d, Partition& p); public: virtual bool run(Report& parent); @@ -44,7 +45,11 @@ class CreateFileSystemJob : public Job Partition& partition() { return m_Partition; } const Partition& partition() const { return m_Partition; } + Device& device() { return m_Device; } + const Device& device() const { return m_Device; } + private: + Device& m_Device; Partition& m_Partition; }; diff --git a/src/ops/createfilesystemoperation.cpp b/src/ops/createfilesystemoperation.cpp index 1a75c63..695bffc 100644 --- a/src/ops/createfilesystemoperation.cpp +++ b/src/ops/createfilesystemoperation.cpp @@ -46,7 +46,7 @@ CreateFileSystemOperation::CreateFileSystemOperation(Device& d, Partition& p, Fi m_NewFileSystem(FileSystemFactory::cloneWithNewType(newType, partition().fileSystem())), m_OldFileSystem(&p.fileSystem()), m_DeleteJob(new DeleteFileSystemJob(targetDevice(), partition())), - m_CreateJob(new CreateFileSystemJob(partition())), + m_CreateJob(new CreateFileSystemJob(targetDevice(), partition())), m_CheckJob(new CheckFileSystemJob(partition())) { // We never know anything about the number of used sectors on a new file system. diff --git a/src/ops/newoperation.cpp b/src/ops/newoperation.cpp index a09327c..b482d01 100644 --- a/src/ops/newoperation.cpp +++ b/src/ops/newoperation.cpp @@ -63,7 +63,7 @@ NewOperation::NewOperation(Device& d, Partition* p) : // label. The operation stack will merge these operations with this one here // and if the jobs don't exist things will break. - m_CreateFileSystemJob = new CreateFileSystemJob(newPartition()); + m_CreateFileSystemJob = new CreateFileSystemJob(targetDevice(), newPartition()); addJob(createFileSystemJob()); m_SetFileSystemLabelJob = new SetFileSystemLabelJob(newPartition(), fs.label()); diff --git a/src/plugins/libparted/libpartedpartitiontable.cpp b/src/plugins/libparted/libpartedpartitiontable.cpp index 59a6f73..98dec6d 100644 --- a/src/plugins/libparted/libpartedpartitiontable.cpp +++ b/src/plugins/libparted/libpartedpartitiontable.cpp @@ -357,3 +357,19 @@ FileSystem::Type LibPartedPartitionTable::detectFileSystemBySector(Report& repor return rval; } + +bool LibPartedPartitionTable::setPartitionSystemType(Report& report, const Partition& partition) +{ + PedFileSystemType* pedFsType = (partition.roles().has(PartitionRole::Extended) || partition.fileSystem().type() == FileSystem::Unformatted) ? NULL : getPedFileSystemType(partition.fileSystem().type()); + + PedPartition* pedPartition = ped_disk_get_partition_by_sector(pedDisk(), partition.firstSector()); + + if (pedFsType == NULL || pedPartition == NULL) + { + report.line() << i18nc("@info/plain", "Could not update the system type for partition %1.", partition.deviceNode()); + return false; + } + + return ped_partition_set_system(pedPartition, pedFsType) != 0; +} + diff --git a/src/plugins/libparted/libpartedpartitiontable.h b/src/plugins/libparted/libpartedpartitiontable.h index 9d033d7..1b9f2d6 100644 --- a/src/plugins/libparted/libpartedpartitiontable.h +++ b/src/plugins/libparted/libpartedpartitiontable.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2010 by Volker Lanz