Add file system specific remove() methods (#670171)

This commit only adds a remove() method to every file system and an
optional call to it in the relevant operations.  All remove() methods
are no operations and not enabled.

The remove() method provides explicit controlled removal of a file
system before the partition is deleted or overwritten by being formatted
or pasted into.  When implemented, it appears as an extra step in the
relevant operation.  The file system specific remove() method is
explicitly allowed to fail and stop the operations currently being
applied.

This is different to the existing erase_filesystem_signatures() which
wipes any previous file system signatures immediately before a new file
system is written to ensure there is no possibility of the partition
containing two or more different file system signatures.  It never fails
or reports anything to the user.

NOTE:
Most file systems should NOT implement a remove() method as it will
prevent recovery from accidental partition deletion.

Bug #670171 - Add LVM PV read-write support
This commit is contained in:
Mike Fleetwood 2012-07-25 21:05:33 +01:00 committed by Curtis Gedak
parent 566ebc1b88
commit 795a92f5b2
40 changed files with 147 additions and 8 deletions

View file

@ -55,7 +55,8 @@ public:
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail ) = 0 ;
virtual bool check_repair( const Partition & partition, OperationDetail & operationdetail ) = 0 ;
virtual bool remove( const Partition & partition, OperationDetail & operationdetail ) = 0 ;
protected:
int execute_command( const Glib::ustring & command, OperationDetail & operationdetail ) ;
int execute_command_timed( const Glib::ustring & command

View file

@ -97,7 +97,9 @@ private:
bool format( const Partition & partition, OperationDetail & operationdetail ) ;
bool Delete( const Partition & partition, OperationDetail & operationdetail ) ;
bool remove_filesystem( const Partition & partition, OperationDetail & operationdetail ) ;
bool label_partition( const Partition & partition, OperationDetail & operation_detail ) ;
bool change_uuid( const Partition & partition, OperationDetail & operation_detail ) ;

View file

@ -125,13 +125,15 @@ struct FS
Support move ; //startpoint and endpoint
Support check ; //some checktool available?
Support copy ;
Support remove ;
Byte_Value MIN ;
Byte_Value MAX ;
FS()
{
read = read_label = write_label = read_uuid = write_uuid = create = grow = shrink = move = check = copy = NONE;
read = read_label = write_label = read_uuid = write_uuid = create = grow = shrink =
move = check = copy = remove = NONE ;
MIN = MAX = 0 ;
}
} ;

View file

@ -43,6 +43,7 @@ public:
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail ) ;
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
bool remove( const Partition & partition, OperationDetail & operationdetail ) ;
private:
static Byte_Value btrfs_size_to_num( Glib::ustring str, Byte_Value ptn_bytes, bool scale_up ) ;

View file

@ -47,6 +47,7 @@ public:
, OperationDetail & operationdetail
) ;
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
bool remove( const Partition & partition, OperationDetail & operationdetail ) ;
};
} //GParted

View file

@ -44,6 +44,7 @@ public:
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail ) ;
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
bool remove( const Partition & partition, OperationDetail & operationdetail ) ;
};
} //GParted

View file

@ -44,6 +44,7 @@ public:
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail ) ;
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
bool remove( const Partition & partition, OperationDetail & operationdetail ) ;
};

View file

@ -43,6 +43,7 @@ public:
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail ) ;
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
bool remove( const Partition & partition, OperationDetail & operationdetail ) ;
};

View file

@ -45,6 +45,7 @@ public:
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail ) ;
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
bool remove( const Partition & partition, OperationDetail & operationdetail ) ;
static const Glib::ustring Change_UUID_Warning [] ;
};

View file

@ -45,6 +45,7 @@ public:
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail ) ;
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
bool remove( const Partition & partition, OperationDetail & operationdetail ) ;
const static Glib::ustring ( & Change_UUID_Warning ) [] ;
};

View file

@ -44,6 +44,7 @@ public:
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail ) ;
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
bool remove( const Partition & partition, OperationDetail & operationdetail ) ;
};
} //GParted

View file

@ -44,6 +44,7 @@ public:
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail ) ;
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
bool remove( const Partition & partition, OperationDetail & operationdetail ) ;
};
} //GParted

View file

@ -44,6 +44,7 @@ public:
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail ) ;
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
bool remove( const Partition & partition, OperationDetail & operationdetail ) ;
};
} //GParted

View file

