2
* Copyright (C) 2014 Sourcefire, Inc.
4
* Authors: Kevin Lin <klin@sourcefire.com>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 2 as
8
* published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25
#include "clamav-config.h"
31
/* GPT sector size is normally 512 bytes be can be set to much larger
32
* values. Sector size for GPT can be found by the offset the GPT header
33
* signature is located (marking the beginning of the second sector.
35
#define GPT_SIGNATURE 0x4546492050415254ULL
36
#define GPT_SIGNATURE_STR "EFI PART"
37
#define GPT_PRIMARY_HDR_LBA 1
38
#define GPT_HDR_RESERVED 0
40
#ifndef HAVE_ATTRIB_PACKED
41
#define __attribute__(x)
44
#ifdef HAVE_PRAGMA_PACK
48
#ifdef HAVE_PRAGMA_PACK_HPPA
52
/* 92-byte gpt_header, these are little endian */
54
uint64_t signature __attribute__ ((packed));
55
uint32_t revision __attribute__ ((packed));
56
uint32_t headerSize __attribute__ ((packed)); /* should be 92 bytes */
57
uint32_t headerCRC32 __attribute__ ((packed));
58
uint32_t reserved __attribute__ ((packed)); /* this MUST be zero */
60
/* LBA values should be 1 and the last sector index */
61
uint64_t currentLBA __attribute__ ((packed));
62
uint64_t backupLBA __attribute__ ((packed));
64
/* data not including the gpt_header and partition table */
65
uint64_t firstUsableLBA __attribute__ ((packed));
66
uint64_t lastUsableLBA __attribute__ ((packed));
70
/* partition table information */
71
uint64_t tableStartLBA __attribute__ ((packed));
72
uint32_t tableNumEntries __attribute__ ((packed));
73
uint32_t tableEntrySize __attribute__ ((packed));
74
uint32_t tableCRC32 __attribute__ ((packed));
75
/* zeroes fill remainder of sector (420 bytes in 512 sector size) */
78
/* 128-byte partition entry, part of an array of 128+ entries, in little_endian */
79
struct gpt_partition_entry {
81
uint8_t uniqueGUID[16];
82
uint64_t firstLBA __attribute__ ((packed));
83
uint64_t lastLBA __attribute__ ((packed));
84
uint64_t attributes __attribute__ ((packed));
85
uint16_t name[36] __attribute__ ((packed));
88
#ifdef HAVE_PRAGMA_PACK
92
#ifdef HAVE_PRAGMA_PACK_HPPA
96
size_t gpt_detect_size(fmap_t *map);
97
int cli_scangpt(cli_ctx *ctx, size_t sectorsize);