[gparted] Display whole disk file systems via partition table "none" (#741430)



commit cbf8bd741d21390e1e7d252f32cd61fc2779e222
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Sat Dec 27 14:10:54 2014 +0000

    Display whole disk file systems via partition table "none" (#741430)
    
    For file systems which libparted recognises, when found on the whole
    disk device, it reports with partition table "loop" and a partition
    covering the whole disk.  GParted duly displays this to the user.
    
    For file systems which libparted doesn't recognise it reports
    "unrecognised disk label".  As of the latest libparted 3.2, these file
    system aren't recognised and can't currently be shown when on the whole
    disk device:
    
        BitLocker, Crypt LUKS, exFAT, F2FS, LVM2 Physical Volume,
        Linux Software RAID, ReFS, Reiser 4
    
    So only when libparted doesn't recognise a file system on the whole disk
    device and GParted does, either via blkid or it's internal code, display
    this with partition table "none".
    
    Bug 741430 - GParted cannot recognise LVM signature on unpartitioned
                 drive

 include/GParted_Core.h |    2 +
 src/GParted_Core.cc    |   90 ++++++++++++++++++++++++++++++++++++-----------
 2 files changed, 71 insertions(+), 21 deletions(-)
---
diff --git a/include/GParted_Core.h b/include/GParted_Core.h
index 5755e13..125aa48 100644
--- a/include/GParted_Core.h
+++ b/include/GParted_Core.h
@@ -78,6 +78,8 @@ private:
        static void read_mountpoints_from_mount_command( std::map< Glib::ustring, std::vector<Glib::ustring> 
& map ) ;
        Glib::ustring get_partition_path( PedPartition * lp_partition ) ;
        void set_device_partitions( Device & device, PedDevice* lp_device, PedDisk* lp_disk ) ;
+       void set_device_one_partition( Device & device, PedDevice * lp_device, FILESYSTEM fstype,
+                                      std::vector<Glib::ustring> & messages );
        void set_partition_label_and_uuid( Partition & partition );
        static FILESYSTEM recognise_filesystem_signature( PedDevice * lp_device, PedPartition * lp_partition 
);
        GParted::FILESYSTEM get_filesystem( PedDevice* lp_device, PedPartition* lp_partition,
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index ce76a8a..5066c3c 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -336,31 +336,43 @@ void GParted_Core::set_devices_thread( std::vector<Device> * pdevices )
                        // Hard disk without a libparted recognised disklabel
                        else
                        {
-                               // FIXME: Replace quick test of whole device signature recognition
-                               std::vector<Glib::ustring> dummy;
-                               FILESYSTEM fstype = get_filesystem( lp_device, NULL, dummy );
-                               std::cout << "DEBUG: " << lp_device->path << " (" << 
Utils::get_filesystem_string( fstype ) << ")" << std::endl;
-
-                               temp_device .disktype =
+                               std::vector<Glib::ustring> messages;
+                               FILESYSTEM fstype = get_filesystem( lp_device, NULL, messages );
+                               // Recognised file system signature on whole disk device
+                               if ( fstype != FS_UNKNOWN )
+                               {
+                                       // Clear the "unrecognised disk label" message
+                                       libparted_messages.clear();
+
+                                       temp_device.disktype = "none";
+                                       temp_device.max_prims = 1;
+                                       set_device_one_partition( temp_device, lp_device, fstype, messages );
+                                       set_mountpoints( temp_device.partitions );
+                                       set_used_sectors( temp_device.partitions, NULL );
+                               }
+                               else
+                               {
+                                       temp_device.disktype =
                                                /* TO TRANSLATORS:  unrecognized
                                                 * means that the partition table for this
                                                 * disk device is unknown or not recognized.
                                                 */
                                                _("unrecognized") ;
-                               temp_device .max_prims = -1 ;
-                               
-                               Partition partition_temp ;
-                               partition_temp .Set_Unallocated( temp_device .get_path(),
-                                                                0,
-                                                                temp_device .length - 1,
-                                                                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() ) ;
-                               libparted_messages .clear() ;
-                               temp_device .partitions .push_back( partition_temp );
+                                       temp_device.max_prims = -1;
+
+                                       Partition partition_temp;
+                                       partition_temp.Set_Unallocated( temp_device .get_path(),
+                                                                       0LL,
+                                                                       temp_device .length - 1LL,
+                                                                       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() );
+                                       libparted_messages.clear();
+                                       temp_device.partitions.push_back( partition_temp );
+                               }
                        }
                                        
                        devices .push_back( temp_device ) ;
@@ -1231,6 +1243,41 @@ void GParted_Core::set_device_partitions( Device & device, PedDevice* lp_device,
        insert_unallocated( device .get_path(), device .partitions, 0, device .length -1, device 
.sector_size, false ) ; 
 }
 
+// Create one Partition object spanning the Device after identifying the file system
+// on the whole disk device.  Much simplified equivalent of set_device_partitions().
+void GParted_Core::set_device_one_partition( Device & device, PedDevice * lp_device, FILESYSTEM fstype,
+                                             std::vector<Glib::ustring> & messages )
+{
+       Proc_Partitions_Info pp_info;  // Use cache of proc partitions information
+
+       device.partitions.clear();
+
+       Glib::ustring path = lp_device->path;
+       bool partition_is_busy = is_busy( fstype, path );
+
+       Partition partition_temp;
+       partition_temp.Set( device.get_path(),
+                           path,
+                           1,
+                           TYPE_PRIMARY,
+                           fstype,
+                           0LL,
+                           device.length - 1LL,
+                           device.sector_size,
+                           false,
+                           partition_is_busy );
+
+       partition_temp.messages = messages;
+       partition_temp.add_paths( pp_info.get_alternate_paths( partition_temp.get_path() ) );
+
+       if ( partition_temp.busy )
+               device.highest_busy = 1;
+
+       set_partition_label_and_uuid( partition_temp );
+
+       device.partitions.push_back( partition_temp );
+}
+
 void GParted_Core::set_partition_label_and_uuid( Partition & partition )
 {
        FS_Info fs_info;  // Use cache of file system information
@@ -1722,7 +1769,8 @@ void GParted_Core::set_used_sectors( std::vector<Partition> & partitions, PedDis
                                                        break ;
 #ifdef HAVE_LIBPARTED_FS_RESIZE
                                                case GParted::FS::LIBPARTED     :
-                                                       LP_set_used_sectors( partitions[ t ], lp_disk ) ;
+                                                       if ( lp_disk )
+                                                               LP_set_used_sectors( partitions[t], lp_disk );
                                                        break ;
 #endif
 


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