[gparted] Make clearing signatures work with whole disk devices (#743181)



commit dc4e69136c3595f3c28253915753b65352004274
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Sat Jan 10 20:00:48 2015 +0000

    Make clearing signatures work with whole disk devices (#743181)
    
    This enables Format to Cleared operation to succeed on whole disk device
    file systems even when libparted doesn't recognise the file system.
    
    (Turns out that making calibrate work in the previous commit happened to
    make Format to Cleared operation succeed, but only if libparted
    recognised the file system on the whole disk device).
    
    Bug 743181 - Add unpartitioned drive read-write support

 src/GParted_Core.cc |   30 +++++++++++++++++++++++-------
 1 files changed, 23 insertions(+), 7 deletions(-)
---
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index ca09f06..1418769 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -3385,10 +3385,21 @@ bool GParted_Core::erase_filesystem_signatures( const Partition & partition, Ope
        bool device_is_open = false ;
        Byte_Value bufsize = 4LL * KIBIBYTE ;
        char * buf = NULL ;
-       if (    get_device_and_disk( partition .device_path, lp_device, lp_disk )
-            && ( lp_partition = ped_disk_get_partition_by_sector( lp_disk, partition .get_sector() ) ) )
+       if ( get_device( partition.device_path, lp_device ) )
        {
-               if ( ped_device_open( lp_device ) )
+               if ( partition.whole_device )
+               {
+                       // Virtual partition spanning whole disk device
+                       overall_success = true;
+               }
+               else if ( get_disk( lp_device, lp_disk ) )
+               {
+                       // Partitioned device
+                       lp_partition = ped_disk_get_partition_by_sector( lp_disk, partition.get_sector() );
+                       overall_success = ( lp_partition != NULL );
+               }
+
+               if ( overall_success && ped_device_open( lp_device ) )
                {
                        device_is_open = true ;
 
@@ -3397,7 +3408,7 @@ bool GParted_Core::erase_filesystem_signatures( const Partition & partition, Ope
                        if ( buf )
                                memset( buf, 0, bufsize ) ;
                }
-               overall_success = device_is_open ;
+               overall_success &= device_is_open;
        }
 
        //Erase all file system super blocks, including their signatures.  The specified
@@ -3487,14 +3498,19 @@ bool GParted_Core::erase_filesystem_signatures( const Partition & partition, Ope
                                                          Utils::format_size( byte_len, 1 ),
                                                          byte_offset ) ) ) ;
 
+                       // Start sector of the whole disk device or the partition
+                       Sector ptn_start = 0LL;
+                       if ( lp_partition )
+                               ptn_start = lp_partition->geom.start;
+
                        while ( written < byte_len )
                        {
                                //Write in bufsize amounts.  Last write may be smaller but
                                //  will still be a whole number of sectors.
                                Byte_Value amount = std::min( bufsize, byte_len - written ) ;
-                               zero_success = ped_geometry_write( & lp_partition ->geom, buf,
-                                                                  ( byte_offset + written ) / lp_device 
->sector_size,
-                                                                  amount / lp_device ->sector_size ) ;
+                               zero_success = ped_device_write( lp_device, buf,
+                                                                ptn_start + ( byte_offset + written ) / 
lp_device->sector_size,
+                                                                amount / lp_device->sector_size );
                                if ( ! zero_success )
                                        break ;
                                written += amount ;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]