Extract common code into generate_encryption_mapping_name() (#59)

Closes #59 - Resize of LUKS2 encrypted file system fails with "Nothing
             to read on input"
This commit is contained in:
Mike Fleetwood 2021-04-03 15:01:24 +01:00 committed by Curtis Gedak
parent 83abcd8873
commit 2ccbc3ec92
3 changed files with 19 additions and 16 deletions

View File

@ -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 ) ;

View File

@ -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 )
{

View File

@ -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 );