From 0c4c47f88dfc15cada154a1cf9b4db88b49890f0 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 25 Apr 2012 19:02:58 -0700 Subject: libsparse: add sparse_file read and convert tools to use it Abstract the logic from simg2img into libsparse, and add logic for reading a regular image into libsparse. simg2img then becomes a simple wrapper around libsparse. img2simg was not actually making the file sparse, it was using sparse files to create multiple files that could be pieced back together. Replace it with a simple wrapper around libsparse. Its functionality will be replaced by an simg2simg that can resparse a file into smaller chunks. Change-Id: I266f70e1c750454183ce46c71a7bb66bbb033a26 --- libsparse/include/sparse/sparse.h | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'libsparse/include/sparse') diff --git a/libsparse/include/sparse/sparse.h b/libsparse/include/sparse/sparse.h index 09a5137..ae54955 100644 --- a/libsparse/include/sparse/sparse.h +++ b/libsparse/include/sparse/sparse.h @@ -158,6 +158,55 @@ int sparse_file_write(struct sparse_file *s, int fd, bool gz, bool sparse, bool crc); /** + * sparse_file_read - read a file into a sparse file cookie + * + * @s - sparse file cookie + * @fd - file descriptor to read from + * @sparse - read a file in the Android sparse file format + * @crc - verify the crc of a file in the Android sparse file format + * + * Reads a file into a sparse file cookie. If sparse is true, the file is + * assumed to be in the Android sparse file format. If sparse is false, the + * file will be sparsed by looking for block aligned chunks of all zeros or + * another 32 bit value. 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(struct sparse_file *s, int fd, bool sparse, bool crc); + +/** + * sparse_file_import - import an existing sparse file + * + * @s - sparse file cookie + * @verbose - print verbose errors while reading the sparse file + * @crc - verify the crc of a file in the Android sparse file format + * + * Reads an existing sparse file 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(int fd, bool verbose, bool crc); + +/** + * sparse_file_import_auto - import an existing sparse or normal file + * + * @fd - file descriptor to read from + * @crc - verify the crc of a file in the Android sparse file format + * + * Reads an existing sparse or normal file into a sparse file cookie. + * Attempts to determine if the file is sparse or not by looking for the sparse + * file magic number in the first 4 bytes. If the file is not sparse, the file + * will be sparsed by looking for block aligned chunks of all zeros or another + * 32 bit value. If crc is true, the crc of the sparse file will be verified. + * + * Returns a new sparse file cookie on success, NULL on error. + */ +struct sparse_file *sparse_file_import_auto(int fd, bool crc); + +/** * sparse_file_verbose - set a sparse file cookie to print verbose errors * * @s - sparse file cookie -- cgit v1.1