]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
make-sparse: Write a zero-byte at the end of the image
authorTheodore Ts'o <tytso@mit.edu>
Sun, 23 Aug 2009 03:02:41 +0000 (23:02 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 23 Aug 2009 03:04:33 +0000 (23:04 -0400)
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>
contrib/make-sparse.c

index 4a7a3155b216bb010c9b7f9e3089d622c7de197b..1b3d5506d79faa5d3eaeabd7866b6850d1d9ceeb 100644 (file)
@@ -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;
 }