Skip to content
Permalink
Browse files

Align and round the partitionable disk space to 4K by default.

Since this would also apply when recovering, make sure not to
align or round when that would have a partition fall outside
the partitionable area.
  • Loading branch information
marcel marcel
marcel authored and marcel committed Apr 12, 2014
1 parent 288923c commit eff424dd1339357d9cf9921b472de2138aa48d31
Showing with 29 additions and 6 deletions.
  1. +29 −6 sys/geom/part/g_part_gpt.c
@@ -1174,9 +1174,12 @@ g_part_gpt_write(struct g_part_table *basetable, struct g_consumer *cp)
static void
g_gpt_set_defaults(struct g_part_table *basetable, struct g_provider *pp)
{
struct g_part_entry *baseentry;
struct g_part_gpt_entry *entry;
struct g_part_gpt_table *table;
quad_t last;
size_t tblsz;
quad_t start, end, min, max;
quad_t lba, last;
size_t spb, tblsz;

table = (struct g_part_gpt_table *)basetable;
last = pp->mediasize / pp->sectorsize - 1;
@@ -1192,11 +1195,31 @@ g_gpt_set_defaults(struct g_part_table *basetable, struct g_provider *pp)
table->state[GPT_ELT_SECHDR] = GPT_STATE_OK;
table->state[GPT_ELT_SECTBL] = GPT_STATE_OK;

table->hdr->hdr_lba_start = 2 + tblsz;
table->hdr->hdr_lba_end = last - tblsz - 1;
max = start = 2 + tblsz;
min = end = last - tblsz - 1;
LIST_FOREACH(baseentry, &basetable->gpt_entry, gpe_entry) {
if (baseentry->gpe_deleted)
continue;
entry = (struct g_part_gpt_entry *)baseentry;
if (entry->ent.ent_lba_start < min)
min = entry->ent.ent_lba_start;
if (entry->ent.ent_lba_end > max)
max = entry->ent.ent_lba_end;
}
spb = 4096 / pp->sectorsize;
if (spb > 1) {
lba = start + ((start % spb) ? spb - start % spb : 0);
if (lba <= min)
start = lba;
lba = end - (end + 1) % spb;
if (max <= lba)
end = lba;
}
table->hdr->hdr_lba_start = start;
table->hdr->hdr_lba_end = end;

basetable->gpt_first = table->hdr->hdr_lba_start;
basetable->gpt_last = table->hdr->hdr_lba_end;
basetable->gpt_first = start;
basetable->gpt_last = end;
}

static void

0 comments on commit eff424d

Please sign in to comment.
You can’t perform that action at this time.