Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Sep 2014 16:05:24 +0000 (UTC)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r272030 - stable/10/usr.bin/mkimg
Message-ID:  <201409231605.s8NG5OwC066303@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marcel
Date: Tue Sep 23 16:05:23 2014
New Revision: 272030
URL: http://svnweb.freebsd.org/changeset/base/272030

Log:
  MFC 271881: Fix partition alignment and image rounding when any of
  -P (block size),  -T (track size) or -H (number of heads) is given.
  
  Approved by:	re@ (gjb)

Modified:
  stable/10/usr.bin/mkimg/apm.c
  stable/10/usr.bin/mkimg/bsd.c
  stable/10/usr.bin/mkimg/ebr.c
  stable/10/usr.bin/mkimg/gpt.c
  stable/10/usr.bin/mkimg/mbr.c
  stable/10/usr.bin/mkimg/mkimg.h
  stable/10/usr.bin/mkimg/pc98.c
  stable/10/usr.bin/mkimg/scheme.c
  stable/10/usr.bin/mkimg/scheme.h
  stable/10/usr.bin/mkimg/vtoc8.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.bin/mkimg/apm.c
==============================================================================
--- stable/10/usr.bin/mkimg/apm.c	Tue Sep 23 16:03:57 2014	(r272029)
+++ stable/10/usr.bin/mkimg/apm.c	Tue Sep 23 16:05:23 2014	(r272030)
@@ -57,13 +57,12 @@ static struct mkimg_alias apm_aliases[] 
     {	ALIAS_NONE, 0 }
 };
 
-static u_int
-apm_metadata(u_int where)
+static lba_t
+apm_metadata(u_int where, lba_t blk)
 {
-	u_int secs;
 
-	secs = (where == SCHEME_META_IMG_START) ? nparts + 2 : 0;
-	return (secs);
+	blk += (where == SCHEME_META_IMG_START) ? nparts + 2 : 0;
+	return (round_block(blk));
 }
 
 static int

Modified: stable/10/usr.bin/mkimg/bsd.c
==============================================================================
--- stable/10/usr.bin/mkimg/bsd.c	Tue Sep 23 16:03:57 2014	(r272029)
+++ stable/10/usr.bin/mkimg/bsd.c	Tue Sep 23 16:05:23 2014	(r272030)
@@ -52,13 +52,17 @@ static struct mkimg_alias bsd_aliases[] 
     {	ALIAS_NONE, 0 }
 };
 
-static u_int
-bsd_metadata(u_int where)
+static lba_t
+bsd_metadata(u_int where, lba_t blk)
 {
-	u_int secs;
 
-	secs = BBSIZE / secsz;
-	return ((where == SCHEME_META_IMG_START) ? secs : 0);
+	if (where == SCHEME_META_IMG_START)
+		blk += BBSIZE / secsz;
+	else if (where == SCHEME_META_IMG_END)
+		blk = round_cylinder(blk);
+	else
+		blk = round_block(blk);
+	return (blk);
 }
 
 static int
@@ -83,12 +87,6 @@ bsd_write(lba_t imgsz, void *bootcode)
 	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) {
-		free(buf);
-		return (error);
-	}
 
 	d = (void *)(buf + secsz);
 	le32enc(&d->d_magic, DISKMAGIC);

Modified: stable/10/usr.bin/mkimg/ebr.c
==============================================================================
--- stable/10/usr.bin/mkimg/ebr.c	Tue Sep 23 16:03:57 2014	(r272029)
+++ stable/10/usr.bin/mkimg/ebr.c	Tue Sep 23 16:05:23 2014	(r272030)
@@ -49,13 +49,12 @@ static struct mkimg_alias ebr_aliases[] 
     {	ALIAS_NONE, 0 }
 };
 
-static u_int
-ebr_metadata(u_int where)
+static lba_t
+ebr_metadata(u_int where, lba_t blk)
 {
-	u_int secs;
 
-	secs = (where == SCHEME_META_PART_BEFORE) ? nsecs : 0;
-	return (secs);
+	blk += (where == SCHEME_META_PART_BEFORE) ? 1 : 0;
+	return (round_track(blk));
 }
 
 static void

Modified: stable/10/usr.bin/mkimg/gpt.c
==============================================================================
--- stable/10/usr.bin/mkimg/gpt.c	Tue Sep 23 16:03:57 2014	(r272029)
+++ stable/10/usr.bin/mkimg/gpt.c	Tue Sep 23 16:05:23 2014	(r272030)
@@ -153,17 +153,15 @@ gpt_tblsz(void)
 	return ((nparts + ents - 1) / ents);
 }
 
-static u_int
-gpt_metadata(u_int where)
+static lba_t
+gpt_metadata(u_int where, lba_t blk)
 {
-	u_int secs;
 
-	if (where != SCHEME_META_IMG_START && where != SCHEME_META_IMG_END)
-		return (0);
-
-	secs = gpt_tblsz();
-	secs += (where == SCHEME_META_IMG_START) ? 2 : 1;
-	return (secs);
+	if (where == SCHEME_META_IMG_START || where == SCHEME_META_IMG_END) {
+		blk += gpt_tblsz();
+		blk += (where == SCHEME_META_IMG_START) ? 2 : 1;
+	}
+	return (round_block(blk));
 }
 
 static int

