blob: 5bb689bb55618118312b47615124e2064d75ce5c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/* SPDX-License-Identifier: GPL-3.0-or-later */
#ifndef COMPRESS_H
#define COMPRESS_H
#include <sys/types.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "squashfs.h"
typedef struct compressor_t compressor_t;
/**
* @struct compressor_t
*
* @brief Encapsultes a compressor with a simple interface to compress or
* uncompress/extract blocks of data
*/
struct compressor_t {
/**
* @brief Compress or uncompress a chunk of data
*
* @param cmp A pointer to the compressor object
* @param in A pointer to the input buffer
* @param size The number of bytes in the input buffer to process
* @param out A pointer to the output buffer
* @param outsize The number of bytes available in the output buffer
*
* @return On success, the number of bytes written to the output
* buffer, -1 on failure, 0 if the output buffer was too small.
* The compressor also returns 0 if the compressed result ends
* up larger than the original input.
*/
ssize_t (*do_block)(compressor_t *cmp, const uint8_t *in, size_t size,
uint8_t *out, size_t outsize);
/**
* @brief Destroy a compressor object and free up all memory it uses
*
* @param cmp A pointer to the compressor object
*/
void (*destroy)(compressor_t *stream);
};
/**
* @brief Check if a given compressor is available
*
* @memberof compressor_t
*
* This function checks if a given compressor is available, since some
* compressors may not be supported yet, or simply disabled in the
* compile configuration.
*
* @param id A SquashFS compressor id
*
* @return true if the given compressor is available
*/
bool compressor_exists(E_SQFS_COMPRESSOR id);
/**
* @brief Create a compressor object
*
* @memberof compressor_t
*
* @param id A SquashFS compressor id
* @param compress true if the resulting object should compress data, false
* if it should actually extract already compressed blocks.
* @param block_size The configured block size for the SquashFS image. May be
* of interest to some compressors.
*
* @return A pointer to a new compressor object or NULL on failure.
*/
compressor_t *compressor_create(E_SQFS_COMPRESSOR id, bool compress,
size_t block_size);
#endif /* COMPRESS_H */
|