]> code.delx.au - refind/blob - refind/gpt.h
Fixed uninitialized-pointer bug that manifested as a crash with
[refind] / refind / gpt.h
1 /*
2 * refind/gpt.h
3 * Functions related to GPT data structures
4 *
5 * Copyright (c) 2014-2015 Roderick W. Smith
6 * All rights reserved.
7 *
8 * This program is distributed under the terms of the GNU General Public
9 * License (GPL) version 3 (GPLv3), a copy of which must be distributed
10 * with this source code or binaries made from it.
11 *
12 */
13
14 #include "global.h"
15
16 #ifndef __GPT_H_
17 #define __GPT_H_
18
19 #ifdef __MAKEWITH_GNUEFI
20 #include "efi.h"
21 #include "efilib.h"
22 #else
23 #include "../include/tiano_includes.h"
24 #endif
25
26 #pragma pack(1)
27 typedef struct {
28 UINT8 flags;
29 UINT8 start_chs[3];
30 UINT8 type;
31 UINT8 end_chs[3];
32 UINT32 start_lba;
33 UINT32 size;
34 } MBR_PART_INFO;
35
36 // A 512-byte data structure into which the MBR can be loaded in one
37 // go. Also used when loading logical partitions.
38
39 typedef struct {
40 UINT8 code[440];
41 UINT32 diskSignature;
42 UINT16 nulls;
43 MBR_PART_INFO partitions[4];
44 UINT16 MBRSignature;
45 } MBR_RECORD;
46
47 typedef struct {
48 UINT64 signature;
49 UINT32 spec_revision;
50 UINT32 header_size;
51 UINT32 header_crc32;
52 UINT32 reserved;
53 UINT64 header_lba;
54 UINT64 alternate_header_lba;
55 UINT64 first_usable_lba;
56 UINT64 last_usable_lba;
57 UINT8 disk_guid[16];
58 UINT64 entry_lba;
59 UINT32 entry_count;
60 UINT32 entry_size;
61 UINT32 entry_crc32;
62 UINT8 reserved2[420];
63 } GPT_HEADER;
64
65 typedef struct {
66 UINT8 type_guid[16];
67 UINT8 partition_guid[16];
68 UINT64 start_lba;
69 UINT64 end_lba;
70 UINT64 attributes;
71 CHAR16 name[36];
72 } GPT_ENTRY;
73
74 typedef struct _gpt_data {
75 MBR_RECORD *ProtectiveMBR;
76 GPT_HEADER *Header;
77 GPT_ENTRY *Entries;
78 struct _gpt_data *NextEntry;
79 } GPT_DATA;
80
81 #pragma pack(0)
82
83 VOID ClearGptData(GPT_DATA *Data);
84 EFI_STATUS ReadGptData(REFIT_VOLUME *Volume, GPT_DATA **Data);
85 // CHAR16 * PartNameFromGuid(EFI_GUID *Guid);
86 GPT_ENTRY * FindPartWithGuid(EFI_GUID *Guid);
87 VOID ForgetPartitionTables(VOID);
88 VOID AddPartitionTable(REFIT_VOLUME *Volume);
89
90 #endif