diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-26 14:33:55 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-26 15:32:38 +0200 |
commit | 248765bd9f6ead4fbe4e5822bcaf46b85fe1687f (patch) | |
tree | 1e487925a3bb4011ea1c355bce77413657e79b06 /lib/sqfshelper/statistics.c | |
parent | 2341da0e0654aa8e89e5f3630f8142346788e061 (diff) |
Remove remnants of the old data writer
- Move the statstics hooks to the rest of the statistics code
- Used the new data writer directly in gensquashfs & tar2sqfs
- Demote what is left to a helper function for processing an
input file and submitting it to the new data writer
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfshelper/statistics.c')
-rw-r--r-- | lib/sqfshelper/statistics.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/sqfshelper/statistics.c b/lib/sqfshelper/statistics.c index 87efc30..26c121f 100644 --- a/lib/sqfshelper/statistics.c +++ b/lib/sqfshelper/statistics.c @@ -7,8 +7,65 @@ #include "config.h" #include "highlevel.h" +#include "sqfs/block.h" + #include <stdio.h> +static void post_block_write(void *user, const sqfs_block_t *block, + sqfs_file_t *file) +{ + data_writer_stats_t *stats = user; + (void)file; + + if (block->size == 0) + return; + + if (block->flags & SQFS_BLK_FRAGMENT_BLOCK) { + stats->frag_blocks_written += 1; + } else { + stats->blocks_written += 1; + } + + stats->bytes_written += block->size; +} + +static void pre_fragment_store(void *user, sqfs_block_t *block) +{ + data_writer_stats_t *stats = user; + (void)block; + + stats->frag_count += 1; +} + +static void notify_blocks_erased(void *user, size_t count, uint64_t bytes) +{ + data_writer_stats_t *stats = user; + + stats->bytes_written -= bytes; + stats->blocks_written -= count; + stats->duplicate_blocks += count; +} + +static void notify_fragment_discard(void *user, const sqfs_block_t *block) +{ + data_writer_stats_t *stats = user; + (void)block; + + stats->frag_dup += 1; +} + +static const sqfs_block_hooks_t hooks = { + .post_block_write = post_block_write, + .pre_fragment_store = pre_fragment_store, + .notify_blocks_erased = notify_blocks_erased, + .notify_fragment_discard = notify_fragment_discard, +}; + +void register_stat_hooks(sqfs_data_writer_t *data, data_writer_stats_t *stats) +{ + sqfs_data_writer_set_hooks(data, stats, &hooks); +} + void sqfs_print_statistics(sqfs_super_t *super, data_writer_stats_t *stats) { size_t ratio; |