/src/libvshadow/libvshadow/libvshadow_store.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Store functions |
3 | | * |
4 | | * Copyright (C) 2011-2023, 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 | | #include <common.h> |
23 | | #include <memory.h> |
24 | | #include <types.h> |
25 | | |
26 | | #include "libvshadow_block.h" |
27 | | #include "libvshadow_block_descriptor.h" |
28 | | #include "libvshadow_block_tree.h" |
29 | | #include "libvshadow_definitions.h" |
30 | | #include "libvshadow_libbfio.h" |
31 | | #include "libvshadow_libcdata.h" |
32 | | #include "libvshadow_libcerror.h" |
33 | | #include "libvshadow_libcthreads.h" |
34 | | #include "libvshadow_store.h" |
35 | | #include "libvshadow_store_descriptor.h" |
36 | | #include "libvshadow_volume.h" |
37 | | |
38 | | /* Creates a store |
39 | | * Make sure the value store is referencing, is set to NULL |
40 | | * Returns 1 if successful or -1 on error |
41 | | */ |
42 | | int libvshadow_store_initialize( |
43 | | libvshadow_store_t **store, |
44 | | libvshadow_io_handle_t *io_handle, |
45 | | libbfio_handle_t *file_io_handle, |
46 | | libvshadow_internal_volume_t *internal_volume, |
47 | | int store_descriptor_index, |
48 | | libcerror_error_t **error ) |
49 | 0 | { |
50 | 0 | libvshadow_internal_store_t *internal_store = NULL; |
51 | 0 | libvshadow_store_descriptor_t *store_descriptor = NULL; |
52 | 0 | static char *function = "libvshadow_store_initialize"; |
53 | |
|
54 | 0 | if( store == NULL ) |
55 | 0 | { |
56 | 0 | libcerror_error_set( |
57 | 0 | error, |
58 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
59 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
60 | 0 | "%s: invalid store.", |
61 | 0 | function ); |
62 | |
|
63 | 0 | return( -1 ); |
64 | 0 | } |
65 | 0 | if( *store != NULL ) |
66 | 0 | { |
67 | 0 | libcerror_error_set( |
68 | 0 | error, |
69 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
70 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
71 | 0 | "%s: invalid store value already set.", |
72 | 0 | function ); |
73 | |
|
74 | 0 | return( -1 ); |
75 | 0 | } |
76 | 0 | if( io_handle == NULL ) |
77 | 0 | { |
78 | 0 | libcerror_error_set( |
79 | 0 | error, |
80 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
81 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
82 | 0 | "%s: invalid IO handle.", |
83 | 0 | function ); |
84 | |
|
85 | 0 | return( -1 ); |
86 | 0 | } |
87 | 0 | if( internal_volume == NULL ) |
88 | 0 | { |
89 | 0 | libcerror_error_set( |
90 | 0 | error, |
91 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
92 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
93 | 0 | "%s: invalid volume.", |
94 | 0 | function ); |
95 | |
|
96 | 0 | return( -1 ); |
97 | 0 | } |
98 | | /* Make sure there is a store descriptor for the store |
99 | | */ |
100 | 0 | if( libcdata_array_get_entry_by_index( |
101 | 0 | internal_volume->store_descriptors_array, |
102 | 0 | store_descriptor_index, |
103 | 0 | (intptr_t **) &store_descriptor, |
104 | 0 | error ) != 1 ) |
105 | 0 | { |
106 | 0 | libcerror_error_set( |
107 | 0 | error, |
108 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
109 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
110 | 0 | "%s: unable to retrieve store descriptor: %d.", |
111 | 0 | function, |
112 | 0 | store_descriptor_index ); |
113 | |
|
114 | 0 | return( -1 ); |
115 | 0 | } |
116 | 0 | internal_store = memory_allocate_structure( |
117 | 0 | libvshadow_internal_store_t ); |
118 | |
|
119 | 0 | if( internal_store == NULL ) |
120 | 0 | { |
121 | 0 | libcerror_error_set( |
122 | 0 | error, |
123 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
124 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
125 | 0 | "%s: unable to create store.", |
126 | 0 | function ); |
127 | |
|
128 | 0 | goto on_error; |
129 | 0 | } |
130 | 0 | if( memory_set( |
131 | 0 | internal_store, |
132 | 0 | 0, |
133 | 0 | sizeof( libvshadow_internal_store_t ) ) == NULL ) |
134 | 0 | { |
135 | 0 | libcerror_error_set( |
136 | 0 | error, |
137 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
138 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
139 | 0 | "%s: unable to clear store.", |
140 | 0 | function ); |
141 | |
|
142 | 0 | memory_free( |
143 | 0 | internal_store ); |
144 | |
|
145 | 0 | return( -1 ); |
146 | 0 | } |
147 | 0 | #if defined( HAVE_LIBVSHADOW_MULTI_THREAD_SUPPORT ) |
148 | 0 | if( libcthreads_read_write_lock_initialize( |
149 | 0 | &( internal_store->read_write_lock ), |
150 | 0 | error ) != 1 ) |
151 | 0 | { |
152 | 0 | libcerror_error_set( |
153 | 0 | error, |
154 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
155 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
156 | 0 | "%s: unable to initialize read/write lock.", |
157 | 0 | function ); |
158 | |
|
159 | 0 | goto on_error; |
160 | 0 | } |
161 | 0 | #endif |
162 | 0 | internal_store->file_io_handle = file_io_handle; |
163 | 0 | internal_store->io_handle = io_handle; |
164 | 0 | internal_store->internal_volume = internal_volume; |
165 | 0 | internal_store->store_descriptor = store_descriptor; |
166 | 0 | internal_store->store_descriptor_index = store_descriptor_index; |
167 | |
|
168 | 0 | *store = (libvshadow_store_t *) internal_store; |
169 | |
|
170 | 0 | return( 1 ); |
171 | | |
172 | 0 | on_error: |
173 | 0 | if( internal_store != NULL ) |
174 | 0 | { |
175 | 0 | memory_free( |
176 | 0 | internal_store ); |
177 | 0 | } |
178 | 0 | return( -1 ); |
179 | 0 | } |
180 | | |
181 | | /* Frees a store |
182 | | * Returns 1 if successful or -1 on error |
183 | | */ |
184 | | int libvshadow_store_free( |
185 | | libvshadow_store_t **store, |
186 | | libcerror_error_t **error ) |
187 | 0 | { |
188 | 0 | libvshadow_internal_store_t *internal_store = NULL; |
189 | 0 | static char *function = "libvshadow_store_free"; |
190 | 0 | int result = 1; |
191 | |
|
192 | 0 | if( store == NULL ) |
193 | 0 | { |
194 | 0 | libcerror_error_set( |
195 | 0 | error, |
196 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
197 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
198 | 0 | "%s: invalid store.", |
199 | 0 | function ); |
200 | |
|
201 | 0 | return( -1 ); |
202 | 0 | } |
203 | 0 | if( *store != NULL ) |
204 | 0 | { |
205 | 0 | internal_store = (libvshadow_internal_store_t *) *store; |
206 | 0 | *store = NULL; |
207 | | |
208 | | /* The file_io_handle, io_handle and internal_volume references are freed elsewhere |
209 | | */ |
210 | 0 | #if defined( HAVE_LIBVSHADOW_MULTI_THREAD_SUPPORT ) |
211 | 0 | if( libcthreads_read_write_lock_free( |
212 | 0 | &( internal_store->read_write_lock ), |
213 | 0 | error ) != 1 ) |
214 | 0 | { |
215 | 0 | libcerror_error_set( |
216 | 0 | error, |
217 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
218 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
219 | 0 | "%s: unable to free read/write lock.", |
220 | 0 | function ); |
221 | |
|
222 | 0 | result = -1; |
223 | 0 | } |
224 | 0 | #endif |
225 | 0 | memory_free( |
226 | 0 | internal_store ); |
227 | 0 | } |
228 | 0 | return( result ); |
229 | 0 | } |
230 | | |
231 | | /* Determines if the store has in-volume data |
232 | | * Returns 1 if the store has in-volume data, 0 if not or -1 on error |
233 | | */ |
234 | | int libvshadow_store_has_in_volume_data( |
235 | | libvshadow_store_t *store, |
236 | | libcerror_error_t **error ) |
237 | 0 | { |
238 | 0 | libvshadow_internal_store_t *internal_store = NULL; |
239 | 0 | static char *function = "libvshadow_store_has_in_volume_data"; |
240 | 0 | int result = 0; |
241 | |
|
242 | 0 | if( store == NULL ) |
243 | 0 | { |
244 | 0 | libcerror_error_set( |
245 | 0 | error, |
246 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
247 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
248 | 0 | "%s: invalid store.", |
249 | 0 | function ); |
250 | |
|
251 | 0 | return( -1 ); |
252 | 0 | } |
253 | 0 | internal_store = (libvshadow_internal_store_t *) store; |
254 | |
|
255 | 0 | if( internal_store->internal_volume == NULL ) |
256 | 0 | { |
257 | 0 | libcerror_error_set( |
258 | 0 | error, |
259 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
260 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
261 | 0 | "%s: invalid store - missing internal volume.", |
262 | 0 | function ); |
263 | |
|
264 | 0 | return( -1 ); |
265 | 0 | } |
266 | 0 | result = libvshadow_store_descriptor_has_in_volume_data( |
267 | 0 | internal_store->store_descriptor, |
268 | 0 | error ); |
269 | |
|
270 | 0 | if( result == -1 ) |
271 | 0 | { |
272 | 0 | libcerror_error_set( |
273 | 0 | error, |
274 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
275 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
276 | 0 | "%s: unable to determine if store descriptor: %d has in-volume data.", |
277 | 0 | function, |
278 | 0 | internal_store->store_descriptor_index ); |
279 | |
|
280 | 0 | return( -1 ); |
281 | 0 | } |
282 | 0 | return( result ); |
283 | 0 | } |
284 | | |
285 | | /* Reads (store) data at the current offset into a buffer using a Basic File IO (bfio) handle |
286 | | * This function is not multi-thread safe acquire write lock before call |
287 | | * Returns the number of bytes read or -1 on error |
288 | | */ |
289 | | ssize_t libvshadow_internal_store_read_buffer_from_file_io_handle( |
290 | | libvshadow_internal_store_t *internal_store, |
291 | | libbfio_handle_t *file_io_handle, |
292 | | void *buffer, |
293 | | size_t buffer_size, |
294 | | libcerror_error_t **error ) |
295 | 0 | { |
296 | 0 | static char *function = "libvshadow_internal_store_read_buffer_from_file_io_handle"; |
297 | 0 | ssize_t read_count = 0; |
298 | |
|
299 | 0 | if( internal_store == NULL ) |
300 | 0 | { |
301 | 0 | libcerror_error_set( |
302 | 0 | error, |
303 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
304 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
305 | 0 | "%s: invalid store.", |
306 | 0 | function ); |
307 | |
|
308 | 0 | return( -1 ); |
309 | 0 | } |
310 | 0 | if( internal_store->internal_volume == NULL ) |
311 | 0 | { |
312 | 0 | libcerror_error_set( |
313 | 0 | error, |
314 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
315 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
316 | 0 | "%s: invalid store - missing internal volume.", |
317 | 0 | function ); |
318 | |
|
319 | 0 | return( -1 ); |
320 | 0 | } |
321 | 0 | if( internal_store->current_offset < 0 ) |
322 | 0 | { |
323 | 0 | libcerror_error_set( |
324 | 0 | error, |
325 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
326 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
327 | 0 | "%s: invalid store - current offset value out of bounds.", |
328 | 0 | function ); |
329 | |
|
330 | 0 | return( -1 ); |
331 | 0 | } |
332 | 0 | if( buffer == NULL ) |
333 | 0 | { |
334 | 0 | libcerror_error_set( |
335 | 0 | error, |
336 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
337 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
338 | 0 | "%s: invalid buffer.", |
339 | 0 | function ); |
340 | |
|
341 | 0 | return( -1 ); |
342 | 0 | } |
343 | 0 | if( buffer_size > (size_t) SSIZE_MAX ) |
344 | 0 | { |
345 | 0 | libcerror_error_set( |
346 | 0 | error, |
347 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
348 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
349 | 0 | "%s: invalid element data size value exceeds maximum.", |
350 | 0 | function ); |
351 | |
|
352 | 0 | return( -1 ); |
353 | 0 | } |
354 | 0 | if( ( buffer_size == 0 ) |
355 | 0 | || ( (size64_t) internal_store->current_offset >= internal_store->internal_volume->size ) ) |
356 | 0 | { |
357 | 0 | return( 0 ); |
358 | 0 | } |
359 | 0 | if( (size64_t) buffer_size > ( internal_store->internal_volume->size - internal_store->current_offset ) ) |
360 | 0 | { |
361 | 0 | buffer_size = (size_t) ( internal_store->internal_volume->size - internal_store->current_offset ); |
362 | 0 | } |
363 | 0 | read_count = libvshadow_store_descriptor_read_buffer( |
364 | 0 | internal_store->store_descriptor, |
365 | 0 | internal_store->io_handle, |
366 | 0 | file_io_handle, |
367 | 0 | (uint8_t *) buffer, |
368 | 0 | buffer_size, |
369 | 0 | internal_store->current_offset, |
370 | 0 | internal_store->store_descriptor_index, |
371 | 0 | error ); |
372 | |
|
373 | 0 | if( read_count != (ssize_t) buffer_size ) |
374 | 0 | { |
375 | 0 | libcerror_error_set( |
376 | 0 | error, |
377 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
378 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
379 | 0 | "%s: unable to read buffer from store descriptor: %d.", |
380 | 0 | function, |
381 | 0 | internal_store->store_descriptor_index ); |
382 | |
|
383 | 0 | return( -1 ); |
384 | 0 | } |
385 | 0 | internal_store->current_offset += read_count; |
386 | |
|
387 | 0 | return( read_count ); |
388 | 0 | } |
389 | | |
390 | | /* Reads (store) data at the current offset into a buffer |
391 | | * Returns the number of bytes read or -1 on error |
392 | | */ |
393 | | ssize_t libvshadow_store_read_buffer( |
394 | | libvshadow_store_t *store, |
395 | | void *buffer, |
396 | | size_t buffer_size, |
397 | | libcerror_error_t **error ) |
398 | 0 | { |
399 | 0 | libvshadow_internal_store_t *internal_store = NULL; |
400 | 0 | static char *function = "libvshadow_store_read_buffer"; |
401 | 0 | ssize_t read_count = 0; |
402 | |
|
403 | 0 | if( store == NULL ) |
404 | 0 | { |
405 | 0 | libcerror_error_set( |
406 | 0 | error, |
407 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
408 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
409 | 0 | "%s: invalid store.", |
410 | 0 | function ); |
411 | |
|
412 | 0 | return( -1 ); |
413 | 0 | } |
414 | 0 | internal_store = (libvshadow_internal_store_t *) store; |
415 | |
|
416 | 0 | #if defined( HAVE_LIBVSHADOW_MULTI_THREAD_SUPPORT ) |
417 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
418 | 0 | internal_store->read_write_lock, |
419 | 0 | error ) != 1 ) |
420 | 0 | { |
421 | 0 | libcerror_error_set( |
422 | 0 | error, |
423 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
424 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
425 | 0 | "%s: unable to grab read/write lock for writing.", |
426 | 0 | function ); |
427 | |
|
428 | 0 | return( -1 ); |
429 | 0 | } |
430 | 0 | #endif |
431 | 0 | read_count = libvshadow_internal_store_read_buffer_from_file_io_handle( |
432 | 0 | internal_store, |
433 | 0 | internal_store->file_io_handle, |
434 | 0 | buffer, |
435 | 0 | buffer_size, |
436 | 0 | error ); |
437 | |
|
438 | 0 | if( read_count == -1 ) |
439 | 0 | { |
440 | 0 | libcerror_error_set( |
441 | 0 | error, |
442 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
443 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
444 | 0 | "%s: unable to read buffer.", |
445 | 0 | function ); |
446 | |
|
447 | 0 | read_count = -1; |
448 | 0 | } |
449 | 0 | #if defined( HAVE_LIBVSHADOW_MULTI_THREAD_SUPPORT ) |
450 | 0 | if( libcthreads_read_write_lock_release_for_write( |
451 | 0 | internal_store->read_write_lock, |
452 | 0 | error ) != 1 ) |
453 | 0 | { |
454 | 0 | libcerror_error_set( |
455 | 0 | error, |
456 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
457 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
458 | 0 | "%s: unable to release read/write lock for writing.", |
459 | 0 | function ); |
460 | |
|
461 | 0 | return( -1 ); |
462 | 0 | } |
463 | 0 | #endif |
464 | 0 | return( read_count ); |
465 | 0 | } |
466 | | |
467 | | /* Reads (store) data at the current offset into a buffer using a Basic File IO (bfio) handle |
468 | | * Returns the number of bytes read or -1 on error |
469 | | */ |
470 | | ssize_t libvshadow_store_read_buffer_from_file_io_handle( |
471 | | libvshadow_store_t *store, |
472 | | libbfio_handle_t *file_io_handle, |
473 | | void *buffer, |
474 | | size_t buffer_size, |
475 | | libcerror_error_t **error ) |
476 | 0 | { |
477 | 0 | libvshadow_internal_store_t *internal_store = NULL; |
478 | 0 | static char *function = "libvshadow_store_read_buffer_from_file_io_handle"; |
479 | 0 | ssize_t read_count = 0; |
480 | |
|
481 | 0 | if( store == NULL ) |
482 | 0 | { |
483 | 0 | libcerror_error_set( |
484 | 0 | error, |
485 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
486 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
487 | 0 | "%s: invalid store.", |
488 | 0 | function ); |
489 | |
|
490 | 0 | return( -1 ); |
491 | 0 | } |
492 | 0 | internal_store = (libvshadow_internal_store_t *) store; |
493 | |
|
494 | 0 | #if defined( HAVE_LIBVSHADOW_MULTI_THREAD_SUPPORT ) |
495 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
496 | 0 | internal_store->read_write_lock, |
497 | 0 | error ) != 1 ) |
498 | 0 | { |
499 | 0 | libcerror_error_set( |
500 | 0 | error, |
501 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
502 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
503 | 0 | "%s: unable to grab read/write lock for writing.", |
504 | 0 | function ); |
505 | |
|
506 | 0 | return( -1 ); |
507 | 0 | } |
508 | 0 | #endif |
509 | 0 | read_count = libvshadow_internal_store_read_buffer_from_file_io_handle( |
510 | 0 | internal_store, |
511 | 0 | file_io_handle, |
512 | 0 | buffer, |
513 | 0 | buffer_size, |
514 | 0 | error ); |
515 | |
|
516 | 0 | if( read_count == -1 ) |
517 | 0 | { |
518 | 0 | libcerror_error_set( |
519 | 0 | error, |
520 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
521 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
522 | 0 | "%s: unable to read buffer.", |
523 | 0 | function ); |
524 | |
|
525 | 0 | read_count = -1; |
526 | 0 | } |
527 | 0 | #if defined( HAVE_LIBVSHADOW_MULTI_THREAD_SUPPORT ) |
528 | 0 | if( libcthreads_read_write_lock_release_for_write( |
529 | 0 | internal_store->read_write_lock, |
530 | 0 | error ) != 1 ) |
531 | 0 | { |
532 | 0 | libcerror_error_set( |
533 | 0 | error, |
534 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
535 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
536 | 0 | "%s: unable to release read/write lock for writing.", |
537 | 0 | function ); |
538 | |
|
539 | 0 | return( -1 ); |
540 | 0 | } |
541 | 0 | #endif |
542 | 0 | return( read_count ); |
543 | 0 | } |
544 | | |
545 | | /* Reads (store) data at a specific offset |
546 | | * Returns the number of bytes read or -1 on error |
547 | | */ |
548 | | ssize_t libvshadow_store_read_buffer_at_offset( |
549 | | libvshadow_store_t *store, |
550 | | void *buffer, |
551 | | size_t buffer_size, |
552 | | off64_t offset, |
553 | | libcerror_error_t **error ) |
554 | 0 | { |
555 | 0 | libvshadow_internal_store_t *internal_store = NULL; |
556 | 0 | static char *function = "libvshadow_store_read_buffer_at_offset"; |
557 | 0 | ssize_t read_count = 0; |
558 | |
|
559 | 0 | if( store == NULL ) |
560 | 0 | { |
561 | 0 | libcerror_error_set( |
562 | 0 | error, |
563 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
564 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
565 | 0 | "%s: invalid store.", |
566 | 0 | function ); |
567 | |
|
568 | 0 | return( -1 ); |
569 | 0 | } |
570 | 0 | internal_store = (libvshadow_internal_store_t *) store; |
571 | |
|
572 | 0 | #if defined( HAVE_LIBVSHADOW_MULTI_THREAD_SUPPORT ) |
573 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
574 | 0 | internal_store->read_write_lock, |
575 | 0 | error ) != 1 ) |
576 | 0 | { |
577 | 0 | libcerror_error_set( |
578 | 0 | error, |
579 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
580 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
581 | 0 | "%s: unable to grab read/write lock for writing.", |
582 | 0 | function ); |
583 | |
|
584 | 0 | return( -1 ); |
585 | 0 | } |
586 | 0 | #endif |
587 | 0 | if( libvshadow_internal_store_seek_offset( |
588 | 0 | internal_store, |
589 | 0 | offset, |
590 | 0 | SEEK_SET, |
591 | 0 | error ) == -1 ) |
592 | 0 | { |
593 | 0 | libcerror_error_set( |
594 | 0 | error, |
595 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
596 | 0 | LIBCERROR_IO_ERROR_SEEK_FAILED, |
597 | 0 | "%s: unable to seek offset.", |
598 | 0 | function ); |
599 | |
|
600 | 0 | read_count = -1; |
601 | 0 | } |
602 | 0 | else |
603 | 0 | { |
604 | 0 | read_count = libvshadow_internal_store_read_buffer_from_file_io_handle( |
605 | 0 | internal_store, |
606 | 0 | internal_store->file_io_handle, |
607 | 0 | buffer, |
608 | 0 | buffer_size, |
609 | 0 | error ); |
610 | |
|
611 | 0 | if( read_count == -1 ) |
612 | 0 | { |
613 | 0 | libcerror_error_set( |
614 | 0 | error, |
615 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
616 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
617 | 0 | "%s: unable to read buffer.", |
618 | 0 | function ); |
619 | |
|
620 | 0 | read_count = -1; |
621 | 0 | } |
622 | 0 | } |
623 | 0 | #if defined( HAVE_LIBVSHADOW_MULTI_THREAD_SUPPORT ) |
624 | 0 | if( libcthreads_read_write_lock_release_for_write( |
625 | 0 | internal_store->read_write_lock, |
626 | 0 | error ) != 1 ) |
627 | 0 | { |
628 | 0 | libcerror_error_set( |
629 | 0 | error, |
630 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
631 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
632 | 0 | "%s: unable to release read/write lock for writing.", |
633 | 0 | function ); |
634 | |
|
635 | 0 | return( -1 ); |
636 | 0 | } |
637 | 0 | #endif |
638 | 0 | return( read_count ); |
639 | 0 | } |
640 | | |
641 | | /* Seeks a certain offset of the (store) data |
642 | | * This function is not multi-thread safe acquire write lock before call |
643 | | * Returns the offset if seek is successful or -1 on error |
644 | | */ |
645 | | off64_t libvshadow_internal_store_seek_offset( |
646 | | libvshadow_internal_store_t *internal_store, |
647 | | off64_t offset, |
648 | | int whence, |
649 | | libcerror_error_t **error ) |
650 | 0 | { |
651 | 0 | static char *function = "libvshadow_internal_store_seek_offset"; |
652 | |
|
653 | 0 | if( internal_store == NULL ) |
654 | 0 | { |
655 | 0 | libcerror_error_set( |
656 | 0 | error, |
657 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
658 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
659 | 0 | "%s: invalid store.", |
660 | 0 | function ); |
661 | |
|
662 | 0 | return( -1 ); |
663 | 0 | } |
664 | 0 | if( internal_store->internal_volume == NULL ) |
665 | 0 | { |
666 | 0 | libcerror_error_set( |
667 | 0 | error, |
668 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
669 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
670 | 0 | "%s: invalid store - missing internal volume.", |
671 | 0 | function ); |
672 | |
|
673 | 0 | return( -1 ); |
674 | 0 | } |
675 | 0 | if( ( whence != SEEK_CUR ) |
676 | 0 | && ( whence != SEEK_END ) |
677 | 0 | && ( whence != SEEK_SET ) ) |
678 | 0 | { |
679 | 0 | libcerror_error_set( |
680 | 0 | error, |
681 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
682 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
683 | 0 | "%s: unsupported whence.", |
684 | 0 | function ); |
685 | |
|
686 | 0 | return( -1 ); |
687 | 0 | } |
688 | 0 | if( whence == SEEK_CUR ) |
689 | 0 | { |
690 | 0 | offset += internal_store->current_offset; |
691 | 0 | } |
692 | 0 | else if( whence == SEEK_END ) |
693 | 0 | { |
694 | 0 | offset += (off64_t) internal_store->internal_volume->size; |
695 | 0 | } |
696 | 0 | if( offset < 0 ) |
697 | 0 | { |
698 | 0 | libcerror_error_set( |
699 | 0 | error, |
700 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
701 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
702 | 0 | "%s: invalid offset value out of bounds.", |
703 | 0 | function ); |
704 | |
|
705 | 0 | return( -1 ); |
706 | 0 | } |
707 | 0 | internal_store->current_offset = offset; |
708 | |
|
709 | 0 | return( offset ); |
710 | 0 | } |
711 | | |
712 | | /* Seeks a certain offset of the (store) data |
713 | | * Returns the offset if seek is successful or -1 on error |
714 | | */ |
715 | | off64_t libvshadow_store_seek_offset( |
716 | | libvshadow_store_t *store, |
717 | | off64_t offset, |
718 | | int whence, |
719 | | libcerror_error_t **error ) |
720 | 0 | { |
721 | 0 | libvshadow_internal_store_t *internal_store = NULL; |
722 | 0 | static char *function = "libvshadow_store_seek_offset"; |
723 | |
|
724 | 0 | if( store == NULL ) |
725 | 0 | { |
726 | 0 | libcerror_error_set( |
727 | 0 | error, |
728 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
729 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
730 | 0 | "%s: invalid store.", |
731 | 0 | function ); |
732 | |
|
733 | 0 | return( -1 ); |
734 | 0 | } |
735 | 0 | internal_store = (libvshadow_internal_store_t *) store; |
736 | |
|
737 | 0 | #if defined( HAVE_LIBVSHADOW_MULTI_THREAD_SUPPORT ) |
738 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
739 | 0 | internal_store->read_write_lock, |
740 | 0 | error ) != 1 ) |
741 | 0 | { |
742 | 0 | libcerror_error_set( |
743 | 0 | error, |
744 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
745 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
746 | 0 | "%s: unable to grab read/write lock for writing.", |
747 | 0 | function ); |
748 | |
|
749 | 0 | return( -1 ); |
750 | 0 | } |
751 | 0 | #endif |
752 | 0 | offset = libvshadow_internal_store_seek_offset( |
753 | 0 | internal_store, |
754 | 0 | offset, |
755 | 0 | whence, |
756 | 0 | error ); |
757 | |
|
758 | 0 | if( offset == -1 ) |
759 | 0 | { |
760 | 0 | libcerror_error_set( |
761 | 0 | error, |
762 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
763 | 0 | LIBCERROR_IO_ERROR_SEEK_FAILED, |
764 | 0 | "%s: unable to seek offset.", |
765 | 0 | function ); |
766 | |
|
767 | 0 | offset = -1; |
768 | 0 | } |
769 | 0 | #if defined( HAVE_LIBVSHADOW_MULTI_THREAD_SUPPORT ) |
770 | 0 | if( libcthreads_read_write_lock_release_for_write( |
771 | 0 | internal_store->read_write_lock, |
772 | 0 | error ) != 1 ) |
773 | 0 | { |
774 | 0 | libcerror_error_set( |
775 | 0 | error, |
776 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
777 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
778 | 0 | "%s: unable to release read/write lock for writing.", |
779 | 0 | function ); |
780 | |
|
781 | 0 | return( -1 ); |
782 | 0 | } |
783 | 0 | #endif |
784 | 0 | return( offset ); |
785 | 0 | } |
786 | | |
787 | | /* Retrieves the current offset of the (store) data |
788 | | * Returns 1 if successful or -1 on error |
789 | | */ |
790 | | int libvshadow_store_get_offset( |
791 | | libvshadow_store_t *store, |
792 | | off64_t *offset, |
793 | | libcerror_error_t **error ) |
794 | 0 | { |
795 | 0 | libvshadow_internal_store_t *internal_store = NULL; |
796 | 0 | static char *function = "libvshadow_store_get_offset"; |
797 | |
|
798 | 0 | if( store == NULL ) |
799 | 0 | { |
800 | 0 | libcerror_error_set( |
801 | 0 | error, |
802 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
803 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
804 | 0 | "%s: invalid store.", |
805 | 0 | function ); |
806 | |
|
807 | 0 | return( -1 ); |
808 | 0 | } |
809 | 0 | internal_store = (libvshadow_internal_store_t *) store; |
810 | |
|
811 | 0 | if( offset == NULL ) |
812 | 0 | { |
813 | 0 | libcerror_error_set( |
814 | 0 | error, |
815 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
816 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
817 | 0 | "%s: invalid offset.", |
818 | 0 | function ); |
819 | |
|
820 | 0 | return( -1 ); |
821 | 0 | } |
822 | 0 | #if defined( HAVE_LIBVSHADOW_MULTI_THREAD_SUPPORT ) |
823 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
824 | 0 | internal_store->read_write_lock, |
825 | 0 | error ) != 1 ) |
826 | 0 | { |
827 | 0 | libcerror_error_set( |
828 | 0 | error, |
829 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
830 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
831 | 0 | "%s: unable to grab read/write lock for reading.", |
832 | 0 | function ); |
833 | |
|
834 | 0 | return( -1 ); |
835 | 0 | } |
836 | 0 | #endif |
837 | 0 | *offset = internal_store->current_offset; |
838 | |
|
839 | 0 | #if defined( HAVE_LIBVSHADOW_MULTI_THREAD_SUPPORT ) |
840 | 0 | if( libcthreads_read_write_lock_release_for_read( |
841 | 0 | internal_store->read_write_lock, |
842 | 0 | error ) != 1 ) |
843 | 0 | { |
844 | 0 | libcerror_error_set( |
845 | 0 | error, |
846 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
847 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
848 | 0 | "%s: unable to release read/write lock for reading.", |
849 | 0 | function ); |
850 | |
|
851 | 0 | return( -1 ); |
852 | 0 | } |
853 | 0 | #endif |
854 | 0 | return( 1 ); |
855 | 0 | } |
856 | | |
857 | | /* Retrieves the size |
858 | | * Returns 1 if successful or -1 on error |
859 | | */ |
860 | | int libvshadow_store_get_size( |
861 | | libvshadow_store_t *store, |
862 | | size64_t *size, |
863 | | libcerror_error_t **error ) |
864 | 0 | { |
865 | 0 | libvshadow_internal_store_t *internal_store = NULL; |
866 | 0 | static char *function = "libvshadow_store_get_size"; |
867 | |
|
868 | 0 | if( store == NULL ) |
869 | 0 | { |
870 | 0 | libcerror_error_set( |
871 | 0 | error, |
872 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
873 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
874 | 0 | "%s: invalid store.", |
875 | 0 | function ); |
876 | |
|
877 | 0 | return( -1 ); |
878 | 0 | } |
879 | 0 | internal_store = (libvshadow_internal_store_t *) store; |
880 | |
|
881 | 0 | if( libvshadow_volume_get_size( |
882 | 0 | (libvshadow_volume_t *) internal_store->internal_volume, |
883 | 0 | size, |
884 | 0 | error ) != 1 ) |
885 | 0 | { |
886 | 0 | libcerror_error_set( |
887 | 0 | error, |
888 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
889 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
890 | 0 | "%s: unable to retrieve size from volume.", |
891 | 0 | function ); |
892 | |
|
893 | 0 | return( -1 ); |
894 | 0 | } |
895 | 0 | return( 1 ); |
896 | 0 | } |
897 | | |
898 | | /* Retrieves the volume size as stored in the store information |
899 | | * Returns 1 if successful or -1 on error |
900 | | */ |
901 | | int libvshadow_store_get_volume_size( |
902 | | libvshadow_store_t *store, |
903 | | size64_t *volume_size, |
904 | | libcerror_error_t **error ) |
905 | 0 | { |
906 | 0 | libvshadow_internal_store_t *internal_store = NULL; |
907 | 0 | static char *function = "libvshadow_store_get_volume_size"; |
908 | |
|
909 | 0 | if( store == NULL ) |
910 | 0 | { |
911 | 0 | libcerror_error_set( |
912 | 0 | error, |
913 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
914 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
915 | 0 | "%s: invalid store.", |
916 | 0 | function ); |
917 | |
|
918 | 0 | return( -1 ); |
919 | 0 | } |
920 | 0 | internal_store = (libvshadow_internal_store_t *) store; |
921 | |
|
922 | 0 | if( internal_store->internal_volume == NULL ) |
923 | 0 | { |
924 | 0 | libcerror_error_set( |
925 | 0 | error, |
926 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
927 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
928 | 0 | "%s: invalid store - missing internal volume.", |
929 | 0 | function ); |
930 | |
|
931 | 0 | return( -1 ); |
932 | 0 | } |
933 | 0 | if( libvshadow_store_descriptor_get_volume_size( |
934 | 0 | internal_store->store_descriptor, |
935 | 0 | volume_size, |
936 | 0 | error ) != 1 ) |
937 | 0 | { |
938 | 0 | libcerror_error_set( |
939 | 0 | error, |
940 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
941 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
942 | 0 | "%s: unable to retrieve volume size from store descriptor: %d.", |
943 | 0 | function, |
944 | 0 | internal_store->store_descriptor_index ); |
945 | |
|
946 | 0 | return( -1 ); |
947 | 0 | } |
948 | 0 | return( 1 ); |
949 | 0 | } |
950 | | |
951 | | /* Retrieves the identifier |
952 | | * Returns 1 if successful or -1 on error |
953 | | */ |
954 | | int libvshadow_store_get_identifier( |
955 | | libvshadow_store_t *store, |
956 | | uint8_t *guid, |
957 | | size_t size, |
958 | | libcerror_error_t **error ) |
959 | 0 | { |
960 | 0 | libvshadow_internal_store_t *internal_store = NULL; |
961 | 0 | static char *function = "libvshadow_store_get_identifier"; |
962 | |
|
963 | 0 | if( store == NULL ) |
964 | 0 | { |
965 | 0 | libcerror_error_set( |
966 | 0 | error, |
967 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
968 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
969 | 0 | "%s: invalid store.", |
970 | 0 | function ); |
971 | |
|
972 | 0 | return( -1 ); |
973 | 0 | } |
974 | 0 | internal_store = (libvshadow_internal_store_t *) store; |
975 | |
|
976 | 0 | if( internal_store->internal_volume == NULL ) |
977 | 0 | { |
978 | 0 | libcerror_error_set( |
979 | 0 | error, |
980 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
981 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
982 | 0 | "%s: invalid store - missing internal volume.", |
983 | 0 | function ); |
984 | |
|
985 | 0 | return( -1 ); |
986 | 0 | } |
987 | 0 | if( libvshadow_store_descriptor_get_identifier( |
988 | 0 | internal_store->store_descriptor, |
989 | 0 | guid, |
990 | 0 | size, |
991 | 0 | error ) != 1 ) |
992 | 0 | { |
993 | 0 | libcerror_error_set( |
994 | 0 | error, |
995 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
996 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
997 | 0 | "%s: unable to retrieve identifier from store descriptor: %d.", |
998 | 0 | function, |
999 | 0 | internal_store->store_descriptor_index ); |
1000 | |
|
1001 | 0 | return( -1 ); |
1002 | 0 | } |
1003 | 0 | return( 1 ); |
1004 | 0 | } |
1005 | | |
1006 | | /* Retrieves the creation date and time |
1007 | | * Returns 1 if successful or -1 on error |
1008 | | */ |
1009 | | int libvshadow_store_get_creation_time( |
1010 | | libvshadow_store_t *store, |
1011 | | uint64_t *filetime, |
1012 | | libcerror_error_t **error ) |
1013 | 0 | { |
1014 | 0 | libvshadow_internal_store_t *internal_store = NULL; |
1015 | 0 | static char *function = "libvshadow_store_get_creation_time"; |
1016 | |
|
1017 | 0 | if( store == NULL ) |
1018 | 0 | { |
1019 | 0 | libcerror_error_set( |
1020 | 0 | error, |
1021 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1022 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1023 | 0 | "%s: invalid store.", |
1024 | 0 | function ); |
1025 | |
|
1026 | 0 | return( -1 ); |
1027 | 0 | } |
1028 | 0 | internal_store = (libvshadow_internal_store_t *) store; |
1029 | |
|
1030 | 0 | if( internal_store->internal_volume == NULL ) |
1031 | 0 | { |
1032 | 0 | libcerror_error_set( |
1033 | 0 | error, |
1034 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1035 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1036 | 0 | "%s: invalid store - missing internal volume.", |
1037 | 0 | function ); |
1038 | |
|
1039 | 0 | return( -1 ); |
1040 | 0 | } |
1041 | 0 | if( libvshadow_store_descriptor_get_creation_time( |
1042 | 0 | internal_store->store_descriptor, |
1043 | 0 | filetime, |
1044 | 0 | error ) != 1 ) |
1045 | 0 | { |
1046 | 0 | libcerror_error_set( |
1047 | 0 | error, |
1048 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1049 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1050 | 0 | "%s: unable to retrieve creation time from store descriptor: %d.", |
1051 | 0 | function, |
1052 | 0 | internal_store->store_descriptor_index ); |
1053 | |
|
1054 | 0 | return( -1 ); |
1055 | 0 | } |
1056 | 0 | return( 1 ); |
1057 | 0 | } |
1058 | | |
1059 | | /* Retrieves the copy identifier |
1060 | | * Returns 1 if successful, 0 if not available or -1 on error |
1061 | | */ |
1062 | | int libvshadow_store_get_copy_identifier( |
1063 | | libvshadow_store_t *store, |
1064 | | uint8_t *guid, |
1065 | | size_t size, |
1066 | | libcerror_error_t **error ) |
1067 | 0 | { |
1068 | 0 | libvshadow_internal_store_t *internal_store = NULL; |
1069 | 0 | static char *function = "libvshadow_store_get_copy_identifier"; |
1070 | 0 | int result = 0; |
1071 | |
|
1072 | 0 | if( store == NULL ) |
1073 | 0 | { |
1074 | 0 | libcerror_error_set( |
1075 | 0 | error, |
1076 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1077 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1078 | 0 | "%s: invalid store.", |
1079 | 0 | function ); |
1080 | |
|
1081 | 0 | return( -1 ); |
1082 | 0 | } |
1083 | 0 | internal_store = (libvshadow_internal_store_t *) store; |
1084 | |
|
1085 | 0 | if( internal_store->internal_volume == NULL ) |
1086 | 0 | { |
1087 | 0 | libcerror_error_set( |
1088 | 0 | error, |
1089 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1090 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1091 | 0 | "%s: invalid store - missing internal volume.", |
1092 | 0 | function ); |
1093 | |
|
1094 | 0 | return( -1 ); |
1095 | 0 | } |
1096 | 0 | result = libvshadow_store_descriptor_get_copy_identifier( |
1097 | 0 | internal_store->store_descriptor, |
1098 | 0 | guid, |
1099 | 0 | size, |
1100 | 0 | error ); |
1101 | |
|
1102 | 0 | if( result == -1 ) |
1103 | 0 | { |
1104 | 0 | libcerror_error_set( |
1105 | 0 | error, |
1106 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1107 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1108 | 0 | "%s: unable to retrieve copy identifier from store descriptor: %d.", |
1109 | 0 | function, |
1110 | 0 | internal_store->store_descriptor_index ); |
1111 | |
|
1112 | 0 | return( -1 ); |
1113 | 0 | } |
1114 | 0 | return( result ); |
1115 | 0 | } |
1116 | | |
1117 | | /* Retrieves the copy set identifier |
1118 | | * Returns 1 if successful, 0 if not available or -1 on error |
1119 | | */ |
1120 | | int libvshadow_store_get_copy_set_identifier( |
1121 | | libvshadow_store_t *store, |
1122 | | uint8_t *guid, |
1123 | | size_t size, |
1124 | | libcerror_error_t **error ) |
1125 | 0 | { |
1126 | 0 | libvshadow_internal_store_t *internal_store = NULL; |
1127 | 0 | static char *function = "libvshadow_store_get_copy_set_identifier"; |
1128 | 0 | int result = 0; |
1129 | |
|
1130 | 0 | if( store == NULL ) |
1131 | 0 | { |
1132 | 0 | libcerror_error_set( |
1133 | 0 | error, |
1134 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1135 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1136 | 0 | "%s: invalid store.", |
1137 | 0 | function ); |
1138 | |
|
1139 | 0 | return( -1 ); |
1140 | 0 | } |
1141 | 0 | internal_store = (libvshadow_internal_store_t *) store; |
1142 | |
|
1143 | 0 | if( internal_store->internal_volume == NULL ) |
1144 | 0 | { |
1145 | 0 | libcerror_error_set( |
1146 | 0 | error, |
1147 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1148 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1149 | 0 | "%s: invalid store - missing internal volume.", |
1150 | 0 | function ); |
1151 | |
|
1152 | 0 | return( -1 ); |
1153 | 0 | } |
1154 | 0 | result = libvshadow_store_descriptor_get_copy_set_identifier( |
1155 | 0 | internal_store->store_descriptor, |
1156 | 0 | guid, |
1157 | 0 | size, |
1158 | 0 | error ); |
1159 | |
|
1160 | 0 | if( result == -1 ) |
1161 | 0 | { |
1162 | 0 | libcerror_error_set( |
1163 | 0 | error, |
1164 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1165 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1166 | 0 | "%s: unable to retrieve copy set identifier from store descriptor: %d.", |
1167 | 0 | function, |
1168 | 0 | internal_store->store_descriptor_index ); |
1169 | |
|
1170 | 0 | return( -1 ); |
1171 | 0 | } |
1172 | 0 | return( result ); |
1173 | 0 | } |
1174 | | |
1175 | | /* Retrieves the attribute flags |
1176 | | * Returns 1 if successful, 0 if not available or -1 on error |
1177 | | */ |
1178 | | int libvshadow_store_get_attribute_flags( |
1179 | | libvshadow_store_t *store, |
1180 | | uint32_t *attribute_flags, |
1181 | | libcerror_error_t **error ) |
1182 | 0 | { |
1183 | 0 | libvshadow_internal_store_t *internal_store = NULL; |
1184 | 0 | static char *function = "libvshadow_store_get_attribute_flags"; |
1185 | 0 | int result = 0; |
1186 | |
|
1187 | 0 | if( store == NULL ) |
1188 | 0 | { |
1189 | 0 | libcerror_error_set( |
1190 | 0 | error, |
1191 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1192 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1193 | 0 | "%s: invalid store.", |
1194 | 0 | function ); |
1195 | |
|
1196 | 0 | return( -1 ); |
1197 | 0 | } |
1198 | 0 | internal_store = (libvshadow_internal_store_t *) store; |
1199 | |
|
1200 | 0 | if( internal_store->internal_volume == NULL ) |
1201 | 0 | { |
1202 | 0 | libcerror_error_set( |
1203 | 0 | error, |
1204 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1205 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1206 | 0 | "%s: invalid store - missing internal volume.", |
1207 | 0 | function ); |
1208 | |
|
1209 | 0 | return( -1 ); |
1210 | 0 | } |
1211 | 0 | result = libvshadow_store_descriptor_get_attribute_flags( |
1212 | 0 | internal_store->store_descriptor, |
1213 | 0 | attribute_flags, |
1214 | 0 | error ); |
1215 | |
|
1216 | 0 | if( result == -1 ) |
1217 | 0 | { |
1218 | 0 | libcerror_error_set( |
1219 | 0 | error, |
1220 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1221 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1222 | 0 | "%s: unable to retrieve attribute flags from store descriptor: %d.", |
1223 | 0 | function, |
1224 | 0 | internal_store->store_descriptor_index ); |
1225 | |
|
1226 | 0 | return( -1 ); |
1227 | 0 | } |
1228 | 0 | return( result ); |
1229 | 0 | } |
1230 | | |
1231 | | /* Retrieves the number of blocks |
1232 | | * Returns 1 if successful or -1 on error |
1233 | | */ |
1234 | | int libvshadow_store_get_number_of_blocks( |
1235 | | libvshadow_store_t *store, |
1236 | | int *number_of_blocks, |
1237 | | libcerror_error_t **error ) |
1238 | 0 | { |
1239 | 0 | libvshadow_internal_store_t *internal_store = NULL; |
1240 | 0 | static char *function = "libvshadow_store_get_number_of_blocks"; |
1241 | |
|
1242 | 0 | if( store == NULL ) |
1243 | 0 | { |
1244 | 0 | libcerror_error_set( |
1245 | 0 | error, |
1246 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1247 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1248 | 0 | "%s: invalid store.", |
1249 | 0 | function ); |
1250 | |
|
1251 | 0 | return( -1 ); |
1252 | 0 | } |
1253 | 0 | internal_store = (libvshadow_internal_store_t *) store; |
1254 | |
|
1255 | 0 | if( internal_store->internal_volume == NULL ) |
1256 | 0 | { |
1257 | 0 | libcerror_error_set( |
1258 | 0 | error, |
1259 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1260 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1261 | 0 | "%s: invalid store - missing internal volume.", |
1262 | 0 | function ); |
1263 | |
|
1264 | 0 | return( -1 ); |
1265 | 0 | } |
1266 | 0 | if( libvshadow_store_descriptor_get_number_of_blocks( |
1267 | 0 | internal_store->store_descriptor, |
1268 | 0 | internal_store->io_handle, |
1269 | 0 | internal_store->file_io_handle, |
1270 | 0 | number_of_blocks, |
1271 | 0 | error ) != 1 ) |
1272 | 0 | { |
1273 | 0 | libcerror_error_set( |
1274 | 0 | error, |
1275 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1276 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1277 | 0 | "%s: unable to retrieve number of blocks store descriptor: %d.", |
1278 | 0 | function, |
1279 | 0 | internal_store->store_descriptor_index ); |
1280 | |
|
1281 | 0 | return( -1 ); |
1282 | 0 | } |
1283 | 0 | return( 1 ); |
1284 | 0 | } |
1285 | | |
1286 | | /* Retrieves a specific block |
1287 | | * Returns 1 if successful or -1 on error |
1288 | | */ |
1289 | | int libvshadow_store_get_block_by_index( |
1290 | | libvshadow_store_t *store, |
1291 | | int block_index, |
1292 | | libvshadow_block_t **block, |
1293 | | libcerror_error_t **error ) |
1294 | 0 | { |
1295 | 0 | libvshadow_block_descriptor_t *block_descriptor = NULL; |
1296 | 0 | libvshadow_internal_store_t *internal_store = NULL; |
1297 | 0 | static char *function = "libvshadow_store_get_block_by_index"; |
1298 | |
|
1299 | 0 | if( store == NULL ) |
1300 | 0 | { |
1301 | 0 | libcerror_error_set( |
1302 | 0 | error, |
1303 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1304 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1305 | 0 | "%s: invalid store.", |
1306 | 0 | function ); |
1307 | |
|
1308 | 0 | return( -1 ); |
1309 | 0 | } |
1310 | 0 | internal_store = (libvshadow_internal_store_t *) store; |
1311 | |
|
1312 | 0 | if( internal_store->internal_volume == NULL ) |
1313 | 0 | { |
1314 | 0 | libcerror_error_set( |
1315 | 0 | error, |
1316 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1317 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1318 | 0 | "%s: invalid store - missing internal volume.", |
1319 | 0 | function ); |
1320 | |
|
1321 | 0 | return( -1 ); |
1322 | 0 | } |
1323 | 0 | if( block == NULL ) |
1324 | 0 | { |
1325 | 0 | libcerror_error_set( |
1326 | 0 | error, |
1327 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1328 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1329 | 0 | "%s: invalid block.", |
1330 | 0 | function ); |
1331 | |
|
1332 | 0 | return( -1 ); |
1333 | 0 | } |
1334 | 0 | if( *block != NULL ) |
1335 | 0 | { |
1336 | 0 | libcerror_error_set( |
1337 | 0 | error, |
1338 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1339 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
1340 | 0 | "%s: invalid block value already set.", |
1341 | 0 | function ); |
1342 | |
|
1343 | 0 | return( -1 ); |
1344 | 0 | } |
1345 | 0 | if( libvshadow_store_descriptor_get_block_descriptor_by_index( |
1346 | 0 | internal_store->store_descriptor, |
1347 | 0 | internal_store->io_handle, |
1348 | 0 | internal_store->file_io_handle, |
1349 | 0 | block_index, |
1350 | 0 | &block_descriptor, |
1351 | 0 | error ) != 1 ) |
1352 | 0 | { |
1353 | 0 | libcerror_error_set( |
1354 | 0 | error, |
1355 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1356 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1357 | 0 | "%s: unable to retrieve block descriptor: %d from store descriptor: %d.", |
1358 | 0 | function, |
1359 | 0 | block_index, |
1360 | 0 | internal_store->store_descriptor_index ); |
1361 | |
|
1362 | 0 | return( -1 ); |
1363 | 0 | } |
1364 | 0 | if( libvshadow_block_initialize( |
1365 | 0 | block, |
1366 | 0 | block_descriptor, |
1367 | 0 | error ) != 1 ) |
1368 | 0 | { |
1369 | 0 | libcerror_error_set( |
1370 | 0 | error, |
1371 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1372 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1373 | 0 | "%s: unable to create block: %d.", |
1374 | 0 | function, |
1375 | 0 | block_index ); |
1376 | |
|
1377 | 0 | return( -1 ); |
1378 | 0 | } |
1379 | 0 | return( 1 ); |
1380 | 0 | } |
1381 | | |