From owner-svn-src-user@FreeBSD.ORG Tue Sep 30 23:29:07 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 A70FEB59; Tue, 30 Sep 2014 23:29:07 +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 93CF33A1; Tue, 30 Sep 2014 23:29:07 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s8UNT78O087312; Tue, 30 Sep 2014 23:29:07 GMT (envelope-from marcel@FreeBSD.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s8UNT7tn087311; Tue, 30 Sep 2014 23:29:07 GMT (envelope-from marcel@FreeBSD.org) Message-Id: <201409302329.s8UNT7tn087311@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: marcel set sender to marcel@FreeBSD.org using -f From: Marcel Moolenaar Date: Tue, 30 Sep 2014 23:29:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r272337 - 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: Tue, 30 Sep 2014 23:29:07 -0000 Author: marcel Date: Tue Sep 30 23:29:06 2014 New Revision: 272337 URL: http://svnweb.freebsd.org/changeset/base/272337 Log: Implement image_data(): we now simply call image_chunk_find() to get the chunk that contains the block and we effectively have the answer right away. Account for the as-of-yet non-existent case of having multiple chunks of type zeroes adjacent to each other and having to handle chunk-crossing -- hence the loop. Modified: user/marcel/mkimg/image.c Modified: user/marcel/mkimg/image.c ============================================================================== --- user/marcel/mkimg/image.c Tue Sep 30 23:16:26 2014 (r272336) +++ user/marcel/mkimg/image.c Tue Sep 30 23:29:06 2014 (r272337) @@ -568,28 +568,22 @@ image_copyout_region(int fd, lba_t blk, int image_data(lba_t blk, lba_t size) { - char *buffer, *p; + struct chunk *ch; + lba_t lim; - blk *= secsz; - if (lseek(image_swap_fd, blk, SEEK_SET) != blk) - return (1); - - size *= secsz; - buffer = malloc(size); - if (buffer == NULL) - return (1); - - if (read(image_swap_fd, buffer, size) != (ssize_t)size) { - free(buffer); - return (1); + while (1) { + ch = image_chunk_find(blk); + if (ch == NULL) + return (0); + if (ch->ch_type != CH_TYPE_ZEROES) + return (1); + lim = ch->ch_block + (ch->ch_size / secsz); + if (lim >= blk + size) + return (0); + size -= lim - blk; + blk = lim; } - - p = buffer; - while (size > 0 && *p == '\0') - size--, p++; - - free(buffer); - return ((size == 0) ? 0 : 1); + /*NOTREACHED*/ } lba_t