summaryrefslogtreecommitdiff
path: root/Platform/ARM/Library/FwsGptSystemFipLib/DiskGpt.h
blob: d6f7752ab17864607e8b2c7fbfe86fedf7d2457b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/** @file

  Copyright (c) 2024, ARM Limited. All rights reserved.<BR>

  SPDX-License-Identifier: BSD-2-Clause-Patent

  @par Reference(s):
  - GUID Partition Table (GPT) Disk Layout
    (https://uefi.org/specs/UEFI/2.10/05_GUID_Partition_Table_Format.html)

**/

#ifndef DISK_GPT_H_
#define DISK_GPT_H_

#include <Uefi/UefiGpt.h>

#define GPT_PROTECTIVE_MBR_SIZE  512
#define GPT_PARTITION_LBA_SIZE   512

/**
  Compare function to find out specific Gpt Partition.

  @param [in]   PartitionEntry       GPT partition.
  @param [in]   Data                 User Data used to compare GPT partition.

  @retval       TRUE                 Found
  @retval       FALSE                No found
**/
typedef BOOLEAN (EFIAPI *MATCH_FUNC_T)(
  CONST EFI_PARTITION_ENTRY *PartitionEntry,
  CONST VOID *Data
  );

#pragma pack(1)

/** GPT partition table.
 */
typedef struct {
  /// GPT header.
  EFI_PARTITION_TABLE_HEADER    Header;

  /// Gpt Partition Entry.
  EFI_PARTITION_ENTRY           PartitionTable[];
} GPT_PARTITION_TABLE;

/**
 * GPT partition handle.
 */
typedef struct {
  /// Block device instance.
  EFI_BLOCK_IO_PROTOCOL    *Instance;

  /// Gpt Partition Table.
  GPT_PARTITION_TABLE      *GptTable;
} GPT_PARTITION_HANDLE;

#pragma pack()

/**
  Read "ReadSize" bytes from a partition at "ReadOffset" bytes from its start.

  @param[in]  GptHandle  GptHandle.
  @param[out] DestBuffer Pointer to the buffer that will store the data read.
  @param[in]  ReadSize   The number of bytes to read.
  @param[in]  ReadOffset The offset to read from within the partition.
  @param[in]  BaseLba    The start Lba of the partition.

  @retval EFI_SUCCESS  ReadSize bytes read successfully.
  @retval Error        No bytes read.

**/
EFI_STATUS
EFIAPI
GptReadPartition (
  IN     GPT_PARTITION_HANDLE  *GptHandle,
  OUT    VOID                  *DestBuffer,
  IN     UINTN                 ReadSize,
  IN     UINTN                 ReadOffset,
  IN     UINTN                 BaseLba
  );

/**
  Write "BufferSize" bytes to a partition at "WriteOffset" bytes from its start.

  @param[in]     GptHandle  GptHandle.
  @param[in]     SrcBuffer   Pointer to the buffer with the data to be written.
  @param[in]     BufferSize  The number of bytes to write.
  @param[in]     WriteOffset The offset to write to within the partition.
  @param[in]     BaseLba     The start Lba of the partition.

  @retval EFI_SUCCESS  BufferSize bytes written successfully.
  @retval Error        No bytes written.

**/
EFI_STATUS
GptWritePartition (
  IN  GPT_PARTITION_HANDLE  *GptHandle,
  IN  VOID                  *SrcBuffer,
  IN  UINTN                 BufferSize,
  IN  UINTN                 WriteOffset,
  IN  UINTN                 BaseLba
  );

/**
  Retrieve first matched GPT partition entry information.

  @param[in]  GptHandle   GptHandle.
  @param[in]  Match       Matching function to find out specific GPT partition.
  @param[in]  Data        Data used in @Match to find out specific GPT partition.
  @param[out] StartLBA    The StartLBA of matched partition.
  @param[out] PartSize    Size of matched partition in bytes.

  @retval EFI_SUCCESS  The GPT partition array was correctly retrieved.
  @retval Error        No information was correctly retrieved.

**/
EFI_STATUS
EFIAPI
GptGetMatchedPartitionStats (
  IN  GPT_PARTITION_HANDLE  *GptHandle,
  IN     MATCH_FUNC_T       Match,
  IN     VOID               *Data,
  OUT    EFI_LBA            *StartLBA,
  OUT    UINTN              *PartSize
  );

/**
  Release GptHandle.

  @param[in] GptHandle    Gpt Handle.

**/
VOID
EFIAPI
GptReleasePartition (
  IN    GPT_PARTITION_HANDLE  *GptHandle
  );

/**
  Open GptHandle.

  @param[in]  Instance    The block IO protocol instance containing a GPT.
  @param[out] GptHandle   Gpt Handle.

  @retval EFI_SUCCESS               Success.
  @retval EFI_INVALID_PARAMETER     Invalid Parameter.
  @retval EFI_ABORT                 Fail to read Gpt Table Header or
                                    Invalid Gpt Table.
  @retval EFI_OUT_OF_RESOURCES      Out of memory.

**/
EFI_STATUS
EFIAPI
GptOpenPartition (
  IN     EFI_BLOCK_IO_PROTOCOL  *Instance,
  OUT    GPT_PARTITION_HANDLE   **GptHandle
  );

#endif /* _DISK_GPT_H_ */