From: Theodore Ts'o Date: Sun, 23 Aug 2009 03:02:41 +0000 (-0400) Subject: make-sparse: Write a zero-byte at the end of the image X-Git-Tag: v1.41.9~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4087bbd68bc129c19f0130ba36679e3e8c80c617;p=thirdparty%2Fe2fsprogs.git 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" --- diff --git a/contrib/make-sparse.c b/contrib/make-sparse.c index 4a7a3155b..1b3d5506d 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; }