summaryrefslogtreecommitdiffstats
path: root/libsparse/sparse.c
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2012-05-24 17:15:43 -0700
committerColin Cross <ccross@android.com>2012-07-09 22:09:37 -0700
commit317a09e2d47257df5e0972c85f14c2a6ffdbbfd2 (patch)
tree1d16d24323042aa16d0994c05de22e2e043f6668 /libsparse/sparse.c
parentbdc6d39ed6c09199a5d806f29b71b44cbb27c5c2 (diff)
downloadsystem_core-317a09e2d47257df5e0972c85f14c2a6ffdbbfd2.zip
system_core-317a09e2d47257df5e0972c85f14c2a6ffdbbfd2.tar.gz
system_core-317a09e2d47257df5e0972c85f14c2a6ffdbbfd2.tar.bz2
libsparse: add sparse_file_len
Add sparse_file_len, which will compute the size of data that would be produced if sparse_file_write was called. Useful combined with sparse_file_callback. Change-Id: I1a156d1071760f5559483954a5c62ffc20298703
Diffstat (limited to 'libsparse/sparse.c')
-rw-r--r--libsparse/sparse.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/libsparse/sparse.c b/libsparse/sparse.c
index 77f02fc..f04f687 100644
--- a/libsparse/sparse.c
+++ b/libsparse/sparse.c
@@ -196,6 +196,30 @@ static int out_counter_write(void *priv, const void *data, int len)
return 0;
}
+int64_t sparse_file_len(struct sparse_file *s, bool sparse, bool crc)
+{
+ int ret;
+ int chunks = sparse_count_chunks(s);
+ int64_t count = 0;
+ struct output_file *out;
+
+ out = open_output_callback(out_counter_write, &count,
+ s->block_size, s->len, false, sparse, chunks, crc);
+ if (!out) {
+ return -1;
+ }
+
+ ret = write_all_blocks(s, out);
+
+ close_output_file(out);
+
+ if (ret < 0) {
+ return -1;
+ }
+
+ return count;
+}
+
static struct backed_block *move_chunks_up_to_len(struct sparse_file *from,
struct sparse_file *to, unsigned int len)
{