[gparted] Add specialist clone method PartitionLUKS::clone_as_plain() (#774818)



commit 30a0f4506c101db25223219fd85f7ef970920aed
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Mon Dec 5 11:14:29 2016 +0000

    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(+), 0 deletions(-)
---
diff --git a/include/PartitionLUKS.h b/include/PartitionLUKS.h
index 8c09e93..7dd7654 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 9157dcc..e927676 100644
--- a/src/PartitionLUKS.cc
+++ b/src/PartitionLUKS.cc
@@ -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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]