Modified: stable/10/usr.bin/mkimg/mbr.c
==============================================================================
--- stable/10/usr.bin/mkimg/mbr.c	Tue Sep 23 16:03:57 2014	(r272029)
+++ stable/10/usr.bin/mkimg/mbr.c	Tue Sep 23 16:05:23 2014	(r272030)
@@ -50,13 +50,12 @@ static struct mkimg_alias mbr_aliases[] 
     {	ALIAS_NONE, 0 }		/* Keep last! */
 };
 
-static u_int
-mbr_metadata(u_int where)
+static lba_t
+mbr_metadata(u_int where, lba_t blk)
 {
-	u_int secs;
 
-	secs = (where == SCHEME_META_IMG_START) ? nsecs : 0;
-	return (secs);
+	blk += (where == SCHEME_META_IMG_START) ? 1 : 0;
+	return (round_track(blk));
 }
 
 static void

Modified: stable/10/usr.bin/mkimg/mkimg.h
==============================================================================
--- stable/10/usr.bin/mkimg/mkimg.h	Tue Sep 23 16:03:57 2014	(r272029)
+++ stable/10/usr.bin/mkimg/mkimg.h	Tue Sep 23 16:05:23 2014	(r272030)
@@ -66,6 +66,21 @@ round_block(lba_t n)
 	return ((n + b - 1) & ~(b - 1));
 }
 
+static inline lba_t
+round_cylinder(lba_t n)
+{
+	u_int cyl = nsecs * nheads;
+	u_int r = n % cyl;
+	return ((r == 0) ? n : n + cyl - r);
+}
+
+static inline lba_t
+round_track(lba_t n)
+{
+	u_int r = n % nsecs;
+	return ((r == 0) ? n : n + nsecs - r);
+}
+
 #if !defined(SPARSE_WRITE)
 #define	sparse_write	write
 #else

Modified: stable/10/usr.bin/mkimg/pc98.c
==============================================================================
--- stable/10/usr.bin/mkimg/pc98.c	Tue Sep 23 16:03:57 2014	(r272029)
+++ stable/10/usr.bin/mkimg/pc98.c	Tue Sep 23 16:05:23 2014	(r272030)
@@ -59,13 +59,12 @@ static struct mkimg_alias pc98_aliases[]
     {	ALIAS_NONE, 0 }
 };
 
-static u_int
-pc98_metadata(u_int where)
+static lba_t
+pc98_metadata(u_int where, lba_t blk)
 {
-	u_int secs;
-
-	secs = PC98_BOOTCODESZ / secsz;
-	return ((where == SCHEME_META_IMG_START) ? secs : 0);
+	if (where == SCHEME_META_IMG_START)
+		blk += PC98_BOOTCODESZ / secsz;
+	return (round_track(blk));
 }
 
 static void

Modified: stable/10/usr.bin/mkimg/scheme.c
==============================================================================
--- stable/10/usr.bin/mkimg/scheme.c	Tue Sep 23 16:03:57 2014	(r272029)
+++ stable/10/usr.bin/mkimg/scheme.c	Tue Sep 23 16:05:23 2014	(r272030)
@@ -171,10 +171,8 @@ scheme_max_secsz(void)
 lba_t
 scheme_metadata(u_int where, lba_t start)
 {
-	lba_t secs;
 
-	secs = scheme->metadata(where);
-	return (round_block(start + secs));
+	return (scheme->metadata(where, start));
 }
 
 int

Modified: stable/10/usr.bin/mkimg/scheme.h
==============================================================================
--- stable/10/usr.bin/mkimg/scheme.h	Tue Sep 23 16:03:57 2014	(r272029)
+++ stable/10/usr.bin/mkimg/scheme.h	Tue Sep 23 16:05:23 2014	(r272030)
@@ -62,7 +62,7 @@ struct mkimg_scheme {
 	const char	*name;
 	const char	*description;
 	struct mkimg_alias *aliases;
-	u_int		(*metadata)(u_int);
+	lba_t		(*metadata)(u_int, lba_t);
 #define	SCHEME_META_IMG_START	1
 #define	SCHEME_META_IMG_END	2
 #define	SCHEME_META_PART_BEFORE	3

Modified: stable/10/usr.bin/mkimg/vtoc8.c
==============================================================================
--- stable/10/usr.bin/mkimg/vtoc8.c	Tue Sep 23 16:03:57 2014	(r272029)
+++ stable/10/usr.bin/mkimg/vtoc8.c	Tue Sep 23 16:05:23 2014	(r272030)
@@ -53,13 +53,12 @@ static struct mkimg_alias vtoc8_aliases[
     {	ALIAS_NONE, 0 }
 };
 
-static u_int
-vtoc8_metadata(u_int where)
+static lba_t
+vtoc8_metadata(u_int where, lba_t blk)
 {
-	u_int secs;
 
-	secs = (where == SCHEME_META_IMG_START) ? nsecs * nheads : 0;
-	return (secs);
+	blk += (where == SCHEME_META_IMG_START) ? 1 : 0;
+	return (round_cylinder(blk));
 }
 
 static int
@@ -87,10 +86,6 @@ vtoc8_write(lba_t imgsz, void *bootcode 
 	be16enc(&vtoc8.nsecs, nsecs);
 	be16enc(&vtoc8.magic, VTOC_MAGIC);
 
-	error = image_set_size(imgsz);
-	if (error)
-		return (error);
-
 	be32enc(&vtoc8.map[VTOC_RAW_PART].nblks, imgsz);
 	STAILQ_FOREACH(part, &partlist, link) {
 		n = part->index + ((part->index >= VTOC_RAW_PART) ? 1 : 0);



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