[gparted] Extract common code into generate_encryption_mapping_name() (#59)
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Extract common code into generate_encryption_mapping_name() (#59)
- Date: Sun, 25 Apr 2021 16:09:18 +0000 (UTC)
commit 2ccbc3ec92f078be88e0e3b3e74b370dae3a2eec
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Sat Apr 3 15:01:24 2021 +0100
Extract common code into generate_encryption_mapping_name() (#59)
Closes #59 - Resize of LUKS2 encrypted file system fails with "Nothing
to read on input"
include/Utils.h | 1 +
src/Utils.cc | 15 +++++++++++++++
src/Win_GParted.cc | 19 +++----------------
3 files changed, 19 insertions(+), 16 deletions(-)
---
diff --git a/include/Utils.h b/include/Utils.h
index eeb9cb3c..da1047d0 100644
--- a/include/Utils.h
+++ b/include/Utils.h
@@ -146,6 +146,7 @@ public:
static const Glib::ustring get_filesystem_string( bool encrypted, FSType fstype );
static const Glib::ustring get_filesystem_kernel_name( FSType fstype );
static Glib::ustring get_filesystem_software(FSType fstype);
+ static const Glib::ustring generate_encryption_mapping_name(const Glib::ustring& path);
static bool kernel_supports_fs( const Glib::ustring & fs ) ;
static bool kernel_version_at_least( int major_ver, int minor_ver, int patch_ver ) ;
static Glib::ustring format_size( Sector sectors, Byte_Value sector_size ) ;
diff --git a/src/Utils.cc b/src/Utils.cc
index 0b08a5cf..856ee3de 100644
--- a/src/Utils.cc
+++ b/src/Utils.cc
@@ -458,6 +458,21 @@ Glib::ustring Utils::get_filesystem_software(FSType fstype)
}
+// Return the encryption mapping name GParted will use when opening it, given it's block
+// device name.
+// E.g., generate_encryption_mapping_name("/dev/sdb1") -> "sdb1_crypt"
+const Glib::ustring Utils::generate_encryption_mapping_name(const Glib::ustring& path)
+{
+ Glib::ustring mapping_name = path;
+
+ Glib::ustring::size_type last_slash = path.rfind("/");
+ if (last_slash != Glib::ustring::npos)
+ mapping_name = path.substr(last_slash + 1);
+
+ return mapping_name + "_crypt";
+}
+
+
//Report whether or not the kernel supports a particular file system
bool Utils::kernel_supports_fs( const Glib::ustring & fs )
{
diff --git a/src/Win_GParted.cc b/src/Win_GParted.cc
index 0789ead9..011d1e96 100644
--- a/src/Win_GParted.cc
+++ b/src/Win_GParted.cc
@@ -2155,15 +2155,9 @@ bool Win_GParted::ask_for_password_for_encrypted_resize_as_required(const Partit
continue;
}
- // Create LUKS mapping name from partition name:
- // "/dev/sdb1" -> "sdb1_crypt"
- Glib::ustring mapping_name = selected_partition_ptr->get_path();
- Glib::ustring::size_type last_slash = mapping_name.rfind("/");
- if (last_slash != Glib::ustring::npos)
- mapping_name = mapping_name.substr(last_slash + 1);
- mapping_name += "_crypt";
-
// Test the password can open the encryption mapping.
+ const Glib::ustring mapping_name = Utils::generate_encryption_mapping_name(
+ selected_partition_ptr->get_path());
Glib::ustring cmd = "cryptsetup luksOpen --test-passphrase " +
Glib::shell_quote(partition.get_path()) + " " +
Glib::shell_quote(mapping_name);
@@ -2703,14 +2697,7 @@ bool Win_GParted::open_encrypted_partition( const Partition & partition,
}
}
- // Create LUKS mapping name from partition name:
- // "/dev/sdb1" -> "sdb1_crypt"
- Glib::ustring mapping_name = selected_partition_ptr->get_path();
- Glib::ustring::size_type last_slash = mapping_name.rfind( "/" );
- if ( last_slash != Glib::ustring::npos )
- mapping_name = mapping_name.substr( last_slash + 1 );
- mapping_name += "_crypt";
-
+ const Glib::ustring mapping_name =
Utils::generate_encryption_mapping_name(selected_partition_ptr->get_path());
Glib::ustring cmd = "cryptsetup luksOpen " +
Glib::shell_quote( partition.get_path() ) + " " +
Glib::shell_quote( mapping_name );
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]