summaryrefslogtreecommitdiffstats
path: root/libsparse/include/sparse
diff options
context:
space:
mode:
authorJerry Zhang <zhangjerry@google.com>2018-06-14 16:58:58 -0700
committerHridya Valsaraju <hridya@google.com>2018-07-25 11:04:03 -0700
commitdb69f0d47f3ccb3ff656c56fe2b68aaf5ab853f6 (patch)
treee10ad5680b134599df00f4322a82242690940eb7 /libsparse/include/sparse
parent1c92fa44800c9d2efd3f2b8f18a3af7e131371be (diff)
downloadsystem_core-db69f0d47f3ccb3ff656c56fe2b68aaf5ab853f6.tar.gz
system_core-db69f0d47f3ccb3ff656c56fe2b68aaf5ab853f6.tar.bz2
system_core-db69f0d47f3ccb3ff656c56fe2b68aaf5ab853f6.zip
libsparse: Add sparse typed callback
Currently, sparse_file_callback uses libsparse's own logic for reading a file into a buffer. However, a caller may want to use their own logic for doing this in order to customize the buffer size and parallelize the reads/writes. Also, a caller may want to implement fill blocks with their own logic as well. To do this add sparse_file_typed_callback which calls a different callback function depending on the type of the sparse chunk being written. Test: Use typed callback for fd writes Bug: 78793464 Change-Id: I75955a464fc05991f806339830fdfa05fda354b9
Diffstat (limited to 'libsparse/include/sparse')
-rw-r--r--libsparse/include/sparse/sparse.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/libsparse/include/sparse/sparse.h b/libsparse/include/sparse/sparse.h
index 3d5fb0c53..586578633 100644
--- a/libsparse/include/sparse/sparse.h
+++ b/libsparse/include/sparse/sparse.h
@@ -210,6 +210,37 @@ int sparse_file_callback(struct sparse_file *s, bool sparse, bool crc,
int (*write)(void *priv, const void *data, size_t len), void *priv);
/**
+ * sparse_file_callback_typed - call a callback for blocks based on type
+ *
+ * @s - sparse file cookie
+ * @sparse - write in the Android sparse file format
+ * @data_write - function to call for data blocks. must not be null
+ * @fd_write - function to call for fd blocks
+ * @fill_write - function to call for fill blocks
+ * @skip_write - function to call for skip blocks
+ * @priv - value that will be passed as the first argument to each write
+ *
+ * Writes a sparse file by calling callback functions. If sparse is true, the
+ * file will be written in the Android sparse file format, and fill and skip blocks
+ * along with metadata will be written with data_write. If sparse is false, the file
+ * will be expanded into normal format and fill and skip blocks will be written with
+ * the given callbacks.
+ * If a callback function is provided, the library will not unroll data into a buffer,
+ * and will instead pass it directly to the caller for custom implementation. If a
+ * callback is not provided, that type of block will be converted into a void* and
+ * written with data_write. If no callbacks other than data are provided, the behavior
+ * is the same as sparse_file_callback(). The callback should return negative on error,
+ * 0 on success.
+ *
+ * Returns 0 on success, negative errno on error.
+ */
+int sparse_file_callback_typed(struct sparse_file* s, bool sparse,
+ int (*data_write)(void* priv, const void* data, size_t len),
+ int (*fd_write)(void* priv, int fd, size_t len),
+ int (*fill_write)(void* priv, uint32_t fill_val, size_t len),
+ int (*skip_write)(void* priv, int64_t len), void* priv);
+
+/**
* sparse_file_foreach_chunk - call a callback for data blocks in sparse file
*
* @s - sparse file cookie