Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 12 Apr 2014 20:28:39 +0000 (UTC)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r264378 - head/sys/geom/part
Message-ID:  <201404122028.s3CKSdo1026394@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marcel
Date: Sat Apr 12 20:28:39 2014
New Revision: 264378
URL: http://svnweb.freebsd.org/changeset/base/264378

Log:
  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.

Modified:
  head/sys/geom/part/g_part_gpt.c

Modified: head/sys/geom/part/g_part_gpt.c
==============================================================================
--- head/sys/geom/part/g_part_gpt.c	Sat Apr 12 20:22:59 2014	(r264377)
+++ head/sys/geom/part/g_part_gpt.c	Sat Apr 12 20:28:39 2014	(r264378)
@@ -1174,9 +1174,12 @@ g_part_gpt_write(struct g_part_table *ba
 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 *
 	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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201404122028.s3CKSdo1026394>