]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - GRUB2/MOD_SRC/grub-2.04/include/grub/partition.h
1.0.95 release
[Ventoy.git] / GRUB2 / MOD_SRC / grub-2.04 / include / grub / partition.h
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 1999,2000,2001,2002,2004,2006,2007 Free Software Foundation, Inc.
4 *
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * GRUB 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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifndef GRUB_PART_HEADER
20 #define GRUB_PART_HEADER 1
21
22 #include <grub/dl.h>
23 #include <grub/list.h>
24
25 struct grub_disk;
26
27 typedef struct grub_partition *grub_partition_t;
28
29 #ifdef GRUB_UTIL
30 typedef enum
31 {
32 GRUB_EMBED_PCBIOS
33 } grub_embed_type_t;
34 #endif
35
36 typedef int (*grub_partition_iterate_hook_t) (struct grub_disk *disk,
37 const grub_partition_t partition,
38 void *data);
39
40 /* Partition map type. */
41 struct grub_partition_map
42 {
43 /* The next partition map type. */
44 struct grub_partition_map *next;
45 struct grub_partition_map **prev;
46
47 /* The name of the partition map type. */
48 const char *name;
49
50 /* Call HOOK with each partition, until HOOK returns non-zero. */
51 grub_err_t (*iterate) (struct grub_disk *disk,
52 grub_partition_iterate_hook_t hook, void *hook_data);
53 #ifdef GRUB_UTIL
54 /* Determine sectors available for embedding. */
55 grub_err_t (*embed) (struct grub_disk *disk, unsigned int *nsectors,
56 unsigned int max_nsectors,
57 grub_embed_type_t embed_type,
58 grub_disk_addr_t **sectors);
59 #endif
60 };
61 typedef struct grub_partition_map *grub_partition_map_t;
62
63 /* Partition description. */
64 struct grub_partition
65 {
66 /* The partition number. */
67 int number;
68
69 /* The start sector (relative to parent). */
70 grub_disk_addr_t start;
71
72 /* The length in sector units. */
73 grub_uint64_t len;
74
75 /* The offset of the partition table. */
76 grub_disk_addr_t offset;
77
78 /* The index of this partition in the partition table. */
79 int index;
80
81 /* Parent partition (physically contains this partition). */
82 struct grub_partition *parent;
83
84 /* The type partition map. */
85 grub_partition_map_t partmap;
86
87 /* The type of partition whne it's on MSDOS.
88 Used for embedding detection. */
89 grub_uint8_t msdostype;
90
91 /* The attrib field for GPT. Needed for priority detection. */
92 grub_uint64_t gpt_attrib;
93 };
94
95 grub_partition_t EXPORT_FUNC(grub_partition_probe) (struct grub_disk *disk,
96 const char *str);
97 int EXPORT_FUNC(grub_partition_iterate) (struct grub_disk *disk,
98 grub_partition_iterate_hook_t hook,
99 void *hook_data);
100 char *EXPORT_FUNC(grub_partition_get_name) (const grub_partition_t partition);
101
102
103 extern grub_partition_map_t EXPORT_VAR(grub_partition_map_list);
104
105 #ifndef GRUB_LST_GENERATOR
106 static inline void
107 grub_partition_map_register (grub_partition_map_t partmap)
108 {
109 grub_list_push (GRUB_AS_LIST_P (&grub_partition_map_list),
110 GRUB_AS_LIST (partmap));
111 }
112 #endif
113
114 static inline void
115 grub_partition_map_unregister (grub_partition_map_t partmap)
116 {
117 grub_list_remove (GRUB_AS_LIST (partmap));
118 }
119
120 #define FOR_PARTITION_MAPS(var) FOR_LIST_ELEMENTS((var), (grub_partition_map_list))
121
122 \f
123 static inline grub_disk_addr_t
124 grub_partition_get_start (const grub_partition_t p)
125 {
126 grub_partition_t part;
127 grub_uint64_t part_start = 0;
128
129 for (part = p; part; part = part->parent)
130 part_start += part->start;
131
132 return part_start;
133 }
134
135 static inline grub_uint64_t
136 grub_partition_get_len (const grub_partition_t p)
137 {
138 return p->len;
139 }
140
141 #endif /* ! GRUB_PART_HEADER */