libsparse: add support for including fds
Add sparse_file_add_fd to include all or part of the contents
of an fd in the output file. Will be useful for re-sparsing files
where fd will point to the input sparse file.
Change-Id: I5d4ab07fb37231e8e9c1912f62a2968c8b0a00ef
diff --git a/libsparse/sparse.c b/libsparse/sparse.c
index fce9dbb..4ebcf0f 100644
--- a/libsparse/sparse.c
+++ b/libsparse/sparse.c
@@ -70,6 +70,12 @@
len, block);
}
+int sparse_file_add_fd(struct sparse_file *s,
+ int fd, int64_t file_offset, unsigned int len, unsigned int block)
+{
+ return backed_block_add_fd(s->backed_block_list, fd, file_offset,
+ len, block);
+}
unsigned int sparse_count_chunks(struct sparse_file *s)
{
struct backed_block *bb;
@@ -122,6 +128,10 @@
write_file_chunk(out, backed_block_len(bb),
backed_block_filename(bb), backed_block_file_offset(bb));
break;
+ case BACKED_BLOCK_FD:
+ write_fd_chunk(out, backed_block_len(bb),
+ backed_block_fd(bb), backed_block_file_offset(bb));
+ break;
case BACKED_BLOCK_FILL:
write_fill_chunk(out, backed_block_len(bb),
backed_block_fill_val(bb));