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
This commit is contained in:
Mike Fleetwood 2016-12-05 11:14:29 +00:00 committed by Curtis Gedak
parent e2c70d5639
commit 30a0f4506c
2 changed files with 29 additions and 0 deletions

View File

@ -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,

View File

@ -14,6 +14,7 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#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