Changeset View
Changeset View
Standalone View
Standalone View
sys/geom/part/g_part_gpt.c
Show First 20 Lines • Show All 546 Lines • ▼ Show 20 Lines | gpt_read_tbl(struct g_part_gpt_table *table, struct g_consumer *cp, | ||||
pp = cp->provider; | pp = cp->provider; | ||||
table->lba[elt] = hdr->hdr_lba_table; | table->lba[elt] = hdr->hdr_lba_table; | ||||
table->state[elt] = GPT_STATE_MISSING; | table->state[elt] = GPT_STATE_MISSING; | ||||
tblsz = hdr->hdr_entries * hdr->hdr_entsz; | tblsz = hdr->hdr_entries * hdr->hdr_entsz; | ||||
sectors = howmany(tblsz, pp->sectorsize); | sectors = howmany(tblsz, pp->sectorsize); | ||||
buf = g_malloc(sectors * pp->sectorsize, M_WAITOK | M_ZERO); | buf = g_malloc(sectors * pp->sectorsize, M_WAITOK | M_ZERO); | ||||
for (idx = 0; idx < sectors; idx += MAXPHYS / pp->sectorsize) { | for (idx = 0; idx < sectors; idx += maxphys / pp->sectorsize) { | ||||
size = (sectors - idx > MAXPHYS / pp->sectorsize) ? MAXPHYS: | size = (sectors - idx > maxphys / pp->sectorsize) ? maxphys: | ||||
(sectors - idx) * pp->sectorsize; | (sectors - idx) * pp->sectorsize; | ||||
p = g_read_data(cp, (table->lba[elt] + idx) * pp->sectorsize, | p = g_read_data(cp, (table->lba[elt] + idx) * pp->sectorsize, | ||||
size, &error); | size, &error); | ||||
if (p == NULL) { | if (p == NULL) { | ||||
g_free(buf); | g_free(buf); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
bcopy(p, buf + idx * pp->sectorsize, size); | bcopy(p, buf + idx * pp->sectorsize, size); | ||||
▲ Show 20 Lines • Show All 667 Lines • ▼ Show 20 Lines | g_part_gpt_write(struct g_part_table *basetable, struct g_consumer *cp) | ||||
/* Write primary meta-data. */ | /* Write primary meta-data. */ | ||||
le32enc(buf + 16, 0); /* hdr_crc_self. */ | le32enc(buf + 16, 0); /* hdr_crc_self. */ | ||||
le64enc(buf + 24, table->lba[GPT_ELT_PRIHDR]); /* hdr_lba_self. */ | le64enc(buf + 24, table->lba[GPT_ELT_PRIHDR]); /* hdr_lba_self. */ | ||||
le64enc(buf + 32, table->lba[GPT_ELT_SECHDR]); /* hdr_lba_alt. */ | le64enc(buf + 32, table->lba[GPT_ELT_SECHDR]); /* hdr_lba_alt. */ | ||||
le64enc(buf + 72, table->lba[GPT_ELT_PRITBL]); /* hdr_lba_table. */ | le64enc(buf + 72, table->lba[GPT_ELT_PRITBL]); /* hdr_lba_table. */ | ||||
crc = crc32(buf, table->hdr->hdr_size); | crc = crc32(buf, table->hdr->hdr_size); | ||||
le32enc(buf + 16, crc); | le32enc(buf + 16, crc); | ||||
for (index = 0; index < tblsz; index += MAXPHYS / pp->sectorsize) { | for (index = 0; index < tblsz; index += maxphys / pp->sectorsize) { | ||||
error = g_write_data(cp, | error = g_write_data(cp, | ||||
(table->lba[GPT_ELT_PRITBL] + index) * pp->sectorsize, | (table->lba[GPT_ELT_PRITBL] + index) * pp->sectorsize, | ||||
buf + (index + 1) * pp->sectorsize, | buf + (index + 1) * pp->sectorsize, | ||||
(tblsz - index > MAXPHYS / pp->sectorsize) ? MAXPHYS: | (tblsz - index > maxphys / pp->sectorsize) ? maxphys : | ||||
(tblsz - index) * pp->sectorsize); | (tblsz - index) * pp->sectorsize); | ||||
if (error) | if (error) | ||||
goto out; | goto out; | ||||
} | } | ||||
error = g_write_data(cp, table->lba[GPT_ELT_PRIHDR] * pp->sectorsize, | error = g_write_data(cp, table->lba[GPT_ELT_PRIHDR] * pp->sectorsize, | ||||
buf, pp->sectorsize); | buf, pp->sectorsize); | ||||
if (error) | if (error) | ||||
goto out; | goto out; | ||||
/* Write secondary meta-data. */ | /* Write secondary meta-data. */ | ||||
le32enc(buf + 16, 0); /* hdr_crc_self. */ | le32enc(buf + 16, 0); /* hdr_crc_self. */ | ||||
le64enc(buf + 24, table->lba[GPT_ELT_SECHDR]); /* hdr_lba_self. */ | le64enc(buf + 24, table->lba[GPT_ELT_SECHDR]); /* hdr_lba_self. */ | ||||
le64enc(buf + 32, table->lba[GPT_ELT_PRIHDR]); /* hdr_lba_alt. */ | le64enc(buf + 32, table->lba[GPT_ELT_PRIHDR]); /* hdr_lba_alt. */ | ||||
le64enc(buf + 72, table->lba[GPT_ELT_SECTBL]); /* hdr_lba_table. */ | le64enc(buf + 72, table->lba[GPT_ELT_SECTBL]); /* hdr_lba_table. */ | ||||
crc = crc32(buf, table->hdr->hdr_size); | crc = crc32(buf, table->hdr->hdr_size); | ||||
le32enc(buf + 16, crc); | le32enc(buf + 16, crc); | ||||
for (index = 0; index < tblsz; index += MAXPHYS / pp->sectorsize) { | for (index = 0; index < tblsz; index += maxphys / pp->sectorsize) { | ||||
error = g_write_data(cp, | error = g_write_data(cp, | ||||
(table->lba[GPT_ELT_SECTBL] + index) * pp->sectorsize, | (table->lba[GPT_ELT_SECTBL] + index) * pp->sectorsize, | ||||
buf + (index + 1) * pp->sectorsize, | buf + (index + 1) * pp->sectorsize, | ||||
(tblsz - index > MAXPHYS / pp->sectorsize) ? MAXPHYS: | (tblsz - index > maxphys / pp->sectorsize) ? maxphys : | ||||
(tblsz - index) * pp->sectorsize); | (tblsz - index) * pp->sectorsize); | ||||
if (error) | if (error) | ||||
goto out; | goto out; | ||||
} | } | ||||
error = g_write_data(cp, table->lba[GPT_ELT_SECHDR] * pp->sectorsize, | error = g_write_data(cp, table->lba[GPT_ELT_SECHDR] * pp->sectorsize, | ||||
buf, pp->sectorsize); | buf, pp->sectorsize); | ||||
out: | out: | ||||
▲ Show 20 Lines • Show All 167 Lines • Show Last 20 Lines |