Date: Tue, 30 Sep 2014 23:29:07 +0000 (UTC) From: Marcel Moolenaar <marcel@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r272337 - user/marcel/mkimg Message-ID: <201409302329.s8UNT7tn087311@svn.freebsd.org>
index | next in thread | raw e-mail
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_thelp
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201409302329.s8UNT7tn087311>
