Recognise APFS (Apple File System) (#23)

Just add detection of APFS using GParted's internal magic string
detection.  It just matches 1 byte of the 2 byte object type and the
4 byte magic field found in the super block [1].  See code comment for
more details.

Blkid has just gained recognition of APFS with util-linux v2.33 released
06-Nov-2018 [2].

This will write enough for GParted's simple internal detection to find
APFS:
    # python -c '
    import sys
    sys.stdout.write("\0"*24 + "\1\0" + "\0"*6 + "NXSB")
    ' > /dev/sdb1

[1] Apple File System Reference
    https://developer.apple.com/support/apple-file-system/Apple-File-System-Reference.pdf

[2] [ANNOUNCE] util-linux v2.33
    https://marc.info/?l=linux-fsdevel&m=154150400305928&w=2

Closes #23 - GParted doesn't detect APFS (Apple File System)
This commit is contained in:
Mike Fleetwood 2018-11-07 20:05:38 +00:00 committed by Curtis Gedak
parent 893b67e2b8
commit 69c1537a38
3 changed files with 29 additions and 11 deletions

View File

@ -92,18 +92,19 @@ enum FSType
FS_XFS = 27,
// Other recognised file system types
FS_BITLOCKER = 28,
FS_GRUB2_CORE_IMG = 29,
FS_ISO9660 = 30,
FS_LINUX_SWRAID = 31,
FS_LINUX_SWSUSPEND = 32,
FS_REFS = 33,
FS_UFS = 34,
FS_ZFS = 35,
FS_APFS = 28,
FS_BITLOCKER = 29,
FS_GRUB2_CORE_IMG = 30,
FS_ISO9660 = 31,
FS_LINUX_SWRAID = 32,
FS_LINUX_SWSUSPEND = 33,
FS_REFS = 34,
FS_UFS = 35,
FS_ZFS = 36,
// Partition space usage colours
FS_USED = 36,
FS_UNUSED = 37
FS_USED = 37,
FS_UNUSED = 38
} ;
enum SIZE_UNIT

View File

@ -1332,7 +1332,8 @@ FSType GParted_Core::detect_filesystem_internal( PedDevice * lp_device, PedParti
{ 0LL, "\x52\xE8\x28\x01", 0LL, NULL , FS_GRUB2_CORE_IMG },
{ 0LL, "\x52\xBF\xF4\x81", 0LL, NULL , FS_GRUB2_CORE_IMG },
{ 0LL, "\x52\x56\xBE\x63", 0LL, NULL , FS_GRUB2_CORE_IMG },
{ 0LL, "\x52\x56\xBE\x56", 0LL, NULL , FS_GRUB2_CORE_IMG }
{ 0LL, "\x52\x56\xBE\x56", 0LL, NULL , FS_GRUB2_CORE_IMG },
{ 24LL, "\x01\x00" , 32LL, "NXSB", FS_APFS }
};
// For simple BitLocker recognition consider validation of BIOS Parameter block
// fields unnecessary.
@ -1343,6 +1344,17 @@ FSType GParted_Core::detect_filesystem_internal( PedDevice * lp_device, PedParti
// instructions it starts with.
// * bootinfoscript v0.77 line 1990 [GRUB2 core.img possible staring 4 bytes]
// https://github.com/arvidjaar/bootinfoscript/blob/009f509d59e2f0d39b8d44692e2a81720f5af7b6/bootinfoscript#L1990
//
// Simple APFS recognition based on matching the following fields in the
// superblock:
// 1) Object type is OBJECT_TYPE_NX_SUPERBLOCK, lower 16-bits of the object type
// field is 0x0001 stored as little endian bytes 0x01, 0x00.
// WARNING: The magic signatures are defined as NUL terminated strings so the
// below code only does a 1-byte match for 0x01, rather than a 2-byte match
// for 0x01, 0x00.
// 2) 4 byte magic "NXSB".
// * Apple File System Reference
// https://developer.apple.com/support/apple-file-system/Apple-File-System-Reference.pdf
for ( unsigned int i = 0 ; i < sizeof( signatures ) / sizeof( signatures[0] ) ; i ++ )
{
@ -1473,6 +1485,8 @@ FSType GParted_Core::detect_filesystem( PedDevice * lp_device, PedPartition * lp
return GParted::FS_UDF;
else if ( fsname == "ufs" )
return GParted::FS_UFS ;
else if ( fsname == "apfs" )
return FS_APFS;
else if ( fsname == "BitLocker" )
return FS_BITLOCKER;
else if ( fsname == "iso9660" )
@ -4182,6 +4196,7 @@ void GParted_Core::init_filesystems()
FILESYSTEM_MAP[FS_REISERFS] = new reiserfs();
FILESYSTEM_MAP[FS_UDF] = new udf();
FILESYSTEM_MAP[FS_XFS] = new xfs();
FILESYSTEM_MAP[FS_APFS] = NULL;
FILESYSTEM_MAP[FS_BITLOCKER] = NULL;
FILESYSTEM_MAP[FS_GRUB2_CORE_IMG] = NULL;
FILESYSTEM_MAP[FS_ISO9660] = NULL;

View File

@ -116,6 +116,7 @@ Glib::ustring Utils::get_color( FSType filesystem )
case FS_REISERFS: return "#ADA7C8"; // Purple Hilight
case FS_UDF: return "#105210"; // Accent Green Shadow [+]
case FS_XFS: return "#EED680"; // Accent Yellow
case FS_APFS: return "#874986"; // Magenta Dark [*]
case FS_BITLOCKER: return "#494066"; // Purple Shadow
case FS_GRUB2_CORE_IMG: return "#666666"; // Dark Gray [*]
case FS_ISO9660: return "#D3D3D3"; // Light Gray [*]
@ -304,6 +305,7 @@ Glib::ustring Utils::get_filesystem_string( FSType filesystem )
case FS_REISERFS: return "reiserfs";
case FS_UDF: return "udf";
case FS_XFS: return "xfs";
case FS_APFS: return "apfs";
case FS_BITLOCKER: return "bitlocker";
case FS_GRUB2_CORE_IMG: return "grub2 core.img";
case FS_ISO9660: return "iso9660";