aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqfs')
-rw-r--r--lib/sqfs/statistics.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/lib/sqfs/statistics.c b/lib/sqfs/statistics.c
new file mode 100644
index 0000000..2bd4acf
--- /dev/null
+++ b/lib/sqfs/statistics.c
@@ -0,0 +1,73 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+#include "config.h"
+#include "highlevel.h"
+
+#include <stdio.h>
+
+void sqfs_print_statistics(fstree_t *fs, sqfs_super_t *super)
+{
+ size_t blocks_written = 0, duplicate_blocks = 0, sparse_blocks = 0;
+ size_t ratio, file_count = 0, file_dup_count = 0;
+ size_t frag_count = 0, frag_dup = 0;
+ size_t i, num_blocks, sparse;
+ uint64_t output_bytes = 0;
+ uint64_t input_bytes = 0;
+ file_info_t *fi;
+
+ for (fi = fs->files; fi != NULL; fi = fi->next) {
+ num_blocks = fi->size / fs->block_size;
+
+ if ((fi->size % fs->block_size) &&
+ !(fi->flags & FILE_FLAG_HAS_FRAGMENT)) {
+ ++num_blocks;
+ }
+
+ for (sparse = 0, i = 0; i < num_blocks; ++i) {
+ if (fi->blocks[i].size == 0)
+ sparse += 1;
+ }
+
+ if (fi->flags & FILE_FLAG_BLOCKS_ARE_DUPLICATE) {
+ duplicate_blocks += num_blocks - sparse;
+ } else {
+ blocks_written += num_blocks - sparse;
+ }
+
+ if ((fi->flags & FILE_FLAG_FRAGMENT_IS_DUPLICATE) &&
+ (fi->flags & FILE_FLAG_BLOCKS_ARE_DUPLICATE)) {
+ file_dup_count += 1;
+ }
+
+ if (fi->flags & FILE_FLAG_HAS_FRAGMENT) {
+ if (fi->flags & FILE_FLAG_FRAGMENT_IS_DUPLICATE) {
+ frag_dup += 1;
+ } else {
+ frag_count += 1;
+ }
+ }
+
+ sparse_blocks += sparse;
+ file_count += 1;
+ input_bytes += fi->size;
+ }
+
+ if (input_bytes > 0) {
+ output_bytes = super->inode_table_start - sizeof(*super);
+ ratio = (100 * output_bytes) / input_bytes;
+ } else {
+ ratio = 100;
+ }
+
+ fputs("---------------------------------------------------\n", stdout);
+ printf("Input files processed: %zu\n", file_count);
+ printf("Files that were complete duplicates: %zu\n", file_dup_count);
+ printf("Data blocks actually written: %zu\n", blocks_written);
+ printf("Fragment blocks written: %u\n", super->fragment_entry_count);
+ printf("Duplicate data blocks omitted: %zu\n", duplicate_blocks);
+ printf("Sparse blocks omitted: %zu\n", sparse_blocks);
+ printf("Fragments actually written: %zu\n", frag_count);
+ printf("Duplicated fragments omitted: %zu\n", frag_dup);
+ printf("Total number of inodes: %u\n", super->inode_count);
+ printf("Number of unique group/user IDs: %u\n", super->id_count);
+ printf("Data compression ratio: %zu%%\n", ratio);
+}