sparse.h revision 1e17b313a6257b7b5081e178e81435c09d60378e
128fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross/*
228fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * Copyright (C) 2012 The Android Open Source Project
328fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
428fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * Licensed under the Apache License, Version 2.0 (the "License");
528fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * you may not use this file except in compliance with the License.
628fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * You may obtain a copy of the License at
728fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
828fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *      http://www.apache.org/licenses/LICENSE-2.0
928fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
1028fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * Unless required by applicable law or agreed to in writing, software
1128fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * distributed under the License is distributed on an "AS IS" BASIS,
1228fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1328fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * See the License for the specific language governing permissions and
1428fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * limitations under the License.
1528fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross */
1628fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross
1728fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross#ifndef _LIBSPARSE_SPARSE_H_
1828fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross#define _LIBSPARSE_SPARSE_H_
1928fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross
2028fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross#include <stdbool.h>
2128fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross#include <stdint.h>
2228fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross
2328fa5bc347390480fe190294c6c385b6a9f0d68bColin Crossstruct sparse_file;
2428fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross
2528fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross/**
2628fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * sparse_file_new - create a new sparse file cookie
2728fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
2828fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * @block_size - minimum size of a chunk
2928fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * @len - size of the expanded sparse file.
3028fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
3128fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * Creates a new sparse_file cookie that can be used to associate data
3228fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * blocks.  Can later be written to a file with a variety of options.
3328fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * block_size specifies the minimum size of a chunk in the file.  The maximum
3428fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * size of the file is 2**32 * block_size (16TB for 4k block size).
3528fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
3628fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * Returns the sparse file cookie, or NULL on error.
3728fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross */
3828fa5bc347390480fe190294c6c385b6a9f0d68bColin Crossstruct sparse_file *sparse_file_new(unsigned int block_size, int64_t len);
3928fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross
4028fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross/**
4128fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * sparse_file_destroy - destroy a sparse file cookie
4228fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
4328fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * @s - sparse file cookie
4428fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
4528fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * Destroys a sparse file cookie.  After destroy, all memory passed in to
4628fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * sparse_file_add_data can be freed by the caller
4728fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross */
4828fa5bc347390480fe190294c6c385b6a9f0d68bColin Crossvoid sparse_file_destroy(struct sparse_file *s);
4928fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross
5028fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross/**
5128fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * sparse_file_add_data - associate a data chunk with a sparse file
5228fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
5328fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * @s - sparse file cookie
5428fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * @data - pointer to data block
5528fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * @len - length of the data block
5628fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * @block - offset in blocks into the sparse file to place the data chunk
5728fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
5828fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * Associates a data chunk with a sparse file cookie.  The region
5928fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * [block * block_size : block * block_size + len) must not already be used in
6028fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * the sparse file. If len is not a multiple of the block size the data
6128fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * will be padded with zeros.
6228fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
6328fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * The data pointer must remain valid until the sparse file is closed or the
6428fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * data block is removed from the sparse file.
6528fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
6628fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * Returns 0 on success, negative errno on error.
6728fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross */
6828fa5bc347390480fe190294c6c385b6a9f0d68bColin Crossint sparse_file_add_data(struct sparse_file *s,
6928fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross		void *data, unsigned int len, unsigned int block);
7028fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross
7128fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross/**
7228fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * sparse_file_add_fill - associate a fill chunk with a sparse file
7328fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
7428fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * @s - sparse file cookie
7528fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * @fill_val - 32 bit fill data
7628fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * @len - length of the fill block
7728fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * @block - offset in blocks into the sparse file to place the fill chunk
7828fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
7928fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * Associates a chunk filled with fill_val with a sparse file cookie.
8028fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * The region [block * block_size : block * block_size + len) must not already
8128fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * be used in the sparse file. If len is not a multiple of the block size the
8228fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * data will be padded with zeros.
8328fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
8428fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * Returns 0 on success, negative errno on error.
8528fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross */
8628fa5bc347390480fe190294c6c385b6a9f0d68bColin Crossint sparse_file_add_fill(struct sparse_file *s,
8728fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross		uint32_t fill_val, unsigned int len, unsigned int block);
8828fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross
8928fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross/**
9028fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * sparse_file_add_file - associate a chunk of a file with a sparse file
9128fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
9228fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * @s - sparse file cookie
9328fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * @filename - filename of the file to be copied
9428fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * @file_offset - offset into the copied file
9528fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * @len - length of the copied block
9628fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * @block - offset in blocks into the sparse file to place the file chunk
9728fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
9828fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * Associates a chunk of an existing file with a sparse file cookie.
9928fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * The region [block * block_size : block * block_size + len) must not already
10028fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * be used in the sparse file. If len is not a multiple of the block size the
10128fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * data will be padded with zeros.
10228fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
10328fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * Allows adding large amounts of data to a sparse file without needing to keep
10428fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * it all mapped.  File size is limited by available virtual address space,
10528fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * exceptionally large files may need to be added in multiple chunks.
10628fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
10728fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * Returns 0 on success, negative errno on error.
10828fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross */
10928fa5bc347390480fe190294c6c385b6a9f0d68bColin Crossint sparse_file_add_file(struct sparse_file *s,
11028fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross		const char *filename, int64_t file_offset, unsigned int len,
11128fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross		unsigned int block);
11228fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross
11328fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross/**
1149e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross * sparse_file_add_file - associate a chunk of a file with a sparse file
1159e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross *
1169e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross * @s - sparse file cookie
1179e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross * @filename - filename of the file to be copied
1189e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross * @file_offset - offset into the copied file
1199e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross * @len - length of the copied block
1209e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross * @block - offset in blocks into the sparse file to place the file chunk
1219e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross *
1229e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross * Associates a chunk of an existing fd with a sparse file cookie.
1239e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross * The region [block * block_size : block * block_size + len) must not already
1249e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross * be used in the sparse file. If len is not a multiple of the block size the
1259e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross * data will be padded with zeros.
1269e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross *
1279e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross * Allows adding large amounts of data to a sparse file without needing to keep
1289e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross * it all mapped.  File size is limited by available virtual address space,
1299e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross * exceptionally large files may need to be added in multiple chunks.
1309e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross *
1319e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross * The fd must remain open until the sparse file is closed or the fd block is
1329e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross * removed from the sparse file.
1339e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross *
1349e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross * Returns 0 on success, negative errno on error.
1359e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross */
1369e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Crossint sparse_file_add_fd(struct sparse_file *s,
1379e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross		int fd, int64_t file_offset, unsigned int len, unsigned int block);
1389e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross
1399e1f17e926fa20255c5f4b4d2f68aa98a964253aColin Cross/**
14028fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * sparse_file_write - write a sparse file to a file
14128fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
14228fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * @s - sparse file cookie
14328fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * @fd - file descriptor to write to
14428fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * @gz - write a gzipped file
14528fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * @sparse - write in the Android sparse file format
14628fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * @crc - append a crc chunk
14728fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
14828fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * Writes a sparse file to a file.  If gz is true, the data will be passed
14928fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * through zlib.  If sparse is true, the file will be written in the Android
15028fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * sparse file format.  If sparse is false, the file will be written by seeking
15128fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * over unused chunks, producing a smaller file if the filesystem supports
15228fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * sparse files.  If crc is true, the crc of the expanded data will be
15328fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * calculated and appended in a crc chunk.
15428fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross *
15528fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross * Returns 0 on success, negative errno on error.
15628fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross */
15728fa5bc347390480fe190294c6c385b6a9f0d68bColin Crossint sparse_file_write(struct sparse_file *s, int fd, bool gz, bool sparse,
15828fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross		bool crc);
15928fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross
160a21930b6b0dbb04a52948566d58fb48c6db58babColin Cross/**
1611e17b313a6257b7b5081e178e81435c09d60378eColin Cross * sparse_file_callback - call a callback for blocks in sparse file
1621e17b313a6257b7b5081e178e81435c09d60378eColin Cross *
1631e17b313a6257b7b5081e178e81435c09d60378eColin Cross * @s - sparse file cookie
1641e17b313a6257b7b5081e178e81435c09d60378eColin Cross * @sparse - write in the Android sparse file format
1651e17b313a6257b7b5081e178e81435c09d60378eColin Cross * @crc - append a crc chunk
1661e17b313a6257b7b5081e178e81435c09d60378eColin Cross * @write - function to call for each block
1671e17b313a6257b7b5081e178e81435c09d60378eColin Cross * @priv - value that will be passed as the first argument to write
1681e17b313a6257b7b5081e178e81435c09d60378eColin Cross *
1691e17b313a6257b7b5081e178e81435c09d60378eColin Cross * Writes a sparse file by calling a callback function.  If sparse is true, the
1701e17b313a6257b7b5081e178e81435c09d60378eColin Cross * file will be written in the Android sparse file format.  If crc is true, the
1711e17b313a6257b7b5081e178e81435c09d60378eColin Cross * crc of the expanded data will be calculated and appended in a crc chunk.
1721e17b313a6257b7b5081e178e81435c09d60378eColin Cross * The callback 'write' will be called with data and length for each data,
1731e17b313a6257b7b5081e178e81435c09d60378eColin Cross * and with data==NULL to skip over a region (only used for non-sparse format).
1741e17b313a6257b7b5081e178e81435c09d60378eColin Cross * The callback should return negative on error, 0 on success.
1751e17b313a6257b7b5081e178e81435c09d60378eColin Cross *
1761e17b313a6257b7b5081e178e81435c09d60378eColin Cross * Returns 0 on success, negative errno on error.
1771e17b313a6257b7b5081e178e81435c09d60378eColin Cross */
1781e17b313a6257b7b5081e178e81435c09d60378eColin Crossint sparse_file_callback(struct sparse_file *s, bool sparse, bool crc,
1791e17b313a6257b7b5081e178e81435c09d60378eColin Cross		int (*write)(void *priv, const void *data, int len), void *priv);
1801e17b313a6257b7b5081e178e81435c09d60378eColin Cross
1811e17b313a6257b7b5081e178e81435c09d60378eColin Cross/**
1820c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * sparse_file_read - read a file into a sparse file cookie
1830c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross *
1840c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * @s - sparse file cookie
1850c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * @fd - file descriptor to read from
1860c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * @sparse - read a file in the Android sparse file format
1870c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * @crc - verify the crc of a file in the Android sparse file format
1880c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross *
1890c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * Reads a file into a sparse file cookie.  If sparse is true, the file is
1900c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * assumed to be in the Android sparse file format.  If sparse is false, the
1910c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * file will be sparsed by looking for block aligned chunks of all zeros or
1920c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * another 32 bit value.  If crc is true, the crc of the sparse file will be
1930c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * verified.
1940c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross *
1950c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * Returns 0 on success, negative errno on error.
1960c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross */
1970c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Crossint sparse_file_read(struct sparse_file *s, int fd, bool sparse, bool crc);
1980c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross
1990c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross/**
2000c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * sparse_file_import - import an existing sparse file
2010c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross *
2020c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * @s - sparse file cookie
2030c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * @verbose - print verbose errors while reading the sparse file
2040c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * @crc - verify the crc of a file in the Android sparse file format
2050c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross *
2060c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * Reads an existing sparse file into a sparse file cookie, recreating the same
2070c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * sparse cookie that was used to write it.  If verbose is true, prints verbose
2080c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * errors when the sparse file is formatted incorrectly.
2090c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross *
2100c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * Returns a new sparse file cookie on success, NULL on error.
2110c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross */
2120c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Crossstruct sparse_file *sparse_file_import(int fd, bool verbose, bool crc);
2130c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross
2140c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross/**
2150c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * sparse_file_import_auto - import an existing sparse or normal file
2160c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross *
2170c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * @fd - file descriptor to read from
2180c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * @crc - verify the crc of a file in the Android sparse file format
2190c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross *
2200c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * Reads an existing sparse or normal file into a sparse file cookie.
2210c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * Attempts to determine if the file is sparse or not by looking for the sparse
2220c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * file magic number in the first 4 bytes.  If the file is not sparse, the file
2230c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * will be sparsed by looking for block aligned chunks of all zeros or another
2240c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * 32 bit value.  If crc is true, the crc of the sparse file will be verified.
2250c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross *
2260c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross * Returns a new sparse file cookie on success, NULL on error.
2270c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross */
2280c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Crossstruct sparse_file *sparse_file_import_auto(int fd, bool crc);
2290c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross
2300c4c47f88dfc15cada154a1cf9b4db88b49890f0Colin Cross/**
231a21930b6b0dbb04a52948566d58fb48c6db58babColin Cross * sparse_file_verbose - set a sparse file cookie to print verbose errors
232a21930b6b0dbb04a52948566d58fb48c6db58babColin Cross *
233a21930b6b0dbb04a52948566d58fb48c6db58babColin Cross * @s - sparse file cookie
234a21930b6b0dbb04a52948566d58fb48c6db58babColin Cross *
235a21930b6b0dbb04a52948566d58fb48c6db58babColin Cross * Print verbose sparse file errors whenever using the sparse file cookie.
236a21930b6b0dbb04a52948566d58fb48c6db58babColin Cross */
237a21930b6b0dbb04a52948566d58fb48c6db58babColin Crossvoid sparse_file_verbose(struct sparse_file *s);
238a21930b6b0dbb04a52948566d58fb48c6db58babColin Cross
239a21930b6b0dbb04a52948566d58fb48c6db58babColin Cross/**
240a21930b6b0dbb04a52948566d58fb48c6db58babColin Cross * sparse_print_verbose - function called to print verbose errors
241a21930b6b0dbb04a52948566d58fb48c6db58babColin Cross *
242a21930b6b0dbb04a52948566d58fb48c6db58babColin Cross * By default, verbose errors will print to standard error.
243a21930b6b0dbb04a52948566d58fb48c6db58babColin Cross * sparse_print_verbose may be overridden to log verbose errors somewhere else.
244a21930b6b0dbb04a52948566d58fb48c6db58babColin Cross *
245a21930b6b0dbb04a52948566d58fb48c6db58babColin Cross */
246a21930b6b0dbb04a52948566d58fb48c6db58babColin Crossextern void (*sparse_print_verbose)(const char *fmt, ...);
247a21930b6b0dbb04a52948566d58fb48c6db58babColin Cross
24828fa5bc347390480fe190294c6c385b6a9f0d68bColin Cross#endif
249