backed_block.h revision bdc6d39ed6c09199a5d806f29b71b44cbb27c5c2
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _BACKED_BLOCK_H_
18#define _BACKED_BLOCK_H_
19
20#include <stdint.h>
21
22struct backed_block_list;
23struct backed_block;
24
25enum backed_block_type {
26	BACKED_BLOCK_DATA,
27	BACKED_BLOCK_FILE,
28	BACKED_BLOCK_FD,
29	BACKED_BLOCK_FILL,
30};
31
32int backed_block_add_data(struct backed_block_list *bbl, void *data,
33		unsigned int len, unsigned int block);
34int backed_block_add_fill(struct backed_block_list *bbl, unsigned int fill_val,
35		unsigned int len, unsigned int block);
36int backed_block_add_file(struct backed_block_list *bbl, const char *filename,
37		int64_t offset, unsigned int len, unsigned int block);
38int backed_block_add_fd(struct backed_block_list *bbl, int fd,
39		int64_t offset, unsigned int len, unsigned int block);
40
41struct backed_block *backed_block_iter_new(struct backed_block_list *bbl);
42struct backed_block *backed_block_iter_next(struct backed_block *bb);
43unsigned int backed_block_len(struct backed_block *bb);
44unsigned int backed_block_block(struct backed_block *bb);
45void *backed_block_data(struct backed_block *bb);
46const char *backed_block_filename(struct backed_block *bb);
47int backed_block_fd(struct backed_block *bb);
48int64_t backed_block_file_offset(struct backed_block *bb);
49uint32_t backed_block_fill_val(struct backed_block *bb);
50enum backed_block_type backed_block_type(struct backed_block *bb);
51int backed_block_split(struct backed_block_list *bbl, struct backed_block *bb,
52		unsigned int max_len);
53
54struct backed_block *backed_block_iter_new(struct backed_block_list *bbl);
55struct backed_block *backed_block_iter_next(struct backed_block *bb);
56
57struct backed_block_list *backed_block_list_new(unsigned int block_size);
58void backed_block_list_destroy(struct backed_block_list *bbl);
59
60void backed_block_list_move(struct backed_block_list *from,
61		struct backed_block_list *to, struct backed_block *start,
62		struct backed_block *end);
63
64#endif
65