From patchwork Thu Feb 16 21:35:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Susi X-Patchwork-Id: 141703 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 5E3BAB6EE6 for ; Fri, 17 Feb 2012 08:43:07 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756006Ab2BPVnA (ORCPT ); Thu, 16 Feb 2012 16:43:00 -0500 Received: from rrcs-67-78-168-186.se.biz.rr.com ([67.78.168.186]:50779 "EHLO iriserv.iradimed.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754269Ab2BPVm7 (ORCPT ); Thu, 16 Feb 2012 16:42:59 -0500 X-Greylist: delayed 461 seconds by postgrey-1.27 at vger.kernel.org; Thu, 16 Feb 2012 16:42:58 EST Received: by iriserv.iradimed.com (Postfix, from userid 1000) id 584B746D00; Thu, 16 Feb 2012 16:35:15 -0500 (EST) From: Phillip Susi To: tytso@mit.edu Cc: linux-ext4@vger.kernel.org, Phillip Susi Subject: [PATCH 1/2] e2image: truncate raw image file to correct size Date: Thu, 16 Feb 2012 16:35:11 -0500 Message-Id: <1329428112-8911-1-git-send-email-psusi@ubuntu.com> X-Mailer: git-send-email 1.7.5.4 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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 --- 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); }