diff options
author | kavsrf <kavsrf@gmail.com> | 2017-01-28 14:12:08 +0300 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2017-06-05 17:36:53 +0200 |
commit | 0d88d54f987fa0e464177febbc04c93257a17b40 (patch) | |
tree | aaacb843bd8912f3c81a332fca4e94854c82279f /Library/DcsCfgLib | |
parent | ac7e30ce323a78006d845c35602bdd97fe893dbd (diff) | |
download | VeraCrypt-DCS-0d88d54f987fa0e464177febbc04c93257a17b40.tar.gz VeraCrypt-DCS-0d88d54f987fa0e464177febbc04c93257a17b40.zip |
full disk encryption support
Diffstat (limited to 'Library/DcsCfgLib')
-rw-r--r-- | Library/DcsCfgLib/GptEdit.c | 202 |
1 files changed, 4 insertions, 198 deletions
diff --git a/Library/DcsCfgLib/GptEdit.c b/Library/DcsCfgLib/GptEdit.c index ea016f1..e1d6d2a 100644 --- a/Library/DcsCfgLib/GptEdit.c +++ b/Library/DcsCfgLib/GptEdit.c @@ -61,200 +61,6 @@ UINTN MirrorPartIdx; // Partitions
//////////////////////////////////////////////////////////////////////////
-
-/**
-Checks the CRC32 value in the table header.
-
-@param MaxSize Max Size limit
-@param Size The size of the table
-@param Hdr Table to check
-
-@return TRUE CRC Valid
-@return FALSE CRC Invalid
-
-**/
-BOOLEAN
-GptHeaderCheckCrcAltSize(
- IN UINTN MaxSize,
- IN UINTN Size,
- IN OUT EFI_TABLE_HEADER *Hdr
- )
-{
- UINT32 Crc;
- UINT32 OrgCrc;
- EFI_STATUS Status;
-
- Crc = 0;
-
- if (Size == 0) {
- //
- // If header size is 0 CRC will pass so return FALSE here
- //
- return FALSE;
- }
-
- if ((MaxSize != 0) && (Size > MaxSize)) {
- return FALSE;
- }
- //
- // clear old crc from header
- //
- OrgCrc = Hdr->CRC32;
- Hdr->CRC32 = 0;
-
- Status = gBS->CalculateCrc32((UINT8 *)Hdr, Size, &Crc);
- if (EFI_ERROR(Status)) {
- return FALSE;
- }
- //
- // set results
- //
- Hdr->CRC32 = OrgCrc;
-
- return (BOOLEAN)(OrgCrc == Crc);
-}
-
-/**
-Checks the CRC32 value in the table header.
-
-@param MaxSize Max Size limit
-@param Hdr Table to check
-
-@return TRUE CRC Valid
-@return FALSE CRC Invalid
-
-**/
-BOOLEAN
-GptHeaderCheckCrc(
- IN UINTN MaxSize,
- IN OUT EFI_TABLE_HEADER *Hdr
- )
-{
- return GptHeaderCheckCrcAltSize(MaxSize, Hdr->HeaderSize, Hdr);
-}
-
-EFI_STATUS
-GptCheckEntryArray(
- IN EFI_PARTITION_TABLE_HEADER *PartHeader,
- IN EFI_PARTITION_ENTRY *Entrys
- )
-{
- EFI_STATUS Status;
- UINT32 Crc;
- UINTN Size;
-
- Size = (UINTN) PartHeader->NumberOfPartitionEntries * (UINTN) PartHeader->SizeOfPartitionEntry;
- Status = gBS->CalculateCrc32(Entrys, Size, &Crc);
- if (EFI_ERROR(Status)) {
- return EFI_CRC_ERROR;
- }
- Status = (PartHeader->PartitionEntryArrayCRC32 == Crc) ? EFI_SUCCESS : EFI_CRC_ERROR;
- return Status;
-}
-
-EFI_STATUS
-GptUpdateCRC(
- IN EFI_PARTITION_TABLE_HEADER *PartHeader,
- IN EFI_PARTITION_ENTRY *Entrys
- )
-{
- EFI_STATUS Status;
- UINT32 Crc;
- UINTN Size;
-
- Size = (UINTN) PartHeader->NumberOfPartitionEntries * (UINTN) PartHeader->SizeOfPartitionEntry;
- Status = gBS->CalculateCrc32(Entrys, Size, &Crc);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- PartHeader->PartitionEntryArrayCRC32 = Crc;
- PartHeader->Header.CRC32 = 0;
-
- Status = gBS->CalculateCrc32((UINT8 *)PartHeader, PartHeader->Header.HeaderSize, &Crc);
- if (EFI_ERROR(Status)) {
- return Status;
- }
- PartHeader->Header.CRC32 = Crc;
- return Status;
-}
-
-/**
-Read GPT
-Check if the CRC field in the Partition table header is valid
-for Partition entry array.
-
-@param[in] DiskIo Disk Io Protocol.
-@param[in] PartHeader Partition table header structure
-
-@retval EFI_SUCCESS the CRC is valid
-**/
-EFI_STATUS
-GptReadEntryArray(
- IN EFI_PARTITION_TABLE_HEADER *PartHeader,
- OUT EFI_PARTITION_ENTRY **Entrys
- )
-{
- EFI_STATUS Status;
- UINT8 *Ptr;
-
- //
- // Read the EFI Partition Entries
- //
- Ptr = MEM_ALLOC(PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry);
- if (Ptr == NULL) {
- return EFI_BUFFER_TOO_SMALL;
- }
-
- Status = BlockIo->ReadBlocks(
- BlockIo,
- BlockIo->Media->MediaId,
- PartHeader->PartitionEntryLBA,
- PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry,
- Ptr
- );
- if (EFI_ERROR(Status)) {
- MEM_FREE(Ptr);
- return Status;
- }
-
- *Entrys = (EFI_PARTITION_ENTRY*)Ptr;
- return GptCheckEntryArray(PartHeader, *Entrys);
-}
-
-EFI_STATUS
-GptReadHeader(
- IN EFI_LBA HeaderLba,
- OUT EFI_PARTITION_TABLE_HEADER **PartHeader
- )
-{
- EFI_STATUS res = EFI_SUCCESS;
- UINT32 BlockSize;
- EFI_PARTITION_TABLE_HEADER *PartHdr;
- UINT32 MediaId;
-
- BlockSize = BlockIo->Media->BlockSize;
- MediaId = BlockIo->Media->MediaId;
- PartHdr = MEM_ALLOC(BlockSize);
-
- res = BlockIo->ReadBlocks(BlockIo, MediaId, HeaderLba, BlockSize, PartHdr);
- if (EFI_ERROR(res)) {
- MEM_FREE(PartHdr);
- return res;
- }
-
- // Check header
- if ((PartHdr->Header.Signature != EFI_PTAB_HEADER_ID) ||
- !GptHeaderCheckCrc(BlockSize, &PartHdr->Header) ||
- PartHdr->MyLBA != HeaderLba ||
- (PartHdr->SizeOfPartitionEntry < sizeof(EFI_PARTITION_ENTRY))
- ) {
- MEM_FREE(PartHdr);
- return EFI_CRC_ERROR;
- }
- *PartHeader = PartHdr;
- return EFI_SUCCESS;
-}
-
VOID
GptPrint(
IN EFI_PARTITION_TABLE_HEADER *PartHdr,
@@ -298,26 +104,26 @@ GptLoadFromDisk( return EFI_NOT_FOUND;
}
- res = GptReadHeader(1, &GptMainHdr);
+ res = GptReadHeader(BlockIo, 1, &GptMainHdr);
if (EFI_ERROR(res)) {
ERR_PRINT(L"Can't read main GPT header: %r\n", res);
goto error;
}
- res = GptReadHeader(GptMainHdr->AlternateLBA, &GptAltHdr);
+ res = GptReadHeader(BlockIo, GptMainHdr->AlternateLBA, &GptAltHdr);
if (EFI_ERROR(res)) {
ERR_PRINT(L"Can't read alt GPT header: %r\n", res);
goto error;
}
- res = GptReadEntryArray(GptMainHdr, &GptMainEntrys);
+ res = GptReadEntryArray(BlockIo, GptMainHdr, &GptMainEntrys);
// Read GPT
if (EFI_ERROR(res)) {
ERR_PRINT(L"Main GPT error: %r\n", res);
goto error;
}
- res = GptReadEntryArray(GptAltHdr, &GptAltEntrys);
+ res = GptReadEntryArray(BlockIo, GptAltHdr, &GptAltEntrys);
// Read GPT
if (EFI_ERROR(res)) {
ERR_PRINT(L"Alt GPT error: %r\n", res);
|