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
This commit is contained in:
Mike Fleetwood 2021-01-11 18:51:36 +00:00 committed by Curtis Gedak
parent bd386f445d
commit b0a061cf7a
1 changed files with 13 additions and 5 deletions

View File

@ -3356,11 +3356,19 @@ bool GParted_Core::set_partition_type( const Partition & partition, OperationDet
if (partition.fstype != FS_CLEARED) if (partition.fstype != FS_CLEARED)
lp_fs_type = ped_file_system_type_get(fs_type.c_str()); lp_fs_type = ped_file_system_type_get(fs_type.c_str());
// If not found, and FS is udf, then try ntfs. // Ensure that UDF and exFAT get the required partition type even
// Actually MBR 07 IFS (Microsoft Installable File System) or // when libparted doesn't know, or is to old to know, about them.
// GPT BDP (Windows Basic Data Partition). // Required partition types:
// Ref: https://serverfault.com/a/829172 // * [on MBR] 07 IFS (Installable File System)
if (! lp_fs_type && partition.fstype == FS_UDF) // * [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" ); lp_fs_type = ped_file_system_type_get( "ntfs" );
// default is Linux (83) // default is Linux (83)