e2image in raw-mode appends an extra byte to image-file

In raw mode (-r), e2image appends an extra byte to the image-file's
end if the last block requires a sparse write. Consequently, the
resulting image-file is one byte larger than the original in
size. This patch fixes the problem by seeking to one less than the
given offset, so that the byte write does not overflow into the next
block.

This problem can be reproduced by doing an e2image -r dev image-file
and comparing the original and resulting image sizes. This assumes the
image is sparse at the end. For my tests, I created a 100MB sparse
image with two files.

Signed-off-by: Arun Thomas <thomasar@us.ibm.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
This commit is contained in:
Arun Thomas 2007-11-09 15:46:10 -05:00 committed by Theodore Ts'o
parent 3eaf8627b0
commit 20abd3ea2a

View File

@ -440,7 +440,8 @@ static void output_meta_data_blocks(ext2_filsys fs, int fd)
}
}
}
write_block(fd, zero_buf, sparse, 1, -1);
if (sparse)
write_block(fd, zero_buf, sparse-1, 1, -1);
free(zero_buf);
free(buf);
}