1 /* 2 * Copyright 2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef EFI_GPT_H 6 #define EFI_GPT_H 7 8 9 #include "guid.h" 10 11 #include <SupportDefs.h> 12 #include <ByteOrder.h> 13 14 15 struct gpt_table_header { 16 char header[8]; 17 uint32 revision; 18 uint32 header_size; 19 uint32 header_crc; 20 uint32 _reserved1; 21 22 uint64 absolute_block; 23 uint64 alternate_block; 24 uint64 first_usable_block; 25 uint64 last_usable_block; 26 guid_t disk_guid; 27 uint64 entries_block; 28 uint32 entry_count; 29 uint32 entry_size; 30 uint32 entries_crc; 31 32 // the rest of the block is reserved 33 34 void SetRevision(uint32 newRevision) 35 { revision = B_HOST_TO_LENDIAN_INT32(newRevision); } 36 uint32 Revision() const 37 { return B_LENDIAN_TO_HOST_INT32(revision); } 38 void SetHeaderSize(uint32 size) 39 { header_size = B_HOST_TO_LENDIAN_INT32(size); } 40 uint32 HeaderSize() const 41 { return B_LENDIAN_TO_HOST_INT32(header_size); } 42 void SetHeaderCRC(uint32 crc) 43 { header_crc = B_HOST_TO_LENDIAN_INT32(crc); } 44 uint32 HeaderCRC() const 45 { return B_LENDIAN_TO_HOST_INT32(header_crc); } 46 47 void SetAbsoluteBlock(uint64 block) 48 { absolute_block = B_HOST_TO_LENDIAN_INT64(block); } 49 uint64 AbsoluteBlock() const 50 { return B_LENDIAN_TO_HOST_INT64(absolute_block); } 51 void SetAlternateBlock(uint64 block) 52 { alternate_block = B_HOST_TO_LENDIAN_INT64(block); } 53 uint64 AlternateBlock() const 54 { return B_LENDIAN_TO_HOST_INT64(alternate_block); } 55 void SetFirstUsableBlock(uint64 block) 56 { first_usable_block = B_HOST_TO_LENDIAN_INT64(block); } 57 uint64 FirstUsableBlock() const 58 { return B_LENDIAN_TO_HOST_INT64(first_usable_block); } 59 void SetLastUsableBlock(uint64 block) 60 { last_usable_block = B_HOST_TO_LENDIAN_INT64(block); } 61 uint64 LastUsableBlock() const 62 { return B_LENDIAN_TO_HOST_INT64(last_usable_block); } 63 64 void SetEntriesBlock(uint64 block) 65 { entries_block = B_HOST_TO_LENDIAN_INT64(block); } 66 uint64 EntriesBlock() const 67 { return B_LENDIAN_TO_HOST_INT64(entries_block); } 68 void SetEntryCount(uint32 count) 69 { entry_count = B_HOST_TO_LENDIAN_INT32(count); } 70 uint32 EntryCount() const 71 { return B_LENDIAN_TO_HOST_INT32(entry_count); } 72 void SetEntrySize(uint32 size) 73 { entry_size = B_HOST_TO_LENDIAN_INT32(size); } 74 uint32 EntrySize() const 75 { return B_LENDIAN_TO_HOST_INT32(entry_size); } 76 void SetEntriesCRC(uint32 crc) 77 { entries_crc = B_HOST_TO_LENDIAN_INT32(crc); } 78 uint32 EntriesCRC() const 79 { return B_LENDIAN_TO_HOST_INT32(entries_crc); } 80 } _PACKED; 81 82 #define EFI_PARTITION_HEADER "EFI PART" 83 #define EFI_HEADER_LOCATION 1 84 #define EFI_TABLE_REVISION 0x00010000 85 86 #define EFI_PARTITION_NAME_LENGTH 36 87 #define EFI_PARTITION_ENTRIES_BLOCK 2 88 #define EFI_PARTITION_ENTRY_COUNT 128 89 #define EFI_PARTITION_ENTRY_SIZE 128 90 91 struct gpt_partition_entry { 92 guid_t partition_type; 93 guid_t unique_guid; 94 uint64 start_block; 95 uint64 end_block; 96 uint64 attributes; 97 uint16 name[EFI_PARTITION_NAME_LENGTH]; 98 99 void SetStartBlock(uint64 block) 100 { start_block = B_HOST_TO_LENDIAN_INT64(block); } 101 uint64 StartBlock() const 102 { return B_LENDIAN_TO_HOST_INT64(start_block); } 103 void SetEndBlock(uint64 block) 104 { end_block = B_HOST_TO_LENDIAN_INT64(block); } 105 uint64 EndBlock() const 106 { return B_LENDIAN_TO_HOST_INT64(end_block); } 107 void SetAttributes(uint64 _attributes) 108 { attributes = B_HOST_TO_LENDIAN_INT64(_attributes); } 109 uint64 Attributes() const 110 { return B_LENDIAN_TO_HOST_INT64(attributes); } 111 112 // convenience functions 113 void SetBlockCount(uint64 blockCount) 114 { SetEndBlock(StartBlock() + blockCount - 1); } 115 uint64 BlockCount() const 116 { return EndBlock() - StartBlock() + 1; } 117 } _PACKED; 118 119 #endif /* EFI_GPT_H */ 120 121