From: Theodore Ts'o Date: Fri, 17 Feb 2012 14:23:12 +0000 (-0500) Subject: e2image: attempt to use ftruncate64 to set i_size for raw images X-Git-Tag: v1.42.1~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=50a676e944356e188917f5174a7478817024213c;p=thirdparty%2Fe2fsprogs.git e2image: attempt to use ftruncate64 to set i_size for raw images If ftruncate64() exists, try to use it to set i_size. This isn't guaranteed to work, per SuSv3, but if it doesn't work, it's guaranteed to return an error. So for file systems and/or operating systems that don't support extending i_size via ftruncate64(), fall back to writing the trailing null. Signed-off-by: "Theodore Ts'o" --- diff --git a/misc/e2image.c b/misc/e2image.c index 3cb92fee2..93359cf5a 100644 --- a/misc/e2image.c +++ b/misc/e2image.c @@ -510,8 +510,19 @@ static void output_meta_data_blocks(ext2_filsys fs, int fd) } } } +#ifdef HAVE_FTRUNCATE64 + if (sparse) { + ext2_loff_t offset = ext2fs_llseek(fd, sparse, SEEK_CUR); + + if (offset < 0) + lseek_error_and_exit(errno); + if (ftruncate64(fd, offset) < 0) + write_block(fd, zero_buf, -1, 1, -1); + } +#else if (sparse) write_block(fd, zero_buf, sparse-1, 1, -1); +#endif ext2fs_free_mem(&zero_buf); ext2fs_free_mem(&buf); }