[gparted] Fix displaying partition names also as file system labels in some cases (#759972)



commit bfb6a3800d2a316a901d9a47c4864efa5bbbf73c
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Wed Dec 30 12:55:46 2015 +0000

    Fix displaying partition names also as file system labels in some cases (#759972)
    
    GParted was also displaying the GPT partition names as the file system
    labels for some type of file systems.
    
    Create 2 empty partitions on a GPT partitioned disk and name them like
    this.  Then create a hfsplus file system with an empty label.  (Actually
    single space character but blkid treats it as empty.  Can't use GParted
    for this because when no label is specified mkfs.hfsplus sets the label
    to "untitled").
    
        # sgdisk -p /dev/sdb
        /dev/sdb: 4194304 sectors, 2.0 GiB
        Logical sector size: 512 bytes
        ...
        Number  Start (sector)    End (sector)  Size       Code  Name
           1            2048          526335   256.0 MiB   8300  empty partition
           2          526336         1050623   256.0 MiB   8300  hfsplus partition
        # mkfs.hfsplus -v " " /dev/sdb2
    
    Even though only the GPT partition names are set to "SOMETHING
    partition", GParted will display them as the file system labels too.
    Also in the Information dialog for the empty partition a file system
    UUID is displayed as well even though none exists.
    
    Blkid output looks like this:
    
        # blkid -V
        blkid from util-linux 2.27.1  (libblkid 2.27.0, 02-Nov-2015)
        # blkid | grep /dev/sdb
        /dev/sdb1: PARTLABEL="empty partition" PARTUUID="bf3d2085-65b7-4ae6-97da-5ff968ad7d2c"
        /dev/sdb2: UUID="2c893037-ff76-38f2-9158-2352ef5dc8de" TYPE="hfsplus" PARTLABEL="hfsplus partition" 
PARTUUID="457e9c2b-e4f2-4235-833b-28208592aaac"
    
    With blkid from util-linux >= 2.22, released September 2012, it is
    including additional PARTLABEL and PARTUUID name and value pairs for
    GPT partitions [1].  The FS_Info module regular expressions used to
    match the file system LABEL and UUID names also happen to match these
    new PARTLABEL and PARTUUID names too.  Hence this bug when GParted has
    to fall back to using the FS_Info module to read the file system label,
    when there is no working file system specific method.  Effects: exfat,
    f2fs, hfs, hfsplus, ufs, unknown.
    
    Fix by requiring all the regular expressions used to search the blkid
    output to also match the space character in front of the name.
    
    [1] Util-linux 2.22 Release Notes
        
https://git.kernel.org/cgit/utils/util-linux/util-linux.git/tree/Documentation/releases/v2.22-ReleaseNotes?h=v2.22
    
    Bug 759972 - GParted displays partition names also as file system labels
                 with new blkid for some file systems

 src/FS_Info.cc |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)
---
diff --git a/src/FS_Info.cc b/src/FS_Info.cc
index cb7d833..02acb87 100644
--- a/src/FS_Info.cc
+++ b/src/FS_Info.cc
@@ -112,8 +112,8 @@ Glib::ustring FS_Info::get_fs_type( const Glib::ustring & path )
        Glib::ustring dev_path_line = get_device_entry( path ) ;
        
        //Retrieve TYPE
-       fs_type     = Utils::regexp_label( dev_path_line, "[^_]TYPE=\"([^\"]*)\"" ) ;
-       fs_sec_type = Utils::regexp_label( dev_path_line, "SEC_TYPE=\"([^\"]*)\"" ) ;
+       fs_type     = Utils::regexp_label( dev_path_line, " TYPE=\"([^\"]*)\"" );
+       fs_sec_type = Utils::regexp_label( dev_path_line, " SEC_TYPE=\"([^\"]*)\"" );
 
        //If vfat, decide whether fat16 or fat32
        Glib::ustring output, error;
@@ -126,7 +126,7 @@ Glib::ustring FS_Info::get_fs_type( const Glib::ustring & path )
                        // prevents correct identification.  Run blkid command again,
                        // bypassing the the cache to get the correct results.
                        if ( ! Utils::execute_command( "blkid -c /dev/null " + path, output, error, true ) )
-                               fs_sec_type = Utils::regexp_label( output, "SEC_TYPE=\"([^\"]*)\"" );
+                               fs_sec_type = Utils::regexp_label( output, " SEC_TYPE=\"([^\"]*)\"" );
                }
                if ( fs_sec_type == "msdos" )
                        fs_type = "fat16" ;
@@ -153,11 +153,11 @@ Glib::ustring FS_Info::get_label( const Glib::ustring & path, bool & found )
        Glib::ustring temp = get_device_entry( path ) ;
        
        //Set indicator if LABEL found
-       if ( Utils::regexp_label( temp, "(LABEL=\")") != "" )
+       if ( Utils::regexp_label( temp, "( LABEL=\")") != "" )
                found = true ;
 
        //Retrieve LABEL
-       label = Utils::regexp_label( temp, "LABEL=\"([^\"]*)\"" ) ;
+       label = Utils::regexp_label( temp, " LABEL=\"([^\"]*)\"" );
        return label ;
 }
 
@@ -167,7 +167,7 @@ Glib::ustring FS_Info::get_uuid( const Glib::ustring & path )
        Glib::ustring temp = get_device_entry( path ) ;
 
        //Retrieve the UUID
-       Glib::ustring uuid = Utils::regexp_label( temp, "UUID=\"([^\"]*)\"" ) ;
+       Glib::ustring uuid = Utils::regexp_label( temp, " UUID=\"([^\"]*)\"" );
 
        if ( uuid .empty() && vol_id_found )
        {
@@ -185,7 +185,7 @@ Glib::ustring FS_Info::get_uuid( const Glib::ustring & path )
 Glib::ustring FS_Info::get_path_by_uuid( const Glib::ustring & uuid )
 {
        //Retrieve the path given the uuid
-       Glib::ustring regexp = "^([^:]*):.*UUID=\"" + uuid + "\".*$" ;
+       Glib::ustring regexp = "^([^:]*):.* UUID=\"" + uuid + "\".*$";
        Glib::ustring path = Utils::regexp_label( fs_info_cache, regexp ) ;
 
        return path ;
@@ -194,7 +194,7 @@ Glib::ustring FS_Info::get_path_by_uuid( const Glib::ustring & uuid )
 Glib::ustring FS_Info::get_path_by_label( const Glib::ustring & label )
 {
        //Retrieve the path given the label
-       Glib::ustring regexp = "^([^:]*):.*LABEL=\"" + label + "\".*$" ;
+       Glib::ustring regexp = "^([^:]*):.* LABEL=\"" + label + "\".*$";
        Glib::ustring path = Utils::regexp_label( fs_info_cache, regexp ) ;
 
        return path ;


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