diff options
author | Jerry Zhang <zhangjerry@google.com> | 2018-06-05 11:44:52 -0700 |
---|---|---|
committer | Jerry Zhang <zhangjerry@google.com> | 2018-06-07 14:33:18 -0700 |
commit | 50e6029a4e4b9c9bd6065548ced523ec5b01e705 (patch) | |
tree | 16b6c5529b11af841a6ebbdbe4b8e9d362946526 /libsparse/include | |
parent | f875aaa339e864410b7243d312d06020f86845f8 (diff) | |
download | system_core-50e6029a4e4b9c9bd6065548ced523ec5b01e705.tar.gz system_core-50e6029a4e4b9c9bd6065548ced523ec5b01e705.tar.bz2 system_core-50e6029a4e4b9c9bd6065548ced523ec5b01e705.zip |
libsparse: Add method to create sparse file from buffer
Refactor elements of sparse file parsing that depend on
an fd into SparseFileSource class, then create implementations
using both fd and buffer. Add sparse_file_read_buf which
reads the given buffer into a sparse file cookie without
copying.
Test: flash system with sparse images
Bug: 78793464
Change-Id: Ice6c8e1ff075d6867e070f80fcf5aa4f530a1b95
Diffstat (limited to 'libsparse/include')
-rw-r--r-- | libsparse/include/sparse/sparse.h | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/libsparse/include/sparse/sparse.h b/libsparse/include/sparse/sparse.h index 1b91ead5c..3d5fb0c53 100644 --- a/libsparse/include/sparse/sparse.h +++ b/libsparse/include/sparse/sparse.h @@ -246,9 +246,24 @@ int sparse_file_foreach_chunk(struct sparse_file *s, bool sparse, bool crc, int sparse_file_read(struct sparse_file *s, int fd, bool sparse, bool crc); /** - * sparse_file_import - import an existing sparse file + * sparse_file_read_buf - read a buffer into a sparse file cookie * * @s - sparse file cookie + * @buf - buffer to read from + * @crc - verify the crc of a file in the Android sparse file format + * + * Reads a buffer into a sparse file cookie. The buffer must remain + * valid until the sparse file cookie is freed. If crc is true, the + * crc of the sparse file will be verified. + * + * Returns 0 on success, negative errno on error. + */ +int sparse_file_read_buf(struct sparse_file *s, char *buf, bool crc); + +/** + * sparse_file_import - import an existing sparse file + * + * @fd - file descriptor to read from * @verbose - print verbose errors while reading the sparse file * @crc - verify the crc of a file in the Android sparse file format * @@ -261,6 +276,21 @@ int sparse_file_read(struct sparse_file *s, int fd, bool sparse, bool crc); struct sparse_file *sparse_file_import(int fd, bool verbose, bool crc); /** + * sparse_file_import_buf - import an existing sparse file from a buffer + * + * @buf - buffer to read from + * @verbose - print verbose errors while reading the sparse file + * @crc - verify the crc of a file in the Android sparse file format + * + * Reads existing sparse file data into a sparse file cookie, recreating the same + * sparse cookie that was used to write it. If verbose is true, prints verbose + * errors when the sparse file is formatted incorrectly. + * + * Returns a new sparse file cookie on success, NULL on error. + */ +struct sparse_file *sparse_file_import_buf(char* buf, bool verbose, bool crc); + +/** * sparse_file_import_auto - import an existing sparse or normal file * * @fd - file descriptor to read from |