2020-04-16 09:15:26 +02:00
|
|
|
/*
|
|
|
|
* APFS.cpp
|
|
|
|
*
|
|
|
|
* Created on: 16 Apr 2020
|
|
|
|
* Author: jief
|
|
|
|
*/
|
|
|
|
|
2020-08-17 21:40:52 +02:00
|
|
|
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
|
2021-02-06 18:16:46 +01:00
|
|
|
#include <Efi.h>
|
|
|
|
|
2020-04-16 09:15:26 +02:00
|
|
|
#include "guid.h"
|
2020-08-07 10:23:46 +02:00
|
|
|
#include "APFS.h"
|
2020-04-16 09:15:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* S. Mitrofanov 08.06.2016
|
|
|
|
* APFS Container introduced new partitions structure
|
|
|
|
* Now we have, for example:
|
|
|
|
* /dev/disk0 (internal, physical):
|
|
|
|
* #: TYPE NAME SIZE IDENTIFIER
|
|
|
|
* 0: GUID_partition_scheme *240.1 GB disk0
|
|
|
|
* 1: EFI EFI 209.7 MB disk0s1
|
|
|
|
* 2: Apple_APFS Container disk1 239.2 GB disk0s2
|
|
|
|
* 3: Apple_KernelCoreDump 655.4 MB disk0s3
|
|
|
|
*
|
|
|
|
* /dev/disk1 (synthesized):
|
|
|
|
* #: TYPE NAME SIZE IDENTIFIER
|
|
|
|
* 0: APFS Container Scheme - +239.2 GB disk1
|
|
|
|
* Physical Store disk0s2
|
|
|
|
* 1: APFS Volume Macintosh SSD 170.8 GB disk1s1
|
|
|
|
* 2: APFS Volume Preboot 17.9 MB disk1s2
|
|
|
|
* 3: APFS Volume Recovery 521.1 MB disk1s3
|
|
|
|
* 4: APFS Volume VM 1.1 GB disk1s4
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2020-08-07 10:23:46 +02:00
|
|
|
/*
|
|
|
|
* Function for obtaining unique part id from APFS partition
|
|
|
|
* IN: DevicePath
|
|
|
|
* OUT: EFI_GUID
|
|
|
|
* returns null if it is not APFS part
|
|
|
|
*/
|
2022-04-26 00:55:56 +02:00
|
|
|
EFI_GUID APFSPartitionUUIDExtract(
|
2020-09-28 17:57:50 +02:00
|
|
|
const EFI_DEVICE_PATH_PROTOCOL *DevicePath
|
2020-04-16 09:15:26 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
while (!IsDevicePathEndType(DevicePath) &&
|
|
|
|
!(DevicePathType(DevicePath) == MEDIA_DEVICE_PATH && DevicePathSubType (DevicePath) == MEDIA_VENDOR_DP)) {
|
|
|
|
DevicePath = NextDevicePathNode(DevicePath);
|
|
|
|
}
|
|
|
|
if (DevicePathType(DevicePath) == MEDIA_DEVICE_PATH && DevicePathSubType (DevicePath) == MEDIA_VENDOR_DP) {
|
2022-04-26 00:55:56 +02:00
|
|
|
//Check that vendor-assigned EFI_GUID defines APFS Container Partition
|
|
|
|
if ( ApfsSignatureUUID == *(EFI_GUID *)((UINT8 *)DevicePath+0x04) ) {
|
|
|
|
return *(EFI_GUID *)((UINT8 *)DevicePath+0x14);
|
2020-04-16 09:15:26 +02:00
|
|
|
}
|
|
|
|
}
|
2022-04-26 00:55:56 +02:00
|
|
|
return nullGuid;
|
2020-04-16 09:15:26 +02:00
|
|
|
}
|
|
|
|
|
2020-08-07 10:23:46 +02:00
|
|
|
|
|
|
|
|