[gparted] Split get_device_and_disk() into two (#743181)



commit 51ac4d56489653854cd22787238a14bfa66a6ad4
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Wed Jan 7 20:07:02 2015 +0000

    Split get_device_and_disk() into two (#743181)
    
    get_device_and_disk() basically calls libparted to get a PedDevice
    object representing a disk device and a PedDisk object representing a
    partition table.  Re-implement get_device_and_disk() using two separate
    functions, get_device() and get_disk(), to get one of these objects
    each.
    
    No functionality changes with this commit.  It enables future commits to
    incrementally add support for whole disk devices into GParted without
    needing libparted to recognise the contents and create a virtual "loop"
    partition table.
    
    Bug 743181 - Add unpartitioned drive read-write support

 include/GParted_Core.h |    2 +
 src/GParted_Core.cc    |   50 +++++++++++++++++++++++++++++++++--------------
 2 files changed, 37 insertions(+), 15 deletions(-)
---
diff --git a/include/GParted_Core.h b/include/GParted_Core.h
index 125aa48..55434c0 100644
--- a/include/GParted_Core.h
+++ b/include/GParted_Core.h
@@ -188,6 +188,8 @@ private:
 
        //general..     
        bool flush_device( PedDevice * lp_device ) ;
+       bool get_device( const Glib::ustring & device_path, PedDevice *& lp_device, bool flush = false );
+       bool get_disk( PedDevice *& lp_device, PedDisk *& lp_disk, bool strict = true );
        bool get_device_and_disk( const Glib::ustring & device_path,
                                  PedDevice*& lp_device, PedDisk*& lp_disk, bool strict = true, bool flush = 
false ) ;
        void destroy_device_and_disk( PedDevice*& lp_device, PedDisk*& lp_disk ) ;
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 945f85e..cabc9c8 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -3626,29 +3626,49 @@ bool GParted_Core::flush_device( PedDevice * lp_device )
        return success ;
 }
 
-bool GParted_Core::get_device_and_disk( const Glib::ustring & device_path,
-                                        PedDevice*& lp_device, PedDisk*& lp_disk, bool strict, bool flush )
+bool GParted_Core::get_device( const Glib::ustring & device_path, PedDevice *& lp_device, bool flush )
 {
-       lp_device = ped_device_get( device_path .c_str() ) ;
-       if ( lp_device )
+       lp_device = ped_device_get( device_path.c_str() );
        {
                if ( flush )
-                       //Force cache coherency before reading the partition table so that
-                       //  libparted reading the whole disk device and the file system
-                       //  tools reading the partition devices read the same data.
-                       flush_device( lp_device ) ;
+                       // Force cache coherency before going on to read the partition
+                       // table so that libparted reading the whole disk device and the
+                       // file system tools reading the partition devices read the same
+                       // data.
+                       flush_device( lp_device );
+
+               return true;
+       }
+       return false;
+}
 
+bool GParted_Core::get_disk( PedDevice *& lp_device, PedDisk *& lp_disk, bool strict )
+{
+       if ( lp_device )
+       {
                lp_disk = ped_disk_new( lp_device );
-       
-               //if ! disk and writeable it's probably a HD without disklabel.
-               //We return true here and deal with them in GParted_Core::get_devices
+
+               // if ! disk and writable it's probably a HD without disklabel.
+               // We return true here and deal with them in
+               // GParted_Core::set_devices_thread().
                if ( lp_disk || ( ! strict && ! lp_device ->read_only ) )
-                       return true ;
-               
-               destroy_device_and_disk( lp_device, lp_disk ) ;
+                       return true;
+
+               destroy_device_and_disk( lp_device, lp_disk );
        }
 
-       return false ;
+       return false;
+}
+
+bool GParted_Core::get_device_and_disk( const Glib::ustring & device_path,
+                                        PedDevice*& lp_device, PedDisk*& lp_disk, bool strict, bool flush )
+{
+       if ( get_device( device_path, lp_device, flush ) )
+       {
+               return get_disk( lp_device, lp_disk, strict );
+       }
+
+       return false;
 }
 
 void GParted_Core::destroy_device_and_disk( PedDevice*& lp_device, PedDisk*& lp_disk )


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