[gparted] Update parsing of btrfs filesystem show for the label (#733601)



commit eca732fb0cefe35db76a7ac96145e2004e8eed08
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Wed Jul 23 00:19:32 2014 +0100

    Update parsing of btrfs filesystem show for the label (#733601)
    
    Issue 2/2 - GParted doesn't show label for mounted btrfs file systems
    
    'btrfs filesystem show /dev/PTN' command is used to query details of a
    btrfs file system including reading the file system label.  When the
    file system is mounted the label is no longer enclosed in single quotes,
    but only when using btrfs-progs v3.12.  This causes GParted to think the
    label is blank when the file system is mounted and therefore no longer
    display it.
    
    File system label not enclosed in single quotes when mounted:
    
        # fgrep sdb1 /proc/mounts
        /dev/sdb1 /mnt/1 btrfs rw,relatime,space_cache 0 0
        # btrfs filesystem show /dev/sdb1
        Label: test1-btrfs  uuid: 1f78fa38-2f85-41d3-9be6-ae0356ae9469
                Total devices 1 FS bytes used 192.00KiB
                devid    1 size 2.00GiB used 240.75MiB path /dev/sdb1
    
        Btrfs v3.12
    
    File system label enclosed in single quotes when unmounted:
    
        # umount /dev/sdb1
        # btrfs filesystem show /dev/sdb1
        Label: 'test1-btrfs'  uuid: 1f78fa38-2f85-41d3-9be6-ae0356ae9469
                Total devices 1 FS bytes used 192.00KiB
                devid    1 size 2.00GiB used 240.75MiB path /dev/sdb1
    
        Btrfs v3.12
    
    Removing the single quotes enclosing the label makes the output
    identical to that from the older 'btrfs-show' command.
    
    Fix by using a common parser to extract the label from both the
    'btrfs filesystem show' and 'btrfs-show' commands which can read the
    label with and without enclosing single quotes.
    
    Patch 2/4 - btrfs::read_label()
    
    This patch changes the btrfs file system label parsing code to resolve
    issue 1/2 by ignoring the exit status from the 'btrfs filesystem show'
    command and relying on parsing the required information to determine
    success or failure.  Issue 2/2 is also resolved as described above.
    
    Bug #733601 - Btrfs: Warnings and missing label with btrfs-progs 3.12
                  and 3.14

 src/btrfs.cc |   53 ++++++++++++++++++++++++-----------------------------
 1 files changed, 24 insertions(+), 29 deletions(-)
---
diff --git a/src/btrfs.cc b/src/btrfs.cc
index 7a6a841..188a41b 100644
--- a/src/btrfs.cc
+++ b/src/btrfs.cc
@@ -365,41 +365,36 @@ bool btrfs::resize( const Partition & partition_new, OperationDetail & operation
 void btrfs::read_label( Partition & partition )
 {
        if ( btrfs_found )
+               Utils::execute_command( "btrfs filesystem show " + partition .get_path(), output, error, true 
) ;
+       else
+               Utils::execute_command( "btrfs-show " + partition .get_path(), output, error, true ) ;
+       //In many cases the exit status doesn't reflect valid output or an error condition
+       //  so rely on parsing the output to determine success.
+
+       if ( output .compare( 0, 18, "Label: none  uuid:" ) == 0 )
        {
-               exit_status = Utils::execute_command( "btrfs filesystem show " + partition .get_path(), 
output, error, true ) ;
-               if ( ! exit_status )
-               {
-                       partition .set_label( Utils::regexp_label( output, "^Label: '(.*)'  uuid:" ) ) ;
-                       //Btrfs filesystem show encloses the label in single
-                       //  quotes or reports "none" without single quotes, so
-                       //  the cases are distinguishable and this regexp won't
-                       //  match the no label case.  In the no match case
-                       //  regexp_label() returns "" and this is used to set
-                       //  the set the blank label.
-               }
+               //Indistinguishable cases of either no label or the label is actually set
+               //  to "none".  Assume no label case.
+               partition .set_label( "" ) ;
        }
        else
        {
-               exit_status = Utils::execute_command( "btrfs-show " + partition .get_path(), output, error, 
true ) ;
-               if ( ! exit_status )
+               //Try matching a label enclosed in single quotes, as used by
+               //  btrfs filesystem show, then without quotes, as used by btrfs-show.
+               Glib::ustring label = Utils::regexp_label( output, "^Label: '(.*)'  uuid:" ) ;
+               if ( label .empty() )
+                       label = Utils::regexp_label( output, "^Label: (.*)  uuid:" ) ;
+
+               if ( ! label .empty() )
+                       partition .set_label( label ) ;
+               else
                {
-                       Glib::ustring label = Utils::regexp_label( output, "^Label: (.*)  uuid:" ) ;
-                       //Btrfs-show reports "none" when there is no label, but
-                       //  this is indistinguishable from the label actually
-                       //  being "none".  Assume no label case.
-                       if ( label != "none" )
-                               partition .set_label( label ) ;
-                       else
-                               partition .set_label( "" ) ;
-               }
-       }
-       if ( exit_status )
-       {
-               if ( ! output .empty() )
-                       partition .messages .push_back( output ) ;
+                       if ( ! output .empty() )
+                               partition .messages .push_back( output ) ;
 
-               if ( ! error .empty() )
-                       partition .messages .push_back( error ) ;
+                       if ( ! error .empty() )
+                               partition .messages .push_back( error ) ;
+               }
        }
 }
 


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