summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Cross2012-05-24 19:15:43 -0500
committerColin Cross2012-07-10 00:09:37 -0500
commit317a09e2d47257df5e0972c85f14c2a6ffdbbfd2 (patch)
tree1d16d24323042aa16d0994c05de22e2e043f6668 /libsparse
parentbdc6d39ed6c09199a5d806f29b71b44cbb27c5c2 (diff)
downloadplatform-system-core-317a09e2d47257df5e0972c85f14c2a6ffdbbfd2.tar.gz
platform-system-core-317a09e2d47257df5e0972c85f14c2a6ffdbbfd2.tar.xz
platform-system-core-317a09e2d47257df5e0972c85f14c2a6ffdbbfd2.zip
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')
-rw-r--r--libsparse/include/sparse/sparse.h14
-rw-r--r--libsparse/sparse.c24
2 files changed, 38 insertions, 0 deletions
diff --git a/libsparse/include/sparse/sparse.h b/libsparse/include/sparse/sparse.h
index fe003f61b..17d085ca4 100644
--- a/libsparse/include/sparse/sparse.h
+++ b/libsparse/include/sparse/sparse.h
@@ -158,6 +158,20 @@ int sparse_file_write(struct sparse_file *s, int fd, bool gz, bool sparse,
158 bool crc); 158 bool crc);
159 159
160/** 160/**
161 * sparse_file_len - return the length of a sparse file if written to disk
162 *
163 * @s - sparse file cookie
164 * @sparse - write in the Android sparse file format
165 * @crc - append a crc chunk
166 *
167 * Returns the size a sparse file would be on disk if it were written in the
168 * specified format. If sparse is true, this is the size of the data in the
169 * sparse format. If sparse is false, this is the size of the normal
170 * non-sparse file.
171 */
172int64_t sparse_file_len(struct sparse_file *s, bool sparse, bool crc);
173
174/**
161 * sparse_file_callback - call a callback for blocks in sparse file 175 * sparse_file_callback - call a callback for blocks in sparse file
162 * 176 *
163 * @s - sparse file cookie 177 * @s - sparse file cookie
diff --git a/libsparse/sparse.c b/libsparse/sparse.c
index 77f02fc49..f04f687b9 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)
196 return 0; 196 return 0;
197} 197}
198 198
199int64_t sparse_file_len(struct sparse_file *s, bool sparse, bool crc)
200{
201 int ret;
202 int chunks = sparse_count_chunks(s);
203 int64_t count = 0;
204 struct output_file *out;
205
206 out = open_output_callback(out_counter_write, &count,
207 s->block_size, s->len, false, sparse, chunks, crc);
208 if (!out) {
209 return -1;
210 }
211
212 ret = write_all_blocks(s, out);
213
214 close_output_file(out);
215
216 if (ret < 0) {
217 return -1;
218 }
219
220 return count;
221}
222
199static struct backed_block *move_chunks_up_to_len(struct sparse_file *from, 223static struct backed_block *move_chunks_up_to_len(struct sparse_file *from,
200 struct sparse_file *to, unsigned int len) 224 struct sparse_file *to, unsigned int len)
201{ 225{