@ -46,6 +46,7 @@ public:
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail ) ;
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
bool remove( const Partition & partition, OperationDetail & operationdetail ) ;
};
} //GParted

View file

@ -44,6 +44,7 @@ public:
, const Glib::ustring & dest_part_path
, OperationDetail & operationdetail ) ;
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
bool remove( const Partition & partition, OperationDetail & operationdetail ) ;
};
} //GParted

View file

@ -44,6 +44,7 @@ public:
, OperationDetail & operationdetail
) ;
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
bool remove( const Partition & partition, OperationDetail & operationdetail ) ;
};
} //GParted

View file

@ -45,6 +45,7 @@ public:
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail ) ;
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
bool remove( const Partition & partition, OperationDetail & operationdetail ) ;
static const Glib::ustring Change_UUID_Warning [] ;
};

View file

@ -44,6 +44,7 @@ public:
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail ) ;
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
bool remove( const Partition & partition, OperationDetail & operationdetail ) ;
};
} //GParted

View file

@ -44,6 +44,7 @@ public:
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail ) ;
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
bool remove( const Partition & partition, OperationDetail & operationdetail ) ;
};
} //GParted

View file

@ -44,6 +44,7 @@ public:
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail ) ;
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
bool remove( const Partition & partition, OperationDetail & operationdetail ) ;
};
} //GParted

View file

@ -44,6 +44,7 @@ public:
const Glib::ustring & dest_part_path,
OperationDetail & operationdetail ) ;
bool check_repair( const Partition & partition, OperationDetail & operationdetail ) ;
bool remove( const Partition & partition, OperationDetail & operationdetail ) ;
};
} //GParted

View file

