From owner-svn-src-user@FreeBSD.ORG Thu Mar 27 22:48:48 2014 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E54C9DAD; Thu, 27 Mar 2014 22:48:48 +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 B94AA14B; Thu, 27 Mar 2014 22:48:48 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s2RMmm5e021946; Thu, 27 Mar 2014 22:48:48 GMT (envelope-from marcel@svn.freebsd.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s2RMmmW2021945; Thu, 27 Mar 2014 22:48:48 GMT (envelope-from marcel@svn.freebsd.org) Message-Id: <201403272248.s2RMmmW2021945@svn.freebsd.org> From: Marcel Moolenaar Date: Thu, 27 Mar 2014 22:48:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r263845 - user/marcel/mkimg X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Mar 2014 22:48:49 -0000 Author: marcel Date: Thu Mar 27 22:48:48 2014 New Revision: 263845 URL: http://svnweb.freebsd.org/changeset/base/263845 Log: Give vtoc8 a change to work: when setting the physical block size to 4K, sectors/track to 8 and number or heads to 1, partitions that are block aligned are also cyclinder aligned. With that trick, fix the vtoc8: 1. Set physcyls, ncyls, altcyls, nheads and nsecs appropriately. 2. Truncate the image size to exactly ncyls * nheads * nsecs * secsz. 3. Properly write the cylinder number as the start of the partition. 4. Oh, and actually calculate the checksum of the label... Modified: user/marcel/mkimg/vtoc8.c Modified: user/marcel/mkimg/vtoc8.c ============================================================================== --- user/marcel/mkimg/vtoc8.c Thu Mar 27 22:45:05 2014 (r263844) +++ user/marcel/mkimg/vtoc8.c Thu Mar 27 22:48:48 2014 (r263845) @@ -62,7 +62,9 @@ vtoc8_write(int fd, lba_t imgsz, void *b { struct vtoc8 vtoc8; struct part *part; + u_char *p; int error; + uint16_t ofs, sum; memset(&vtoc8, 0, sizeof(vtoc8)); sprintf(vtoc8.ascii, "FreeBSD%lldM", (long long)(imgsz / 2048)); @@ -70,21 +72,31 @@ vtoc8_write(int fd, lba_t imgsz, void *b be16enc(&vtoc8.nparts, VTOC8_NPARTS); be32enc(&vtoc8.sanity, VTOC_SANITY); be16enc(&vtoc8.rpm, 3600); - be16enc(&vtoc8.physcyls, 2); /* XXX */ - be16enc(&vtoc8.ncyls, 0); /* XXX */ - be16enc(&vtoc8.altcyls, 2); - be16enc(&vtoc8.nheads, 1); /* XXX */ - be16enc(&vtoc8.nsecs, 1); /* XXX */ + be16enc(&vtoc8.physcyls, ncyls); + be16enc(&vtoc8.ncyls, ncyls); + be16enc(&vtoc8.altcyls, 0); + be16enc(&vtoc8.nheads, nheads); + be16enc(&vtoc8.nsecs, nsecs); be16enc(&vtoc8.magic, VTOC_MAGIC); + ftruncate(fd, ncyls * nheads * nsecs *secsz); + STAILQ_FOREACH(part, &partlist, link) { be16enc(&vtoc8.part[part->index].tag, ALIAS_TYPE2INT(part->type)); be32enc(&vtoc8.map[part->index].cyl, - part->block); /* XXX */ + part->block / (nsecs * nheads)); be32enc(&vtoc8.map[part->index].nblks, part->size); } + + /* Calculate checksum. */ + sum = 0; + p = (void *)&vtoc8; + for (ofs = 0; ofs < sizeof(vtoc8) - 2; ofs += 2) + sum ^= be16dec(p + ofs); + be16enc(&vtoc8.cksum, sum); + error = mkimg_seek(fd, 0); if (error == 0) { if (write(fd, &vtoc8, sizeof(vtoc8)) != sizeof(vtoc8))