Git fork
1/*
2 * Copyright 2020 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style
5 * license that can be found in the LICENSE file or at
6 * https://developers.google.com/open-source/licenses/bsd
7 */
8
9#ifndef REFTABLE_BLOCKSOURCE_H
10#define REFTABLE_BLOCKSOURCE_H
11
12#include <stdint.h>
13
14/*
15 * Generic wrapper for a seekable readable file.
16 */
17struct reftable_block_source {
18 struct reftable_block_source_vtable *ops;
19 void *arg;
20};
21
22/* a contiguous segment of bytes. It keeps track of its generating block_source
23 * so it can return itself into the pool. */
24struct reftable_block_data {
25 uint8_t *data;
26 size_t len;
27 struct reftable_block_source source;
28};
29
30/* block_source_vtable are the operations that make up block_source */
31struct reftable_block_source_vtable {
32 /* Returns the size of a block source. */
33 uint64_t (*size)(void *source);
34
35 /*
36 * Reads a segment from the block source. It is an error to read beyond
37 * the end of the block.
38 */
39 ssize_t (*read_data)(void *source, struct reftable_block_data *dest,
40 uint64_t off, uint32_t size);
41
42 /* Mark the block as read; may release the data. */
43 void (*release_data)(void *source, struct reftable_block_data *data);
44
45 /* Release all resources associated with the block source. */
46 void (*close)(void *source);
47};
48
49/* opens a file on the file system as a block_source */
50int reftable_block_source_from_file(struct reftable_block_source *block_src,
51 const char *name);
52
53#endif