Colin Cross | 28fa5bc | 2012-05-20 13:28:05 -0700 | [diff] [blame] | 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 | |
Colin Cross | b55dcee | 2012-04-24 23:07:49 -0700 | [diff] [blame] | 20 | #include <stdint.h> |
| 21 | |
Colin Cross | 411619e | 2012-04-24 18:51:42 -0700 | [diff] [blame] | 22 | struct backed_block_list; |
Colin Cross | b55dcee | 2012-04-24 23:07:49 -0700 | [diff] [blame] | 23 | struct backed_block; |
Colin Cross | 28fa5bc | 2012-05-20 13:28:05 -0700 | [diff] [blame] | 24 | |
Colin Cross | b55dcee | 2012-04-24 23:07:49 -0700 | [diff] [blame] | 25 | enum backed_block_type { |
Jerry Zhang | 7b444f0 | 2018-06-12 16:42:09 -0700 | [diff] [blame] | 26 | BACKED_BLOCK_DATA, |
| 27 | BACKED_BLOCK_FILE, |
| 28 | BACKED_BLOCK_FD, |
| 29 | BACKED_BLOCK_FILL, |
Colin Cross | b55dcee | 2012-04-24 23:07:49 -0700 | [diff] [blame] | 30 | }; |
Colin Cross | 28fa5bc | 2012-05-20 13:28:05 -0700 | [diff] [blame] | 31 | |
Hyeongseok Kim | e8d02c5 | 2020-08-10 12:11:57 +0900 | [diff] [blame] | 32 | int backed_block_add_data(struct backed_block_list* bbl, void* data, uint64_t len, |
Jerry Zhang | 7b444f0 | 2018-06-12 16:42:09 -0700 | [diff] [blame] | 33 | unsigned int block); |
Hyeongseok Kim | e8d02c5 | 2020-08-10 12:11:57 +0900 | [diff] [blame] | 34 | int backed_block_add_fill(struct backed_block_list* bbl, unsigned int fill_val, uint64_t len, |
Jerry Zhang | 7b444f0 | 2018-06-12 16:42:09 -0700 | [diff] [blame] | 35 | unsigned int block); |
| 36 | int backed_block_add_file(struct backed_block_list* bbl, const char* filename, int64_t offset, |
Hyeongseok Kim | e8d02c5 | 2020-08-10 12:11:57 +0900 | [diff] [blame] | 37 | uint64_t len, unsigned int block); |
| 38 | int backed_block_add_fd(struct backed_block_list* bbl, int fd, int64_t offset, uint64_t len, |
Jerry Zhang | 7b444f0 | 2018-06-12 16:42:09 -0700 | [diff] [blame] | 39 | unsigned int block); |
Colin Cross | 28fa5bc | 2012-05-20 13:28:05 -0700 | [diff] [blame] | 40 | |
Jerry Zhang | 7b444f0 | 2018-06-12 16:42:09 -0700 | [diff] [blame] | 41 | struct backed_block* backed_block_iter_new(struct backed_block_list* bbl); |
| 42 | struct backed_block* backed_block_iter_next(struct backed_block* bb); |
Hyeongseok Kim | e8d02c5 | 2020-08-10 12:11:57 +0900 | [diff] [blame] | 43 | uint64_t backed_block_len(struct backed_block* bb); |
Jerry Zhang | 7b444f0 | 2018-06-12 16:42:09 -0700 | [diff] [blame] | 44 | unsigned int backed_block_block(struct backed_block* bb); |
| 45 | void* backed_block_data(struct backed_block* bb); |
| 46 | const char* backed_block_filename(struct backed_block* bb); |
| 47 | int backed_block_fd(struct backed_block* bb); |
| 48 | int64_t backed_block_file_offset(struct backed_block* bb); |
| 49 | uint32_t backed_block_fill_val(struct backed_block* bb); |
| 50 | enum backed_block_type backed_block_type(struct backed_block* bb); |
| 51 | int backed_block_split(struct backed_block_list* bbl, struct backed_block* bb, unsigned int max_len); |
Colin Cross | b55dcee | 2012-04-24 23:07:49 -0700 | [diff] [blame] | 52 | |
Jerry Zhang | 7b444f0 | 2018-06-12 16:42:09 -0700 | [diff] [blame] | 53 | struct backed_block* backed_block_iter_new(struct backed_block_list* bbl); |
| 54 | struct backed_block* backed_block_iter_next(struct backed_block* bb); |
Colin Cross | b55dcee | 2012-04-24 23:07:49 -0700 | [diff] [blame] | 55 | |
Jerry Zhang | 7b444f0 | 2018-06-12 16:42:09 -0700 | [diff] [blame] | 56 | struct backed_block_list* backed_block_list_new(unsigned int block_size); |
| 57 | void backed_block_list_destroy(struct backed_block_list* bbl); |
Colin Cross | 28fa5bc | 2012-05-20 13:28:05 -0700 | [diff] [blame] | 58 | |
Jerry Zhang | 7b444f0 | 2018-06-12 16:42:09 -0700 | [diff] [blame] | 59 | void backed_block_list_move(struct backed_block_list* from, struct backed_block_list* to, |
| 60 | struct backed_block* start, struct backed_block* end); |
Colin Cross | bdc6d39 | 2012-05-02 15:18:22 -0700 | [diff] [blame] | 61 | |
Colin Cross | 28fa5bc | 2012-05-20 13:28:05 -0700 | [diff] [blame] | 62 | #endif |