svn commit: r272337 - user/marcel/mkimg

Marcel Moolenaar marcel at FreeBSD.org
Tue Sep 30 23:29:07 UTC 2014


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


More information about the svn-src-user mailing list