gpt: Correct naming. efi_* also conflicts with some efi headers

Change-Id: I19b5b2c4609da8474b26588ae8d7d4caf72a826b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2018
Reviewed-by: Fredrik Holmqvist <[email protected]>
Reviewed-by: Alex von Gluck IV <[email protected]>
This commit is contained in:
Alexander von Gluck IV
2019-12-13 23:53:07 +00:00
committed by Alex von Gluck IV
parent 418e068de3
commit ed7204fad2
11 changed files with 44 additions and 44 deletions
@@ -17,7 +17,7 @@
#include <AutoDeleter.h> #include <AutoDeleter.h>
#include <disk_device_types.h> #include <disk_device_types.h>
#include "efi_gpt.h" #include "gpt.h"
#include "GPTPartitionHandle.h" #include "GPTPartitionHandle.h"
#include "Utility.h" #include "Utility.h"
@@ -59,7 +59,7 @@ Header::Header(int fd, uint64 lastBlock, uint32 blockSize)
// Read and check the partition table header // Read and check the partition table header
fStatus = _Read(fd, (uint64)EFI_HEADER_LOCATION * blockSize, fStatus = _Read(fd, (uint64)EFI_HEADER_LOCATION * blockSize,
&fHeader, sizeof(efi_table_header)); &fHeader, sizeof(gpt_table_header));
if (fStatus == B_OK) { if (fStatus == B_OK) {
if (!_IsHeaderValid(fHeader, EFI_HEADER_LOCATION)) if (!_IsHeaderValid(fHeader, EFI_HEADER_LOCATION))
fStatus = B_BAD_DATA; fStatus = B_BAD_DATA;
@@ -73,7 +73,7 @@ Header::Header(int fd, uint64 lastBlock, uint32 blockSize)
// Read backup header, too // Read backup header, too
status_t status = _Read(fd, lastBlock * blockSize, &fBackupHeader, status_t status = _Read(fd, lastBlock * blockSize, &fBackupHeader,
sizeof(efi_table_header)); sizeof(gpt_table_header));
if (status == B_OK) { if (status == B_OK) {
if (!_IsHeaderValid(fBackupHeader, lastBlock)) if (!_IsHeaderValid(fBackupHeader, lastBlock))
status = B_BAD_DATA; status = B_BAD_DATA;
@@ -275,12 +275,12 @@ Header::_WriteHeader(int fd)
_UpdateCRC(); _UpdateCRC();
status_t status = _Write(fd, fHeader.AbsoluteBlock() * fBlockSize, status_t status = _Write(fd, fHeader.AbsoluteBlock() * fBlockSize,
&fHeader, sizeof(efi_table_header)); &fHeader, sizeof(gpt_table_header));
if (status != B_OK) if (status != B_OK)
return status; return status;
return _Write(fd, fBackupHeader.AbsoluteBlock() * fBlockSize, return _Write(fd, fBackupHeader.AbsoluteBlock() * fBlockSize,
&fBackupHeader, sizeof(efi_table_header)); &fBackupHeader, sizeof(gpt_table_header));
} }
@@ -306,11 +306,11 @@ Header::_UpdateCRC()
void void
Header::_UpdateCRC(efi_table_header& header) Header::_UpdateCRC(gpt_table_header& header)
{ {
header.SetEntriesCRC(crc32(fEntries, _EntryArraySize())); header.SetEntriesCRC(crc32(fEntries, _EntryArraySize()));
header.SetHeaderCRC(0); header.SetHeaderCRC(0);
header.SetHeaderCRC(crc32((uint8*)&header, sizeof(efi_table_header))); header.SetHeaderCRC(crc32((uint8*)&header, sizeof(gpt_table_header)));
} }
#endif // !_BOOT_MODE #endif // !_BOOT_MODE
@@ -329,7 +329,7 @@ Header::_Read(int fd, off_t offset, void* data, size_t size) const
bool bool
Header::_IsHeaderValid(efi_table_header& header, uint64 block) Header::_IsHeaderValid(gpt_table_header& header, uint64 block)
{ {
return !memcmp(header.header, EFI_PARTITION_HEADER, sizeof(header.header)) return !memcmp(header.header, EFI_PARTITION_HEADER, sizeof(header.header))
&& _ValidateHeaderCRC(header) && _ValidateHeaderCRC(header)
@@ -338,13 +338,13 @@ Header::_IsHeaderValid(efi_table_header& header, uint64 block)
bool bool
Header::_ValidateHeaderCRC(efi_table_header& header) Header::_ValidateHeaderCRC(gpt_table_header& header)
{ {
uint32 originalCRC = header.HeaderCRC(); uint32 originalCRC = header.HeaderCRC();
header.SetHeaderCRC(0); header.SetHeaderCRC(0);
bool matches = originalCRC == crc32((const uint8*)&header, bool matches = originalCRC == crc32((const uint8*)&header,
sizeof(efi_table_header)); sizeof(gpt_table_header));
header.SetHeaderCRC(originalCRC); header.SetHeaderCRC(originalCRC);
return matches; return matches;
@@ -385,7 +385,7 @@ Header::_PrintGUID(const guid_t &id)
void void
Header::_Dump(const efi_table_header& header) Header::_Dump(const gpt_table_header& header)
{ {
dprintf("EFI header: %.8s\n", header.header); dprintf("EFI header: %.8s\n", header.header);
dprintf("EFI revision: %" B_PRIx32 "\n", header.Revision()); dprintf("EFI revision: %" B_PRIx32 "\n", header.Revision());
@@ -407,7 +407,7 @@ void
Header::_DumpPartitions() Header::_DumpPartitions()
{ {
for (uint32 i = 0; i < EntryCount(); i++) { for (uint32 i = 0; i < EntryCount(); i++) {
const efi_partition_entry &entry = EntryAt(i); const gpt_partition_entry &entry = EntryAt(i);
if (entry.partition_type == kEmptyGUID) if (entry.partition_type == kEmptyGUID)
continue; continue;
@@ -8,7 +8,7 @@
#define GPT_HEADER_H #define GPT_HEADER_H
#include "efi_gpt.h" #include "gpt.h"
namespace EFI { namespace EFI {
@@ -31,13 +31,13 @@ public:
{ return fHeader.FirstUsableBlock(); } { return fHeader.FirstUsableBlock(); }
uint64 LastUsableBlock() const uint64 LastUsableBlock() const
{ return fHeader.LastUsableBlock(); } { return fHeader.LastUsableBlock(); }
const efi_table_header& TableHeader() const const gpt_table_header& TableHeader() const
{ return fHeader; } { return fHeader; }
uint32 EntryCount() const uint32 EntryCount() const
{ return fHeader.EntryCount(); } { return fHeader.EntryCount(); }
efi_partition_entry& EntryAt(int32 index) const gpt_partition_entry& EntryAt(int32 index) const
{ return *(efi_partition_entry*)(fEntries { return *(gpt_partition_entry*)(fEntries
+ fHeader.EntrySize() * index); } + fHeader.EntrySize() * index); }
#ifndef _BOOT_MODE #ifndef _BOOT_MODE
@@ -51,14 +51,14 @@ private:
status_t _Write(int fd, off_t offset, const void* data, status_t _Write(int fd, off_t offset, const void* data,
size_t size) const; size_t size) const;
void _UpdateCRC(); void _UpdateCRC();
void _UpdateCRC(efi_table_header& header); void _UpdateCRC(gpt_table_header& header);
#endif #endif
status_t _Read(int fd, off_t offset, void* data, status_t _Read(int fd, off_t offset, void* data,
size_t size) const; size_t size) const;
static bool _IsHeaderValid(efi_table_header& header, static bool _IsHeaderValid(gpt_table_header& header,
uint64 block); uint64 block);
static bool _ValidateHeaderCRC(efi_table_header& header); static bool _ValidateHeaderCRC(gpt_table_header& header);
bool _ValidateEntriesCRC() const; bool _ValidateEntriesCRC() const;
void _SetBackupHeaderFromPrimary(uint64 lastBlock); void _SetBackupHeaderFromPrimary(uint64 lastBlock);
size_t _EntryArraySize() const size_t _EntryArraySize() const
@@ -66,14 +66,14 @@ private:
* fHeader.EntryCount(); } * fHeader.EntryCount(); }
const char* _PrintGUID(const guid_t& id); const char* _PrintGUID(const guid_t& id);
void _Dump(const efi_table_header& header); void _Dump(const gpt_table_header& header);
void _DumpPartitions(); void _DumpPartitions();
private: private:
uint32 fBlockSize; uint32 fBlockSize;
status_t fStatus; status_t fStatus;
efi_table_header fHeader; gpt_table_header fHeader;
efi_table_header fBackupHeader; gpt_table_header fBackupHeader;
uint8* fEntries; uint8* fEntries;
bool fDirty; bool fDirty;
}; };
@@ -20,7 +20,7 @@ if $(TARGET_ARCH) = "x86" || $(TARGET_ARCH) = "x86_64" {
} }
KernelAddon efi_gpt : KernelAddon efi_gpt :
efi_gpt.cpp gpt.cpp
Header.cpp Header.cpp
crc32.cpp crc32.cpp
utility.cpp utility.cpp
@@ -6,7 +6,7 @@
*/ */
#include "efi_gpt.h" #include "gpt.h"
#include <KernelExport.h> #include <KernelExport.h>
#include <disk_device_manager/ddm_modules.h> #include <disk_device_manager/ddm_modules.h>
@@ -115,7 +115,7 @@ efi_gpt_scan_partition(int fd, partition_data* partition, void* _cookie)
uint32 index = 0; uint32 index = 0;
for (uint32 i = 0; i < header->EntryCount(); i++) { for (uint32 i = 0; i < header->EntryCount(); i++) {
const efi_partition_entry& entry = header->EntryAt(i); const gpt_partition_entry& entry = header->EntryAt(i);
if (entry.partition_type == kEmptyGUID) if (entry.partition_type == kEmptyGUID)
continue; continue;
@@ -378,7 +378,7 @@ efi_gpt_validate_create_child(partition_data* partition, off_t* start,
EFI::Header* header = (EFI::Header*)partition->content_cookie; EFI::Header* header = (EFI::Header*)partition->content_cookie;
int32 entryIndex = -1; int32 entryIndex = -1;
for (uint32 i = 0; i < header->EntryCount(); i++) { for (uint32 i = 0; i < header->EntryCount(); i++) {
const efi_partition_entry& entry = header->EntryAt(i); const gpt_partition_entry& entry = header->EntryAt(i);
if (entry.partition_type == kEmptyGUID) { if (entry.partition_type == kEmptyGUID) {
entryIndex = i; entryIndex = i;
break; break;
@@ -524,7 +524,7 @@ efi_gpt_resize_child(int fd, partition_id partitionID, off_t size,
update_disk_device_job_progress(job, 0.0); update_disk_device_job_progress(job, 0.0);
efi_partition_entry& entry = header->EntryAt(entryIndex); gpt_partition_entry& entry = header->EntryAt(entryIndex);
entry.SetBlockCount(validatedSize / partition->block_size); entry.SetBlockCount(validatedSize / partition->block_size);
status_t result = header->WriteEntry(fd, entryIndex); status_t result = header->WriteEntry(fd, entryIndex);
@@ -589,7 +589,7 @@ efi_gpt_move_child(int fd, partition_id partitionID, partition_id childID,
update_disk_device_job_progress(job, 0.0); update_disk_device_job_progress(job, 0.0);
efi_partition_entry& entry = header->EntryAt(entryIndex); gpt_partition_entry& entry = header->EntryAt(entryIndex);
uint64 blockCount = entry.BlockCount(); uint64 blockCount = entry.BlockCount();
entry.SetStartBlock((validatedOffset - partition->offset) entry.SetStartBlock((validatedOffset - partition->offset)
/ partition->block_size); / partition->block_size);
@@ -639,7 +639,7 @@ efi_gpt_set_name(int fd, partition_id partitionID, const char* name,
update_disk_device_job_progress(job, 0.0); update_disk_device_job_progress(job, 0.0);
efi_partition_entry& entry = header->EntryAt(entryIndex); gpt_partition_entry& entry = header->EntryAt(entryIndex);
to_ucs2(name, strlen(name), entry.name, EFI_PARTITION_NAME_LENGTH); to_ucs2(name, strlen(name), entry.name, EFI_PARTITION_NAME_LENGTH);
status_t result = header->WriteEntry(fd, entryIndex); status_t result = header->WriteEntry(fd, entryIndex);
@@ -689,7 +689,7 @@ efi_gpt_set_type(int fd, partition_id partitionID, const char* type,
update_disk_device_job_progress(job, 0.0); update_disk_device_job_progress(job, 0.0);
efi_partition_entry& entry = header->EntryAt(entryIndex); gpt_partition_entry& entry = header->EntryAt(entryIndex);
entry.partition_type = typeGUID; entry.partition_type = typeGUID;
status_t result = header->WriteEntry(fd, entryIndex); status_t result = header->WriteEntry(fd, entryIndex);
@@ -815,7 +815,7 @@ efi_gpt_create_child(int fd, partition_id partitionID, off_t offset,
if (child == NULL) if (child == NULL)
return B_ERROR; return B_ERROR;
efi_partition_entry& entry = header->EntryAt(entryIndex); gpt_partition_entry& entry = header->EntryAt(entryIndex);
entry.partition_type = typeGUID; entry.partition_type = typeGUID;
uuid_t uuid; uuid_t uuid;
uuid_generate_random(uuid); uuid_generate_random(uuid);
@@ -882,8 +882,8 @@ efi_gpt_delete_child(int fd, partition_id partitionID, partition_id childID,
if (!delete_partition(childID)) if (!delete_partition(childID))
return B_ERROR; return B_ERROR;
efi_partition_entry& entry = header->EntryAt(entryIndex); gpt_partition_entry& entry = header->EntryAt(entryIndex);
memset(&entry, 0, sizeof(efi_partition_entry)); memset(&entry, 0, sizeof(gpt_partition_entry));
entry.partition_type = kEmptyGUID; entry.partition_type = kEmptyGUID;
status_t result = header->WriteEntry(fd, entryIndex); status_t result = header->WriteEntry(fd, entryIndex);
@@ -12,7 +12,7 @@
#include <ByteOrder.h> #include <ByteOrder.h>
struct efi_table_header { struct gpt_table_header {
char header[8]; char header[8];
uint32 revision; uint32 revision;
uint32 header_size; uint32 header_size;
@@ -88,7 +88,7 @@ struct efi_table_header {
#define EFI_PARTITION_ENTRY_COUNT 128 #define EFI_PARTITION_ENTRY_COUNT 128
#define EFI_PARTITION_ENTRY_SIZE 128 #define EFI_PARTITION_ENTRY_SIZE 128
struct efi_partition_entry { struct gpt_partition_entry {
guid_t partition_type; guid_t partition_type;
guid_t unique_guid; guid_t unique_guid;
uint64 start_block; uint64 start_block;
@@ -272,7 +272,7 @@ get_partition_offset(int deviceFD, off_t deviceStart, off_t deviceSize,
EFI::Header gptHeader(deviceFD, deviceSize, blockSize); EFI::Header gptHeader(deviceFD, deviceSize, blockSize);
error = gptHeader.InitCheck(); error = gptHeader.InitCheck();
if (error == B_OK && partitionIndex < gptHeader.EntryCount()) { if (error == B_OK && partitionIndex < gptHeader.EntryCount()) {
efi_partition_entry partition = gptHeader.EntryAt(partitionIndex - 1); gpt_partition_entry partition = gptHeader.EntryAt(partitionIndex - 1);
static_guid bfs_uuid = {0x42465331, 0x3BA3, 0x10F1, static_guid bfs_uuid = {0x42465331, 0x3BA3, 0x10F1,
0x802A4861696B7521LL}; 0x802A4861696B7521LL};
+2 -2
View File
@@ -135,7 +135,7 @@ for platform in [ MultiBootSubDirSetup ] {
amiga_rdb.cpp amiga_rdb.cpp
apple.cpp apple.cpp
efi_gpt.cpp gpt.cpp
Header.cpp Header.cpp
crc32.cpp crc32.cpp
utility.cpp utility.cpp
@@ -164,7 +164,7 @@ for platform in [ MultiBootSubDirSetup ] {
SEARCH on [ FGristFiles apple.cpp ] SEARCH on [ FGristFiles apple.cpp ]
= [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems apple ] ; = [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems apple ] ;
SEARCH on [ FGristFiles efi_gpt.cpp Header.cpp crc32.cpp utility.cpp ] SEARCH on [ FGristFiles gpt.cpp Header.cpp crc32.cpp utility.cpp ]
= [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems gpt ] ; = [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems gpt ] ;
SEARCH on [ FGristFiles intel.cpp PartitionMap.cpp PartitionMapParser.cpp ] SEARCH on [ FGristFiles intel.cpp PartitionMap.cpp PartitionMapParser.cpp ]
+2 -2
View File
@@ -414,7 +414,7 @@ device_contains_partition(EfiDevice *device, boot::Partition *partition)
return false; return false;
if (memcmp(deviceHeader, &header->TableHeader(), if (memcmp(deviceHeader, &header->TableHeader(),
sizeof(efi_table_header)) != 0) sizeof(gpt_table_header)) != 0)
return false; return false;
// partition->cookie == int partition entry index // partition->cookie == int partition entry index
@@ -427,7 +427,7 @@ device_contains_partition(EfiDevice *device, boot::Partition *partition)
return false; return false;
if (memcmp(&entries[index], &header->EntryAt(index), if (memcmp(&entries[index], &header->EntryAt(index),
sizeof(efi_partition_entry)) != 0) sizeof(gpt_partition_entry)) != 0)
return false; return false;
for (size_t i = 0; i < sizeof(kTypeMap) / sizeof(struct type_map); ++i) for (size_t i = 0; i < sizeof(kTypeMap) / sizeof(struct type_map); ++i)
@@ -46,7 +46,7 @@ SEARCH_SOURCE
+= [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems efi ] ; += [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems efi ] ;
Addon <userland>efi_gpt : Addon <userland>efi_gpt :
efi_gpt.cpp gpt.cpp
PartitionLocker.cpp PartitionLocker.cpp
: <nogrist>PartitioningSystemsTest libkernelland_emu.so : <nogrist>PartitioningSystemsTest libkernelland_emu.so
; ;
+3 -3
View File
@@ -37,7 +37,7 @@ ObjectDefines
amiga_rdb.cpp amiga_rdb.cpp
apple.cpp apple.cpp
efi_gpt.cpp gpt.cpp
Header.cpp Header.cpp
crc32.cpp crc32.cpp
utility.cpp utility.cpp
@@ -104,7 +104,7 @@ SimpleTest BootLoaderTest :
amiga_rdb.cpp amiga_rdb.cpp
apple.cpp apple.cpp
efi_gpt.cpp gpt.cpp
Header.cpp Header.cpp
crc32.cpp crc32.cpp
utility.cpp utility.cpp
@@ -153,7 +153,7 @@ SEARCH on [ FGristFiles amiga_rdb.cpp ]
SEARCH on [ FGristFiles apple.cpp ] SEARCH on [ FGristFiles apple.cpp ]
= [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems apple ] ; = [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems apple ] ;
SEARCH on [ FGristFiles efi_gpt.cpp Header.cpp crc32.cpp utility.cpp ] SEARCH on [ FGristFiles gpt.cpp Header.cpp crc32.cpp utility.cpp ]
= [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems gpt ] ; = [ FDirName $(HAIKU_TOP) src add-ons kernel partitioning_systems gpt ] ;
SEARCH on [ FGristFiles intel.cpp PartitionMap.cpp PartitionMapParser.cpp ] SEARCH on [ FGristFiles intel.cpp PartitionMap.cpp PartitionMapParser.cpp ]