From owner-svn-src-all@FreeBSD.ORG Sat Aug 9 04:47:13 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1699DF10 for ; Sat, 9 Aug 2014 04:47:13 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id DF1972A80 for ; Sat, 9 Aug 2014 04:47:12 +0000 (UTC) Received: from marcel (uid 782) (envelope-from marcel@FreeBSD.org) id 2ec7 by svn.freebsd.org (DragonFly Mail Agent v0.9+); Sat, 09 Aug 2014 04:47:12 +0000 From: Marcel Moolenaar Date: Sat, 9 Aug 2014 04:47:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r269745 - head/usr.bin/mkimg X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Message-Id: <53e5a7d0.2ec7.26d23fe2@svn.freebsd.org> X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 09 Aug 2014 04:47:13 -0000 Author: marcel Date: Sat Aug 9 04:47:12 2014 New Revision: 269745 URL: http://svnweb.freebsd.org/changeset/base/269745 Log: Create a redundant grain directory and table. Previously we were cheating by assigning the same sector offset to both directories, but it seems that VirtualBox doesn't like that. Neither does qemu from the looks of it. We now actually write the directory and table twice. MFC after: 3 days Modified: head/usr.bin/mkimg/vmdk.c Modified: head/usr.bin/mkimg/vmdk.c ============================================================================== --- head/usr.bin/mkimg/vmdk.c Fri Aug 8 23:55:22 2014 (r269744) +++ head/usr.bin/mkimg/vmdk.c Sat Aug 9 04:47:12 2014 (r269745) @@ -110,7 +110,7 @@ static int vmdk_write(int fd) { struct vmdk_header hdr; - uint32_t *gt, *gd; + uint32_t *gt, *gd, *rgd; char *buf, *desc; off_t cur, lim; uint64_t imagesz; @@ -143,25 +143,37 @@ vmdk_write(int fd) le32enc(&hdr.ngtes, VMDK_NGTES); sec = desc_len / VMDK_SECTOR_SIZE + 1; - le64enc(&hdr.rgd_offset, sec); - le64enc(&hdr.gd_offset, sec); ngrains = imagesz / grainsz; ngts = (ngrains + VMDK_NGTES - 1) / VMDK_NGTES; gdsz = (ngts * sizeof(uint32_t) + VMDK_SECTOR_SIZE - 1) & ~(VMDK_SECTOR_SIZE - 1); + gd = calloc(gdsz, 1); if (gd == NULL) { free(desc); return (ENOMEM); } - + le64enc(&hdr.gd_offset, sec); sec += gdsz / VMDK_SECTOR_SIZE; for (n = 0; n < ngts; n++) { le32enc(gd + n, sec); sec += VMDK_NGTES * sizeof(uint32_t) / VMDK_SECTOR_SIZE; } + rgd = calloc(gdsz, 1); + if (rgd == NULL) { + free(gd); + free(desc); + return (ENOMEM); + } + le64enc(&hdr.rgd_offset, sec); + sec += gdsz / VMDK_SECTOR_SIZE; + for (n = 0; n < ngts; n++) { + le32enc(rgd + n, sec); + sec += VMDK_NGTES * sizeof(uint32_t) / VMDK_SECTOR_SIZE; + } + sec = (sec + grainsz - 1) & ~(grainsz - 1); if (verbose) @@ -174,6 +186,7 @@ vmdk_write(int fd) gtsz = ngts * VMDK_NGTES * sizeof(uint32_t); gt = calloc(gtsz, 1); if (gt == NULL) { + free(rgd); free(gd); free(desc); return (ENOMEM); @@ -198,13 +211,18 @@ vmdk_write(int fd) error = errno; if (!error && sparse_write(fd, gt, gtsz) < 0) error = errno; + if (!error && sparse_write(fd, rgd, gdsz) < 0) + error = errno; + if (!error && sparse_write(fd, gt, gtsz) < 0) + error = errno; free(gt); + free(rgd); free(gd); free(desc); if (error) return (error); - cur = VMDK_SECTOR_SIZE + desc_len + gdsz + gtsz; + cur = VMDK_SECTOR_SIZE + desc_len + (gdsz + gtsz) * 2; lim = sec * VMDK_SECTOR_SIZE; if (cur < lim) { buf = calloc(VMDK_SECTOR_SIZE, 1);