49 #define MAXTBLENTS 128
52 #define BOOTPROG "Unknown"
55 static struct gpt_hdr hdr_primary, hdr_backup, *gpthdr;
56 static u_int64_t hdr_primary_lba, hdr_backup_lba;
58 static struct gpt_ent *gpttable;
59 static int curent, bootonce;
68 int entries_per_sec, firstent;
80 slba = curent / entries_per_sec;
81 firstent = slba * entries_per_sec;
84 if ( devInfo->
write( devInfo->
info, secbuf, slba, 1 ) ) {
85 kprintf(
"%s: unable to update %s GPT partition table\n",
BOOTPROG, which );
109 ent = &gpttable[
part - 1];
118 firsttry = (curent == -1);
130 ent = &gpttable[curent];
144 ent = &gpttable[curent];
159 for ( curent = 0; curent < gpthdr->
hdr_entries; curent++ ) {
160 ent = &gpttable[curent];
168 found: drvInfo->
part = curent + 1;
169 ent = &gpttable[curent];
178 if ( hdr_primary_lba > 0 ) {
180 gptupdate(
"primary", devInfo, &hdr_primary, table_primary );
182 if ( hdr_backup_lba > 0 ) {
184 gptupdate(
"backup", devInfo, &hdr_backup, table_backup );
193 if ( devInfo->
read( devInfo->
info, secbuf, hdrlba, 1 ) ) {
198 bcopy( secbuf, hdr,
sizeof(*hdr) );
221 if ( hdr_primary_lba > 0 ) {
224 gptupdate(
"primary", devInfo, &hdr_primary, table_primary );
226 if ( hdr_backup_lba > 0 ) {
229 gptupdate(
"backup", devInfo, &hdr_backup, table_backup );
236 int table_updated, sector_updated;
237 int entries_per_sec, nent, part;
241 for ( nent = 0, slba = hdr->
hdr_lba_table; slba < hdr->hdr_lba_table + hdr->
hdr_entries / entries_per_sec; slba++, nent += entries_per_sec ) {
243 for ( part = 0; part < entries_per_sec; part++ ) {
244 ent = &table[nent + part];
253 if ( !sector_updated )
256 if ( devInfo->
write( devInfo->
info, secbuf, slba, 1 ) ) {
257 kprintf(
"%s: unable to update %s GPT partition table\n",
BOOTPROG, which );
260 if ( !table_updated )
284 if ( devInfo->
read(devInfo->
info, secbuf, slba, 1 ) ) {
285 kprintf(
"%s: unable to read %s GPT partition table\n",
BOOTPROG, which );
288 ent = (
struct gpt_ent *) secbuf;
289 for ( part = 0; part < entries_per_sec; part++, ent++ ) {
290 bcopy( ent, &table[nent],
sizeof(table[nent]) );
313 hdr_primary_lba = hdr_backup_lba = 0;
321 if ( gptread_hdr(
"primary", devInfo, &hdr_primary, 1 ) == 0 && gptread_table(
"primary",
uuid, devInfo, &hdr_primary, table_primary ) == 0 ) {
322 hdr_primary_lba = hdr_primary.hdr_lba_self;
323 gpthdr = &hdr_primary;
324 gpttable = table_primary;
327 if ( hdr_primary_lba > 0 ) {
332 altlba = hdr_primary.hdr_lba_alt;
343 else if ( gptread_hdr(
"backup", devInfo, &hdr_backup, altlba ) == 0 && gptread_table(
"backup",
uuid, devInfo, &hdr_backup, table_backup ) == 0 ) {
344 hdr_backup_lba = hdr_backup.hdr_lba_self;
345 if ( hdr_primary_lba == 0 ) {
346 gpthdr = &hdr_backup;
347 gpttable = table_backup;
361 if ( hdr_primary_lba != 0 )
362 gptbootconv(
"primary", devInfo, &hdr_primary, table_primary );
363 if ( hdr_backup_lba != 0 )
364 gptbootconv(
"backup", devInfo, &hdr_backup, table_backup );
366 if ( hdr_primary_lba == 0 && hdr_backup_lba == 0 )