Thread (22 messages) 22 messages, 3 authors, 2012-02-17
STALE5227d

[PATCH 2/2] e2image: attempt to use ftruncate64 to set i_size for raw images

From: Theodore Ts'o <tytso@mit.edu>
Date: 2012-02-17 14:32:46
Subsystem: the rest · Maintainer: Linus Torvalds

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(), then fall back to
writing the trailing null.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
---
 misc/e2image.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/misc/e2image.c b/misc/e2image.c
index 3cb92fe..90d69ec 100644
--- a/misc/e2image.c
+++ b/misc/e2image.c
@@ -510,6 +510,16 @@ 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 &&
+		    ftruncate64(fd, offset) < 0)
+			write_block(fd, zero_buf, -1, 1, -1);
+		sparse = 0;
+	}
+#endif
 	if (sparse)
 		write_block(fd, zero_buf, sparse-1, 1, -1);
 	ext2fs_free_mem(&zero_buf);
-- 
1.7.9.107.g97f9a
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help