From owner-svn-src-user@FreeBSD.ORG Wed Oct 1 16:09:12 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.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 69A3EB3; Wed, 1 Oct 2014 16:09:12 +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 568EFDEE; Wed, 1 Oct 2014 16:09:12 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s91G9CW9066527; Wed, 1 Oct 2014 16:09:12 GMT (envelope-from marcel@FreeBSD.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s91G9CkA066526; Wed, 1 Oct 2014 16:09:12 GMT (envelope-from marcel@FreeBSD.org) Message-Id: <201410011609.s91G9CkA066526@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: marcel set sender to marcel@FreeBSD.org using -f From: Marcel Moolenaar Date: Wed, 1 Oct 2014 16:09:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r272370 - 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.18-1 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: Wed, 01 Oct 2014 16:09:12 -0000 Author: marcel Date: Wed Oct 1 16:09:11 2014 New Revision: 272370 URL: https://svnweb.freebsd.org/changeset/base/272370 Log: Fix sloppy code (that was commented as such): Map the file with partition data using smaller pieces at at time. It's rather hard to map a 10G partition in memory on a 32-bit machine... Modified: user/marcel/mkimg/image.c Modified: user/marcel/mkimg/image.c ============================================================================== --- user/marcel/mkimg/image.c Wed Oct 1 16:08:19 2014 (r272369) +++ user/marcel/mkimg/image.c Wed Oct 1 16:09:11 2014 (r272370) @@ -377,7 +377,7 @@ image_copyin_mapped(lba_t blk, int fd, u off_t cur, data, end, hole, pos; void *buf; uint64_t bytesize; - size_t sz; + size_t iosz, sz; int error; /* @@ -398,6 +398,8 @@ image_copyin_mapped(lba_t blk, int fd, u if (fd == -1) return (errno); + iosz = secsz * image_swap_pgsz; + bytesize = 0; cur = pos = 0; error = 0; @@ -427,19 +429,22 @@ image_copyin_mapped(lba_t blk, int fd, u data = pos; pos = (hole + secsz - 1) & ~(secsz - 1); - /* Sloppy... */ - sz = pos - data; - assert((off_t)sz == pos - data); - - buf = image_file_map(fd, data, sz); - if (buf != NULL) { - error = image_chunk_copyin(blk, buf, sz, - data, fd); - image_file_unmap(buf, sz); - } else - error = errno; - blk += sz / secsz; - bytesize += sz; + while (data < pos) { + sz = (pos - data > (off_t)iosz) + ? iosz : (size_t)(pos - data); + + buf = image_file_map(fd, data, sz); + if (buf != NULL) { + error = image_chunk_copyin(blk, buf, + sz, data, fd); + image_file_unmap(buf, sz); + } else + error = errno; + + blk += sz / secsz; + bytesize += sz; + data += sz; + } cur = hole; } else { /*