summaryrefslogtreecommitdiff
path: root/include/meta_writer.h
blob: 6bcb29b7e23e5152de4640d4c5cdcfdc1804f557 (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
/* SPDX-License-Identifier: GPL-3.0-or-later */
#ifndef META_WRITER_H
#define META_WRITER_H

#include "compress.h"
#include "squashfs.h"

typedef struct meta_writer_t meta_writer_t;

/**
 * @brief Create a meta data writer
 *
 * @memberof meta_writer_t
 *
 * @note This function internally prints error message to stderr on failure
 *
 * @param fd  The underlying file descriptor to write from
 * @param cmp A pointer to a compressor to use for compressing the data
 *
 * @return A pointer to a meta data writer, NULL on failure
 */
meta_writer_t *meta_writer_create(int fd, compressor_t *cmp);

/**
 * @brief Destroy a meta data writer and free all memory used by it
 *
 * @memberof meta_writer_t
 *
 * @param m A pointer to a meta data reader
 */
void meta_writer_destroy(meta_writer_t *m);

/**
 * @brief Flush the currently unfinished meta data block to disk
 *
 * @memberof meta_writer_t
 *
 * @note This function internally prints error message to stderr on failure
 *
 * If data has been collected in the block buffer but it is not complete yet,
 * this function tries to compress it and write it out anyway and reset the
 * internal counters.
 *
 * @param m A pointer to a meta data reader
 *
 * @return Zero on success, -1 on failure
 */
int meta_writer_flush(meta_writer_t *m);

/**
 * @brief Append data to the current meta data block
 *
 * @memberof meta_writer_t
 *
 * @note This function internally prints error message to stderr on failure
 *
 * This function appends the input data to an internal meta data buffer. If
 * the internal buffer is full, it is compressed and written to disk using
 * @ref meta_writer flush, i.e. the function allows for transparent writing
 * across meta data blocks.
 *
 * @param m    A pointer to a meta data reader
 * @param data A pointer to the data block to append
 * @param size The number of bytes to read from the data blob
 *
 * @return Zero on success, -1 on failure
 */
int meta_writer_append(meta_writer_t *m, const void *data, size_t size);

void meta_writer_get_position(const meta_writer_t *m, uint64_t *block_start,
			      uint32_t *offset);

void meta_writer_reset(meta_writer_t *m);

#endif /* META_WRITER_H */