@ -655,7 +655,8 @@ bool GParted_Core::apply_operation_to_disk( Operation * operation )
switch ( operation ->type )
{
case OPERATION_DELETE:
succes = Delete( operation ->partition_original, operation ->operation_detail ) ;
succes = remove_filesystem( operation ->partition_original, operation ->operation_detail ) &&
Delete( operation ->partition_original, operation ->operation_detail ) ;
break ;
case OPERATION_CHECK:
succes = check_repair_filesystem( operation ->partition_original, operation ->operation_detail ) &&
@ -675,7 +676,8 @@ bool GParted_Core::apply_operation_to_disk( Operation * operation )
operation ->operation_detail ) ;
break ;
case OPERATION_FORMAT:
succes = format( operation ->partition_new, operation ->operation_detail ) ;
succes = remove_filesystem( operation ->partition_original, operation ->operation_detail ) &&
format( operation ->partition_new, operation ->operation_detail ) ;
break ;
case OPERATION_COPY:
//FIXME: in case of a new partition we should make sure the new partition is >= the source partition...
@ -685,7 +687,7 @@ bool GParted_Core::apply_operation_to_disk( Operation * operation )
calibrate_partition( static_cast<OperationCopy*>( operation ) ->partition_copied,
operation ->operation_detail ) &&
remove_filesystem( operation ->partition_original, operation ->operation_detail ) &&
copy( static_cast<OperationCopy*>( operation ) ->partition_copied,
operation ->partition_new,
static_cast<OperationCopy*>( operation ) ->partition_copied .get_byte_length(),
@ -1840,6 +1842,30 @@ bool GParted_Core::Delete( const Partition & partition, OperationDetail & operat
return succes ;
}
bool GParted_Core::remove_filesystem( const Partition & partition, OperationDetail & operationdetail )
{
bool success = true ;
switch ( get_fs( partition .filesystem ) .remove )
{
case FS::EXTERNAL:
//Run file system specific remove method to delete the file system. Most
// file systems should NOT implement a remove() method as it will prevent
// recovery from accidental partition deletion.
operationdetail .add_child( OperationDetail( String::ucompose(
_("delete %1 file system"),
Utils::get_filesystem_string( partition .filesystem ) ) ) ) ;
success = set_proper_filesystem( partition .filesystem ) &&
p_filesystem ->remove( partition, operationdetail .get_last_child() ) ;
operationdetail .get_last_child() .set_status( success ? STATUS_SUCCES : STATUS_ERROR ) ;
break ;
default:
break ;
}
return success ;
}
bool GParted_Core::label_partition( const Partition & partition, OperationDetail & operationdetail )
{
if( partition .label .empty() ) {

View file

@ -306,6 +306,11 @@ void btrfs::read_uuid( Partition & partition )
}
}
bool btrfs::remove( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
//Private methods
//Return the value of a btrfs tool formatted size, including reversing

View file

@ -88,5 +88,10 @@ bool exfat::check_repair( const Partition & partition, OperationDetail & operati
return true ;
}
bool exfat::remove( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
} //GParted

View file

@ -183,6 +183,11 @@ bool ext2::check_repair( const Partition & partition, OperationDetail & operatio
return ( exit_status == 0 || exit_status == 1 || exit_status == 2 || exit_status == 256 ) ;
}
bool ext2::remove( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
} //GParted

View file

@ -182,6 +182,11 @@ bool ext3::check_repair( const Partition & partition, OperationDetail & operatio
//this is quite normal (especially after a copy) so we let the function return true...
return ( exit_status == 0 || exit_status == 1 || exit_status == 2 || exit_status == 256 ) ;
}
bool ext3::remove( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
} //GParted

View file

@ -185,5 +185,10 @@ bool ext4::check_repair( const Partition & partition, OperationDetail & operatio
//this is quite normal (especially after a copy) so we let the function return true...
return ( exit_status == 0 || exit_status == 1 || exit_status == 2 || exit_status == 256 ) ;
}
bool ext4::remove( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
} //GParted

View file

@ -296,6 +296,11 @@ bool fat16::check_repair( const Partition & partition, OperationDetail & operati
return ( exit_status == 0 || exit_status == 1 || exit_status == 256 ) ;
}
bool fat16::remove( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
} //GParted

View file

@ -284,4 +284,9 @@ bool fat32::check_repair( const Partition & partition, OperationDetail & operati
return ( exit_status == 0 || exit_status == 1 || exit_status == 256 ) ;
}
bool fat32::remove( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
} //GParted

View file

@ -123,4 +123,9 @@ bool hfs::check_repair( const Partition & partition, OperationDetail & operation
return ! execute_command( "hfsck -v " + partition .get_path(), operationdetail ) ;
}
bool hfs::remove( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
} //GParted

View file

@ -120,4 +120,9 @@ bool hfsplus::check_repair( const Partition & partition, OperationDetail & opera
return ! execute_command( "fsck.hfsplus -f -y " + partition .get_path(), operationdetail ) ;
}
bool hfsplus::remove( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
} //GParted

View file

@ -200,6 +200,11 @@ bool jfs::check_repair( const Partition & partition, OperationDetail & operation
return ( exit_status == 0 || exit_status == 1 ) ;
}
bool jfs::remove( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
} //GParted

View file

@ -179,4 +179,9 @@ bool linux_swap::check_repair( const Partition & partition, OperationDetail & op
return true ;
}
bool linux_swap::remove( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
} //GParted

View file

@ -145,4 +145,9 @@ bool lvm2_pv::check_repair( const Partition & partition, OperationDetail & opera
return ! execute_command( "lvm pvck -v " + partition .get_path(), operationdetail ) ;
}
bool lvm2_pv::remove( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
} //GParted

View file

@ -205,4 +205,9 @@ bool nilfs2::check_repair( const Partition & partition, OperationDetail & operat
return true ;
}
bool nilfs2::remove( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
} //GParted

View file

@ -238,6 +238,11 @@ bool ntfs::check_repair( const Partition & partition, OperationDetail & operatio
return ! execute_command( "ntfsresize -P -i -f -v " + partition .get_path(), operationdetail ) ;
}
bool ntfs::remove( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
} //GParted

View file

@ -164,6 +164,11 @@ bool reiser4::check_repair( const Partition & partition, OperationDetail & opera
return ! execute_command( "fsck.reiser4 --yes --fix --quiet " + partition .get_path(), operationdetail ) ;
}
bool reiser4::remove( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
} //GParted

View file

@ -189,4 +189,9 @@ bool reiserfs::check_repair( const Partition & partition, OperationDetail & oper
return ( exit_status == 0 || exit_status == 1 || exit_status == 256 ) ;
}
bool reiserfs::remove( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
} //GParted

View file

@ -86,6 +86,11 @@ bool ufs::check_repair( const Partition & partition, OperationDetail & operation
return true ;
}
bool ufs::remove( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
} //GParted

View file

@ -257,6 +257,11 @@ bool xfs::check_repair( const Partition & partition, OperationDetail & operation
return ! execute_command( "xfs_repair -v " + partition .get_path(), operationdetail ) ;
}
bool xfs::remove( const Partition & partition, OperationDetail & operationdetail )
{
return true ;
}
} //GParted