From 1b55dfad5b271f1c9dc4ab1651cfe22cf923b7b4 Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Sun, 3 Jan 2016 08:42:49 +0000 Subject: [PATCH] Move DEV_MAPPER_PATH from DMRaid.h to Utils.h (#760080) Renamed from DEV_MAP_PATH to DEV_MAPPER_PATH. Moved so that the constant is logically intended for use outside of the DMRaid class. Also specifically make the string constant have external linkage, rather than the default internal (static) linkage for constants, so that there is only one copy of the variable in the program, rather than one copy in each compilation unit which included DMRaid.h. Namely DMRaid.cc and GParted_Core.cc. References: [1] Proper way to do const std::string in a header file? http://stackoverflow.com/questions/10201880/proper-way-to-do-const-stdstring-in-a-header-file [2] What is external linkage and internal linkage in C++ http://stackoverflow.com/questions/1358400/what-is-external-linkage-and-internal-linkage-in-c/1358796#1358796 Bug 760080 - Implement read-only LUKS support --- include/DMRaid.h | 3 --- include/Utils.h | 2 ++ src/DMRaid.cc | 22 +++++++++++----------- src/Utils.cc | 2 ++ 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/include/DMRaid.h b/include/DMRaid.h index 377fede6..92cd8f52 100644 --- a/include/DMRaid.h +++ b/include/DMRaid.h @@ -32,9 +32,6 @@ #include -//Declare some constants -const Glib::ustring DEV_MAP_PATH = "/dev/mapper/" ; - namespace GParted { diff --git a/include/Utils.h b/include/Utils.h index 5793b83f..8cef57b7 100644 --- a/include/Utils.h +++ b/include/Utils.h @@ -55,6 +55,8 @@ const Byte_Value EXBIBYTE=(PEBIBYTE * KIBIBYTE); const Glib::ustring UUID_RANDOM = _("(New UUID - will be randomly generated)") ; const Glib::ustring UUID_RANDOM_NTFS_HALF = _("(Half new UUID - will be randomly generated)") ; +extern const Glib::ustring DEV_MAPPER_PATH; + enum FILESYSTEM { // Special partition types and functions diff --git a/src/DMRaid.cc b/src/DMRaid.cc index 290bf742..077831f8 100644 --- a/src/DMRaid.cc +++ b/src/DMRaid.cc @@ -167,7 +167,7 @@ void DMRaid::get_devices( std::vector & device_list ) device_list .clear() ; for ( unsigned int k=0; k < dmraid_devices .size(); k++ ) - device_list .push_back( DEV_MAP_PATH + dmraid_devices[k] ) ; + device_list.push_back( DEV_MAPPER_PATH + dmraid_devices[k] ); } Glib::ustring DMRaid::get_dmraid_name( const Glib::ustring & dev_path ) @@ -220,7 +220,7 @@ void DMRaid::get_dmraid_dir_entries( const Glib::ustring & dev_path, std::vector //Loop through the entries in the directory Glib::ustring filename = "" ; - Glib::Dir dir( DEV_MAP_PATH) ; + Glib::Dir dir( DEV_MAPPER_PATH ); while ( ( filename = dir .read_name() ) != "" ) { if ( filename == "control" ) @@ -287,11 +287,11 @@ Glib::ustring DMRaid::make_path_dmraid_compatible( Glib::ustring partition_path for ( unsigned int k=0; k < dmraid_devices .size(); k++ ) { - reg_exp = DEV_MAP_PATH + dmraid_devices[ k ] + "p([0-9]+)" ; + reg_exp = DEV_MAPPER_PATH + dmraid_devices[k] + "p([0-9]+)"; partition_number = Utils::regexp_label( partition_path, reg_exp ) ; if ( ! partition_number .empty() ) { - partition_path = DEV_MAP_PATH + dmraid_devices[ k ] + partition_number ; + partition_path = DEV_MAPPER_PATH + dmraid_devices[k] + partition_number; return partition_path ; } } @@ -308,7 +308,7 @@ Glib::ustring DMRaid::make_path_dmraid_compatible( Glib::ustring partition_path if ( ! device_path .empty() ) { device_path = get_udev_dm_name( device_path ) ; - partition_path = DEV_MAP_PATH + device_path + partition_number ; + partition_path = DEV_MAPPER_PATH + device_path + partition_number; } } @@ -323,7 +323,7 @@ bool DMRaid::create_dev_map_entries( const Partition & partition, OperationDetai bool exit_status = true ; /*TO TRANSLATORS: looks like create missing /dev/mapper entries */ - Glib::ustring tmp = String::ucompose ( _("create missing %1 entries"), DEV_MAP_PATH ) ; + Glib::ustring tmp = String::ucompose ( _("create missing %1 entries"), DEV_MAPPER_PATH ); operationdetail .add_child( OperationDetail( tmp ) ); //Newer dmraid defaults to always inserting the letter 'p' between the device name @@ -422,14 +422,14 @@ bool DMRaid::delete_affected_dev_map_entries( const Partition & partition, Opera bool exit_status = true ; /*TO TRANSLATORS: looks like delete affected /dev/mapper entries */ - Glib::ustring tmp = String::ucompose ( _("delete affected %1 entries"), DEV_MAP_PATH ) ; + Glib::ustring tmp = String::ucompose ( _("delete affected %1 entries"), DEV_MAPPER_PATH ); operationdetail .add_child( OperationDetail( tmp ) ); get_affected_dev_map_entries( partition, affected_entries ) ; for ( unsigned int k=0; k < affected_entries .size(); k++ ) { - command = "dmsetup remove " + DEV_MAP_PATH + affected_entries[k] ; + command = "dmsetup remove " + DEV_MAPPER_PATH + affected_entries[k]; if ( execute_command( command, operationdetail .get_last_child() ) ) exit_status = false ; //command failed } @@ -445,7 +445,7 @@ bool DMRaid::delete_dev_map_entry( const Partition & partition, OperationDetail bool exit_status = true ; /*TO TRANSLATORS: looks like delete /dev/mapper entry */ - Glib::ustring tmp = String::ucompose ( _("delete %1 entry"), DEV_MAP_PATH ) ; + Glib::ustring tmp = String::ucompose ( _("delete %1 entry"), DEV_MAPPER_PATH ); operationdetail .add_child( OperationDetail( tmp ) ); std::vector partition_entries ; @@ -476,7 +476,7 @@ bool DMRaid::purge_dev_map_entries( const Glib::ustring & dev_path ) for ( unsigned int k=0; k < dir_list .size(); k++ ) { - command = "dmsetup remove " + DEV_MAP_PATH + dir_list[k] ; + command = "dmsetup remove " + DEV_MAPPER_PATH + dir_list[k]; if ( Utils::execute_command( command, output, error, true ) ) exit_status = false ; //command failed } @@ -495,7 +495,7 @@ bool DMRaid::update_dev_map_entry( const Partition & partition, OperationDetail bool exit_status = true ; /*TO TRANSLATORS: looks like update /dev/mapper entry */ - Glib::ustring tmp = String::ucompose ( _("update %1 entry"), DEV_MAP_PATH ) ; + Glib::ustring tmp = String::ucompose ( _("update %1 entry"), DEV_MAPPER_PATH ); operationdetail .add_child( OperationDetail( tmp ) ); if( ! delete_dev_map_entry( partition , operationdetail .get_last_child() ) ) diff --git a/src/Utils.cc b/src/Utils.cc index 0d862938..d9250965 100644 --- a/src/Utils.cc +++ b/src/Utils.cc @@ -39,6 +39,8 @@ namespace GParted { +const Glib::ustring DEV_MAPPER_PATH = "/dev/mapper/"; + Sector Utils::round( double double_value ) { return static_cast( double_value + 0.5 ) ;