3 * Common header for gptsync and showpart
5 * Copyright (c) 2006 Christoph Pfisterer
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the
20 * * Neither the name of Christoph Pfisterer nor the names of the
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 /* Changes copyright (c) 2013 Roderick W. Smith */
38 #define VERSION L"0.9.1"
45 #if defined(EFI32) || defined(EFIX64) || defined(EFIAARCH64)
50 // platform-dependent types
55 #ifdef __MAKEWITH_GNUEFI
59 #include "../include/tiano_includes.h"
62 #define copy_guid(destguid, srcguid) (CopyMem(destguid, srcguid, 16))
63 #define guids_are_equal(guid1, guid2) (CompareMem(guid1, guid2, 16) == 0)
79 #include <sys/types.h>
86 typedef unsigned int UINTN;
87 typedef unsigned char UINT8;
88 typedef unsigned short UINT16;
89 typedef unsigned long UINT32;
90 typedef unsigned long long UINT64;
102 typedef unsigned short CHAR16
;
106 void Print(wchar_t *format
, ...);
108 // FUTURE: use STR(), #define Print printf
110 #define copy_guid(destguid, srcguid) (memcpy(destguid, srcguid, 16))
111 #define guids_are_equal(guid1, guid2) (memcmp(guid1, guid2, 16) == 0)
113 #define EFI_UNSUPPORTED 1
114 #define EFI_ABORTED 2
118 #define GPT_KIND_SYSTEM (0)
119 #define GPT_KIND_DATA (1)
120 #define GPT_KIND_BASIC_DATA (2)
121 #define GPT_KIND_FATAL (3)
123 #define MAX_MBR_LBA 0xFFFFFFFF
126 // platform-independent types
145 UINT32 spec_revision
;
150 UINT64 alternate_header_lba
;
151 UINT64 first_usable_lba
;
152 UINT64 last_usable_lba
;
162 UINT8 partition_guid
[16];
182 GPT_PARTTYPE
*gpt_parttype
;
187 // functions provided by the OS-specific module
190 UINT64
disk_size(VOID
);
191 UINTN
read_sector(UINT64 lba
, UINT8
*buffer
);
192 UINTN
write_sector(UINT64 lba
, UINT8
*buffer
);
193 UINTN
input_boolean(CHARN
*prompt
, BOOLEAN
*bool_out
);
196 // vars and functions provided by the common lib module
199 extern UINT8 empty_guid
[16];
201 extern PARTITION_INFO mbr_parts
[4];
202 extern UINTN mbr_part_count
;
203 extern PARTITION_INFO gpt_parts
[128];
204 extern UINTN gpt_part_count
;
206 extern PARTITION_INFO new_mbr_parts
[4];
207 extern UINTN new_mbr_part_count
;
209 extern UINT8 sector
[512];
211 extern MBR_PARTTYPE mbr_types
[];
212 extern GPT_PARTTYPE gpt_types
[];
213 extern GPT_PARTTYPE gpt_dummy_type
;
215 CHARN
* mbr_parttype_name(UINT8 type
);
216 UINTN
read_mbr(VOID
);
218 GPT_PARTTYPE
* gpt_parttype(UINT8
*type_guid
);
219 UINTN
read_gpt(VOID
);
221 UINTN
detect_mbrtype_fs(UINT64 partlba
, UINTN
*parttype
, CHARN
**fsname
);
224 // actual platform-independent programs
228 UINTN
showpart(VOID
);