[gparted] Set the partition type for exFAT correctly (!30)



commit b0a061cf7a7618f68ae0083b456ae679534069f2
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Mon Jan 11 18:51:36 2021 +0000

    Set the partition type for exFAT correctly (!30)
    
    Libparted only allows selection of the partition type indirectly by
    specifying the type of the file system it will contain [1] and so far
    doesn't know about the exFAT file system.  Therefore when GParted is
    creating a new exFAT partition, it gets the GParted default of 83
    (Linux file system) on MBR partition tables.
    
    Example operation details:
        Create Primary Partition #1 (exfat, 512.00 MiB) on /dev/sdb
        * create empty partition
        * clear old file system signatures in /dev/sdb1
        * set partition type on /dev/sdb1
            new partition type: ext2
        * create new exfat file system
    
    fdisk report:
        # fdisk -l /dev/sdb
        Disk /dev/sdb: 8 GiB, 8589934592 bytes, 16777216 sectors
        Disk model: VBOX HARDDISK
        Units: sectors of 1 * 512 = 512 bytes
        Sector size (logical/physical): 512 bytes / 512 bytes
        I/O size (minimum/optimal): 512 bytes / 512 bytes
        Disklabel type: dos
        Disk identifier: 0xa2aab629
    
        Device     Boot Start     End Sectors  Size Id Type
        /dev/sdb1        2048 1050623 1048576  512M 83 Linux
    
    However the "exFAT file system specification" says:
        https://docs.microsoft.com/en-us/windows/win32/fileio/exfat-specification
        "10.2 Partition Tables
    
        To ensure interoperability of exFAT volumes in a broad set of usage
        scenarios, implementations should use partition type 07h for MBR
        partitioned storage and partition GUID
        {EBD0A0A2-B9E5-4433-87C0-68B6B72699C7} for GPT partitioned storage.
        "
    
    Fix this.
    
    [1] ped_partition_new(..., const PedFileSystemType* fs_type, ...)
        https://www.gnu.org/software/parted/api/group__PedPartition.html#g2f94ca75880f9e0c3ce57f7a4b72faf5
        ped_partition_set_system(..., const PedFileSystemType* fs_type)
        https://www.gnu.org/software/parted/api/group__PedPartition.html#g2f94ca75880f9e0c3ce57f7a4b72faf5
    
    Closes !30 - Add exFAT support

 src/GParted_Core.cc | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
---
diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc
index 7229a2a4..b71df63a 100644
--- a/src/GParted_Core.cc
+++ b/src/GParted_Core.cc
@@ -3356,11 +3356,19 @@ bool GParted_Core::set_partition_type( const Partition & partition, OperationDet
                        if (partition.fstype != FS_CLEARED)
                                lp_fs_type = ped_file_system_type_get(fs_type.c_str());
 
-                       // If not found, and FS is udf, then try ntfs.
-                       // Actually MBR 07 IFS (Microsoft Installable File System) or
-                       // GPT BDP (Windows Basic Data Partition).
-                       // Ref: https://serverfault.com/a/829172
-                       if (! lp_fs_type && partition.fstype == FS_UDF)
+                       // Ensure that UDF and exFAT get the required partition type even
+                       // when libparted doesn't know, or is to old to know, about them.
+                       // Required partition types:
+                       // * [on MBR] 07 IFS (Installable File System)
+                       // * [on GPT] BDP (Basic Data Partition)
+                       // Use NTFS to achieve this.
+                       // References:
+                       // * What is the partition id / filesystem type for UDF?
+                       //   https://serverfault.com/a/829172
+                       // * exFAT file system specification
+                       //   https://docs.microsoft.com/en-us/windows/win32/fileio/exfat-specification
+                       //   10.2 Partition Tables
+                       if (! lp_fs_type && (partition.fstype == FS_UDF || partition.fstype == FS_EXFAT))
                                lp_fs_type = ped_file_system_type_get( "ntfs" );
 
                        // default is Linux (83)


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