Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 1 Sep 2014 07:34:37 +0000 (UTC)
From:      "Andrey V. Elsukov" <ae@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r270918 - stable/9/sys/boot/common
Message-ID:  <201409010734.s817Ybxf063186@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ae
Date: Mon Sep  1 07:34:36 2014
New Revision: 270918
URL: http://svnweb.freebsd.org/changeset/base/270918

Log:
  MFC r270445:
    The size of the GPT table can not be less than one sector.
  
  MFC r270521:
    Since the size of GPT entry may differ from the sizeof(struct gpt_ent),
    use the size from GPT header to iterate entries.

Modified:
  stable/9/sys/boot/common/part.c
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/sys/boot/   (props changed)

Modified: stable/9/sys/boot/common/part.c
==============================================================================
--- stable/9/sys/boot/common/part.c	Mon Sep  1 07:34:16 2014	(r270917)
+++ stable/9/sys/boot/common/part.c	Mon Sep  1 07:34:36 2014	(r270918)
@@ -212,8 +212,8 @@ gpt_checktbl(const struct gpt_hdr *hdr, 
 			return (-1);
 		}
 	}
-	ent = (struct gpt_ent *)tbl;
-	for (i = 0; i < cnt; i++, ent++) {
+	for (i = 0; i < cnt; i++) {
+		ent = (struct gpt_ent *)(tbl + i * hdr->hdr_entsz);
 		uuid_letoh(&ent->ent_type);
 		if (uuid_equal(&ent->ent_type, &gpt_uuid_unused, NULL))
 			continue;
@@ -254,8 +254,8 @@ ptable_gptread(struct ptable *table, voi
 	    table->sectorsize);
 	if (phdr != NULL) {
 		/* Read the primary GPT table. */
-		size = MIN(MAXTBLSZ,
-		    phdr->hdr_entries * phdr->hdr_entsz / table->sectorsize);
+		size = MIN(MAXTBLSZ, (phdr->hdr_entries * phdr->hdr_entsz +
+		    table->sectorsize - 1) / table->sectorsize);
 		if (dread(dev, tbl, size, phdr->hdr_lba_table) == 0 &&
 		    gpt_checktbl(phdr, tbl, size * table->sectorsize,
 		    table->sectors - 1) == 0) {
@@ -287,8 +287,9 @@ ptable_gptread(struct ptable *table, voi
 		    hdr.hdr_entsz != phdr->hdr_entsz ||
 		    hdr.hdr_crc_table != phdr->hdr_crc_table) {
 			/* Read the backup GPT table. */
-			size = MIN(MAXTBLSZ, phdr->hdr_entries *
-			    phdr->hdr_entsz / table->sectorsize);
+			size = MIN(MAXTBLSZ, (phdr->hdr_entries *
+			    phdr->hdr_entsz + table->sectorsize - 1) /
+			    table->sectorsize);
 			if (dread(dev, tbl, size, phdr->hdr_lba_table) == 0 &&
 			    gpt_checktbl(phdr, tbl, size * table->sectorsize,
 			    table->sectors - 1) == 0) {
@@ -302,10 +303,10 @@ ptable_gptread(struct ptable *table, voi
 		table->type = PTABLE_NONE;
 		goto out;
 	}
-	ent = (struct gpt_ent *)tbl;
 	size = MIN(hdr.hdr_entries * hdr.hdr_entsz,
 	    MAXTBLSZ * table->sectorsize);
-	for (i = 0; i < size / hdr.hdr_entsz; i++, ent++) {
+	for (i = 0; i < size / hdr.hdr_entsz; i++) {
+		ent = (struct gpt_ent *)(tbl + i * hdr.hdr_entsz);
 		if (uuid_equal(&ent->ent_type, &gpt_uuid_unused, NULL))
 			continue;
 		entry = malloc(sizeof(*entry));



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