From owner-svn-src-all@FreeBSD.ORG Sat Apr 12 20:28:40 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 237ACB6D; Sat, 12 Apr 2014 20:28:40 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id EA74D1B32; Sat, 12 Apr 2014 20:28:39 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s3CKSdbp026395; Sat, 12 Apr 2014 20:28:39 GMT (envelope-from marcel@svn.freebsd.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s3CKSdo1026394; Sat, 12 Apr 2014 20:28:39 GMT (envelope-from marcel@svn.freebsd.org) Message-Id: <201404122028.s3CKSdo1026394@svn.freebsd.org> From: Marcel Moolenaar Date: Sat, 12 Apr 2014 20:28:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r264378 - head/sys/geom/part X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Apr 2014 20:28:40 -0000 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