Use wipefs to clear old signatures before creating new file systems (#688882)
Previously the function erase_filesystem_signatures() was used to clear file system signatures when a new partition was created and when an existing partition was formatted with a file system. However this was only available with libparted <= 2.4 and then only for the file systems which libparted supports. Having multiple different file system signatures on a partition leads to misidentification of file system. For example creating a nilfs2 over the top of a fat32 file system is detected as a fat32, not nilfs2. This shows that old file system signatures must be cleared before a new file system is created. Fix by always using "wipefs -a /dev/PARTITION" command to clear all old file system signatures rather than libparted API calls. Failure from wipefs is only considered a warning so doesn't fail the file system creation. (This doesn't yet fully meet the "MUST be cleared" requirement above. Will be fully met later in this patchset). Output from the wipefs command is displayed as a new sub-step which looks like this: v Format /dev/sda7 as xfs 00:00:05 > calibrate /dev/sda14 00:00:01 v clear old file system signatures in /dev/sda7 00:00:01 [NEW] > wipefs -a /dev/sda7 [NEW] > set partition type on /dev/sda7 00:00:02 v create new xfs file system 00:00:01 > mkfs.xfs -f -L "" /dev/sda7 Also signatures are only cleared immediately before a new file system is written and not when an unformatted partition is created. This allows recovery from accidental partition deletion by re-creating the deleted partition as unformatted. Bug #688882 - Improve clearing of file system signatures
This commit is contained in:
parent
12d2cad682
commit
3c75f3f5b1
|
@ -178,9 +178,7 @@ private:
|
|||
Partition & partition_new,
|
||||
OperationDetail & operationdetail ) ;
|
||||
FileSystem* set_proper_filesystem( const FILESYSTEM & filesystem ) ;
|
||||
#ifndef HAVE_LIBPARTED_3_0_0_PLUS
|
||||
bool erase_filesystem_signatures( const Partition & partition ) ;
|
||||
#endif
|
||||
bool erase_filesystem_signatures( const Partition & partition, OperationDetail & operationdetail ) ;
|
||||
bool update_bootsector( const Partition & partition, OperationDetail & operationdetail ) ;
|
||||
|
||||
//general..
|
||||
|
|
|
@ -1700,8 +1700,9 @@ bool GParted_Core::create( const Device & device, Partition & new_partition, Ope
|
|||
if ( new_partition .filesystem == GParted::FS_UNFORMATTED )
|
||||
return true ;
|
||||
else
|
||||
return set_partition_type( new_partition, operationdetail ) &&
|
||||
create_filesystem( new_partition, operationdetail ) ;
|
||||
return erase_filesystem_signatures( new_partition, operationdetail )
|
||||
&& set_partition_type( new_partition, operationdetail )
|
||||
&& create_filesystem( new_partition, operationdetail ) ;
|
||||
}
|
||||
|
||||
return false ;
|
||||
|
@ -1796,11 +1797,7 @@ bool GParted_Core::create_partition( Partition & new_partition, OperationDetail
|
|||
close_device_and_disk( lp_device, lp_disk ) ;
|
||||
}
|
||||
|
||||
bool succes = new_partition .partition_number > 0
|
||||
#ifndef HAVE_LIBPARTED_3_0_0_PLUS
|
||||
&& erase_filesystem_signatures( new_partition )
|
||||
#endif
|
||||
;
|
||||
bool succes = new_partition .partition_number > 0 ;
|
||||
|
||||
#ifndef USE_LIBPARTED_DMRAID
|
||||
//create dev map entries if dmraid
|
||||
|
@ -1849,12 +1846,9 @@ bool GParted_Core::create_filesystem( const Partition & partition, OperationDeta
|
|||
|
||||
bool GParted_Core::format( const Partition & partition, OperationDetail & operationdetail )
|
||||
{
|
||||
#ifndef HAVE_LIBPARTED_3_0_0_PLUS
|
||||
//remove all file system signatures...
|
||||
erase_filesystem_signatures( partition ) ;
|
||||
#endif
|
||||
|
||||
return set_partition_type( partition, operationdetail ) && create_filesystem( partition, operationdetail ) ;
|
||||
return erase_filesystem_signatures( partition, operationdetail )
|
||||
&& set_partition_type( partition, operationdetail )
|
||||
&& create_filesystem( partition, operationdetail ) ;
|
||||
}
|
||||
|
||||
bool GParted_Core::Delete( const Partition & partition, OperationDetail & operationdetail )
|
||||
|
@ -3123,36 +3117,27 @@ bool GParted_Core::filesystem_resize_disallowed( const Partition & partition )
|
|||
return false ;
|
||||
}
|
||||
|
||||
#ifndef HAVE_LIBPARTED_3_0_0_PLUS
|
||||
bool GParted_Core::erase_filesystem_signatures( const Partition & partition )
|
||||
bool GParted_Core::erase_filesystem_signatures( const Partition & partition, OperationDetail & operationdetail )
|
||||
{
|
||||
bool return_value = false ;
|
||||
|
||||
PedDevice* lp_device = NULL ;
|
||||
PedDisk* lp_disk = NULL ;
|
||||
if ( open_device_and_disk( partition .device_path, lp_device, lp_disk ) )
|
||||
if ( ! Glib::find_program_in_path( "wipefs" ) .empty() )
|
||||
{
|
||||
PedPartition* lp_partition = ped_disk_get_partition_by_sector( lp_disk, partition .get_sector() ) ;
|
||||
|
||||
if ( lp_partition && ped_file_system_clobber( & lp_partition ->geom ) )
|
||||
{
|
||||
//file systems not yet supported by libparted
|
||||
if ( ped_device_open( lp_device ) )
|
||||
{
|
||||
//reiser4 stores "ReIsEr4" at sector 128 with a sector size of 512 bytes
|
||||
// FIXME writing block of partially uninitialized bytes (security/privacy)
|
||||
return_value = ped_geometry_write( & lp_partition ->geom, "0000000", (65536 / lp_device ->sector_size), 1 ) ;
|
||||
|
||||
ped_device_close( lp_device ) ;
|
||||
}
|
||||
operationdetail .add_child( OperationDetail(
|
||||
String::ucompose( _("clear old file system signatures in %1"),
|
||||
partition .get_path() ) ) ) ;
|
||||
OperationDetail & od = operationdetail .get_last_child() ;
|
||||
Glib::ustring output, error ;
|
||||
Glib::ustring command = "wipefs -a " + partition .get_path() ;
|
||||
od .add_child( OperationDetail( command, STATUS_NONE, FONT_BOLD_ITALIC ) ) ;
|
||||
int exit_status = Utils::execute_command( command, output, error, true ) ;
|
||||
if ( ! output .empty() )
|
||||
od .get_last_child() .add_child( OperationDetail( output, STATUS_NONE, FONT_ITALIC ) ) ;
|
||||
if ( ! error .empty() )
|
||||
od .get_last_child() .add_child( OperationDetail( error, STATUS_NONE, FONT_ITALIC ) ) ;
|
||||
od .set_status( exit_status == 0 ? STATUS_SUCCES : STATUS_N_A ) ;
|
||||
}
|
||||
|
||||
close_device_and_disk( lp_device, lp_disk ) ;
|
||||
}
|
||||
|
||||
return return_value ;
|
||||
return true ;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool GParted_Core::update_bootsector( const Partition & partition, OperationDetail & operationdetail )
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue