OcBootManagementLib: Add support for detecting bootcamp

This commit is contained in:
vit9696 2019-04-06 13:45:32 +03:00
parent 95a4ec8065
commit aeb2b324fe
9 changed files with 127 additions and 68 deletions

View File

@ -50,23 +50,6 @@ LocateRootVolume (
IN EFI_DEVICE_PATH_PROTOCOL *FilePath OPTIONAL
);
/**
@param[in] FileHandle A pointer to file handle.
@param[in] InformationType A pointer to file info GUID.
@param[in] MinFileInfoSize Minimal size of the info provided.
@param[out] RealFileInfoSize Actual info size read (optional).
@retval read file info or NULL.
**/
VOID *
GetFileInfo (
IN EFI_FILE_PROTOCOL *FileHandle,
IN EFI_GUID *InformationType,
IN UINTN MinFileInfoSize,
OUT UINTN *RealFileInfoSize OPTIONAL
);
/**
@param[in] FileSystem A pointer to the file system protocol of the volume.
@ -93,7 +76,22 @@ VOID *
ReadFile (
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem,
IN CONST CHAR16 *FilePath,
OUT UINTN *FileSize OPTIONAL
OUT UINT32 *FileSize OPTIONAL
);
/**
Determine file size if it is less than 4 GB.
@param[in] File A pointer to the file protocol.
@param[out] Size 32-bit file size.
@retval EFI_SUCCESS on success.
**/
EFI_STATUS
ReadFileSize (
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem,
IN CONST CHAR16 *FilePath,
OUT UINT32 *Size
);
/**
@ -107,7 +105,7 @@ ReadFile (
@retval EFI_SUCCESS on success.
**/
EFI_STATUS
ReadFileData (
GetFileData (
IN EFI_FILE_PROTOCOL *File,
IN UINT32 Position,
IN UINT32 Size,
@ -126,13 +124,31 @@ ReadFileData (
@retval EFI_SUCCESS on success.
**/
EFI_STATUS
WriteFileData (
SetFileData (
IN EFI_FILE_PROTOCOL *WritableFs OPTIONAL,
IN CONST CHAR16 *FileName,
IN CONST VOID *Buffer,
IN UINT32 Size
);
/**
Get file information of specified type.
@param[in] FileHandle A pointer to file handle.
@param[in] InformationType A pointer to file info GUID.
@param[in] MinFileInfoSize Minimal size of the info provided.
@param[out] RealFileInfoSize Actual info size read (optional).
@retval read file info or NULL.
**/
VOID *
GetFileInfo (
IN EFI_FILE_PROTOCOL *File,
IN EFI_GUID *InformationType,
IN UINTN MinFileInfoSize,
OUT UINTN *RealFileInfoSize OPTIONAL
);
/**
Determine file size if it is less than 4 GB.
@ -142,7 +158,7 @@ WriteFileData (
@retval EFI_SUCCESS on success.
**/
EFI_STATUS
ReadFileSize (
GetFileSize (
IN EFI_FILE_PROTOCOL *File,
OUT UINT32 *Size
);
@ -156,7 +172,7 @@ ReadFileSize (
@retval EFI_SUCCESS on success.
**/
EFI_STATUS
ReadFileModifcationTime (
GetFileModifcationTime (
IN EFI_FILE_PROTOCOL *File,
OUT EFI_TIME *Time
);

View File

@ -171,7 +171,7 @@ ParseCompressedHeader (
return KernelSize;
}
Status = ReadFileData (File, Offset + sizeof (MACH_COMP_HEADER), CompressedSize, CompressedBuffer);
Status = GetFileData (File, Offset + sizeof (MACH_COMP_HEADER), CompressedSize, CompressedBuffer);
if (RETURN_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "Comp kernel (%u bytes) cannot be read at %08X\n", CompressedSize, Offset));
FreePool (CompressedBuffer);
@ -213,7 +213,7 @@ ReadAppleKernelImage (
BOOLEAN ForbidFat;
BOOLEAN Compressed;
Status = ReadFileData (File, Offset, KERNEL_HEADER_SIZE, *Buffer);
Status = GetFileData (File, Offset, KERNEL_HEADER_SIZE, *Buffer);
if (RETURN_ERROR (Status)) {
return Status;
}
@ -250,7 +250,7 @@ ReadAppleKernelImage (
//
// Figure out size for a non fat image.
//
Status = ReadFileSize (File, KernelSize);
Status = GetFileSize (File, KernelSize);
if (RETURN_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "Kernel size cannot be determined - %r\n", Status));
return RETURN_OUT_OF_RESOURCES;
@ -265,7 +265,7 @@ ReadAppleKernelImage (
return Status;
}
Status = ReadFileData (File, Offset, *KernelSize, *Buffer);
Status = GetFileData (File, Offset, *KernelSize, *Buffer);
if (RETURN_ERROR (Status)) {
DEBUG ((DEBUG_INFO, "Kernel (%u bytes) cannot be read at %08X\n", *KernelSize, Offset));
}

View File

@ -49,7 +49,7 @@ GetAppleDiskLabel (
UINTN DiskLabelPathSize;
CHAR8 *AsciiDiskLabel;
CHAR16 *UnicodeDiskLabel;
UINTN DiskLabelLength;
UINT32 DiskLabelLength;
DiskLabelPathSize = StrSize (BootDirectoryName) + StrLen (LabelFilename) * sizeof (CHAR16);
DiskLabelPath = AllocatePool (DiskLabelPathSize);
@ -76,7 +76,7 @@ STATIC
CHAR16 *
GetAppleRecoveryNameFromPlist (
IN CHAR8 *SystemVersionData,
IN UINTN SystemVersionDataSize
IN UINT32 SystemVersionDataSize
)
{
XML_DOCUMENT *Document;
@ -89,7 +89,7 @@ GetAppleRecoveryNameFromPlist (
CHAR16 *RecoveryName;
UINTN RecoveryNameSize;
Document = XmlDocumentParse (SystemVersionData, (UINT32) SystemVersionDataSize, FALSE);
Document = XmlDocumentParse (SystemVersionData, SystemVersionDataSize, FALSE);
if (Document == NULL) {
return NULL;
@ -141,7 +141,7 @@ GetAppleRecoveryName (
UINTN SystemVersionPathSize;
CHAR8 *SystemVersionData;
CHAR16 *UnicodeDiskLabel;
UINTN SystemVersionDataSize;
UINT32 SystemVersionDataSize;
SystemVersionPathSize = StrSize (BootDirectoryName) + L_STR_SIZE_NT (L"SystemVersion.plist");
SystemVersionPath = AllocatePool (SystemVersionPathSize);
@ -257,7 +257,7 @@ OcDescribeBootEntry (
CHAR16 *RecoveryBootName;
EFI_HANDLE Device;
EFI_HANDLE ApfsVolumeHandle;
UINT32 BcdSize;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem;
Status = BootPolicy->GetBootInfo (
@ -289,6 +289,10 @@ OcDescribeBootEntry (
if (BootEntry->Name == NULL) {
BootEntry->Name = GetAppleDiskLabel (FileSystem, BootDirectoryName, L".disk_label.contentDetails");
}
Status = ReadFileSize (FileSystem, L"\\EFI\\Microsoft\\Boot\\BCD", &BcdSize);
if (!EFI_ERROR (Status)) {
BootEntry->Name = AllocateCopyPool(sizeof (L"BOOTCAMP Windows"), L"BOOTCAMP Windows");
}
if (BootEntry->Name == NULL) {
BootEntry->Name = GetVolumeLabel (FileSystem);
if (BootEntry->Name != NULL

View File

@ -24,7 +24,7 @@
#include <Library/UefiBootServicesTableLib.h>
EFI_STATUS
ReadFileData (
GetFileData (
IN EFI_FILE_PROTOCOL *File,
IN UINT32 Position,
IN UINT32 Size,
@ -53,7 +53,7 @@ ReadFileData (
}
EFI_STATUS
ReadFileSize (
GetFileSize (
IN EFI_FILE_PROTOCOL *File,
OUT UINT32 *Size
)
@ -81,7 +81,7 @@ ReadFileSize (
}
EFI_STATUS
ReadFileModifcationTime (
GetFileModifcationTime (
IN EFI_FILE_PROTOCOL *File,
OUT EFI_TIME *Time
)
@ -206,7 +206,7 @@ FindWritableFileSystem (
}
EFI_STATUS
WriteFileData (
SetFileData (
IN EFI_FILE_PROTOCOL *WritableFs OPTIONAL,
IN CONST CHAR16 *FileName,
IN CONST VOID *Buffer,

View File

@ -30,7 +30,7 @@
VOID *
GetFileInfo (
IN EFI_FILE_PROTOCOL *FileHandle,
IN EFI_FILE_PROTOCOL *File,
IN EFI_GUID *InformationType,
IN UINTN MinFileInfoSize,
OUT UINTN *RealFileInfoSize OPTIONAL
@ -44,8 +44,8 @@ GetFileInfo (
FileInfoSize = 0;
FileInfoBuffer = NULL;
Status = FileHandle->GetInfo (
FileHandle,
Status = File->GetInfo (
File,
InformationType,
&FileInfoSize,
NULL
@ -55,8 +55,8 @@ GetFileInfo (
FileInfoBuffer = AllocateZeroPool (FileInfoSize);
if (FileInfoBuffer != NULL) {
Status = FileHandle->GetInfo (
FileHandle,
Status = File->GetInfo (
File,
InformationType,
&FileInfoSize,
FileInfoBuffer

View File

@ -33,16 +33,15 @@ VOID *
ReadFile (
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem,
IN CONST CHAR16 *FilePath,
OUT UINTN *FileSize OPTIONAL
OUT UINT32 *FileSize OPTIONAL
)
{
EFI_STATUS Status;
EFI_FILE_HANDLE Volume;
EFI_FILE_HANDLE FileHandle;
EFI_FILE_INFO *FileInfo;
UINT8 *FileBuffer;
UINTN FileBufferSize;
UINTN FileReadSize;
UINT32 FileBufferSize;
UINT32 FileReadSize;
ASSERT (FileSystem != NULL);
ASSERT (FilePath != NULL);
@ -63,40 +62,36 @@ ReadFile (
0
);
Volume->Close (Volume);
if (EFI_ERROR (Status)) {
Volume->Close (Volume);
return NULL;
}
FileInfo = GetFileInfo (
Status = GetFileSize (
FileHandle,
&gEfiFileInfoGuid,
sizeof (EFI_FILE_INFO),
NULL
&FileReadSize
);
if (FileInfo == NULL
|| OcOverflowAddUN(FileInfo->FileSize, sizeof (CHAR16), &FileBufferSize)) {
if (EFI_ERROR (Status)
|| OcOverflowAddU32 (FileReadSize, sizeof (CHAR16), &FileBufferSize)) {
FileHandle->Close (FileHandle);
Volume->Close (Volume);
return NULL;
}
FileBuffer = AllocatePool (FileBufferSize);
if (FileBuffer != NULL) {
FileReadSize = FileInfo->FileSize;
Status = FileHandle->Read (
Status = GetFileData (
FileHandle,
&FileReadSize,
0,
FileReadSize,
FileBuffer
);
if (!EFI_ERROR (Status) && FileReadSize == FileInfo->FileSize) {
FileBuffer[FileInfo->FileSize] = 0;
FileBuffer[FileInfo->FileSize + 1] = 0;
if (!EFI_ERROR (Status)) {
FileBuffer[FileReadSize] = 0;
FileBuffer[FileReadSize + 1] = 0;
if (FileSize != NULL) {
*FileSize = FileInfo->FileSize;
*FileSize = FileReadSize;
}
} else {
FreePool (FileBuffer);
@ -105,6 +100,50 @@ ReadFile (
}
FileHandle->Close (FileHandle);
Volume->Close (Volume);
return FileBuffer;
}
EFI_STATUS
ReadFileSize (
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem,
IN CONST CHAR16 *FilePath,
OUT UINT32 *Size
)
{
EFI_STATUS Status;
EFI_FILE_HANDLE Volume;
EFI_FILE_HANDLE FileHandle;
ASSERT (FileSystem != NULL);
ASSERT (FilePath != NULL);
ASSERT (Size != NULL);
Status = FileSystem->OpenVolume (
FileSystem,
&Volume
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = Volume->Open (
Volume,
&FileHandle,
(CHAR16 *) FilePath,
EFI_FILE_MODE_READ,
0
);
Volume->Close (Volume);
if (EFI_ERROR (Status)) {
return Status;
}
Status = GetFileSize (
FileHandle,
Size
);
return Status;
}

View File

@ -104,7 +104,7 @@ OcStorageReadFileUnicode (
return NULL;
}
Status = ReadFileSize (File, &Size);
Status = GetFileSize (File, &Size);
if (EFI_ERROR (Status) || Size >= MAX_UINT32 - 1) {
File->Close (File);
return NULL;
@ -116,7 +116,7 @@ OcStorageReadFileUnicode (
return NULL;
}
Status = ReadFileData (File, 0, Size, FileBuffer);
Status = GetFileData (File, 0, Size, FileBuffer);
File->Close (File);
if (EFI_ERROR (Status)) {
FreePool (FileBuffer);

View File

@ -501,7 +501,7 @@ TestFileOpen (
0
);
Status = ReadFileModifcationTime (*NewHandle, &ModificationTime);
Status = GetFileModifcationTime (*NewHandle, &ModificationTime);
if (EFI_ERROR (Status)) {
ZeroMem (&ModificationTime, sizeof (ModificationTime));
}
@ -533,7 +533,7 @@ TestFileOpen (
Print (
L"Writing resulting kernel of %u bytes - %r\n",
KernelSize,
WriteFileData (NULL, DumpName, Kernel, KernelSize)
SetFileData (NULL, DumpName, Kernel, KernelSize)
);
#endif

View File

@ -427,7 +427,7 @@ UINT8 *Prelinked;
UINT32 PrelinkedSize;
EFI_STATUS
ReadFileData (
GetFileData (
IN EFI_FILE_PROTOCOL *File,
IN UINT32 Position,
IN UINT32 Size,
@ -445,7 +445,7 @@ ReadFileData (
}
EFI_STATUS
ReadFileSize (
GetFileSize (
IN EFI_FILE_PROTOCOL *File,
OUT UINT32 *Size
)