source: mainline/uspace/lib/gpt/libgpt.h@ 44c4886

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 44c4886 was 44c4886, checked in by Dominik Taborsky (AT DOT) <brembyseznamcz>, 13 years ago

GPT API changes

  • Property mode set to 100644
File size: 5.3 KB
Line 
1/*
2 * Copyright (c) 2009 Jiri Svoboda
3 * Copyright (c) 2011, 2012, 2013 Dominik Taborsky
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup libgpt
31 * @{
32 */
33/** @file
34 */
35
36#ifndef __GPT_H__
37#define __GPT_H__
38
39#define LIBGPT_NAME "libgpt"
40
41#include <loc.h>
42#include <sys/types.h>
43
44/** Block address of GPT header. */
45#define GPT_HDR_BA 1
46/** Block size of GPT header. */
47#define GPT_HDR_BS 1
48/** Minimum number of GPT partition entries */
49#define GPT_MIN_PART_NUM 128
50/** Basic number of GPT partition entries */
51#define GPT_BASE_PART_NUM (GPT_MIN_PART_NUM)
52/** How much fill we ignore before resizing partition array */
53#define GPT_IGNORE_FILL_NUM 10
54
55/** GPT header signature ("EFI PART" in ASCII) */
56extern const uint8_t efi_signature[8];
57
58typedef enum {
59 AT_REQ_PART = 0,
60 AT_NO_BLOCK_IO,
61 AT_LEGACY_BOOT,
62 AT_UNDEFINED,
63 AT_SPECIFIC = 48
64} GPT_ATTR;
65
66/** GPT header
67 * - all in little endian.
68 */
69typedef struct {
70 uint8_t efi_signature[8];
71 uint32_t revision;
72 uint32_t header_size;
73 uint32_t header_crc32;
74 uint32_t reserved;
75 uint64_t my_lba;
76 uint64_t alternate_lba;
77 uint64_t first_usable_lba;
78 uint64_t last_usable_lba;
79 uint8_t disk_guid[16];
80 uint64_t entry_lba;
81 uint32_t fillries;
82 uint32_t entry_size;
83 uint32_t pe_array_crc32;
84} __attribute__((packed)) gpt_header_t;
85
86typedef struct {
87 /** Raw header. Has more bytes alloced than sizeof(gpt_header_t)!
88 * See gpt_alloc_header() to know why. */
89 gpt_header_t *header;
90} gpt_t;
91
92/** GPT partition entry */
93typedef struct {
94 uint8_t part_type[16];
95 uint8_t part_id[16];
96 uint64_t start_lba;
97 uint64_t end_lba;
98 uint64_t attributes;
99 uint8_t part_name[72];
100} __attribute__((packed)) gpt_entry_t;
101
102
103//typedef struct g_part {
104 ///** Partition entry is in use **/
105 //bool present;
106 ///** Address of first block */
107 //aoff64_t start_addr;
108 ///** Number of blocks */
109 //aoff64_t length;
110 ///** Raw data access */
111 //gpt_entry_t raw_data; //TODO: a pointer or just a member?
112//}gpt_part_t;
113typedef gpt_entry_t gpt_part_t;
114
115
116typedef struct gpt_parts {
117 /** Number of entries */
118 size_t fill;
119 /** Size of the array */
120 size_t arr_size;
121 /** Resizable partition array */
122 gpt_entry_t *part_array;
123} gpt_partitions_t;
124
125
126typedef struct gpt_table {
127 gpt_t *gpt;
128 gpt_partitions_t *parts;
129 service_id_t device;
130} gpt_label_t;
131
132struct partition_type {
133 const char *desc;
134 const char *guid;
135};
136
137extern const struct partition_type gpt_ptypes[];
138
139extern gpt_label_t * gpt_alloc_label(void);
140extern void gpt_free_label(gpt_label_t *);
141
142extern gpt_t * gpt_alloc_header(size_t);
143extern int gpt_read_header(gpt_label_t *, service_id_t);
144extern int gpt_write_header(gpt_label_t *, service_id_t);
145
146extern gpt_partitions_t * gpt_alloc_partitions(void);
147extern int gpt_read_partitions (gpt_label_t *);
148extern int gpt_write_partitions(gpt_label_t *, service_id_t);
149extern gpt_part_t * gpt_alloc_partition (void);
150extern gpt_part_t * gpt_get_partition (gpt_label_t *);
151extern int gpt_add_partition (gpt_label_t *, gpt_part_t *);
152extern int gpt_remove_partition(gpt_label_t *, size_t);
153
154extern size_t gpt_get_part_type(gpt_part_t *);
155extern void gpt_set_part_type(gpt_part_t *, size_t);
156extern void gpt_set_start_lba(gpt_part_t *, uint64_t);
157extern uint64_t gpt_get_start_lba(gpt_part_t *);
158extern void gpt_set_end_lba (gpt_part_t *, uint64_t);
159extern uint64_t gpt_get_end_lba (gpt_part_t *);
160extern unsigned char * gpt_get_part_name(gpt_part_t *);
161extern void gpt_set_part_name(gpt_part_t *, char *[], size_t);
162extern bool gpt_get_flag (gpt_part_t *, GPT_ATTR);
163extern void gpt_set_flag (gpt_part_t *, GPT_ATTR, bool);
164
165
166
167#define gpt_part_foreach(parts, iterator) \
168 for(gpt_part_t * iterator = (parts)->part_array; \
169 iterator < (parts)->part_array + (parts)->fill; ++iterator)
170
171extern void gpt_free_gpt(gpt_t *);
172extern void gpt_free_partitions(gpt_partitions_t *);
173
174#endif
175
Note: See TracBrowser for help on using the repository browser.