From 4087bbd68bc129c19f0130ba36679e3e8c80c617 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sat, 22 Aug 2009 23:02:41 -0400 Subject: [PATCH] make-sparse: Write a zero-byte at the end of the image This is necessary to preserve the i_size of the output file; otherwise programs like e2fsck will complain that the filesystem has been truncated. Signed-off-by: "Theodore Ts'o" --- contrib/make-sparse.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/contrib/make-sparse.c b/contrib/make-sparse.c index 4a7a315..1b3d550 100644 --- a/contrib/make-sparse.c +++ b/contrib/make-sparse.c @@ -48,6 +48,7 @@ int full_read(int fd, char *buf, size_t count) int main(int argc, char **argv) { int fd, got, i; + int zflag = 0; char buf[1024]; if (argc != 2) { @@ -69,11 +70,18 @@ int main(int argc, char **argv) break; if (i == sizeof(buf)) { lseek(fd, sizeof(buf), SEEK_CUR); + zflag = 1; continue; } } + zflag = 0; write(fd, buf, got); } + if (zflag) { + lseek(fd, -1, SEEK_CUR); + buf[0] = 0; + write(fd, buf, 1); + } return 0; } -- 1.8.3.1