xref: /haiku/src/add-ons/kernel/partitioning_systems/gpt/gpt.h (revision ed7204fad26a97ef873402c0be74928e80b63e8a)
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 
SetRevisiongpt_table_header34 	void SetRevision(uint32 newRevision)
35 		{ revision = B_HOST_TO_LENDIAN_INT32(newRevision); }
Revisiongpt_table_header36 	uint32 Revision() const
37 		{ return B_LENDIAN_TO_HOST_INT32(revision); }
SetHeaderSizegpt_table_header38 	void SetHeaderSize(uint32 size)
39 		{ header_size = B_HOST_TO_LENDIAN_INT32(size); }
HeaderSizegpt_table_header40 	uint32 HeaderSize() const
41 		{ return B_LENDIAN_TO_HOST_INT32(header_size); }
SetHeaderCRCgpt_table_header42 	void SetHeaderCRC(uint32 crc)
43 		{ header_crc = B_HOST_TO_LENDIAN_INT32(crc); }
HeaderCRCgpt_table_header44 	uint32 HeaderCRC() const
45 		{ return B_LENDIAN_TO_HOST_INT32(header_crc); }
46 
SetAbsoluteBlockgpt_table_header47 	void SetAbsoluteBlock(uint64 block)
48 		{ absolute_block = B_HOST_TO_LENDIAN_INT64(block); }
AbsoluteBlockgpt_table_header49 	uint64 AbsoluteBlock() const
50 		{ return B_LENDIAN_TO_HOST_INT64(absolute_block); }
SetAlternateBlockgpt_table_header51 	void SetAlternateBlock(uint64 block)
52 		{ alternate_block = B_HOST_TO_LENDIAN_INT64(block); }
AlternateBlockgpt_table_header53 	uint64 AlternateBlock() const
54 		{ return B_LENDIAN_TO_HOST_INT64(alternate_block); }
SetFirstUsableBlockgpt_table_header55 	void SetFirstUsableBlock(uint64 block)
56 		{ first_usable_block = B_HOST_TO_LENDIAN_INT64(block); }
FirstUsableBlockgpt_table_header57 	uint64 FirstUsableBlock() const
58 		{ return B_LENDIAN_TO_HOST_INT64(first_usable_block); }
SetLastUsableBlockgpt_table_header59 	void SetLastUsableBlock(uint64 block)
60 		{ last_usable_block = B_HOST_TO_LENDIAN_INT64(block); }
LastUsableBlockgpt_table_header61 	uint64 LastUsableBlock() const
62 		{ return B_LENDIAN_TO_HOST_INT64(last_usable_block); }
63 
SetEntriesBlockgpt_table_header64 	void SetEntriesBlock(uint64 block)
65 		{ entries_block = B_HOST_TO_LENDIAN_INT64(block); }
EntriesBlockgpt_table_header66 	uint64 EntriesBlock() const
67 		{ return B_LENDIAN_TO_HOST_INT64(entries_block); }
SetEntryCountgpt_table_header68 	void SetEntryCount(uint32 count)
69 		{ entry_count = B_HOST_TO_LENDIAN_INT32(count); }
EntryCountgpt_table_header70 	uint32 EntryCount() const
71 		{ return B_LENDIAN_TO_HOST_INT32(entry_count); }
SetEntrySizegpt_table_header72 	void SetEntrySize(uint32 size)
73 		{ entry_size = B_HOST_TO_LENDIAN_INT32(size); }
EntrySizegpt_table_header74 	uint32 EntrySize() const
75 		{ return B_LENDIAN_TO_HOST_INT32(entry_size); }
SetEntriesCRCgpt_table_header76 	void SetEntriesCRC(uint32 crc)
77 		{ entries_crc = B_HOST_TO_LENDIAN_INT32(crc); }
EntriesCRCgpt_table_header78 	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 
SetStartBlockgpt_partition_entry99 	void SetStartBlock(uint64 block)
100 		{ start_block = B_HOST_TO_LENDIAN_INT64(block); }
StartBlockgpt_partition_entry101 	uint64 StartBlock() const
102 		{ return B_LENDIAN_TO_HOST_INT64(start_block); }
SetEndBlockgpt_partition_entry103 	void SetEndBlock(uint64 block)
104 		{ end_block = B_HOST_TO_LENDIAN_INT64(block); }
EndBlockgpt_partition_entry105 	uint64 EndBlock() const
106 		{ return B_LENDIAN_TO_HOST_INT64(end_block); }
SetAttributesgpt_partition_entry107 	void SetAttributes(uint64 _attributes)
108 		{ attributes = B_HOST_TO_LENDIAN_INT64(_attributes); }
Attributesgpt_partition_entry109 	uint64 Attributes() const
110 		{ return B_LENDIAN_TO_HOST_INT64(attributes); }
111 
112 	// convenience functions
SetBlockCountgpt_partition_entry113 	void SetBlockCount(uint64 blockCount)
114 		{ SetEndBlock(StartBlock() + blockCount - 1); }
BlockCountgpt_partition_entry115 	uint64 BlockCount() const
116 		{ return EndBlock() - StartBlock() + 1; }
117 } _PACKED;
118 
119 #endif	/* EFI_GPT_H */
120 
121