xref: /spdk/module/bdev/gpt/gpt.h (revision 3a39d90b03f7581d60716e3e9cf4dbcf7c48b08a)
1488570ebSJim Harris /*   SPDX-License-Identifier: BSD-3-Clause
2a6dbe372Spaul luse  *   Copyright (C) 2017 Intel Corporation.
307fe6a43SSeth Howell  *   All rights reserved.
407fe6a43SSeth Howell  */
507fe6a43SSeth Howell 
607fe6a43SSeth Howell /** \file
707fe6a43SSeth Howell  * GPT internal Interface
807fe6a43SSeth Howell  */
907fe6a43SSeth Howell 
1007fe6a43SSeth Howell #ifndef SPDK_INTERNAL_GPT_H
1107fe6a43SSeth Howell #define SPDK_INTERNAL_GPT_H
1207fe6a43SSeth Howell 
1307fe6a43SSeth Howell #include "spdk/stdinc.h"
1407fe6a43SSeth Howell 
1507fe6a43SSeth Howell #include "spdk/gpt_spec.h"
16*3a39d90bSJim Harris #include "spdk/log.h"
1707fe6a43SSeth Howell 
18*3a39d90bSJim Harris #define SPDK_GPT_PART_TYPE_GUID     SPDK_GPT_GUID(0x6527994e, 0x2c5a, 0x4eec, 0x9613, 0x8f5944074e8b)
19*3a39d90bSJim Harris 
20*3a39d90bSJim Harris /* PART_TYPE_GUID_OLD partitions will be constructed as bdevs with one fewer block than expected.
21*3a39d90bSJim Harris  * See GitHub issue #2801.
22*3a39d90bSJim Harris  */
23*3a39d90bSJim Harris #ifdef REGISTER_GUID_DEPRECATION
24*3a39d90bSJim Harris /* Register the deprecation in the header file, to make it clear to readers that this GUID
25*3a39d90bSJim Harris  * shouldn't be used for new SPDK GPT partitions.  We will never actually log this deprecation
26*3a39d90bSJim Harris  * though, since we are not recommending that users try to migrate existing partitions with the
27*3a39d90bSJim Harris  * old GUID to the new GUID. Wrap it in this REGISTER_GUID_DEPRECATION flag to avoid defining
28*3a39d90bSJim Harris  * this deprecation in multiple compilation units.
29*3a39d90bSJim Harris  */
30*3a39d90bSJim Harris SPDK_LOG_DEPRECATION_REGISTER(old_gpt_guid, "old gpt guid", "Never", 0)
31*3a39d90bSJim Harris #endif
32*3a39d90bSJim Harris #define SPDK_GPT_PART_TYPE_GUID_OLD SPDK_GPT_GUID(0x7c5222bd, 0x8f5d, 0x4087, 0x9c00, 0xbf9843c7b58c)
33*3a39d90bSJim Harris 
3407fe6a43SSeth Howell #define SPDK_GPT_BUFFER_SIZE 32768  /* 32KB */
3507fe6a43SSeth Howell #define	SPDK_GPT_GUID_EQUAL(x,y) (memcmp(x, y, sizeof(struct spdk_gpt_guid)) == 0)
3607fe6a43SSeth Howell 
3707fe6a43SSeth Howell enum spdk_gpt_parse_phase {
3807fe6a43SSeth Howell 	SPDK_GPT_PARSE_PHASE_INVALID = 0,
3907fe6a43SSeth Howell 	SPDK_GPT_PARSE_PHASE_PRIMARY,
4007fe6a43SSeth Howell 	SPDK_GPT_PARSE_PHASE_SECONDARY,
4107fe6a43SSeth Howell };
4207fe6a43SSeth Howell 
4307fe6a43SSeth Howell struct spdk_gpt {
4407fe6a43SSeth Howell 	uint8_t parse_phase;
4507fe6a43SSeth Howell 	unsigned char *buf;
4607fe6a43SSeth Howell 	uint64_t buf_size;
4707fe6a43SSeth Howell 	uint64_t lba_start;
4807fe6a43SSeth Howell 	uint64_t lba_end;
4907fe6a43SSeth Howell 	uint64_t total_sectors;
5007fe6a43SSeth Howell 	uint32_t sector_size;
5107fe6a43SSeth Howell 	struct spdk_gpt_header *header;
5207fe6a43SSeth Howell 	struct spdk_gpt_partition_entry *partitions;
5307fe6a43SSeth Howell };
5407fe6a43SSeth Howell 
551d2faf6dSSeth Howell int gpt_parse_mbr(struct spdk_gpt *gpt);
561d2faf6dSSeth Howell int gpt_parse_partition_table(struct spdk_gpt *gpt);
5707fe6a43SSeth Howell 
5807fe6a43SSeth Howell #endif  /* SPDK_INTERNAL_GPT_H */
59