Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Drake <dsd@laptop.org>2012-12-17 07:34:20 (GMT)
committer Daniel Drake <dsd@laptop.org>2012-12-17 07:57:15 (GMT)
commit4d71a3c391f53cefdb1abfceac698d1f8d68a49c (patch)
tree28c3855236643e2bf00950779a097a3c72a1bf3c
parentb54f96d3fc54854da7bb71a03e2de69a3a544811 (diff)
zhashfs: correct output when last block is not occupied (#12402)HEADmaster
zhashfs was writing the eblocks: count line based on the file size of the input. However, this assumes that the last block of the input file had data in it, which is not necessarily true. Resultant .zd images flashed OK but caused OFW to produce a warning. WARNING: The file said highest block 15911 but wrote only as high as block 15903 Adjust the calculation to look at the last occupied data block to fix this. Test case, last block used is in the middle of the file: rm -f testfile dd if=/dev/zero of=testfile count=0 seek=128M bs=1 dd if=/dev/zero of=testfile count=1 seek=64M bs=1 conv=notrunc ./bin/zhashfs 0x20000 sha256 testfile testfile.zsp testfile.zd The output used to trigger the OFW warning, now it does not. Test case, last block used is at the end of the file: rm -f testfile dd if=/dev/zero of=testfile count=0 seek=128M bs=1 dd if=/dev/zero of=testfile count=1 seek=134217727 bs=1 ./bin/zhashfs 0x20000 sha256 testfile testfile.zsp testfile.zd The output here is unchanged by this patch - good.
-rw-r--r--bin/zhashfs.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/bin/zhashfs.c b/bin/zhashfs.c
index 9832f31..c52c045 100644
--- a/bin/zhashfs.c
+++ b/bin/zhashfs.c
@@ -127,7 +127,7 @@ struct fiemap *read_fiemap(int fd)
/* Given a file extent, determine which eblocks in the output file need to
* represent that extent, and mark them as used in the eblocks_used map. */
-static void process_extent(struct fiemap_extent *ex)
+static long process_extent(struct fiemap_extent *ex)
{
long i;
uint64_t last_byte = ex->fe_logical + ex->fe_length - 1;
@@ -137,17 +137,22 @@ static void process_extent(struct fiemap_extent *ex)
printf("Extent(%lld, %lld) occupies eblocks %d to %d\n", ex->fe_logical, ex->fe_length, first_eblock, last_eblock);
for (i = first_eblock; i <= last_eblock; i++)
eblocks_used[i] = 1;
+
+ return last_eblock;
}
/*
* Use FIEMAP to determine the extents that make up a file.
* Allocate eblocks_used array based on length of file, and then mark
* the set of eblocks that contain data based on the extents.
+ * Returns the index of the last occupied eblock.
*/
-static void read_extents(FILE *infile)
+static long read_extents(FILE *infile)
{
int i;
struct fiemap *fiemap = read_fiemap(fileno(infile));
+ long ret;
+
LTC_ARGCHK(fiemap != NULL);
eblocks_used = malloc(eblocks);
@@ -155,7 +160,9 @@ static void read_extents(FILE *infile)
memset(eblocks_used, 0, eblocks);
for (i=0; i < fiemap->fm_mapped_extents; i++)
- process_extent(&fiemap->fm_extents[i]);
+ ret = process_extent(&fiemap->fm_extents[i]);
+
+ return ret;
}
int main(int argc, char **argv)
@@ -226,7 +233,7 @@ int main(int argc, char **argv)
// LTC_ARGCHK((eblocks * zblocksize) == insize);
}
- read_extents(infile);
+ eblocks = read_extents(infile) + 1;
/* Remove possible path prefix */
fname = strrchr(argv[5], '/');