Display messages for encrypted file systems (#760080)

At the moment any messages for an encrypted file system aren't shown,
only messages from the outer PartitionLUKS object are shown.  Also in
Win_GParted::activate_paste() the selected Partition object, possibly
a derived PartitionLUKS, is cloned and the messages cleared.

Therefore a set of accessor methods must be provided to query and modify
partition messages.  Messages will be stored in the Partition object to
which they are added and retrieved from all.  So in the case of a
derived PartitionLUKS they will be retrieved from the messages vector of
the PartitionLUKS object itself and the messages vector for the
encrypted file system it contains.

To replace code like this in GParted_Core:

    partition_temp->messages = messages;

We might naturally provide a set_messages() method which assigns the
messages vector and is used like this:

    partition_temp->set_messages( messages );

However on a PartitionLUKS object what should set_messages() do?  By the
name it will replace any existing messages in the PartitionLUKS object
itself, but what should happen to the messages for the contained
encrypted Partition object?  Should they be cleared or left alone?
Rather than implement set_messages() with unclear semantics implement
append_messages(), which in the PartitionLUKS object case will clearly
leave any messages for the contained encrypted Partition object alone.
Append_messages() is then used to add messages as the Partition or
PartitionLUKS objects when populating the data in GParted_Core.

Bug 760080 - Implement read-only LUKS support
This commit is contained in:
Mike Fleetwood 2015-12-31 16:32:08 +00:00 committed by Curtis Gedak
parent f91d7e19dd
commit 2d910494d3
20 changed files with 138 additions and 102 deletions

View File

@ -116,6 +116,21 @@ public:
virtual Glib::ustring get_filesystem_label() const;
void set_filesystem_label( const Glib::ustring & filesystem_label );
// Message accessors. Messages are stored locally and accessed globally.
// Stored locally means the messages are stored in the Partition object to which
// they are added so push_back_messages() and append_messages() are non-virtual.
// Accessed globally means that in the case of derived objects which are composed
// of more that one Partition object, i.e. PartitionLUKS, the messages have to be
// accessible from all copies within the derived object hierarchy. Hence
// have_messages(), get_messages() and clear_messages() are virtual to allow for
// overridden implementations.
virtual bool have_messages() const { return ! messages.empty(); };
virtual std::vector<Glib::ustring> get_messages() const { return messages; };
virtual void clear_messages() { messages.clear(); };
void push_back_message( Glib::ustring msg ) { messages.push_back( msg ); };
void append_messages( const std::vector<Glib::ustring> msgs )
{ messages.insert( messages.end(), msgs.begin(), msgs.end() ); }
bool operator==( const Partition & partition ) const ;
bool operator!=( const Partition & partition ) const ;
@ -137,7 +152,6 @@ public:
Sector significant_threshold; //Threshold from intrinsic to significant unallocated sectors
bool inside_extended;
bool busy;
std::vector<Glib::ustring> messages ;
std::vector<Glib::ustring> flags ;
PartitionVector logicals;
@ -161,6 +175,7 @@ private:
std::vector<Glib::ustring> mountpoints ;
bool have_filesystem_label;
Glib::ustring filesystem_label;
std::vector<Glib::ustring> messages;
};
}//GParted

View File

@ -40,6 +40,9 @@ public:
virtual Sector get_sectors_unused() const;
virtual Sector get_sectors_unallocated() const;
virtual Glib::ustring get_filesystem_label() const;
virtual bool have_messages() const;
virtual std::vector<Glib::ustring> get_messages() const;
virtual void clear_messages();
private:
Partition encrypted;

View File

