Ejemplo n.º 1
0
static void
gptupdate(const char *which, struct dsk *dskp, struct gpt_hdr *hdr,
    struct gpt_ent *table)
{
	int entries_per_sec, firstent;
	daddr_t slba;

	/*
	 * We need to update the following for both primary and backup GPT:
	 * 1. Sector on disk that contains current partition.
	 * 2. Partition table checksum.
	 * 3. Header checksum.
	 * 4. Header on disk.
	 */

	entries_per_sec = DEV_BSIZE / hdr->hdr_entsz;
	slba = curent / entries_per_sec;
	firstent = slba * entries_per_sec;
	bcopy(&table[firstent], secbuf, DEV_BSIZE);
	slba += hdr->hdr_lba_table;
	if (drvwrite(dskp, secbuf, slba, 1)) {
		printf("%s: unable to update %s GPT partition table\n",
		    BOOTPROG, which);
		return;
	}
	hdr->hdr_crc_table = crc32(table, hdr->hdr_entries * hdr->hdr_entsz);
	hdr->hdr_crc_self = 0;
	hdr->hdr_crc_self = crc32(hdr, hdr->hdr_size);
	bzero(secbuf, DEV_BSIZE);
	bcopy(hdr, secbuf, hdr->hdr_size);
	if (drvwrite(dskp, secbuf, hdr->hdr_lba_self, 1)) {
		printf("%s: unable to update %s GPT header\n", BOOTPROG, which);
		return;
	}
}
Ejemplo n.º 2
0
static void
gptbootconv(const char *which, struct dsk *dskp, struct gpt_hdr *hdr,
    struct gpt_ent *table)
{
	struct gpt_ent *ent;
	daddr_t slba;
	int table_updated, sector_updated;
	int entries_per_sec, nent, part;

	table_updated = 0;
	entries_per_sec = DEV_BSIZE / hdr->hdr_entsz;
	for (nent = 0, slba = hdr->hdr_lba_table;
	    slba < hdr->hdr_lba_table + hdr->hdr_entries / entries_per_sec;
	    slba++, nent += entries_per_sec) {
		sector_updated = 0;
		for (part = 0; part < entries_per_sec; part++) {
			ent = &table[nent + part];
			if ((ent->ent_attr & (GPT_ENT_ATTR_BOOTME |
			    GPT_ENT_ATTR_BOOTONCE |
			    GPT_ENT_ATTR_BOOTFAILED)) !=
			    GPT_ENT_ATTR_BOOTONCE) {
				continue;
			}
			ent->ent_attr &= ~GPT_ENT_ATTR_BOOTONCE;
			ent->ent_attr |= GPT_ENT_ATTR_BOOTFAILED;
			table_updated = 1;
			sector_updated = 1;
		}
		if (!sector_updated)
			continue;
		bcopy(&table[nent], secbuf, DEV_BSIZE);
		if (drvwrite(dskp, secbuf, slba, 1)) {
			printf("%s: unable to update %s GPT partition table\n",
			    BOOTPROG, which);
		}
	}
	if (!table_updated)
		return;
	hdr->hdr_crc_table = crc32(0, Z_NULL, 0);
	hdr->hdr_crc_table = crc32(hdr->hdr_crc_table, table,
	    hdr->hdr_entries * hdr->hdr_entsz);
	hdr->hdr_crc_self = crc32(0, Z_NULL, 0);
	hdr->hdr_crc_self = crc32(hdr->hdr_crc_self, hdr, hdr->hdr_size);
	bzero(secbuf, DEV_BSIZE);
	bcopy(hdr, secbuf, hdr->hdr_size);
	if (drvwrite(dskp, secbuf, hdr->hdr_lba_self, 1))
		printf("%s: unable to update %s GPT header\n", BOOTPROG, which);
}