svn commit: r272370 - user/marcel/mkimg

Marcel Moolenaar marcel at FreeBSD.org
Wed Oct 1 16:09:12 UTC 2014


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 {
 			/*


More information about the svn-src-user mailing list