1 /* 2 * The internal pool functions 3 * 4 * Copyright (C) 2009-2020, Joachim Metz <joachim.metz@gmail.com> 5 * 6 * Refer to AUTHORS for acknowledgements. 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License 19 * along with this program. If not, see <https://www.gnu.org/licenses/>. 20 */ 21 22 #if !defined( _LIBBFIO_POOL_H ) 23 #define _LIBBFIO_POOL_H 24 25 #include <common.h> 26 #include <types.h> 27 28 #include "libbfio_extern.h" 29 #include "libbfio_libcdata.h" 30 #include "libbfio_libcerror.h" 31 #include "libbfio_libcthreads.h" 32 #include "libbfio_types.h" 33 34 #if defined( __cplusplus ) 35 extern "C" { 36 #endif 37 38 typedef struct libbfio_internal_pool libbfio_internal_pool_t; 39 40 struct libbfio_internal_pool 41 { 42 /* The number of used handles in the pool 43 */ 44 int number_of_used_handles; 45 46 /* The number of open handles in the pool 47 */ 48 int number_of_open_handles; 49 50 /* The maximum number of open handles in the pool 51 */ 52 int maximum_number_of_open_handles; 53 54 /* The handles array 55 */ 56 libcdata_array_t *handles_array; 57 58 /* The current entry 59 */ 60 int current_entry; 61 62 /* The current file IO handle 63 */ 64 libbfio_handle_t *current_handle; 65 66 /* A list containing the file IO handles in order of the last use 67 * it starts with the last used at the beginning of the list 68 * the value of the list element refers to the corresponding file IO handle 69 */ 70 libcdata_list_t *last_used_list; 71 72 #if defined( HAVE_MULTI_THREAD_SUPPORT ) && !defined( HAVE_LOCAL_LIBBFIO ) 73 /* The read/write lock 74 */ 75 libcthreads_read_write_lock_t *read_write_lock; 76 #endif 77 }; 78 79 LIBBFIO_EXTERN \ 80 int libbfio_pool_initialize( 81 libbfio_pool_t **pool, 82 int number_of_handles, 83 int maximum_number_of_open_handles, 84 libcerror_error_t **error ); 85 86 LIBBFIO_EXTERN \ 87 int libbfio_pool_free( 88 libbfio_pool_t **pool, 89 libcerror_error_t **error ); 90 91 LIBBFIO_EXTERN \ 92 int libbfio_pool_clone( 93 libbfio_pool_t **destination_pool, 94 libbfio_pool_t *source_pool, 95 libcerror_error_t **error ); 96 97 LIBBFIO_EXTERN \ 98 int libbfio_pool_resize( 99 libbfio_pool_t *pool, 100 int number_of_handles, 101 libcerror_error_t **error ); 102 103 int libbfio_internal_pool_open_handle( 104 libbfio_internal_pool_t *internal_pool, 105 libbfio_handle_t *handle, 106 int access_flags, 107 libcerror_error_t **error ); 108 109 int libbfio_internal_pool_append_handle_to_last_used_list( 110 libbfio_internal_pool_t *internal_pool, 111 const libbfio_handle_t *handle, 112 libcerror_error_t **error ); 113 114 int libbfio_internal_pool_move_handle_to_front_of_last_used_list( 115 libbfio_internal_pool_t *internal_pool, 116 libbfio_handle_t *handle, 117 libcerror_error_t **error ); 118 119 int libbfio_internal_pool_remove_handle_from_last_used_list( 120 libbfio_internal_pool_t *internal_pool, 121 const libbfio_handle_t *handle, 122 libcerror_error_t **error ); 123 124 LIBBFIO_EXTERN \ 125 int libbfio_pool_get_number_of_handles( 126 libbfio_pool_t *pool, 127 int *number_of_handles, 128 libcerror_error_t **error ); 129 130 LIBBFIO_EXTERN \ 131 int libbfio_pool_get_handle( 132 libbfio_pool_t *pool, 133 int entry, 134 libbfio_handle_t **handle, 135 libcerror_error_t **error ); 136 137 LIBBFIO_EXTERN \ 138 int libbfio_pool_append_handle( 139 libbfio_pool_t *pool, 140 int *entry, 141 libbfio_handle_t *handle, 142 int access_flags, 143 libcerror_error_t **error ); 144 145 LIBBFIO_EXTERN \ 146 int libbfio_pool_set_handle( 147 libbfio_pool_t *pool, 148 int entry, 149 libbfio_handle_t *handle, 150 int access_flags, 151 libcerror_error_t **error ); 152 153 LIBBFIO_EXTERN \ 154 int libbfio_pool_remove_handle( 155 libbfio_pool_t *pool, 156 int entry, 157 libbfio_handle_t **handle, 158 libcerror_error_t **error ); 159 160 LIBBFIO_EXTERN \ 161 int libbfio_pool_get_maximum_number_of_open_handles( 162 libbfio_pool_t *pool, 163 int *maximum_number_of_open_handles, 164 libcerror_error_t **error ); 165 166 LIBBFIO_EXTERN \ 167 int libbfio_pool_set_maximum_number_of_open_handles( 168 libbfio_pool_t *pool, 169 int maximum_number_of_open_handles, 170 libcerror_error_t **error ); 171 172 int libbfio_internal_pool_open( 173 libbfio_internal_pool_t *internal_pool, 174 int entry, 175 int access_flags, 176 libcerror_error_t **error ); 177 178 LIBBFIO_EXTERN \ 179 int libbfio_pool_open( 180 libbfio_pool_t *pool, 181 int entry, 182 int access_flags, 183 libcerror_error_t **error ); 184 185 LIBBFIO_EXTERN \ 186 int libbfio_pool_reopen( 187 libbfio_pool_t *pool, 188 int entry, 189 int access_flags, 190 libcerror_error_t **error ); 191 192 int libbfio_internal_pool_close( 193 libbfio_internal_pool_t *internal_pool, 194 int entry, 195 libcerror_error_t **error ); 196 197 LIBBFIO_EXTERN \ 198 int libbfio_pool_close( 199 libbfio_pool_t *pool, 200 int entry, 201 libcerror_error_t **error ); 202 203 LIBBFIO_EXTERN \ 204 int libbfio_pool_close_all( 205 libbfio_pool_t *pool, 206 libcerror_error_t **error ); 207 208 int libbfio_internal_pool_get_open_handle( 209 libbfio_internal_pool_t *internal_pool, 210 int entry, 211 libbfio_handle_t **handle, 212 libcerror_error_t **error ); 213 214 LIBBFIO_EXTERN \ 215 ssize_t libbfio_pool_read_buffer( 216 libbfio_pool_t *pool, 217 int entry, 218 uint8_t *buffer, 219 size_t size, 220 libcerror_error_t **error ); 221 222 LIBBFIO_EXTERN \ 223 ssize_t libbfio_pool_read_buffer_at_offset( 224 libbfio_pool_t *pool, 225 int entry, 226 uint8_t *buffer, 227 size_t size, 228 off64_t offset, 229 libcerror_error_t **error ); 230 231 LIBBFIO_EXTERN \ 232 ssize_t libbfio_pool_write_buffer( 233 libbfio_pool_t *pool, 234 int entry, 235 const uint8_t *buffer, 236 size_t size, 237 libcerror_error_t **error ); 238 239 LIBBFIO_EXTERN \ 240 ssize_t libbfio_pool_write_buffer_at_offset( 241 libbfio_pool_t *pool, 242 int entry, 243 const uint8_t *buffer, 244 size_t size, 245 off64_t offset, 246 libcerror_error_t **error ); 247 248 LIBBFIO_EXTERN \ 249 off64_t libbfio_pool_seek_offset( 250 libbfio_pool_t *pool, 251 int entry, 252 off64_t offset, 253 int whence, 254 libcerror_error_t **error ); 255 256 LIBBFIO_EXTERN \ 257 int libbfio_pool_get_offset( 258 libbfio_pool_t *pool, 259 int entry, 260 off64_t *offset, 261 libcerror_error_t **error ); 262 263 LIBBFIO_EXTERN \ 264 int libbfio_pool_get_size( 265 libbfio_pool_t *pool, 266 int entry, 267 size64_t *size, 268 libcerror_error_t **error ); 269 270 #if defined( __cplusplus ) 271 } 272 #endif 273 274 #endif /* !defined( _LIBBFIO_POOL_H ) */ 275 276