From 30a0f4506c101db25223219fd85f7ef970920aed Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Mon, 5 Dec 2016 11:14:29 +0000 Subject: [PATCH] Add specialist clone method PartitionLUKS::clone_as_plain() (#774818) Implement a specialist PartitionLUKS clone method. Creates a new Partition object which has the same space usage as the source encrypted file system, but is a plain file system. Namely, the overhead of the LUKS header has been added to the file system usage. This is ready for feeding this representation of the partition to the Resize/Move dialog. Bug 774818 - Implement LUKS read-write actions NOT requiring a passphrase --- include/PartitionLUKS.h | 1 + src/PartitionLUKS.cc | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/PartitionLUKS.h b/include/PartitionLUKS.h index 8c09e936..7dd76544 100644 --- a/include/PartitionLUKS.h +++ b/include/PartitionLUKS.h @@ -32,6 +32,7 @@ public: PartitionLUKS(); virtual ~PartitionLUKS(); virtual PartitionLUKS * clone() const; + Partition * clone_as_plain() const; void set_luks( const Glib::ustring & path, FILESYSTEM fstype, diff --git a/src/PartitionLUKS.cc b/src/PartitionLUKS.cc index 9157dcc1..e927676b 100644 --- a/src/PartitionLUKS.cc +++ b/src/PartitionLUKS.cc @@ -14,6 +14,7 @@ * along with this program; if not, see . */ +#include "Partition.h" #include "PartitionLUKS.h" #include "Utils.h" @@ -37,6 +38,33 @@ PartitionLUKS * PartitionLUKS::clone() const return new PartitionLUKS( *this ); } +// Specialist clone creating a plain Partition object from a PartitionLUKS object. +// Created partition is as though the file system wasn't encrypted, but adds the LUKS +// overhead into the file system usage. +Partition * PartitionLUKS::clone_as_plain() const +{ + // Clone the partition. + // WARNING: + // Deliberate object slicing of *this from PartitionLUKS to Partition. + Partition * plain_ptn = new Partition( *this ); + + // Copy over file system attributes. + plain_ptn->filesystem = this->encrypted.filesystem; + plain_ptn->uuid = this->encrypted.uuid; + plain_ptn->busy = this->encrypted.busy; + plain_ptn->fs_block_size = this->encrypted.fs_block_size; + Sector fs_size = this->header_size + this->encrypted.sectors_used + this->encrypted.sectors_unused; + plain_ptn->set_sector_usage( fs_size, this->encrypted.sectors_unused ); + plain_ptn->clear_mountpoints(); + plain_ptn->add_mountpoints( this->encrypted.get_mountpoints() ); + if ( this->encrypted.filesystem_label_known() ) + plain_ptn->set_filesystem_label( this->encrypted.get_filesystem_label() ); + plain_ptn->clear_messages(); + plain_ptn->append_messages( this->encrypted.get_messages() ); + + return plain_ptn; +} + // Mostly a convenience method calling Partition::Set() on the encrypted Partition but // also sets private header_size. Makes encrypted Partition object look like a whole disk // device as /dev/mapper/CRYPTNAME contains no partition table and the file system starts