summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2009-08-22 23:02:41 -0400
committerTheodore Ts'o <tytso@mit.edu>2009-08-22 23:04:33 -0400
commit4087bbd68bc129c19f0130ba36679e3e8c80c617 (patch)
tree59b6e797bac3249487ae18e7adcffc10b8535f5d
parent154a5d7537c35959aa646ef8f18daed8c9f1a2be (diff)
downloade2fsprogs-4087bbd68bc129c19f0130ba36679e3e8c80c617.tar.gz
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" <tytso@mit.edu>
-rw-r--r--contrib/make-sparse.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/contrib/make-sparse.c b/contrib/make-sparse.c
index 4a7a3155..1b3d5506 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;
}