Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 12 Sep 2014 03:54:16 +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: r271448 - head/usr.bin/mkimg
Message-ID:  <201409120354.s8C3sG5S050611@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marcel
Date: Fri Sep 12 03:54:16 2014
New Revision: 271448
URL: http://svnweb.freebsd.org/changeset/base/271448

Log:
  Fix checksum calculation:
  1.  Iterate over all partitions counted in the label, which can be more
      than the number of partitions given to mkimg(1).
  2.  Start the checksum from the beginning of the label; not the beginning
      of the bootarea.
  
  Tested with bsdlabel(8).
  
  MFC after:	3 days

Modified:
  head/usr.bin/mkimg/bsd.c

Modified: head/usr.bin/mkimg/bsd.c
==============================================================================
--- head/usr.bin/mkimg/bsd.c	Fri Sep 12 02:38:10 2014	(r271447)
+++ head/usr.bin/mkimg/bsd.c	Fri Sep 12 03:54:16 2014	(r271448)
@@ -68,7 +68,7 @@ bsd_write(lba_t imgsz, void *bootcode)
 	struct disklabel *d;
 	struct partition *dp;
 	struct part *part;
-	int error, n;
+	int bsdparts, error, n;
 	uint16_t checksum;
 
 	buf = malloc(BBSIZE);
@@ -80,6 +80,9 @@ bsd_write(lba_t imgsz, void *bootcode)
 	} else
 		memset(buf, 0, BBSIZE);
 
+	bsdparts = nparts + 1;	/* Account for c partition */
+	if (bsdparts < MAXPARTITIONS)
+		bsdparts = MAXPARTITIONS;
 	imgsz = (lba_t)ncyls * nheads * nsecs;
 	error = image_set_size(imgsz);
 	if (error) {
@@ -97,7 +100,7 @@ bsd_write(lba_t imgsz, void *bootcode)
 	le32enc(&d->d_secperunit, imgsz);
 	le16enc(&d->d_rpm, 3600);
 	le32enc(&d->d_magic2, DISKMAGIC);
-	le16enc(&d->d_npartitions, (8 > nparts + 1) ? 8 : nparts + 1);
+	le16enc(&d->d_npartitions, bsdparts);
 	le32enc(&d->d_bbsize, BBSIZE);
 
 	dp = &d->d_partitions[RAW_PART];
@@ -110,9 +113,9 @@ bsd_write(lba_t imgsz, void *bootcode)
 		dp->p_fstype = ALIAS_TYPE2INT(part->type);
 	}
 
-	dp = &d->d_partitions[nparts + 1];
+	dp = &d->d_partitions[bsdparts];
 	checksum = 0;
-	for (p = buf; p < (u_char *)dp; p += 2)
+	for (p = (void *)d; p < (u_char *)dp; p += 2)
 		checksum ^= le16dec(p);
 	le16enc(&d->d_checksum, checksum);
 



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