Update a partition's system type when creating a new file system on it.
BUG:263346 svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1249913
This commit is contained in:
parent
5156f466b8
commit
cce6cdbacf
|
@ -1,5 +1,5 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2010 by Volker Lanz <vl@fidra.de *
|
||||
* Copyright (C) 2010,2011 by Volker Lanz <vl@fidra.de *
|
||||
* *
|
||||
* 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 *
|
||||
|
@ -117,6 +117,15 @@ class LIBPARTITIONMANAGERPRIVATE_EXPORT CoreBackendPartitionTable
|
|||
* @return true on success
|
||||
*/
|
||||
virtual bool updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end) = 0;
|
||||
|
||||
/**
|
||||
* Set the system type (e.g. 83 for Linux) of a partition. The type to set is taken from
|
||||
* the partition's file system.
|
||||
* @param report the report to write information to
|
||||
* @param partition the partition to set the system type for
|
||||
* @return true on success
|
||||
*/
|
||||
virtual bool setPartitionSystemType(Report& report, const Partition& partition) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
||||
* Copyright (C) 2008,2011 by Volker Lanz <vl@fidra.de> *
|
||||
* *
|
||||
* 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 <filename>%1</filename>.", partition().deviceNode());
|
||||
|
||||
delete backendPartitionTable;
|
||||
}
|
||||
else
|
||||
report->line() << i18nc("@info/plain", "Could not open partition table on device <filename>%1</filename> to set the system type for partition <filename>%2</filename>.", device().deviceNode(), partition().deviceNode());
|
||||
|
||||
delete backendDevice;
|
||||
}
|
||||
else
|
||||
report->line() << i18nc("@info/plain", "Could not open device <filename>%1</filename> to set the system type for partition <filename>%2</filename>.", device().deviceNode(), partition().deviceNode());
|
||||
}
|
||||
}
|
||||
|
||||
jobFinished(*report, rval);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
||||
* Copyright (C) 2008,2011 by Volker Lanz <vl@fidra.de> *
|
||||
* *
|
||||
* 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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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 <filename>%1</filename>.", partition.deviceNode());
|
||||
return false;
|
||||
}
|
||||
|
||||
return ped_partition_set_system(pedPartition, pedFsType) != 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2010 by Volker Lanz <vl@fidra.de *
|
||||
* Copyright (C) 2010,2011 by Volker Lanz <vl@fidra.de *
|
||||
* *
|
||||
* 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 *
|
||||
|
@ -54,6 +54,7 @@ class LibPartedPartitionTable : public CoreBackendPartitionTable
|
|||
virtual bool clobberFileSystem(Report& report, const Partition& partition);
|
||||
virtual bool resizeFileSystem(Report& report, const Partition& partition, qint64 newLength);
|
||||
virtual FileSystem::Type detectFileSystemBySector(Report& report, const Device& device, qint64 sector);
|
||||
virtual bool setPartitionSystemType(Report& report, const Partition& partition);
|
||||
|
||||
private:
|
||||
PedDevice* pedDevice() { return m_PedDevice; }
|
||||
|
|
Loading…
Reference in New Issue