1 /* 2 * Copyright (C) 2015-2016 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 #pragma once 18 19 #include <lk/reflist.h> 20 #include <sys/types.h> 21 22 #include "block_device.h" 23 24 struct block_mac; 25 struct fs; 26 struct iv; 27 struct transaction; 28 29 enum block_read_error { 30 BLOCK_READ_SUCCESS = 0, 31 BLOCK_READ_IO_ERROR, 32 BLOCK_READ_NO_DATA, 33 }; 34 35 void block_cache_complete_read(struct block_device* dev, 36 data_block_t block, 37 const void* data, 38 size_t data_size, 39 enum block_read_error res); 40 41 enum block_write_error { 42 BLOCK_WRITE_SUCCESS = 0, 43 BLOCK_WRITE_FAILED, 44 BLOCK_WRITE_FAILED_UNKNOWN_STATE, 45 BLOCK_WRITE_SYNC_FAILED, 46 }; 47 48 void block_cache_complete_write(struct block_device* dev, 49 data_block_t block, 50 enum block_write_error res); 51 52 void block_cache_init(void); 53 54 void block_cache_dev_destroy(struct block_device* dev); 55 56 void block_cache_clean_transaction(struct transaction* tr); 57 58 void block_cache_discard_transaction(struct transaction* tr, bool discard_all); 59 60 const void* block_get_no_read(struct transaction* tr, 61 data_block_t block, 62 struct obj_ref* ref); 63 64 const void* block_get_super(struct fs* fs, 65 data_block_t block, 66 struct obj_ref* ref); 67 68 const void* block_get_super_with_mac(struct fs* fs, 69 const struct block_mac* block_mac, 70 struct obj_ref* ref); 71 72 const void* block_get_no_tr_fail(struct transaction* tr, 73 const struct block_mac* block_mac, 74 const struct iv* iv, 75 struct obj_ref* ref); 76 77 const void* block_get(struct transaction* tr, 78 const struct block_mac* block_mac, 79 const struct iv* iv, 80 struct obj_ref* ref); 81 82 void* block_dirty(struct transaction* tr, const void* data, bool is_tmp); 83 84 bool block_is_clean(struct block_device* dev, data_block_t block); 85 86 void block_discard_dirty(const void* data); 87 88 void block_discard_dirty_by_block(struct block_device* dev, data_block_t block); 89 90 void block_put_dirty(struct transaction* tr, 91 void* data, 92 struct obj_ref* data_ref, 93 struct block_mac* block_mac, 94 void* block_mac_ref); 95 96 void block_put_dirty_no_mac(void* data, 97 struct obj_ref* data_ref, 98 bool allow_tampering); 99 100 void block_put_dirty_discard(void* data, struct obj_ref* data_ref); 101 102 void* block_get_write_no_read(struct transaction* tr, 103 data_block_t block, 104 bool is_tmp, 105 struct obj_ref* ref); 106 107 void* block_get_write(struct transaction* tr, 108 const struct block_mac* block_mac, 109 const struct iv* iv, 110 bool is_tmp, 111 struct obj_ref* ref); 112 113 void* block_get_cleared(struct transaction* tr, 114 data_block_t block, 115 bool is_tmp, 116 struct obj_ref* ref); 117 118 void* block_get_cleared_super(struct transaction* tr, 119 data_block_t block, 120 struct obj_ref* ref, 121 bool pinned); 122 123 void* block_move(struct transaction* tr, 124 const void* data, 125 data_block_t block, 126 bool is_tmp); 127 128 void* block_get_copy(struct transaction* tr, 129 const void* data, 130 data_block_t block, 131 bool is_tmp, 132 struct obj_ref* new_ref); 133 134 void block_put(const void* data, struct obj_ref* ref); 135 136 bool block_probe(struct fs* fs, 137 const struct block_mac* block_mac, 138 bool allow_invalid); 139 140 data_block_t data_to_block_num(const void* data); /* test api, remove ? */ 141 142 unsigned int block_cache_debug_get_ref_block_count(void); 143