linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] e2image: truncate raw image file to correct size
@ 2012-02-16 21:35 Phillip Susi
  2012-02-16 21:35 ` [PATCH 2/2] e2image: add -a switch to include all data Phillip Susi
  2012-02-16 22:58 ` [PATCH 1/2] e2image: truncate raw image file to correct size Ted Ts'o
  0 siblings, 2 replies; 22+ messages in thread
From: Phillip Susi @ 2012-02-16 21:35 UTC (permalink / raw)
  To: tytso; +Cc: linux-ext4, Phillip Susi

At the end of writing the raw image file, output_meta_data_blocks()
wrote a single zero byte.  Not only does this cause the last block
of the image file to be non sparse, but this was being skipped if
there were no leftover sparse bytes from the main loop.  This would
happen if the source fs happened to have an even multiple of 1MiB
of free blocks at the end, leaving the sparse image file shorter
than it should be.

Instead of writing a null byte, just truncate() the file instead,
whether or not there are any leftover sparse bytes.

Signed-off-by: Phillip Susi <psusi@ubuntu.com>
---
 misc/e2image.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/misc/e2image.c b/misc/e2image.c
index d888e5a..722737c 100644
--- a/misc/e2image.c
+++ b/misc/e2image.c
@@ -511,8 +511,7 @@ static void output_meta_data_blocks(ext2_filsys fs, int fd)
 			}
 		}
 	}
-	if (sparse)
-		write_block(fd, zero_buf, sparse-1, 1, -1);
+	ftruncate(fd, lseek(fd, sparse, SEEK_CUR));
 	ext2fs_free_mem(&zero_buf);
 	ext2fs_free_mem(&buf);
 }
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2012-02-17 20:39 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-16 21:35 [PATCH 1/2] e2image: truncate raw image file to correct size Phillip Susi
2012-02-16 21:35 ` [PATCH 2/2] e2image: add -a switch to include all data Phillip Susi
2012-02-16 23:17   ` Ted Ts'o
2012-02-17  0:17     ` Phillip Susi
2012-02-17  9:17       ` Lukas Czerner
2012-02-17 14:50         ` Ted Ts'o
2012-02-17 15:35           ` Lukas Czerner
2012-02-17 15:39             ` Lukas Czerner
2012-02-17 20:39             ` Ted Ts'o
2012-02-16 22:58 ` [PATCH 1/2] e2image: truncate raw image file to correct size Ted Ts'o
2012-02-16 23:10   ` Phillip Susi
2012-02-16 23:30     ` Ted Ts'o
2012-02-17  0:21       ` Phillip Susi
2012-02-17 10:04       ` Lukas Czerner
2012-02-17 14:30         ` Ted Ts'o
2012-02-17 14:32           ` [PATCH 1/2] e2image: fix logic bug which could cause a raw image not to be extended Theodore Ts'o
2012-02-17 14:32             ` [PATCH 2/2] e2image: attempt to use ftruncate64 to set i_size for raw images Theodore Ts'o
2012-02-17 14:35               ` [PATCH 2/2 -v2] " Theodore Ts'o
2012-02-17 20:19                 ` Lukas Czerner
2012-02-17 20:18             ` [PATCH 1/2] e2image: fix logic bug which could cause a raw image not to be extended Lukas Czerner
2012-02-17 14:46           ` [PATCH 1/2] e2image: truncate raw image file to correct size Phillip Susi
2012-02-17 14:31         ` Phillip Susi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).