[gparted] Fix writing FAT16/32 FS labels on Alpine Linux (!104)



commit 54dbc87b3b844da5e1ef5927e663019e6c99aad1
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Fri Jun 17 11:52:35 2022 +0100

    Fix writing FAT16/32 FS labels on Alpine Linux (!104)
    
    Unit test writing FAT16/32 file system labels fails on Alpine Linux like
    this:
        $ ./test_SupportedFileSystems --gtest_filter='*CreateAndWriteLabel/fat16'
        ...
        [ RUN      ] My/SupportedFileSystemsTest.CreateAndWriteLabel/fat16
        test_SupportedFileSystems.cc:601: Failure
        Value of: m_fs_object->write_label(m_partition, m_operation_detail)
          Actual: false
        Expected: true
        Operation details:
        mkfs.fat -F16 -v -I -n 'FIRST      ' 
'/home/alpine/programming/c/gparted/tests/test_SupportedFileSystems.img'    00:00:00  (SUCCESS)
        ...
        mlabel ::'SECOND     ' -i '/home/alpine/programming/c/gparted/tests/test_SupportedFileSystems.img'    
00:00:00  (ERROR)
    
        Mtools version 4.0.39, dated April 10th, 2022
        Usage: mlabel [-vscVn] [-N serial] drive:
    
        [  FAILED  ] My/SupportedFileSystemsTest.CreateAndWriteLabel/fat16, where GetParam() = 13 (29 ms)
    
    Using GParted on Alpine Linux to perform the same action produces the
    same error in the operation results.  Reproduce this on the command
    line:
        # mkfs.fat -F 16 -v -I -n FIRST /dev/sdb1
        # mlabel ::SECOND -i /dev/sdb1
        Mtools version 4.0.39, dated April 10th, 2022
        Usage: mlabel [-vscVn] [-N serial] drive:
        # echo $?
        1
    
    Again, this is because musl libc's getopt(3) is POSIX compliant and
    stops parsing options at '::', the first non-option argument.  Apply the
    same fix of moving the non-option argument to the end of the mlabel
    command line:
        # mlabel -i /dev/sdb1 ::SECOND
        # echo $?
        0
        # mlabel -s -i /dev/sdb1
         Volume label is SECOND
    
    And for the clearing label case:
        # mlabel -c -i /dev/sdb1 ::
        # echo $?
        0
        # mlabel -s -i /dev/sdb1
         Volume has no label
    
    Closes !104 - Add Alpine Linux CI jobs and resolve label and UUID issues
                  with FAT16/32

 src/fat16.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
---
diff --git a/src/fat16.cc b/src/fat16.cc
index bf37c195..5f1ae66d 100644
--- a/src/fat16.cc
+++ b/src/fat16.cc
@@ -211,10 +211,10 @@ bool fat16::write_label( const Partition & partition, OperationDetail & operatio
 {
        Glib::ustring cmd = "" ;
        if ( partition.get_filesystem_label().empty() )
-               cmd = "mlabel -c :: -i " + Glib::shell_quote( partition.get_path() );
+               cmd = "mlabel -c -i " + Glib::shell_quote(partition.get_path()) + " ::";
        else
-               cmd = "mlabel ::" + Glib::shell_quote( sanitize_label( partition.get_filesystem_label() ) ) +
-                     " -i " + Glib::shell_quote( partition.get_path() );
+               cmd = "mlabel -i " + Glib::shell_quote(partition.get_path()) +
+                     " ::" + Glib::shell_quote(sanitize_label(partition.get_filesystem_label()));
 
        return ! execute_command( cmd, operationdetail, EXEC_CHECK_STATUS );
 }


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