@ -40,7 +40,7 @@ Dialog_Partition_Info::Dialog_Partition_Info( const Partition & partition ) : pa
// Set minimum dialog height so it fits on an 800x600 screen without too much
// whitespace (~500 px max for GNOME desktop). Allow extra space if have any
// messages or for LVM2 PV or LUKS encryption.
if ( partition.messages.size() > 0 ||
if ( partition.have_messages() ||
partition.filesystem == FS_LVM2_PV ||
partition.filesystem == FS_LUKS )
this ->set_size_request( -1, 460) ;
@ -73,7 +73,7 @@ Dialog_Partition_Info::Dialog_Partition_Info( const Partition & partition ) : pa
Display_Info() ;
//display messages (if any)
if ( partition .messages .size() > 0 )
if ( partition.have_messages() )
{
frame = manage( new Gtk::Frame() );
@ -90,29 +90,30 @@ Dialog_Partition_Info::Dialog_Partition_Info( const Partition & partition ) : pa
frame ->set_label_widget( *hbox ) ;
//Merge all messages for display so that they can be selected together.
// Use a blank line between individual messages so that each message can be
// distinguished. Therefore each message should have been formatted as one
// or more non-blank lines, with an optional trailing new line. This is
// true of GParted internal messages and probably all external messages and
// errors from libparted and executed commands too.
Glib::ustring all_messages ;
for ( unsigned int t = 0; t < partition .messages .size(); t ++ )
// Concatenate all messages for display so that they can be selected
// together. Use a blank line between individual messages so that each
// message can be distinguished. Therefore each message should have been
// formatted as one or more non-blank lines, with an optional trailing new
// line. This is true of GParted internal messages and probably all
// external messages and errors from libparted and executed commands too.
std::vector<Glib::ustring> messages = partition.get_messages();
Glib::ustring concatenated_messages;
for ( unsigned int i = 0; i < messages.size(); i ++ )
{
if ( all_messages .size() > 0 )
all_messages += "\n\n" ;
if ( concatenated_messages.size() > 0 )
concatenated_messages += "\n\n";
Glib::ustring::size_type take = partition .messages[ t ] .size() ;
Glib::ustring::size_type take = messages[i].size();
if ( take > 0 )
{
if ( partition .messages[ t ][ take-1 ] == '\n' )
if ( messages[i][take-1] == '\n' )
take -- ; //Skip optional trailing new line
all_messages += "<i>" + partition .messages[ t ] .substr( 0, take ) + "</i>" ;
concatenated_messages += "<i>" + messages[i].substr( 0, take ) + "</i>";
}
}
Gtk::VBox *vbox( manage( new Gtk::VBox() ) ) ;
vbox ->set_border_width( 5 ) ;
vbox ->pack_start( *Utils::mk_label( all_messages, true, true, true ), Gtk::PACK_SHRINK ) ;
vbox->pack_start( *Utils::mk_label( concatenated_messages, true, true, true ), Gtk::PACK_SHRINK );
frame ->add( *vbox ) ;
info_msg_vbox .pack_start( *frame, Gtk::PACK_EXPAND_WIDGET ) ;

View File

@ -353,7 +353,7 @@ void GParted_Core::set_devices_thread( std::vector<Device> * pdevices )
false,
false );
// Place unknown file system message in this partition.
partition_temp->messages = messages;
partition_temp->append_messages( messages );
temp_device.partitions.push_back_adopt( partition_temp );
}
// Unrecognised, unpartitioned drive.
@ -375,9 +375,7 @@ void GParted_Core::set_devices_thread( std::vector<Device> * pdevices )
temp_device.sector_size,
false );
// Place libparted messages in this unallocated partition
partition_temp->messages.insert( partition_temp->messages.end(),
libparted_messages.begin(),
libparted_messages.end() );
partition_temp->append_messages( libparted_messages );
libparted_messages.clear();
temp_device.partitions.push_back_adopt( partition_temp );
}
@ -1298,7 +1296,7 @@ void GParted_Core::set_device_partitions( Device & device, PedDevice* lp_device,
device.sector_size,
( lp_partition->type == PED_PARTITION_LOGICAL ),
partition_is_busy );
partition_temp->messages = detect_messages;
partition_temp->append_messages( detect_messages );
partition_temp->add_paths( pp_info.get_alternate_paths( partition_temp->get_path() ) );
set_flags( *partition_temp, lp_partition );
@ -1347,9 +1345,7 @@ void GParted_Core::set_device_partitions( Device & device, PedDevice* lp_device,
if ( device.partition_naming_supported() )
partition_temp->name = Glib::ustring( ped_partition_get_name( lp_partition ) );
partition_temp->messages.insert( partition_temp->messages.end(),
libparted_messages.begin(),
libparted_messages.end() );
partition_temp->append_messages( libparted_messages );
if ( ! partition_temp->inside_extended )
device.partitions.push_back_adopt( partition_temp );
@ -1414,7 +1410,7 @@ void GParted_Core::set_device_one_partition( Device & device, PedDevice * lp_dev
false,
partition_is_busy );
partition_temp->messages = messages;
partition_temp->append_messages( messages );
partition_temp->add_paths( pp_info.get_alternate_paths( partition_temp->get_path() ) );
if ( fstype == FS_LUKS )
@ -1465,7 +1461,7 @@ void GParted_Core::set_luks_partition( PartitionLUKS & partition )
partition.sector_size,
false,
fs_busy );
encrypted.messages = detect_messages;
encrypted.append_messages( detect_messages );
Proc_Partitions_Info pp_info; // Use cache of proc partitions information
encrypted.add_paths( pp_info.get_alternate_paths( encrypted.get_path() ) );
@ -1869,7 +1865,7 @@ void GParted_Core::set_mountpoints( Partition & partition )
}
if ( partition.get_mountpoints().empty() )
partition.messages.push_back( _("Unable to find mount point") );
partition.push_back_message( _("Unable to find mount point") );
}
else // Not busy file system
{
@ -1996,7 +1992,7 @@ void GParted_Core::set_used_sectors( Partition & partition, PedDisk* lp_disk )
Utils::get_filesystem_software( partition.filesystem )
);
}
partition.messages.push_back( temp );
partition.push_back_message( temp );
}
else if ( ( unallocated = partition.get_sectors_unallocated() ) > 0 )
{
@ -2015,7 +2011,7 @@ void GParted_Core::set_used_sectors( Partition & partition, PedDisk* lp_disk )
temp += "\n";
temp += _("Partition --> Check.");
}
partition.messages.push_back( temp );
partition.push_back_message( temp );
}
if ( filesystem_resize_disallowed( partition ) )
@ -2023,7 +2019,7 @@ void GParted_Core::set_used_sectors( Partition & partition, PedDisk* lp_disk )
Glib::ustring temp = get_filesystem_object( partition.filesystem )
->get_custom_text( CTEXT_RESIZE_DISALLOWED_WARNING );
if ( ! temp.empty() )
partition.messages.push_back( temp );
partition.push_back_message( temp );
}
}
}
@ -2040,7 +2036,7 @@ void GParted_Core::mounted_set_used_sectors( Partition & partition )
partition .set_sector_usage( fs_size / partition .sector_size,
fs_free / partition .sector_size ) ;
else
partition .messages .push_back( error_message ) ;
partition.push_back_message( error_message );
}
}

