Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 29 Mar 2014 03:14:00 +0000 (UTC)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r263893 - user/marcel/mkimg
Message-ID:  <201403290314.s2T3E08D034265@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marcel
Date: Sat Mar 29 03:14:00 2014
New Revision: 263893
URL: http://svnweb.freebsd.org/changeset/base/263893

Log:
  Handle the raw partition of the BSD and VTOC schemes.

Modified:
  user/marcel/mkimg/bsd.c
  user/marcel/mkimg/vtoc8.c

Modified: user/marcel/mkimg/bsd.c
==============================================================================
--- user/marcel/mkimg/bsd.c	Sat Mar 29 00:48:50 2014	(r263892)
+++ user/marcel/mkimg/bsd.c	Sat Mar 29 03:14:00 2014	(r263893)
@@ -63,7 +63,7 @@ bsd_write(int fd, lba_t imgsz, void *boo
 	struct disklabel *d;
 	struct partition *dp;
 	struct part *part;
-	int error;
+	int error, n;
 	uint16_t checksum;
 
 	buf = malloc(BBSIZE);
@@ -88,17 +88,20 @@ bsd_write(int fd, lba_t imgsz, void *boo
 	le32enc(&d->d_secperunit, imgsz);
 	le16enc(&d->d_rpm, 3600);
 	le32enc(&d->d_magic2, DISKMAGIC);
-	le16enc(&d->d_npartitions, (8 > nparts) ? 8 : nparts);
+	le16enc(&d->d_npartitions, (8 > nparts + 1) ? 8 : nparts + 1);
 	le32enc(&d->d_bbsize, BBSIZE);
 
+	dp = &d->d_partitions[RAW_PART];
+	le32enc(&dp->p_size, imgsz);
 	STAILQ_FOREACH(part, &partlist, link) {
-		dp = &d->d_partitions[part->index];
+		n = part->index + ((part->index >= RAW_PART) ? 1 : 0);
+		dp = &d->d_partitions[n];
 		le32enc(&dp->p_size, part->size);
 		le32enc(&dp->p_offset, part->block);
 		dp->p_fstype = ALIAS_TYPE2INT(part->type);
 	}
 
-	dp = &d->d_partitions[nparts];
+	dp = &d->d_partitions[nparts + 1];
 	checksum = 0;
 	for (p = buf; p < (u_char *)dp; p += 2)
 		checksum ^= le16dec(p);
@@ -119,7 +122,7 @@ static struct mkimg_scheme bsd_scheme = 
 	.aliases = bsd_aliases,
 	.metadata = bsd_metadata,
 	.write = bsd_write,
-	.nparts = 20,
+	.nparts = 19,
 	.bootcode = BBSIZE,
 	.maxsecsz = 512
 };

Modified: user/marcel/mkimg/vtoc8.c
==============================================================================
--- user/marcel/mkimg/vtoc8.c	Sat Mar 29 00:48:50 2014	(r263892)
+++ user/marcel/mkimg/vtoc8.c	Sat Mar 29 03:14:00 2014	(r263893)
@@ -63,11 +63,14 @@ vtoc8_write(int fd, lba_t imgsz, void *b
 	struct vtoc8 vtoc8;
 	struct part *part;
 	u_char *p;
-	int error;
+	int error, n;
 	uint16_t ofs, sum;
 
+	imgsz = ncyls * nheads * nsecs;
+
 	memset(&vtoc8, 0, sizeof(vtoc8));
-	sprintf(vtoc8.ascii, "FreeBSD%lldM", (long long)(imgsz / 2048));
+	sprintf(vtoc8.ascii, "FreeBSD%lldM",
+	    (long long)(imgsz * secsz / 1048576));
 	be32enc(&vtoc8.version, VTOC_VERSION);
 	be16enc(&vtoc8.nparts, VTOC8_NPARTS);
 	be32enc(&vtoc8.sanity, VTOC_SANITY);
@@ -79,15 +82,14 @@ vtoc8_write(int fd, lba_t imgsz, void *b
 	be16enc(&vtoc8.nsecs, nsecs);
 	be16enc(&vtoc8.magic, VTOC_MAGIC);
 
-	ftruncate(fd, ncyls * nheads * nsecs *secsz);
+	ftruncate(fd, imgsz * secsz);
 
+	be32enc(&vtoc8.map[VTOC_RAW_PART].nblks, imgsz);
 	STAILQ_FOREACH(part, &partlist, link) {
-		be16enc(&vtoc8.part[part->index].tag,
-		    ALIAS_TYPE2INT(part->type));
-		be32enc(&vtoc8.map[part->index].cyl,
-		    part->block / (nsecs * nheads));
-		be32enc(&vtoc8.map[part->index].nblks,
-		    part->size);
+		n = part->index + ((part->index >= VTOC_RAW_PART) ? 1 : 0);
+		be16enc(&vtoc8.part[n].tag, ALIAS_TYPE2INT(part->type));
+		be32enc(&vtoc8.map[n].cyl, part->block / (nsecs * nheads));
+		be32enc(&vtoc8.map[n].nblks, part->size);
 	}
 
 	/* Calculate checksum. */
@@ -111,7 +113,7 @@ static struct mkimg_scheme vtoc8_scheme 
 	.aliases = vtoc8_aliases,
 	.metadata = vtoc8_metadata,
 	.write = vtoc8_write,
-	.nparts = VTOC8_NPARTS,
+	.nparts = VTOC8_NPARTS - 1,
 	.maxsecsz = 512
 };
 



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