View File

@ -149,4 +149,29 @@ Glib::ustring PartitionLUKS::get_filesystem_label() const
return "";
}
bool PartitionLUKS::have_messages() const
{
if ( busy )
return Partition::have_messages() || encrypted.have_messages();
return Partition::have_messages();
}
std::vector<Glib::ustring> PartitionLUKS::get_messages() const
{
if ( busy )
{
std::vector<Glib::ustring> msgs = Partition::get_messages();
std::vector<Glib::ustring> msgs2 = encrypted.get_messages();
msgs.insert( msgs.end(), msgs2.begin(), msgs2.end() );
return msgs;
}
return Partition::get_messages();
}
void PartitionLUKS::clear_messages()
{
Partition::clear_messages();
encrypted.clear_messages();
}
} //GParted

View File

@ -167,7 +167,7 @@ void TreeView_Detail::create_row( const Gtk::TreeRow & treerow, const Partition
treerow[ treeview_detail_columns .icon1 ] =
render_icon( Gtk::Stock::DIALOG_AUTHENTICATION, Gtk::ICON_SIZE_BUTTON );
if ( partition .messages .size() > 0 )
if ( partition.have_messages() > 0 )
{
if ( ! static_cast< Glib::RefPtr<Gdk::Pixbuf> >( treerow[ treeview_detail_columns .icon1 ] ) )
treerow[ treeview_detail_columns .icon1 ] =

View File

@ -1836,7 +1836,7 @@ void Win_GParted::activate_paste()
// We don't want the messages, mount points or name of the source
// partition for the new partition being created.
Partition * part_temp = copied_partition->clone();
part_temp->messages.clear();
part_temp->clear_messages();
part_temp->clear_mountpoints();
part_temp->name.clear();
@ -1897,7 +1897,7 @@ void Win_GParted::activate_paste()
new_size,
new_size - copied_partition->sectors_used );
}
partition_new->messages.clear();
partition_new->clear_messages();
Operation * operation = new OperationCopy( devices[current_device],
*selected_partition_ptr,

View File

@ -285,10 +285,10 @@ void btrfs::set_used_sectors( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}
@ -402,10 +402,10 @@ void btrfs::read_label( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}
}
@ -425,10 +425,10 @@ void btrfs::read_uuid( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}

View File

@ -146,7 +146,7 @@ void ext2::set_used_sectors( Partition & partition )
else
{
N = -1 ;
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}
else
@ -166,10 +166,10 @@ void ext2::set_used_sectors( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}
@ -182,10 +182,10 @@ void ext2::read_label( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}
@ -205,10 +205,10 @@ void ext2::read_uuid( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}

View File

@ -164,10 +164,10 @@ void fat16::set_used_sectors( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}
@ -180,10 +180,10 @@ void fat16::read_label( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}
@ -212,10 +212,10 @@ void fat16::read_uuid( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}

View File

@ -68,10 +68,10 @@ void hfs::read_label( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}

View File

@ -66,10 +66,10 @@ void hfsplus::read_label( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}

View File

@ -106,10 +106,10 @@ void jfs::set_used_sectors( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}
@ -122,10 +122,10 @@ void jfs::read_label( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}
@ -144,10 +144,10 @@ void jfs::read_uuid( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}

View File

@ -93,7 +93,7 @@ void linux_swap::set_used_sectors( Partition & partition )
}
else
{
partition .messages .push_back( "open(\"/proc/swaps\", O_RDONLY): " + Glib::strerror( errno ) ) ;
partition.push_back_message( "open(\"/proc/swaps\", O_RDONLY): " + Glib::strerror( errno ) );
}
if ( N > -1 )
{
@ -123,10 +123,10 @@ void linux_swap::read_label( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}
@ -145,10 +145,10 @@ void linux_swap::read_uuid( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}

View File

@ -89,11 +89,7 @@ void lvm2_pv::set_used_sectors( Partition & partition )
}
std::vector<Glib::ustring> error_messages = LVM2_PV_Info::get_error_messages( partition.get_path() );
if ( ! error_messages .empty() )
{
for ( unsigned int i = 0 ; i < error_messages .size() ; i ++ )
partition .messages .push_back( error_messages [ i ] ) ;
}
partition.append_messages( error_messages );
}
bool lvm2_pv::create( const Partition & new_partition, OperationDetail & operationdetail )

View File

@ -106,10 +106,10 @@ void nilfs2::set_used_sectors( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}
@ -126,10 +126,10 @@ void nilfs2::read_label( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}
@ -149,10 +149,10 @@ void nilfs2::read_uuid( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}

View File

@ -148,10 +148,10 @@ void ntfs::set_used_sectors( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}
@ -164,10 +164,10 @@ void ntfs::read_label( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}

View File

@ -89,10 +89,10 @@ void reiser4::set_used_sectors( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}
@ -113,10 +113,10 @@ void reiser4::read_label( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}
@ -129,10 +129,10 @@ void reiser4::read_uuid( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}

View File

@ -106,10 +106,10 @@ void reiserfs::set_used_sectors( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}
@ -122,10 +122,10 @@ void reiserfs::read_label( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}
@ -145,10 +145,10 @@ void reiserfs::read_uuid( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}

View File

@ -116,10 +116,10 @@ void xfs::set_used_sectors( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}
@ -132,10 +132,10 @@ void xfs::read_label( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}
@ -158,10 +158,10 @@ void xfs::read_uuid( Partition & partition )
else
{
if ( ! output .empty() )
partition .messages .push_back( output ) ;
partition.push_back_message( output );
if ( ! error .empty() )
partition .messages .push_back( error ) ;
partition.push_back_message( error );
}
}