/src/libewf/libewf/libewf_handle.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Handle functions |
3 | | * |
4 | | * Copyright (C) 2006-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 <narrow_string.h> |
25 | | #include <types.h> |
26 | | #include <wide_string.h> |
27 | | |
28 | | #include "libewf_analytical_data.h" |
29 | | #include "libewf_case_data.h" |
30 | | #include "libewf_case_data_section.h" |
31 | | #include "libewf_chunk_data.h" |
32 | | #include "libewf_chunk_table.h" |
33 | | #include "libewf_codepage.h" |
34 | | #include "libewf_compression.h" |
35 | | #include "libewf_data_chunk.h" |
36 | | #include "libewf_debug.h" |
37 | | #include "libewf_definitions.h" |
38 | | #include "libewf_device_information.h" |
39 | | #include "libewf_device_information_section.h" |
40 | | #include "libewf_digest_section.h" |
41 | | #include "libewf_error2_section.h" |
42 | | #include "libewf_file_entry.h" |
43 | | #include "libewf_handle.h" |
44 | | #include "libewf_hash_sections.h" |
45 | | #include "libewf_hash_values.h" |
46 | | #include "libewf_header_sections.h" |
47 | | #include "libewf_header_values.h" |
48 | | #include "libewf_io_handle.h" |
49 | | #include "libewf_lef_file_entry.h" |
50 | | #include "libewf_libbfio.h" |
51 | | #include "libewf_libcdata.h" |
52 | | #include "libewf_libcerror.h" |
53 | | #include "libewf_libcnotify.h" |
54 | | #include "libewf_libcthreads.h" |
55 | | #include "libewf_libfcache.h" |
56 | | #include "libewf_libfdata.h" |
57 | | #include "libewf_libfvalue.h" |
58 | | #include "libewf_ltree_section.h" |
59 | | #include "libewf_md5_hash_section.h" |
60 | | #include "libewf_restart_data.h" |
61 | | #include "libewf_section.h" |
62 | | #include "libewf_section_descriptor.h" |
63 | | #include "libewf_sector_range.h" |
64 | | #include "libewf_sector_range_list.h" |
65 | | #include "libewf_segment_file.h" |
66 | | #include "libewf_session_section.h" |
67 | | #include "libewf_sha1_hash_section.h" |
68 | | #include "libewf_single_file_tree.h" |
69 | | #include "libewf_single_files.h" |
70 | | #include "libewf_types.h" |
71 | | #include "libewf_unused.h" |
72 | | #include "libewf_value_table.h" |
73 | | #include "libewf_write_io_handle.h" |
74 | | |
75 | | #include "ewf_data.h" |
76 | | #include "ewf_file_header.h" |
77 | | |
78 | | /* Creates a handle |
79 | | * Make sure the value handle is referencing, is set to NULL |
80 | | * Returns 1 if successful or -1 on error |
81 | | */ |
82 | | int libewf_handle_initialize( |
83 | | libewf_handle_t **handle, |
84 | | libcerror_error_t **error ) |
85 | 3.03k | { |
86 | 3.03k | libewf_internal_handle_t *internal_handle = NULL; |
87 | 3.03k | static char *function = "libewf_handle_initialize"; |
88 | | |
89 | 3.03k | if( handle == NULL ) |
90 | 0 | { |
91 | 0 | libcerror_error_set( |
92 | 0 | error, |
93 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
94 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
95 | 0 | "%s: invalid handle.", |
96 | 0 | function ); |
97 | |
|
98 | 0 | return( -1 ); |
99 | 0 | } |
100 | 3.03k | if( *handle != NULL ) |
101 | 0 | { |
102 | 0 | libcerror_error_set( |
103 | 0 | error, |
104 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
105 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
106 | 0 | "%s: invalid handle value already set.", |
107 | 0 | function ); |
108 | |
|
109 | 0 | return( -1 ); |
110 | 0 | } |
111 | 3.03k | internal_handle = memory_allocate_structure( |
112 | 3.03k | libewf_internal_handle_t ); |
113 | | |
114 | 3.03k | if( internal_handle == NULL ) |
115 | 0 | { |
116 | 0 | libcerror_error_set( |
117 | 0 | error, |
118 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
119 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
120 | 0 | "%s: unable to create handle.", |
121 | 0 | function ); |
122 | |
|
123 | 0 | goto on_error; |
124 | 0 | } |
125 | 3.03k | if( memory_set( |
126 | 3.03k | internal_handle, |
127 | 3.03k | 0, |
128 | 3.03k | sizeof( libewf_internal_handle_t ) ) == NULL ) |
129 | 0 | { |
130 | 0 | libcerror_error_set( |
131 | 0 | error, |
132 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
133 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
134 | 0 | "%s: unable to clear handle.", |
135 | 0 | function ); |
136 | |
|
137 | 0 | memory_free( |
138 | 0 | internal_handle ); |
139 | |
|
140 | 0 | return( -1 ); |
141 | 0 | } |
142 | 3.03k | if( libewf_io_handle_initialize( |
143 | 3.03k | &( internal_handle->io_handle ), |
144 | 3.03k | error ) != 1 ) |
145 | 0 | { |
146 | 0 | libcerror_error_set( |
147 | 0 | error, |
148 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
149 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
150 | 0 | "%s: unable to create IO handle.", |
151 | 0 | function ); |
152 | |
|
153 | 0 | goto on_error; |
154 | 0 | } |
155 | 3.03k | if( libewf_media_values_initialize( |
156 | 3.03k | &( internal_handle->media_values ), |
157 | 3.03k | error ) != 1 ) |
158 | 0 | { |
159 | 0 | libcerror_error_set( |
160 | 0 | error, |
161 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
162 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
163 | 0 | "%s: unable to create media values.", |
164 | 0 | function ); |
165 | |
|
166 | 0 | goto on_error; |
167 | 0 | } |
168 | 3.03k | if( libcdata_array_initialize( |
169 | 3.03k | &( internal_handle->sessions ), |
170 | 3.03k | 0, |
171 | 3.03k | error ) != 1 ) |
172 | 0 | { |
173 | 0 | libcerror_error_set( |
174 | 0 | error, |
175 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
176 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
177 | 0 | "%s: unable to create sessions array.", |
178 | 0 | function ); |
179 | |
|
180 | 0 | goto on_error; |
181 | 0 | } |
182 | 3.03k | if( libcdata_array_initialize( |
183 | 3.03k | &( internal_handle->tracks ), |
184 | 3.03k | 0, |
185 | 3.03k | error ) != 1 ) |
186 | 0 | { |
187 | 0 | libcerror_error_set( |
188 | 0 | error, |
189 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
190 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
191 | 0 | "%s: unable to create tracks array.", |
192 | 0 | function ); |
193 | |
|
194 | 0 | goto on_error; |
195 | 0 | } |
196 | 3.03k | if( libcdata_range_list_initialize( |
197 | 3.03k | &( internal_handle->acquiry_errors ), |
198 | 3.03k | error ) != 1 ) |
199 | 0 | { |
200 | 0 | libcerror_error_set( |
201 | 0 | error, |
202 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
203 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
204 | 0 | "%s: unable to create acquiry errors range list.", |
205 | 0 | function ); |
206 | |
|
207 | 0 | goto on_error; |
208 | 0 | } |
209 | 3.03k | if( libewf_segment_table_initialize( |
210 | 3.03k | &( internal_handle->segment_table ), |
211 | 3.03k | internal_handle->io_handle, |
212 | 3.03k | LIBEWF_DEFAULT_SEGMENT_FILE_SIZE, |
213 | 3.03k | error ) != 1 ) |
214 | 0 | { |
215 | 0 | libcerror_error_set( |
216 | 0 | error, |
217 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
218 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
219 | 0 | "%s: unable to create segment table.", |
220 | 0 | function ); |
221 | |
|
222 | 0 | goto on_error; |
223 | 0 | } |
224 | 3.03k | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
225 | 3.03k | if( libcthreads_read_write_lock_initialize( |
226 | 3.03k | &( internal_handle->read_write_lock ), |
227 | 3.03k | error ) != 1 ) |
228 | 0 | { |
229 | 0 | libcerror_error_set( |
230 | 0 | error, |
231 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
232 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
233 | 0 | "%s: unable to initialize read/write lock.", |
234 | 0 | function ); |
235 | |
|
236 | 0 | goto on_error; |
237 | 0 | } |
238 | 3.03k | #endif |
239 | 3.03k | internal_handle->date_format = LIBEWF_DATE_FORMAT_CTIME; |
240 | 3.03k | internal_handle->maximum_number_of_open_handles = LIBBFIO_POOL_UNLIMITED_NUMBER_OF_OPEN_HANDLES; |
241 | | |
242 | 3.03k | *handle = (libewf_handle_t *) internal_handle; |
243 | | |
244 | 3.03k | return( 1 ); |
245 | | |
246 | 0 | on_error: |
247 | 0 | if( internal_handle != NULL ) |
248 | 0 | { |
249 | 0 | if( internal_handle->acquiry_errors != NULL ) |
250 | 0 | { |
251 | 0 | libcdata_range_list_free( |
252 | 0 | &( internal_handle->acquiry_errors ), |
253 | 0 | NULL, |
254 | 0 | NULL ); |
255 | 0 | } |
256 | 0 | if( internal_handle->tracks != NULL ) |
257 | 0 | { |
258 | 0 | libcdata_array_free( |
259 | 0 | &( internal_handle->tracks ), |
260 | 0 | NULL, |
261 | 0 | NULL ); |
262 | 0 | } |
263 | 0 | if( internal_handle->sessions != NULL ) |
264 | 0 | { |
265 | 0 | libcdata_array_free( |
266 | 0 | &( internal_handle->sessions ), |
267 | 0 | NULL, |
268 | 0 | NULL ); |
269 | 0 | } |
270 | 0 | if( internal_handle->media_values != NULL ) |
271 | 0 | { |
272 | 0 | libewf_media_values_free( |
273 | 0 | &( internal_handle->media_values ), |
274 | 0 | NULL ); |
275 | 0 | } |
276 | 0 | if( internal_handle->io_handle != NULL ) |
277 | 0 | { |
278 | 0 | libewf_io_handle_free( |
279 | 0 | &( internal_handle->io_handle ), |
280 | 0 | NULL ); |
281 | 0 | } |
282 | 0 | memory_free( |
283 | 0 | internal_handle ); |
284 | 0 | } |
285 | 0 | return( -1 ); |
286 | 3.03k | } |
287 | | |
288 | | /* Frees a handle |
289 | | * Returns 1 if successful or -1 on error |
290 | | */ |
291 | | int libewf_handle_free( |
292 | | libewf_handle_t **handle, |
293 | | libcerror_error_t **error ) |
294 | 3.03k | { |
295 | 3.03k | libewf_internal_handle_t *internal_handle = NULL; |
296 | 3.03k | static char *function = "libewf_internal_handle_free"; |
297 | 3.03k | int result = 1; |
298 | | |
299 | 3.03k | if( handle == 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 handle.", |
306 | 0 | function ); |
307 | |
|
308 | 0 | return( -1 ); |
309 | 0 | } |
310 | 3.03k | if( *handle != NULL ) |
311 | 3.03k | { |
312 | 3.03k | internal_handle = (libewf_internal_handle_t *) *handle; |
313 | | |
314 | 3.03k | if( internal_handle->file_io_pool != NULL ) |
315 | 0 | { |
316 | 0 | if( libewf_handle_close( |
317 | 0 | *handle, |
318 | 0 | error ) != 0 ) |
319 | 0 | { |
320 | 0 | libcerror_error_set( |
321 | 0 | error, |
322 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
323 | 0 | LIBCERROR_IO_ERROR_CLOSE_FAILED, |
324 | 0 | "%s: unable to close handle.", |
325 | 0 | function ); |
326 | |
|
327 | 0 | result = -1; |
328 | 0 | } |
329 | 0 | } |
330 | 3.03k | *handle = NULL; |
331 | | |
332 | 3.03k | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
333 | 3.03k | if( libcthreads_read_write_lock_free( |
334 | 3.03k | &( internal_handle->read_write_lock ), |
335 | 3.03k | error ) != 1 ) |
336 | 0 | { |
337 | 0 | libcerror_error_set( |
338 | 0 | error, |
339 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
340 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
341 | 0 | "%s: unable to free read/write lock.", |
342 | 0 | function ); |
343 | |
|
344 | 0 | result = -1; |
345 | 0 | } |
346 | 3.03k | #endif |
347 | 3.03k | if( libewf_segment_table_free( |
348 | 3.03k | &( internal_handle->segment_table ), |
349 | 3.03k | error ) != 1 ) |
350 | 0 | { |
351 | 0 | libcerror_error_set( |
352 | 0 | error, |
353 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
354 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
355 | 0 | "%s: unable to free segment table.", |
356 | 0 | function ); |
357 | |
|
358 | 0 | result = -1; |
359 | 0 | } |
360 | 3.03k | if( libcdata_range_list_free( |
361 | 3.03k | &( internal_handle->acquiry_errors ), |
362 | 3.03k | NULL, |
363 | 3.03k | error ) != 1 ) |
364 | 0 | { |
365 | 0 | libcerror_error_set( |
366 | 0 | error, |
367 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
368 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
369 | 0 | "%s: unable to free acquiry errors range list.", |
370 | 0 | function ); |
371 | |
|
372 | 0 | result = -1; |
373 | 0 | } |
374 | 3.03k | if( libcdata_array_free( |
375 | 3.03k | &( internal_handle->tracks ), |
376 | 3.03k | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_sector_range_free, |
377 | 3.03k | error ) != 1 ) |
378 | 0 | { |
379 | 0 | libcerror_error_set( |
380 | 0 | error, |
381 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
382 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
383 | 0 | "%s: unable to free tracks array.", |
384 | 0 | function ); |
385 | |
|
386 | 0 | result = -1; |
387 | 0 | } |
388 | 3.03k | if( libcdata_array_free( |
389 | 3.03k | &( internal_handle->sessions ), |
390 | 3.03k | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_sector_range_free, |
391 | 3.03k | error ) != 1 ) |
392 | 0 | { |
393 | 0 | libcerror_error_set( |
394 | 0 | error, |
395 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
396 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
397 | 0 | "%s: unable to free sessions array.", |
398 | 0 | function ); |
399 | |
|
400 | 0 | result = -1; |
401 | 0 | } |
402 | 3.03k | if( libewf_media_values_free( |
403 | 3.03k | &( internal_handle->media_values ), |
404 | 3.03k | error ) != 1 ) |
405 | 0 | { |
406 | 0 | libcerror_error_set( |
407 | 0 | error, |
408 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
409 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
410 | 0 | "%s: unable to free media values.", |
411 | 0 | function ); |
412 | |
|
413 | 0 | result = -1; |
414 | 0 | } |
415 | 3.03k | if( libewf_io_handle_free( |
416 | 3.03k | &( internal_handle->io_handle ), |
417 | 3.03k | error ) != 1 ) |
418 | 0 | { |
419 | 0 | libcerror_error_set( |
420 | 0 | error, |
421 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
422 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
423 | 0 | "%s: unable to free IO handle.", |
424 | 0 | function ); |
425 | |
|
426 | 0 | result = -1; |
427 | 0 | } |
428 | 3.03k | memory_free( |
429 | 3.03k | internal_handle ); |
430 | 3.03k | } |
431 | 3.03k | return( result ); |
432 | 3.03k | } |
433 | | |
434 | | /* Clones the handle including elements |
435 | | * Returns 1 if successful or -1 on error |
436 | | */ |
437 | | int libewf_handle_clone( |
438 | | libewf_handle_t **destination_handle, |
439 | | libewf_handle_t *source_handle, |
440 | | libcerror_error_t **error ) |
441 | 0 | { |
442 | 0 | libewf_internal_handle_t *internal_destination_handle = NULL; |
443 | 0 | libewf_internal_handle_t *internal_source_handle = NULL; |
444 | 0 | static char *function = "libewf_handle_clone"; |
445 | |
|
446 | 0 | if( destination_handle == NULL ) |
447 | 0 | { |
448 | 0 | libcerror_error_set( |
449 | 0 | error, |
450 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
451 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
452 | 0 | "%s: invalid destination handle.", |
453 | 0 | function ); |
454 | |
|
455 | 0 | return( -1 ); |
456 | 0 | } |
457 | 0 | if( *destination_handle != NULL ) |
458 | 0 | { |
459 | 0 | libcerror_error_set( |
460 | 0 | error, |
461 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
462 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
463 | 0 | "%s: invalid destination handle value already set.", |
464 | 0 | function ); |
465 | |
|
466 | 0 | return( -1 ); |
467 | 0 | } |
468 | 0 | if( source_handle == NULL ) |
469 | 0 | { |
470 | 0 | *destination_handle = NULL; |
471 | |
|
472 | 0 | return( 1 ); |
473 | 0 | } |
474 | 0 | internal_source_handle = (libewf_internal_handle_t *) source_handle; |
475 | |
|
476 | 0 | if( internal_source_handle->io_handle == NULL ) |
477 | 0 | { |
478 | 0 | libcerror_error_set( |
479 | 0 | error, |
480 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
481 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
482 | 0 | "%s: invalid source handle - missing IO handle.", |
483 | 0 | function ); |
484 | |
|
485 | 0 | return( -1 ); |
486 | 0 | } |
487 | 0 | if( ( internal_source_handle->io_handle->access_flags & LIBEWF_ACCESS_FLAG_READ ) != 0 ) |
488 | 0 | { |
489 | 0 | libcerror_error_set( |
490 | 0 | error, |
491 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
492 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
493 | 0 | "%s: write access currently not supported.", |
494 | 0 | function ); |
495 | |
|
496 | 0 | return( -1 ); |
497 | 0 | } |
498 | 0 | internal_destination_handle = memory_allocate_structure( |
499 | 0 | libewf_internal_handle_t ); |
500 | |
|
501 | 0 | if( internal_destination_handle == NULL ) |
502 | 0 | { |
503 | 0 | libcerror_error_set( |
504 | 0 | error, |
505 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
506 | 0 | LIBCERROR_MEMORY_ERROR_INSUFFICIENT, |
507 | 0 | "%s: unable to create destination handle.", |
508 | 0 | function ); |
509 | |
|
510 | 0 | goto on_error; |
511 | 0 | } |
512 | 0 | if( memory_set( |
513 | 0 | internal_destination_handle, |
514 | 0 | 0, |
515 | 0 | sizeof( libewf_internal_handle_t ) ) == NULL ) |
516 | 0 | { |
517 | 0 | libcerror_error_set( |
518 | 0 | error, |
519 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
520 | 0 | LIBCERROR_MEMORY_ERROR_SET_FAILED, |
521 | 0 | "%s: unable to clear destination handle.", |
522 | 0 | function ); |
523 | |
|
524 | 0 | goto on_error; |
525 | 0 | } |
526 | 0 | if( libewf_io_handle_clone( |
527 | 0 | &( internal_destination_handle->io_handle ), |
528 | 0 | internal_source_handle->io_handle, |
529 | 0 | error ) != 1 ) |
530 | 0 | { |
531 | 0 | libcerror_error_set( |
532 | 0 | error, |
533 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
534 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
535 | 0 | "%s: unable to create destination IO handle.", |
536 | 0 | function ); |
537 | |
|
538 | 0 | goto on_error; |
539 | 0 | } |
540 | 0 | if( libewf_media_values_clone( |
541 | 0 | &( internal_destination_handle->media_values ), |
542 | 0 | internal_source_handle->media_values, |
543 | 0 | error ) != 1 ) |
544 | 0 | { |
545 | 0 | libcerror_error_set( |
546 | 0 | error, |
547 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
548 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
549 | 0 | "%s: unable to create destination media values.", |
550 | 0 | function ); |
551 | |
|
552 | 0 | goto on_error; |
553 | 0 | } |
554 | 0 | if( libcdata_array_clone( |
555 | 0 | &( internal_destination_handle->sessions ), |
556 | 0 | internal_source_handle->sessions, |
557 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_sector_range_free, |
558 | 0 | (int (*)(intptr_t **, intptr_t *, libcerror_error_t **)) &libewf_sector_range_clone, |
559 | 0 | error ) != 1 ) |
560 | 0 | { |
561 | 0 | libcerror_error_set( |
562 | 0 | error, |
563 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
564 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
565 | 0 | "%s: unable to create destination sessions array.", |
566 | 0 | function ); |
567 | |
|
568 | 0 | goto on_error; |
569 | 0 | } |
570 | 0 | if( libcdata_array_clone( |
571 | 0 | &( internal_destination_handle->tracks ), |
572 | 0 | internal_source_handle->tracks, |
573 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_sector_range_free, |
574 | 0 | (int (*)(intptr_t **, intptr_t *, libcerror_error_t **)) &libewf_sector_range_clone, |
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_INITIALIZE_FAILED, |
581 | 0 | "%s: unable to create destination tracks array.", |
582 | 0 | function ); |
583 | |
|
584 | 0 | goto on_error; |
585 | 0 | } |
586 | 0 | if( libcdata_range_list_clone( |
587 | 0 | &( internal_destination_handle->acquiry_errors ), |
588 | 0 | internal_source_handle->acquiry_errors, |
589 | 0 | NULL, |
590 | 0 | NULL, |
591 | 0 | error ) != 1 ) |
592 | 0 | { |
593 | 0 | libcerror_error_set( |
594 | 0 | error, |
595 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
596 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
597 | 0 | "%s: unable to create destination acquiry errors range list.", |
598 | 0 | function ); |
599 | |
|
600 | 0 | goto on_error; |
601 | 0 | } |
602 | 0 | if( internal_source_handle->file_io_pool != NULL ) |
603 | 0 | { |
604 | 0 | if( libbfio_pool_clone( |
605 | 0 | &( internal_destination_handle->file_io_pool ), |
606 | 0 | internal_source_handle->file_io_pool, |
607 | 0 | error ) != 1 ) |
608 | 0 | { |
609 | 0 | libcerror_error_set( |
610 | 0 | error, |
611 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
612 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
613 | 0 | "%s: unable to create destination file IO pool.", |
614 | 0 | function ); |
615 | |
|
616 | 0 | goto on_error; |
617 | 0 | } |
618 | 0 | internal_destination_handle->file_io_pool_created_in_library = 1; |
619 | 0 | } |
620 | 0 | if( internal_source_handle->read_io_handle != NULL ) |
621 | 0 | { |
622 | 0 | if( libewf_read_io_handle_clone( |
623 | 0 | &( internal_destination_handle->read_io_handle ), |
624 | 0 | internal_source_handle->read_io_handle, |
625 | 0 | error ) != 1 ) |
626 | 0 | { |
627 | 0 | libcerror_error_set( |
628 | 0 | error, |
629 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
630 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
631 | 0 | "%s: unable to create destination read IO handle.", |
632 | 0 | function ); |
633 | |
|
634 | 0 | goto on_error; |
635 | 0 | } |
636 | 0 | } |
637 | 0 | if( internal_source_handle->write_io_handle != NULL ) |
638 | 0 | { |
639 | 0 | if( libewf_write_io_handle_clone( |
640 | 0 | &( internal_destination_handle->write_io_handle ), |
641 | 0 | internal_source_handle->write_io_handle, |
642 | 0 | error ) != 1 ) |
643 | 0 | { |
644 | 0 | libcerror_error_set( |
645 | 0 | error, |
646 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
647 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
648 | 0 | "%s: unable to create destination write IO handle.", |
649 | 0 | function ); |
650 | |
|
651 | 0 | goto on_error; |
652 | 0 | } |
653 | 0 | } |
654 | 0 | if( libewf_segment_table_clone( |
655 | 0 | &( internal_destination_handle->segment_table ), |
656 | 0 | internal_source_handle->segment_table, |
657 | 0 | error ) != 1 ) |
658 | 0 | { |
659 | 0 | libcerror_error_set( |
660 | 0 | error, |
661 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
662 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
663 | 0 | "%s: unable to create destination segment table.", |
664 | 0 | function ); |
665 | |
|
666 | 0 | goto on_error; |
667 | 0 | } |
668 | 0 | if( internal_source_handle->chunk_table != NULL ) |
669 | 0 | { |
670 | 0 | if( libewf_chunk_table_clone( |
671 | 0 | &( internal_destination_handle->chunk_table ), |
672 | 0 | internal_source_handle->chunk_table, |
673 | 0 | error ) != 1 ) |
674 | 0 | { |
675 | 0 | libcerror_error_set( |
676 | 0 | error, |
677 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
678 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
679 | 0 | "%s: unable to create destination chunk table.", |
680 | 0 | function ); |
681 | |
|
682 | 0 | goto on_error; |
683 | 0 | } |
684 | 0 | } |
685 | 0 | if( internal_source_handle->hash_sections != NULL ) |
686 | 0 | { |
687 | 0 | if( libewf_hash_sections_clone( |
688 | 0 | &( internal_destination_handle->hash_sections ), |
689 | 0 | internal_source_handle->hash_sections, |
690 | 0 | error ) != 1 ) |
691 | 0 | { |
692 | 0 | libcerror_error_set( |
693 | 0 | error, |
694 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
695 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
696 | 0 | "%s: unable to create destination hash sections.", |
697 | 0 | function ); |
698 | |
|
699 | 0 | goto on_error; |
700 | 0 | } |
701 | 0 | } |
702 | 0 | if( internal_source_handle->header_values != NULL ) |
703 | 0 | { |
704 | 0 | if( libfvalue_table_clone( |
705 | 0 | &( internal_destination_handle->header_values ), |
706 | 0 | internal_source_handle->header_values, |
707 | 0 | error ) != 1 ) |
708 | 0 | { |
709 | 0 | libcerror_error_set( |
710 | 0 | error, |
711 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
712 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
713 | 0 | "%s: unable to create destination header values.", |
714 | 0 | function ); |
715 | |
|
716 | 0 | goto on_error; |
717 | 0 | } |
718 | 0 | internal_destination_handle->header_values_parsed = internal_source_handle->header_values_parsed; |
719 | 0 | } |
720 | 0 | if( internal_source_handle->hash_values != NULL ) |
721 | 0 | { |
722 | 0 | if( libfvalue_table_clone( |
723 | 0 | &( internal_destination_handle->hash_values ), |
724 | 0 | internal_source_handle->hash_values, |
725 | 0 | error ) != 1 ) |
726 | 0 | { |
727 | 0 | libcerror_error_set( |
728 | 0 | error, |
729 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
730 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
731 | 0 | "%s: unable to create destination hash values.", |
732 | 0 | function ); |
733 | |
|
734 | 0 | goto on_error; |
735 | 0 | } |
736 | 0 | internal_destination_handle->hash_values_parsed = internal_source_handle->hash_values_parsed; |
737 | 0 | } |
738 | 0 | internal_destination_handle->maximum_number_of_open_handles = internal_source_handle->maximum_number_of_open_handles; |
739 | 0 | internal_destination_handle->date_format = internal_source_handle->date_format; |
740 | |
|
741 | 0 | *destination_handle = (libewf_handle_t *) internal_destination_handle; |
742 | |
|
743 | 0 | return( 1 ); |
744 | | |
745 | 0 | on_error: |
746 | 0 | if( internal_destination_handle != NULL ) |
747 | 0 | { |
748 | 0 | if( internal_destination_handle->hash_values != NULL ) |
749 | 0 | { |
750 | 0 | libfvalue_table_free( |
751 | 0 | &( internal_destination_handle->hash_values ), |
752 | 0 | NULL ); |
753 | 0 | } |
754 | 0 | if( internal_destination_handle->header_values != NULL ) |
755 | 0 | { |
756 | 0 | libfvalue_table_free( |
757 | 0 | &( internal_destination_handle->header_values ), |
758 | 0 | NULL ); |
759 | 0 | } |
760 | 0 | if( internal_destination_handle->hash_sections != NULL ) |
761 | 0 | { |
762 | 0 | libewf_hash_sections_free( |
763 | 0 | &( internal_destination_handle->hash_sections ), |
764 | 0 | NULL ); |
765 | 0 | } |
766 | 0 | if( internal_destination_handle->chunk_table != NULL ) |
767 | 0 | { |
768 | 0 | libewf_chunk_table_free( |
769 | 0 | &( internal_destination_handle->chunk_table ), |
770 | 0 | NULL ); |
771 | 0 | } |
772 | 0 | if( internal_destination_handle->segment_table != NULL ) |
773 | 0 | { |
774 | 0 | libewf_segment_table_free( |
775 | 0 | &( internal_destination_handle->segment_table ), |
776 | 0 | NULL ); |
777 | 0 | } |
778 | 0 | if( internal_destination_handle->write_io_handle != NULL ) |
779 | 0 | { |
780 | 0 | libewf_write_io_handle_free( |
781 | 0 | &( internal_destination_handle->write_io_handle ), |
782 | 0 | NULL ); |
783 | 0 | } |
784 | 0 | if( internal_destination_handle->read_io_handle != NULL ) |
785 | 0 | { |
786 | 0 | libewf_read_io_handle_free( |
787 | 0 | &( internal_destination_handle->read_io_handle ), |
788 | 0 | NULL ); |
789 | 0 | } |
790 | 0 | if( internal_destination_handle->file_io_pool != NULL ) |
791 | 0 | { |
792 | 0 | libbfio_pool_free( |
793 | 0 | &( internal_destination_handle->file_io_pool ), |
794 | 0 | NULL ); |
795 | 0 | } |
796 | 0 | if( internal_destination_handle->acquiry_errors != NULL ) |
797 | 0 | { |
798 | 0 | libcdata_range_list_free( |
799 | 0 | &( internal_destination_handle->acquiry_errors ), |
800 | 0 | NULL, |
801 | 0 | NULL ); |
802 | 0 | } |
803 | 0 | if( internal_destination_handle->tracks != NULL ) |
804 | 0 | { |
805 | 0 | libcdata_array_free( |
806 | 0 | &( internal_destination_handle->tracks ), |
807 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_sector_range_free, |
808 | 0 | NULL ); |
809 | 0 | } |
810 | 0 | if( internal_destination_handle->sessions != NULL ) |
811 | 0 | { |
812 | 0 | libcdata_array_free( |
813 | 0 | &( internal_destination_handle->sessions ), |
814 | 0 | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_sector_range_free, |
815 | 0 | NULL ); |
816 | 0 | } |
817 | 0 | if( internal_destination_handle->media_values != NULL ) |
818 | 0 | { |
819 | 0 | libewf_media_values_free( |
820 | 0 | &( internal_destination_handle->media_values ), |
821 | 0 | NULL ); |
822 | 0 | } |
823 | 0 | if( internal_destination_handle->io_handle != NULL ) |
824 | 0 | { |
825 | 0 | libewf_io_handle_free( |
826 | 0 | &( internal_destination_handle->io_handle ), |
827 | 0 | NULL ); |
828 | 0 | } |
829 | 0 | memory_free( |
830 | 0 | internal_destination_handle ); |
831 | 0 | } |
832 | 0 | return( -1 ); |
833 | 0 | } |
834 | | |
835 | | /* Signals the handle to abort its current activity |
836 | | * Returns 1 if successful or -1 on error |
837 | | */ |
838 | | int libewf_handle_signal_abort( |
839 | | libewf_handle_t *handle, |
840 | | libcerror_error_t **error ) |
841 | 0 | { |
842 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
843 | 0 | static char *function = "libewf_handle_signal_abort"; |
844 | |
|
845 | 0 | if( handle == NULL ) |
846 | 0 | { |
847 | 0 | libcerror_error_set( |
848 | 0 | error, |
849 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
850 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
851 | 0 | "%s: invalid handle.", |
852 | 0 | function ); |
853 | |
|
854 | 0 | return( -1 ); |
855 | 0 | } |
856 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
857 | |
|
858 | 0 | if( internal_handle->io_handle == NULL ) |
859 | 0 | { |
860 | 0 | libcerror_error_set( |
861 | 0 | error, |
862 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
863 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
864 | 0 | "%s: invalid handle - missing IO handle.", |
865 | 0 | function ); |
866 | |
|
867 | 0 | return( -1 ); |
868 | 0 | } |
869 | 0 | internal_handle->io_handle->abort = 1; |
870 | |
|
871 | 0 | return( 1 ); |
872 | 0 | } |
873 | | |
874 | | /* Opens a set of EWF file(s) |
875 | | * For reading files should contain all filenames that make up an EWF image |
876 | | * For writing files should contain the base of the filename, extentions like .e01 will be automatically added |
877 | | * Returns 1 if successful or -1 on error |
878 | | */ |
879 | | int libewf_handle_open( |
880 | | libewf_handle_t *handle, |
881 | | char * const filenames[], |
882 | | int number_of_filenames, |
883 | | int access_flags, |
884 | | libcerror_error_t **error ) |
885 | 0 | { |
886 | 0 | libbfio_handle_t *file_io_handle = NULL; |
887 | 0 | libbfio_pool_t *file_io_pool = NULL; |
888 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
889 | 0 | char *first_segment_filename = NULL; |
890 | 0 | static char *function = "libewf_handle_open"; |
891 | 0 | size_t filename_length = 0; |
892 | 0 | int file_io_pool_entry = 0; |
893 | 0 | int filename_index = 0; |
894 | 0 | int maximum_number_of_open_handles = 0; |
895 | 0 | int result = 0; |
896 | |
|
897 | 0 | if( handle == NULL ) |
898 | 0 | { |
899 | 0 | libcerror_error_set( |
900 | 0 | error, |
901 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
902 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
903 | 0 | "%s: invalid handle.", |
904 | 0 | function ); |
905 | |
|
906 | 0 | return( -1 ); |
907 | 0 | } |
908 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
909 | |
|
910 | 0 | if( filenames == NULL ) |
911 | 0 | { |
912 | 0 | libcerror_error_set( |
913 | 0 | error, |
914 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
915 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
916 | 0 | "%s: invalid filenames.", |
917 | 0 | function ); |
918 | |
|
919 | 0 | return( -1 ); |
920 | 0 | } |
921 | 0 | if( number_of_filenames <= 0 ) |
922 | 0 | { |
923 | 0 | libcerror_error_set( |
924 | 0 | error, |
925 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
926 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_ZERO_OR_LESS, |
927 | 0 | "%s: invalid number of files zero or less.", |
928 | 0 | function ); |
929 | |
|
930 | 0 | return( -1 ); |
931 | 0 | } |
932 | 0 | #if !defined( HAVE_WRITE_SUPPORT ) |
933 | 0 | if( ( access_flags & LIBEWF_ACCESS_FLAG_WRITE ) != 0 ) |
934 | 0 | { |
935 | 0 | libcerror_error_set( |
936 | 0 | error, |
937 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
938 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
939 | 0 | "%s: write access currently not supported - compiled without zlib.", |
940 | 0 | function ); |
941 | |
|
942 | 0 | return( -1 ); |
943 | 0 | } |
944 | 0 | #endif |
945 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
946 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
947 | 0 | internal_handle->read_write_lock, |
948 | 0 | error ) != 1 ) |
949 | 0 | { |
950 | 0 | libcerror_error_set( |
951 | 0 | error, |
952 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
953 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
954 | 0 | "%s: unable to grab read/write lock for reading.", |
955 | 0 | function ); |
956 | |
|
957 | 0 | return( -1 ); |
958 | 0 | } |
959 | 0 | #endif |
960 | 0 | maximum_number_of_open_handles = internal_handle->maximum_number_of_open_handles; |
961 | |
|
962 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
963 | 0 | if( libcthreads_read_write_lock_release_for_read( |
964 | 0 | internal_handle->read_write_lock, |
965 | 0 | error ) != 1 ) |
966 | 0 | { |
967 | 0 | libcerror_error_set( |
968 | 0 | error, |
969 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
970 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
971 | 0 | "%s: unable to release read/write lock for reading.", |
972 | 0 | function ); |
973 | |
|
974 | 0 | return( -1 ); |
975 | 0 | } |
976 | 0 | #endif |
977 | 0 | if( libbfio_pool_initialize( |
978 | 0 | &file_io_pool, |
979 | 0 | 0, |
980 | 0 | maximum_number_of_open_handles, |
981 | 0 | error ) != 1 ) |
982 | 0 | { |
983 | 0 | libcerror_error_set( |
984 | 0 | error, |
985 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
986 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
987 | 0 | "%s: unable to create file IO pool.", |
988 | 0 | function ); |
989 | |
|
990 | 0 | goto on_error; |
991 | 0 | } |
992 | 0 | if( ( ( access_flags & LIBEWF_ACCESS_FLAG_READ ) != 0 ) |
993 | 0 | || ( ( access_flags & LIBEWF_ACCESS_FLAG_RESUME ) != 0 ) ) |
994 | 0 | { |
995 | 0 | for( filename_index = 0; |
996 | 0 | filename_index < number_of_filenames; |
997 | 0 | filename_index++ ) |
998 | 0 | { |
999 | 0 | filename_length = narrow_string_length( |
1000 | 0 | filenames[ filename_index ] ); |
1001 | | |
1002 | | /* Make sure there is more to the filename than the extension |
1003 | | */ |
1004 | 0 | if( filename_length <= 4 ) |
1005 | 0 | { |
1006 | 0 | libcerror_error_set( |
1007 | 0 | error, |
1008 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1009 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
1010 | 0 | "%s: filename: %s is too small.", |
1011 | 0 | function, |
1012 | 0 | filenames[ filename_index ] ); |
1013 | |
|
1014 | 0 | goto on_error; |
1015 | 0 | } |
1016 | 0 | if( libbfio_file_initialize( |
1017 | 0 | &file_io_handle, |
1018 | 0 | error ) != 1 ) |
1019 | 0 | { |
1020 | 0 | libcerror_error_set( |
1021 | 0 | error, |
1022 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1023 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1024 | 0 | "%s: unable to create file IO handle.", |
1025 | 0 | function ); |
1026 | |
|
1027 | 0 | goto on_error; |
1028 | 0 | } |
1029 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1030 | | if( libbfio_handle_set_track_offsets_read( |
1031 | | file_io_handle, |
1032 | | 1, |
1033 | | error ) != 1 ) |
1034 | | { |
1035 | | libcerror_error_set( |
1036 | | error, |
1037 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1038 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1039 | | "%s: unable to set track offsets read in file IO handle.", |
1040 | | function ); |
1041 | | |
1042 | | goto on_error; |
1043 | | } |
1044 | | #endif |
1045 | 0 | if( libbfio_file_set_name( |
1046 | 0 | file_io_handle, |
1047 | 0 | filenames[ filename_index ], |
1048 | 0 | filename_length, |
1049 | 0 | error ) != 1 ) |
1050 | 0 | { |
1051 | 0 | libcerror_error_set( |
1052 | 0 | error, |
1053 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1054 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1055 | 0 | "%s: unable to set name in file IO handle.", |
1056 | 0 | function ); |
1057 | |
|
1058 | 0 | goto on_error; |
1059 | 0 | } |
1060 | 0 | if( libbfio_pool_append_handle( |
1061 | 0 | file_io_pool, |
1062 | 0 | &file_io_pool_entry, |
1063 | 0 | file_io_handle, |
1064 | 0 | LIBBFIO_OPEN_READ, |
1065 | 0 | error ) != 1 ) |
1066 | 0 | { |
1067 | 0 | libcerror_error_set( |
1068 | 0 | error, |
1069 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1070 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
1071 | 0 | "%s: unable to append file IO handle to pool.", |
1072 | 0 | function ); |
1073 | |
|
1074 | 0 | goto on_error; |
1075 | 0 | } |
1076 | 0 | file_io_handle = NULL; |
1077 | |
|
1078 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1079 | | if( libcnotify_verbose != 0 ) |
1080 | | { |
1081 | | libcnotify_printf( |
1082 | | "%s: added file IO pool entry: %d with filename: %s.\n", |
1083 | | function, |
1084 | | file_io_pool_entry, |
1085 | | filenames[ filename_index ] ); |
1086 | | } |
1087 | | #endif |
1088 | 0 | if( ( filenames[ filename_index ][ filename_length - 3 ] == 'e' ) |
1089 | 0 | || ( filenames[ filename_index ][ filename_length - 3 ] == 'E' ) |
1090 | 0 | || ( filenames[ filename_index ][ filename_length - 3 ] == 'l' ) |
1091 | 0 | || ( filenames[ filename_index ][ filename_length - 3 ] == 'L' ) |
1092 | 0 | || ( filenames[ filename_index ][ filename_length - 3 ] == 's' ) |
1093 | 0 | || ( filenames[ filename_index ][ filename_length - 3 ] == 'S' ) ) |
1094 | 0 | { |
1095 | 0 | if( ( filenames[ filename_index ][ filename_length - 2 ] == '0' ) |
1096 | 0 | && ( filenames[ filename_index ][ filename_length - 1 ] == '1' ) ) |
1097 | 0 | { |
1098 | 0 | first_segment_filename = filenames[ filename_index ]; |
1099 | 0 | } |
1100 | 0 | } |
1101 | 0 | } |
1102 | 0 | } |
1103 | 0 | if( ( ( access_flags & LIBEWF_ACCESS_FLAG_READ ) != 0 ) |
1104 | 0 | || ( ( access_flags & LIBEWF_ACCESS_FLAG_RESUME ) != 0 ) ) |
1105 | 0 | { |
1106 | | /* Get the basename of the first segment file |
1107 | | */ |
1108 | 0 | if( first_segment_filename != NULL ) |
1109 | 0 | { |
1110 | 0 | filename_length = narrow_string_length( |
1111 | 0 | first_segment_filename ); |
1112 | | |
1113 | | /* Set segment table basename |
1114 | | */ |
1115 | 0 | if( libewf_segment_table_set_basename( |
1116 | 0 | internal_handle->segment_table, |
1117 | 0 | first_segment_filename, |
1118 | 0 | filename_length - 4, |
1119 | 0 | error ) != 1 ) |
1120 | 0 | { |
1121 | 0 | libcerror_error_set( |
1122 | 0 | error, |
1123 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1124 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1125 | 0 | "%s: unable to set basename in segment table.", |
1126 | 0 | function ); |
1127 | |
|
1128 | 0 | goto on_error; |
1129 | 0 | } |
1130 | 0 | } |
1131 | 0 | } |
1132 | 0 | else if( ( access_flags & LIBEWF_ACCESS_FLAG_WRITE ) != 0 ) |
1133 | 0 | { |
1134 | | /* Get the basename and store it in the segment tables |
1135 | | */ |
1136 | 0 | filename_length = narrow_string_length( |
1137 | 0 | filenames[ 0 ] ); |
1138 | | |
1139 | | /* Set segment table basename |
1140 | | */ |
1141 | 0 | if( libewf_segment_table_set_basename( |
1142 | 0 | internal_handle->segment_table, |
1143 | 0 | filenames[ 0 ], |
1144 | 0 | filename_length, |
1145 | 0 | error ) != 1 ) |
1146 | 0 | { |
1147 | 0 | libcerror_error_set( |
1148 | 0 | error, |
1149 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1150 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1151 | 0 | "%s: unable to set basename in segment table.", |
1152 | 0 | function ); |
1153 | |
|
1154 | 0 | goto on_error; |
1155 | 0 | } |
1156 | 0 | } |
1157 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
1158 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
1159 | 0 | internal_handle->read_write_lock, |
1160 | 0 | error ) != 1 ) |
1161 | 0 | { |
1162 | 0 | libcerror_error_set( |
1163 | 0 | error, |
1164 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1165 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1166 | 0 | "%s: unable to grab read/write lock for writing.", |
1167 | 0 | function ); |
1168 | |
|
1169 | 0 | goto on_error; |
1170 | 0 | } |
1171 | 0 | #endif |
1172 | 0 | result = libewf_internal_handle_open_file_io_pool( |
1173 | 0 | internal_handle, |
1174 | 0 | file_io_pool, |
1175 | 0 | access_flags, |
1176 | 0 | internal_handle->segment_table, |
1177 | 0 | error ); |
1178 | |
|
1179 | 0 | if( result != 1 ) |
1180 | 0 | { |
1181 | 0 | libcerror_error_set( |
1182 | 0 | error, |
1183 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1184 | 0 | LIBCERROR_IO_ERROR_OPEN_FAILED, |
1185 | 0 | "%s: unable to open handle using a file IO pool.", |
1186 | 0 | function ); |
1187 | |
|
1188 | 0 | libbfio_pool_free( |
1189 | 0 | &file_io_pool, |
1190 | 0 | NULL ); |
1191 | |
|
1192 | 0 | result = -1; |
1193 | 0 | } |
1194 | 0 | else |
1195 | 0 | { |
1196 | 0 | internal_handle->file_io_pool = file_io_pool; |
1197 | 0 | internal_handle->file_io_pool_created_in_library = 1; |
1198 | 0 | } |
1199 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
1200 | 0 | if( libcthreads_read_write_lock_release_for_write( |
1201 | 0 | internal_handle->read_write_lock, |
1202 | 0 | error ) != 1 ) |
1203 | 0 | { |
1204 | 0 | libcerror_error_set( |
1205 | 0 | error, |
1206 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1207 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1208 | 0 | "%s: unable to release read/write lock for writing.", |
1209 | 0 | function ); |
1210 | |
|
1211 | 0 | result = -1; |
1212 | 0 | } |
1213 | 0 | #endif |
1214 | 0 | if( result != 1 ) |
1215 | 0 | { |
1216 | 0 | goto on_error; |
1217 | 0 | } |
1218 | 0 | return( 1 ); |
1219 | | |
1220 | 0 | on_error: |
1221 | 0 | if( file_io_handle != NULL ) |
1222 | 0 | { |
1223 | 0 | libbfio_handle_free( |
1224 | 0 | &file_io_handle, |
1225 | 0 | NULL ); |
1226 | 0 | } |
1227 | 0 | if( file_io_pool != NULL ) |
1228 | 0 | { |
1229 | 0 | libbfio_pool_free( |
1230 | 0 | &file_io_pool, |
1231 | 0 | NULL ); |
1232 | 0 | } |
1233 | 0 | internal_handle->file_io_pool = NULL; |
1234 | 0 | internal_handle->file_io_pool_created_in_library = 0; |
1235 | |
|
1236 | 0 | return( -1 ); |
1237 | 0 | } |
1238 | | |
1239 | | #if defined( HAVE_WIDE_CHARACTER_TYPE ) |
1240 | | |
1241 | | /* Opens a set of EWF file(s) |
1242 | | * For reading files should contain all filenames that make up an EWF image |
1243 | | * For writing files should contain the base of the filename, extentions like .e01 will be automatically added |
1244 | | * Returns 1 if successful or -1 on error |
1245 | | */ |
1246 | | int libewf_handle_open_wide( |
1247 | | libewf_handle_t *handle, |
1248 | | wchar_t * const filenames[], |
1249 | | int number_of_filenames, |
1250 | | int access_flags, |
1251 | | libcerror_error_t **error ) |
1252 | | { |
1253 | | libbfio_handle_t *file_io_handle = NULL; |
1254 | | libbfio_pool_t *file_io_pool = NULL; |
1255 | | libewf_internal_handle_t *internal_handle = NULL; |
1256 | | wchar_t *first_segment_filename = NULL; |
1257 | | static char *function = "libewf_handle_open_wide"; |
1258 | | size_t filename_length = 0; |
1259 | | int file_io_pool_entry = 0; |
1260 | | int filename_index = 0; |
1261 | | int maximum_number_of_open_handles = 0; |
1262 | | int result = 0; |
1263 | | |
1264 | | if( handle == NULL ) |
1265 | | { |
1266 | | libcerror_error_set( |
1267 | | error, |
1268 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1269 | | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1270 | | "%s: invalid handle.", |
1271 | | function ); |
1272 | | |
1273 | | return( -1 ); |
1274 | | } |
1275 | | internal_handle = (libewf_internal_handle_t *) handle; |
1276 | | |
1277 | | if( filenames == NULL ) |
1278 | | { |
1279 | | libcerror_error_set( |
1280 | | error, |
1281 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1282 | | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1283 | | "%s: invalid filenames.", |
1284 | | function ); |
1285 | | |
1286 | | return( -1 ); |
1287 | | } |
1288 | | if( number_of_filenames <= 0 ) |
1289 | | { |
1290 | | libcerror_error_set( |
1291 | | error, |
1292 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1293 | | LIBCERROR_ARGUMENT_ERROR_VALUE_ZERO_OR_LESS, |
1294 | | "%s: invalid number of files zero or less.", |
1295 | | function ); |
1296 | | |
1297 | | return( -1 ); |
1298 | | } |
1299 | | #if !defined( HAVE_WRITE_SUPPORT ) |
1300 | | if( ( access_flags & LIBEWF_ACCESS_FLAG_WRITE ) != 0 ) |
1301 | | { |
1302 | | libcerror_error_set( |
1303 | | error, |
1304 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1305 | | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
1306 | | "%s: write access currently not supported - compiled without zlib.", |
1307 | | function ); |
1308 | | |
1309 | | return( -1 ); |
1310 | | } |
1311 | | #endif |
1312 | | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
1313 | | if( libcthreads_read_write_lock_grab_for_read( |
1314 | | internal_handle->read_write_lock, |
1315 | | error ) != 1 ) |
1316 | | { |
1317 | | libcerror_error_set( |
1318 | | error, |
1319 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1320 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1321 | | "%s: unable to grab read/write lock for reading.", |
1322 | | function ); |
1323 | | |
1324 | | return( -1 ); |
1325 | | } |
1326 | | #endif |
1327 | | maximum_number_of_open_handles = internal_handle->maximum_number_of_open_handles; |
1328 | | |
1329 | | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
1330 | | if( libcthreads_read_write_lock_release_for_read( |
1331 | | internal_handle->read_write_lock, |
1332 | | error ) != 1 ) |
1333 | | { |
1334 | | libcerror_error_set( |
1335 | | error, |
1336 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1337 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1338 | | "%s: unable to release read/write lock for reading.", |
1339 | | function ); |
1340 | | |
1341 | | return( -1 ); |
1342 | | } |
1343 | | #endif |
1344 | | if( libbfio_pool_initialize( |
1345 | | &file_io_pool, |
1346 | | 0, |
1347 | | maximum_number_of_open_handles, |
1348 | | error ) != 1 ) |
1349 | | { |
1350 | | libcerror_error_set( |
1351 | | error, |
1352 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1353 | | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1354 | | "%s: unable to create file IO pool.", |
1355 | | function ); |
1356 | | |
1357 | | goto on_error; |
1358 | | } |
1359 | | if( ( ( access_flags & LIBEWF_ACCESS_FLAG_READ ) != 0 ) |
1360 | | || ( ( access_flags & LIBEWF_ACCESS_FLAG_RESUME ) != 0 ) ) |
1361 | | { |
1362 | | for( filename_index = 0; |
1363 | | filename_index < number_of_filenames; |
1364 | | filename_index++ ) |
1365 | | { |
1366 | | filename_length = wide_string_length( |
1367 | | filenames[ filename_index ] ); |
1368 | | |
1369 | | /* Make sure there is more to the filename than the extension |
1370 | | */ |
1371 | | if( filename_length <= 4 ) |
1372 | | { |
1373 | | libcerror_error_set( |
1374 | | error, |
1375 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1376 | | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
1377 | | "%s: filename: %ls is too small.", |
1378 | | function, |
1379 | | filenames[ filename_index ] ); |
1380 | | |
1381 | | goto on_error; |
1382 | | } |
1383 | | if( libbfio_file_initialize( |
1384 | | &file_io_handle, |
1385 | | error ) != 1 ) |
1386 | | { |
1387 | | libcerror_error_set( |
1388 | | error, |
1389 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1390 | | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1391 | | "%s: unable to create file IO handle.", |
1392 | | function ); |
1393 | | |
1394 | | goto on_error; |
1395 | | } |
1396 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1397 | | if( libbfio_handle_set_track_offsets_read( |
1398 | | file_io_handle, |
1399 | | 1, |
1400 | | error ) != 1 ) |
1401 | | { |
1402 | | libcerror_error_set( |
1403 | | error, |
1404 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1405 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1406 | | "%s: unable to set track offsets read in file IO handle.", |
1407 | | function ); |
1408 | | |
1409 | | goto on_error; |
1410 | | } |
1411 | | #endif |
1412 | | if( libbfio_file_set_name_wide( |
1413 | | file_io_handle, |
1414 | | filenames[ filename_index ], |
1415 | | filename_length, |
1416 | | error ) != 1 ) |
1417 | | { |
1418 | | libcerror_error_set( |
1419 | | error, |
1420 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1421 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1422 | | "%s: unable to set name in file IO handle.", |
1423 | | function ); |
1424 | | |
1425 | | goto on_error; |
1426 | | } |
1427 | | if( libbfio_pool_append_handle( |
1428 | | file_io_pool, |
1429 | | &file_io_pool_entry, |
1430 | | file_io_handle, |
1431 | | LIBBFIO_OPEN_READ, |
1432 | | error ) != 1 ) |
1433 | | { |
1434 | | libcerror_error_set( |
1435 | | error, |
1436 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1437 | | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
1438 | | "%s: unable to append file IO handle to pool.", |
1439 | | function ); |
1440 | | |
1441 | | goto on_error; |
1442 | | } |
1443 | | file_io_handle = NULL; |
1444 | | |
1445 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1446 | | if( libcnotify_verbose != 0 ) |
1447 | | { |
1448 | | libcnotify_printf( |
1449 | | "%s: added file IO pool entry: %d with filename: %ls.\n", |
1450 | | function, |
1451 | | file_io_pool_entry, |
1452 | | filenames[ filename_index ] ); |
1453 | | } |
1454 | | #endif |
1455 | | if( ( filenames[ filename_index ][ filename_length - 3 ] == 'e' ) |
1456 | | || ( filenames[ filename_index ][ filename_length - 3 ] == 'E' ) |
1457 | | || ( filenames[ filename_index ][ filename_length - 3 ] == 'l' ) |
1458 | | || ( filenames[ filename_index ][ filename_length - 3 ] == 'L' ) |
1459 | | || ( filenames[ filename_index ][ filename_length - 3 ] == 's' ) |
1460 | | || ( filenames[ filename_index ][ filename_length - 3 ] == 'S' ) ) |
1461 | | { |
1462 | | if( ( filenames[ filename_index ][ filename_length - 2 ] == '0' ) |
1463 | | && ( filenames[ filename_index ][ filename_length - 1 ] == '1' ) ) |
1464 | | { |
1465 | | first_segment_filename = filenames[ filename_index ]; |
1466 | | } |
1467 | | } |
1468 | | } |
1469 | | } |
1470 | | if( ( ( access_flags & LIBEWF_ACCESS_FLAG_READ ) != 0 ) |
1471 | | || ( ( access_flags & LIBEWF_ACCESS_FLAG_RESUME ) != 0 ) ) |
1472 | | { |
1473 | | /* Get the basename of the first segment file |
1474 | | */ |
1475 | | if( first_segment_filename != NULL ) |
1476 | | { |
1477 | | filename_length = wide_string_length( |
1478 | | first_segment_filename ); |
1479 | | |
1480 | | /* Set segment table basename |
1481 | | */ |
1482 | | if( libewf_segment_table_set_basename_wide( |
1483 | | internal_handle->segment_table, |
1484 | | first_segment_filename, |
1485 | | filename_length - 4, |
1486 | | error ) != 1 ) |
1487 | | { |
1488 | | libcerror_error_set( |
1489 | | error, |
1490 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1491 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1492 | | "%s: unable to set basename in segment table.", |
1493 | | function ); |
1494 | | |
1495 | | goto on_error; |
1496 | | } |
1497 | | } |
1498 | | } |
1499 | | else if( ( access_flags & LIBEWF_ACCESS_FLAG_WRITE ) != 0 ) |
1500 | | { |
1501 | | /* Get the basename and store it in the segment tables |
1502 | | */ |
1503 | | filename_length = wide_string_length( |
1504 | | filenames[ 0 ] ); |
1505 | | |
1506 | | /* Set segment table basename |
1507 | | */ |
1508 | | if( libewf_segment_table_set_basename_wide( |
1509 | | internal_handle->segment_table, |
1510 | | filenames[ 0 ], |
1511 | | filename_length, |
1512 | | error ) != 1 ) |
1513 | | { |
1514 | | libcerror_error_set( |
1515 | | error, |
1516 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1517 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1518 | | "%s: unable to set basename in segment table.", |
1519 | | function ); |
1520 | | |
1521 | | goto on_error; |
1522 | | } |
1523 | | } |
1524 | | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
1525 | | if( libcthreads_read_write_lock_grab_for_write( |
1526 | | internal_handle->read_write_lock, |
1527 | | error ) != 1 ) |
1528 | | { |
1529 | | libcerror_error_set( |
1530 | | error, |
1531 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1532 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1533 | | "%s: unable to grab read/write lock for writing.", |
1534 | | function ); |
1535 | | |
1536 | | goto on_error; |
1537 | | } |
1538 | | #endif |
1539 | | result = libewf_internal_handle_open_file_io_pool( |
1540 | | internal_handle, |
1541 | | file_io_pool, |
1542 | | access_flags, |
1543 | | internal_handle->segment_table, |
1544 | | error ); |
1545 | | |
1546 | | if( result != 1 ) |
1547 | | { |
1548 | | libcerror_error_set( |
1549 | | error, |
1550 | | LIBCERROR_ERROR_DOMAIN_IO, |
1551 | | LIBCERROR_IO_ERROR_OPEN_FAILED, |
1552 | | "%s: unable to open handle using a file IO pool.", |
1553 | | function ); |
1554 | | |
1555 | | result = -1; |
1556 | | } |
1557 | | else |
1558 | | { |
1559 | | internal_handle->file_io_pool = file_io_pool; |
1560 | | internal_handle->file_io_pool_created_in_library = 1; |
1561 | | } |
1562 | | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
1563 | | if( libcthreads_read_write_lock_release_for_write( |
1564 | | internal_handle->read_write_lock, |
1565 | | error ) != 1 ) |
1566 | | { |
1567 | | libcerror_error_set( |
1568 | | error, |
1569 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1570 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
1571 | | "%s: unable to release read/write lock for writing.", |
1572 | | function ); |
1573 | | |
1574 | | result = -1; |
1575 | | } |
1576 | | #endif |
1577 | | if( result != 1 ) |
1578 | | { |
1579 | | goto on_error; |
1580 | | } |
1581 | | return( 1 ); |
1582 | | |
1583 | | on_error: |
1584 | | if( file_io_handle != NULL ) |
1585 | | { |
1586 | | libbfio_handle_free( |
1587 | | &file_io_handle, |
1588 | | NULL ); |
1589 | | } |
1590 | | if( file_io_pool != NULL ) |
1591 | | { |
1592 | | libbfio_pool_free( |
1593 | | &file_io_pool, |
1594 | | NULL ); |
1595 | | } |
1596 | | internal_handle->file_io_pool = NULL; |
1597 | | internal_handle->file_io_pool_created_in_library = 0; |
1598 | | |
1599 | | return( -1 ); |
1600 | | } |
1601 | | |
1602 | | #endif /* defined( HAVE_WIDE_CHARACTER_TYPE ) */ |
1603 | | |
1604 | | /* Reads the section data from a segment file |
1605 | | * Returns 1 if successful or -1 on error |
1606 | | */ |
1607 | | int libewf_internal_handle_open_read_segment_file_section_data( |
1608 | | libewf_internal_handle_t *internal_handle, |
1609 | | libewf_segment_file_t *segment_file, |
1610 | | libbfio_pool_t *file_io_pool, |
1611 | | int file_io_pool_entry, |
1612 | | libcerror_error_t **error ) |
1613 | 2.58k | { |
1614 | 2.58k | libewf_header_sections_t *header_sections = NULL; |
1615 | 2.58k | libewf_section_descriptor_t *section = NULL; |
1616 | 2.58k | libfcache_cache_t *sections_cache = NULL; |
1617 | 2.58k | uint8_t *single_files_data = NULL; |
1618 | 2.58k | uint8_t *single_files_section_data = NULL; |
1619 | 2.58k | uint8_t *string_data = NULL; |
1620 | 2.58k | static char *function = "libewf_internal_handle_open_read_segment_file_section_data"; |
1621 | 2.58k | size_t single_files_data_size = 0; |
1622 | 2.58k | size_t single_files_section_data_size = 0; |
1623 | 2.58k | size_t string_data_size = 0; |
1624 | 2.58k | ssize_t read_count = 0; |
1625 | 2.58k | off64_t section_data_offset = 0; |
1626 | 2.58k | uint8_t header_section_found = 0; |
1627 | 2.58k | uint8_t initialize_chunk_values = 0; |
1628 | 2.58k | int number_of_sections = 0; |
1629 | 2.58k | int read_table_sections = 0; |
1630 | 2.58k | int result = 0; |
1631 | 2.58k | int section_index = 0; |
1632 | 2.58k | int set_identifier_change = 0; |
1633 | | |
1634 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
1635 | | int known_section = 0; |
1636 | | #endif |
1637 | | |
1638 | 2.58k | if( internal_handle == NULL ) |
1639 | 0 | { |
1640 | 0 | libcerror_error_set( |
1641 | 0 | error, |
1642 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1643 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1644 | 0 | "%s: invalid handle.", |
1645 | 0 | function ); |
1646 | |
|
1647 | 0 | return( -1 ); |
1648 | 0 | } |
1649 | 2.58k | if( internal_handle->io_handle == NULL ) |
1650 | 0 | { |
1651 | 0 | libcerror_error_set( |
1652 | 0 | error, |
1653 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1654 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1655 | 0 | "%s: invalid handle - missing IO handle.", |
1656 | 0 | function ); |
1657 | |
|
1658 | 0 | return( -1 ); |
1659 | 0 | } |
1660 | 2.58k | if( internal_handle->read_io_handle == NULL ) |
1661 | 0 | { |
1662 | 0 | libcerror_error_set( |
1663 | 0 | error, |
1664 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1665 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1666 | 0 | "%s: invalid handle - missing read IO handle.", |
1667 | 0 | function ); |
1668 | |
|
1669 | 0 | return( -1 ); |
1670 | 0 | } |
1671 | 2.58k | if( internal_handle->media_values == NULL ) |
1672 | 0 | { |
1673 | 0 | libcerror_error_set( |
1674 | 0 | error, |
1675 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1676 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
1677 | 0 | "%s: invalid handle - missing media values.", |
1678 | 0 | function ); |
1679 | |
|
1680 | 0 | return( -1 ); |
1681 | 0 | } |
1682 | 2.58k | if( internal_handle->single_files != NULL ) |
1683 | 0 | { |
1684 | 0 | libcerror_error_set( |
1685 | 0 | error, |
1686 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1687 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
1688 | 0 | "%s: invalid handle - single files value already set.", |
1689 | 0 | function ); |
1690 | |
|
1691 | 0 | return( -1 ); |
1692 | 0 | } |
1693 | 2.58k | if( segment_file == NULL ) |
1694 | 0 | { |
1695 | 0 | libcerror_error_set( |
1696 | 0 | error, |
1697 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
1698 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
1699 | 0 | "%s: invalid segment file.", |
1700 | 0 | function ); |
1701 | |
|
1702 | 0 | return( -1 ); |
1703 | 0 | } |
1704 | 2.58k | if( libfcache_cache_initialize( |
1705 | 2.58k | §ions_cache, |
1706 | 2.58k | LIBEWF_MAXIMUM_CACHE_ENTRIES_SECTIONS, |
1707 | 2.58k | error ) != 1 ) |
1708 | 0 | { |
1709 | 0 | libcerror_error_set( |
1710 | 0 | error, |
1711 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1712 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1713 | 0 | "%s: unable to create sections cache.", |
1714 | 0 | function ); |
1715 | |
|
1716 | 0 | goto on_error; |
1717 | 0 | } |
1718 | 2.58k | if( libewf_header_sections_initialize( |
1719 | 2.58k | &header_sections, |
1720 | 2.58k | error ) != 1 ) |
1721 | 0 | { |
1722 | 0 | libcerror_error_set( |
1723 | 0 | error, |
1724 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1725 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
1726 | 0 | "%s: unable to create header sections.", |
1727 | 0 | function ); |
1728 | |
|
1729 | 0 | goto on_error; |
1730 | 0 | } |
1731 | 2.58k | if( libfdata_list_get_number_of_elements( |
1732 | 2.58k | segment_file->sections_list, |
1733 | 2.58k | &number_of_sections, |
1734 | 2.58k | error ) != 1 ) |
1735 | 0 | { |
1736 | 0 | libcerror_error_set( |
1737 | 0 | error, |
1738 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1739 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1740 | 0 | "%s: unable to retrieve the number of sections in the sections list.", |
1741 | 0 | function ); |
1742 | |
|
1743 | 0 | goto on_error; |
1744 | 0 | } |
1745 | 2.58k | for( section_index = 0; |
1746 | 9.19k | section_index < number_of_sections; |
1747 | 6.60k | section_index++ ) |
1748 | 8.08k | { |
1749 | 8.08k | if( libfdata_list_get_element_value_by_index( |
1750 | 8.08k | segment_file->sections_list, |
1751 | 8.08k | (intptr_t *) file_io_pool, |
1752 | 8.08k | (libfdata_cache_t *) sections_cache, |
1753 | 8.08k | section_index, |
1754 | 8.08k | (intptr_t **) §ion, |
1755 | 8.08k | 0, |
1756 | 8.08k | error ) != 1 ) |
1757 | 0 | { |
1758 | 0 | libcerror_error_set( |
1759 | 0 | error, |
1760 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1761 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1762 | 0 | "%s: unable to retrieve section: %d from sections list.", |
1763 | 0 | function, |
1764 | 0 | section_index ); |
1765 | |
|
1766 | 0 | goto on_error; |
1767 | 0 | } |
1768 | 8.08k | result = libewf_section_get_data_offset( |
1769 | 8.08k | section, |
1770 | 8.08k | segment_file->major_version, |
1771 | 8.08k | §ion_data_offset, |
1772 | 8.08k | error ); |
1773 | | |
1774 | 8.08k | if( result == -1 ) |
1775 | 0 | { |
1776 | 0 | libcerror_error_set( |
1777 | 0 | error, |
1778 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
1779 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
1780 | 0 | "%s: unable to retrieve section: %d data offset.", |
1781 | 0 | function, |
1782 | 0 | section_index ); |
1783 | |
|
1784 | 0 | goto on_error; |
1785 | 0 | } |
1786 | 8.08k | else if( result != 0 ) |
1787 | 8.08k | { |
1788 | 8.08k | if( libewf_segment_file_seek_offset( |
1789 | 8.08k | segment_file, |
1790 | 8.08k | file_io_pool, |
1791 | 8.08k | file_io_pool_entry, |
1792 | 8.08k | section_data_offset, |
1793 | 8.08k | error ) == -1 ) |
1794 | 0 | { |
1795 | 0 | libcerror_error_set( |
1796 | 0 | error, |
1797 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
1798 | 0 | LIBCERROR_IO_ERROR_OPEN_FAILED, |
1799 | 0 | "%s: unable to seek section: %d data offset: %" PRIu64 ".", |
1800 | 0 | function, |
1801 | 0 | section_index, |
1802 | 0 | section_data_offset ); |
1803 | |
|
1804 | 0 | goto on_error; |
1805 | 0 | } |
1806 | | #if defined( HAVE_DEBUG_OUTPUT ) |
1807 | | if( libcnotify_verbose != 0 ) |
1808 | | { |
1809 | | if( segment_file->major_version == 1 ) |
1810 | | { |
1811 | | libcnotify_printf( |
1812 | | "%s: reading %s section data from file IO pool entry: %d at offset: %" PRIi64 " (0x%08" PRIx64 ")\n", |
1813 | | function, |
1814 | | (char *) section->type_string, |
1815 | | file_io_pool_entry, |
1816 | | segment_file->current_offset, |
1817 | | segment_file->current_offset ); |
1818 | | } |
1819 | | else if( segment_file->major_version == 2 ) |
1820 | | { |
1821 | | libcnotify_printf( |
1822 | | "%s: reading 0x%08" PRIx32 " section data from file IO pool entry: %d at offset: %" PRIi64 " (0x%08" PRIx64 ")\n", |
1823 | | function, |
1824 | | section->type, |
1825 | | file_io_pool_entry, |
1826 | | segment_file->current_offset, |
1827 | | segment_file->current_offset ); |
1828 | | } |
1829 | | } |
1830 | | #endif /* defined( HAVE_DEBUG_OUTPUT ) */ |
1831 | 8.08k | } |
1832 | 8.08k | if( section->type != 0 ) |
1833 | 1.84k | { |
1834 | 1.84k | switch( section->type ) |
1835 | 1.84k | { |
1836 | 0 | case LIBEWF_SECTION_TYPE_DEVICE_INFORMATION: |
1837 | 0 | read_count = libewf_device_information_section_read_file_io_pool( |
1838 | 0 | section, |
1839 | 0 | internal_handle->io_handle, |
1840 | 0 | file_io_pool, |
1841 | 0 | file_io_pool_entry, |
1842 | 0 | internal_handle->read_io_handle, |
1843 | 0 | internal_handle->media_values, |
1844 | 0 | internal_handle->header_values, |
1845 | 0 | error ); |
1846 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
1847 | | known_section = 1; |
1848 | | #endif |
1849 | 0 | break; |
1850 | | |
1851 | 0 | case LIBEWF_SECTION_TYPE_CASE_DATA: |
1852 | 0 | if( internal_handle->read_io_handle->case_data == NULL ) |
1853 | 0 | { |
1854 | 0 | initialize_chunk_values = 1; |
1855 | 0 | } |
1856 | 0 | read_count = libewf_case_data_section_read_file_io_pool( |
1857 | 0 | section, |
1858 | 0 | internal_handle->io_handle, |
1859 | 0 | file_io_pool, |
1860 | 0 | file_io_pool_entry, |
1861 | 0 | internal_handle->read_io_handle, |
1862 | 0 | internal_handle->media_values, |
1863 | 0 | internal_handle->header_values, |
1864 | 0 | error ); |
1865 | |
|
1866 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
1867 | | known_section = 1; |
1868 | | #endif |
1869 | 0 | break; |
1870 | | |
1871 | 768 | case LIBEWF_SECTION_TYPE_SECTOR_DATA: |
1872 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
1873 | | if( libcnotify_verbose != 0 ) |
1874 | | { |
1875 | | if( internal_handle->io_handle->segment_file_type == LIBEWF_SEGMENT_FILE_TYPE_EWF1_SMART ) |
1876 | | { |
1877 | | libcnotify_printf( |
1878 | | "%s: found sectors section in EWF-S01 format.\n", |
1879 | | function ); |
1880 | | } |
1881 | | } |
1882 | | #endif |
1883 | | /* Nothing to do for the sectors section |
1884 | | */ |
1885 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
1886 | | known_section = 1; |
1887 | | #endif |
1888 | 768 | break; |
1889 | | |
1890 | 777 | case LIBEWF_SECTION_TYPE_SECTOR_TABLE: |
1891 | | /* If the chunk_size was unknown when the segment file was opened we |
1892 | | * have to read the chunk groups here |
1893 | | */ |
1894 | 777 | if( segment_file->number_of_chunks == 0 ) |
1895 | 775 | { |
1896 | 775 | read_table_sections = 1; |
1897 | 775 | } |
1898 | 777 | if( read_table_sections != 0 ) |
1899 | 777 | { |
1900 | 777 | read_count = libewf_segment_file_read_table_section( |
1901 | 777 | segment_file, |
1902 | 777 | section, |
1903 | 777 | file_io_pool, |
1904 | 777 | file_io_pool_entry, |
1905 | 777 | internal_handle->media_values->chunk_size, |
1906 | 777 | error ); |
1907 | 777 | } |
1908 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
1909 | | known_section = 1; |
1910 | | #endif |
1911 | 777 | break; |
1912 | | |
1913 | 5 | case LIBEWF_SECTION_TYPE_ERROR_TABLE: |
1914 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
1915 | | if( libcnotify_verbose != 0 ) |
1916 | | { |
1917 | | if( internal_handle->io_handle->segment_file_type == LIBEWF_SEGMENT_FILE_TYPE_EWF1_SMART ) |
1918 | | { |
1919 | | libcnotify_printf( |
1920 | | "%s: found error section in EWF-S01 format.\n", |
1921 | | function ); |
1922 | | } |
1923 | | } |
1924 | | #endif |
1925 | 5 | read_count = libewf_error2_section_read_file_io_pool( |
1926 | 5 | section, |
1927 | 5 | internal_handle->io_handle, |
1928 | 5 | file_io_pool, |
1929 | 5 | file_io_pool_entry, |
1930 | 5 | segment_file->major_version, |
1931 | 5 | internal_handle->acquiry_errors, |
1932 | 5 | error ); |
1933 | | |
1934 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
1935 | | known_section = 1; |
1936 | | #endif |
1937 | 5 | break; |
1938 | | |
1939 | 181 | case LIBEWF_SECTION_TYPE_SESSION_TABLE: |
1940 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
1941 | | if( libcnotify_verbose != 0 ) |
1942 | | { |
1943 | | if( internal_handle->io_handle->segment_file_type == LIBEWF_SEGMENT_FILE_TYPE_EWF1_SMART ) |
1944 | | { |
1945 | | libcnotify_printf( |
1946 | | "%s: found session section in EWF-S01 format.\n", |
1947 | | function ); |
1948 | | } |
1949 | | } |
1950 | | #endif |
1951 | 181 | read_count = libewf_session_section_read_file_io_pool( |
1952 | 181 | section, |
1953 | 181 | internal_handle->io_handle, |
1954 | 181 | file_io_pool, |
1955 | 181 | file_io_pool_entry, |
1956 | 181 | segment_file->major_version, |
1957 | 181 | internal_handle->media_values, |
1958 | 181 | internal_handle->sessions, |
1959 | 181 | internal_handle->tracks, |
1960 | 181 | error ); |
1961 | | |
1962 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
1963 | | known_section = 1; |
1964 | | #endif |
1965 | 181 | break; |
1966 | | |
1967 | 0 | case LIBEWF_SECTION_TYPE_INCREMENT_DATA: |
1968 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
1969 | | known_section = 1; |
1970 | | #endif |
1971 | 0 | break; |
1972 | | |
1973 | 57 | case LIBEWF_SECTION_TYPE_MD5_HASH: |
1974 | 57 | read_count = libewf_md5_hash_section_read_file_io_pool( |
1975 | 57 | section, |
1976 | 57 | internal_handle->io_handle, |
1977 | 57 | file_io_pool, |
1978 | 57 | file_io_pool_entry, |
1979 | 57 | segment_file->major_version, |
1980 | 57 | internal_handle->hash_sections, |
1981 | 57 | error ); |
1982 | | |
1983 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
1984 | | known_section = 1; |
1985 | | #endif |
1986 | 57 | break; |
1987 | | |
1988 | 0 | case LIBEWF_SECTION_TYPE_SHA1_HASH: |
1989 | 0 | read_count = libewf_sha1_hash_section_read_file_io_pool( |
1990 | 0 | section, |
1991 | 0 | internal_handle->io_handle, |
1992 | 0 | file_io_pool, |
1993 | 0 | file_io_pool_entry, |
1994 | 0 | internal_handle->hash_sections, |
1995 | 0 | error ); |
1996 | |
|
1997 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
1998 | | known_section = 1; |
1999 | | #endif |
2000 | 0 | break; |
2001 | | |
2002 | 0 | case LIBEWF_SECTION_TYPE_RESTART_DATA: |
2003 | 0 | read_count = libewf_section_compressed_string_read( |
2004 | 0 | section, |
2005 | 0 | internal_handle->io_handle, |
2006 | 0 | file_io_pool, |
2007 | 0 | file_io_pool_entry, |
2008 | 0 | internal_handle->io_handle->compression_method, |
2009 | 0 | &string_data, |
2010 | 0 | &string_data_size, |
2011 | 0 | error ); |
2012 | |
|
2013 | 0 | if( read_count == -1 ) |
2014 | 0 | { |
2015 | 0 | libcerror_error_set( |
2016 | 0 | error, |
2017 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2018 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2019 | 0 | "%s: unable to read restart data file object string.", |
2020 | 0 | function ); |
2021 | |
|
2022 | 0 | goto on_error; |
2023 | 0 | } |
2024 | 0 | if( libewf_restart_data_parse( |
2025 | 0 | string_data, |
2026 | 0 | string_data_size, |
2027 | 0 | error ) != 1 ) |
2028 | 0 | { |
2029 | 0 | libcerror_error_set( |
2030 | 0 | error, |
2031 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2032 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2033 | 0 | "%s: unable to parse restart data.", |
2034 | 0 | function ); |
2035 | |
|
2036 | 0 | goto on_error; |
2037 | 0 | } |
2038 | 0 | memory_free( |
2039 | 0 | string_data ); |
2040 | |
|
2041 | 0 | string_data = NULL; |
2042 | |
|
2043 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2044 | | known_section = 1; |
2045 | | #endif |
2046 | 0 | break; |
2047 | | |
2048 | 0 | case LIBEWF_SECTION_TYPE_ENCRYPTION_KEYS: |
2049 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2050 | | known_section = 1; |
2051 | | #endif |
2052 | 0 | break; |
2053 | | |
2054 | 0 | case LIBEWF_SECTION_TYPE_MEMORY_EXTENTS_TABLE: |
2055 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2056 | | known_section = 1; |
2057 | | #endif |
2058 | 0 | break; |
2059 | | |
2060 | 0 | case LIBEWF_SECTION_TYPE_NEXT: |
2061 | | /* Nothing to do for the next section |
2062 | | */ |
2063 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2064 | | known_section = 1; |
2065 | | #endif |
2066 | 0 | break; |
2067 | | |
2068 | 0 | case LIBEWF_SECTION_TYPE_FINAL_INFORMATION: |
2069 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2070 | | known_section = 1; |
2071 | | #endif |
2072 | 0 | break; |
2073 | | |
2074 | 8 | case LIBEWF_SECTION_TYPE_DONE: |
2075 | | /* Nothing to do for the done section |
2076 | | */ |
2077 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2078 | | known_section = 1; |
2079 | | #endif |
2080 | 8 | break; |
2081 | | |
2082 | 0 | case LIBEWF_SECTION_TYPE_ANALYTICAL_DATA: |
2083 | 0 | read_count = libewf_section_compressed_string_read( |
2084 | 0 | section, |
2085 | 0 | internal_handle->io_handle, |
2086 | 0 | file_io_pool, |
2087 | 0 | file_io_pool_entry, |
2088 | 0 | internal_handle->io_handle->compression_method, |
2089 | 0 | &string_data, |
2090 | 0 | &string_data_size, |
2091 | 0 | error ); |
2092 | |
|
2093 | 0 | if( read_count == -1 ) |
2094 | 0 | { |
2095 | 0 | libcerror_error_set( |
2096 | 0 | error, |
2097 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2098 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2099 | 0 | "%s: unable to read analytical data file object string.", |
2100 | 0 | function ); |
2101 | |
|
2102 | 0 | goto on_error; |
2103 | 0 | } |
2104 | 0 | else if( read_count != 0 ) |
2105 | 0 | { |
2106 | 0 | if( libewf_analytical_data_parse( |
2107 | 0 | string_data, |
2108 | 0 | string_data_size, |
2109 | 0 | error ) != 1 ) |
2110 | 0 | { |
2111 | 0 | libcerror_error_set( |
2112 | 0 | error, |
2113 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2114 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2115 | 0 | "%s: unable to parse analytical data.", |
2116 | 0 | function ); |
2117 | |
|
2118 | 0 | goto on_error; |
2119 | 0 | } |
2120 | 0 | memory_free( |
2121 | 0 | string_data ); |
2122 | |
|
2123 | 0 | string_data = NULL; |
2124 | 0 | } |
2125 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2126 | | known_section = 1; |
2127 | | #endif |
2128 | 0 | break; |
2129 | | |
2130 | 49 | case LIBEWF_SECTION_TYPE_SINGLE_FILES_DATA: |
2131 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2132 | | if( ( internal_handle->io_handle->segment_file_type != LIBEWF_SEGMENT_FILE_TYPE_EWF1_LOGICAL ) |
2133 | | && ( internal_handle->io_handle->segment_file_type != LIBEWF_SEGMENT_FILE_TYPE_EWF2_LOGICAL ) ) |
2134 | | { |
2135 | | if( libcnotify_verbose != 0 ) |
2136 | | { |
2137 | | libcnotify_printf( |
2138 | | "%s: found single files data section in none logical evidence format.\n", |
2139 | | function ); |
2140 | | } |
2141 | | } |
2142 | | #endif |
2143 | 49 | read_count = libewf_ltree_section_read_file_io_pool( |
2144 | 49 | section, |
2145 | 49 | internal_handle->io_handle, |
2146 | 49 | file_io_pool, |
2147 | 49 | file_io_pool_entry, |
2148 | 49 | segment_file->major_version, |
2149 | 49 | &single_files_section_data, |
2150 | 49 | &single_files_section_data_size, |
2151 | 49 | &single_files_data, |
2152 | 49 | &single_files_data_size, |
2153 | 49 | error ); |
2154 | | |
2155 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2156 | | known_section = 1; |
2157 | | #endif |
2158 | 49 | break; |
2159 | 1.84k | } |
2160 | 1.84k | } |
2161 | 6.24k | else if( section->type_string_length == 4 ) |
2162 | 650 | { |
2163 | 650 | if( memory_compare( |
2164 | 650 | (void *) section->type_string, |
2165 | 650 | (void *) "data", |
2166 | 650 | 4 ) == 0 ) |
2167 | 641 | { |
2168 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2169 | | if( libcnotify_verbose != 0 ) |
2170 | | { |
2171 | | if( internal_handle->io_handle->segment_file_type == LIBEWF_SEGMENT_FILE_TYPE_EWF1_SMART ) |
2172 | | { |
2173 | | libcnotify_printf( |
2174 | | "%s: found data section in EWF-S01 format.\n", |
2175 | | function ); |
2176 | | } |
2177 | | } |
2178 | | #endif |
2179 | 641 | read_count = libewf_section_data_read( |
2180 | 641 | section, |
2181 | 641 | internal_handle->io_handle, |
2182 | 641 | file_io_pool, |
2183 | 641 | file_io_pool_entry, |
2184 | 641 | internal_handle->media_values, |
2185 | 641 | &set_identifier_change, |
2186 | 641 | error ); |
2187 | | |
2188 | 641 | if( set_identifier_change != 0 ) |
2189 | 86 | { |
2190 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2191 | | if( libcnotify_verbose != 0 ) |
2192 | | { |
2193 | | libcnotify_printf( |
2194 | | "%s: set identifier does not match.", |
2195 | | function ); |
2196 | | } |
2197 | | #endif |
2198 | 86 | segment_file->flags |= LIBEWF_SEGMENT_FILE_FLAG_IS_CORRUPTED; |
2199 | 86 | } |
2200 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2201 | | known_section = 1; |
2202 | | #endif |
2203 | 641 | } |
2204 | 9 | else if( memory_compare( |
2205 | 9 | (void *) section->type_string, |
2206 | 9 | (void *) "disk", |
2207 | 9 | 4 ) == 0 ) |
2208 | 0 | { |
2209 | 0 | read_count = libewf_segment_file_read_volume_section( |
2210 | 0 | segment_file, |
2211 | 0 | section, |
2212 | 0 | file_io_pool, |
2213 | 0 | file_io_pool_entry, |
2214 | 0 | internal_handle->media_values, |
2215 | 0 | error ); |
2216 | |
|
2217 | 0 | initialize_chunk_values = 1; |
2218 | |
|
2219 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2220 | | known_section = 1; |
2221 | | #endif |
2222 | 0 | } |
2223 | 650 | } |
2224 | 5.59k | else if( section->type_string_length == 5 ) |
2225 | 29 | { |
2226 | 29 | if( memory_compare( |
2227 | 29 | (void *) section->type_string, |
2228 | 29 | (void *) "xhash", |
2229 | 29 | 5 ) == 0 ) |
2230 | 0 | { |
2231 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2232 | | if( libcnotify_verbose != 0 ) |
2233 | | { |
2234 | | if( internal_handle->io_handle->segment_file_type == LIBEWF_SEGMENT_FILE_TYPE_EWF1_SMART ) |
2235 | | { |
2236 | | libcnotify_printf( |
2237 | | "%s: found xhash section in EWF-S01 format.\n", |
2238 | | function ); |
2239 | | } |
2240 | | } |
2241 | | #endif |
2242 | 0 | read_count = libewf_section_compressed_string_read( |
2243 | 0 | section, |
2244 | 0 | internal_handle->io_handle, |
2245 | 0 | file_io_pool, |
2246 | 0 | file_io_pool_entry, |
2247 | 0 | internal_handle->io_handle->compression_method, |
2248 | 0 | &string_data, |
2249 | 0 | &string_data_size, |
2250 | 0 | error ); |
2251 | |
|
2252 | 0 | if( read_count == -1 ) |
2253 | 0 | { |
2254 | 0 | libcerror_error_set( |
2255 | 0 | error, |
2256 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2257 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2258 | 0 | "%s: unable to read xhash string.", |
2259 | 0 | function ); |
2260 | |
|
2261 | 0 | goto on_error; |
2262 | 0 | } |
2263 | | #if defined( HAVE_DEBUG_OUTPUT ) |
2264 | | if( libcnotify_verbose != 0 ) |
2265 | | { |
2266 | | if( libewf_debug_utf8_stream_print( |
2267 | | "XHash", |
2268 | | string_data, |
2269 | | string_data_size, |
2270 | | error ) != 1 ) |
2271 | | { |
2272 | | libcerror_error_set( |
2273 | | error, |
2274 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2275 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
2276 | | "%s: unable to print xhash.", |
2277 | | function ); |
2278 | | |
2279 | | goto on_error; |
2280 | | } |
2281 | | } |
2282 | | #endif |
2283 | 0 | if( internal_handle->hash_sections->xhash == NULL ) |
2284 | 0 | { |
2285 | 0 | internal_handle->hash_sections->xhash = string_data; |
2286 | 0 | internal_handle->hash_sections->xhash_size = string_data_size; |
2287 | 0 | } |
2288 | 0 | else |
2289 | 0 | { |
2290 | 0 | memory_free( |
2291 | 0 | string_data ); |
2292 | 0 | } |
2293 | 0 | string_data = NULL; |
2294 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2295 | | known_section = 1; |
2296 | | #endif |
2297 | 0 | } |
2298 | 29 | } |
2299 | 5.56k | else if( section->type_string_length == 6 ) |
2300 | 2.60k | { |
2301 | 2.60k | if( memory_compare( |
2302 | 2.60k | (void *) section->type_string, |
2303 | 2.60k | (void *) "digest", |
2304 | 2.60k | 6 ) == 0 ) |
2305 | 6 | { |
2306 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2307 | | if( libcnotify_verbose != 0 ) |
2308 | | { |
2309 | | if( internal_handle->io_handle->segment_file_type == LIBEWF_SEGMENT_FILE_TYPE_EWF1_SMART ) |
2310 | | { |
2311 | | libcnotify_printf( |
2312 | | "%s: found digest section in EWF-S01 format.\n", |
2313 | | function ); |
2314 | | } |
2315 | | } |
2316 | | #endif |
2317 | 6 | read_count = libewf_digest_section_read_file_io_pool( |
2318 | 6 | section, |
2319 | 6 | internal_handle->io_handle, |
2320 | 6 | file_io_pool, |
2321 | 6 | file_io_pool_entry, |
2322 | 6 | internal_handle->hash_sections, |
2323 | 6 | error ); |
2324 | | |
2325 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2326 | | known_section = 1; |
2327 | | #endif |
2328 | 6 | } |
2329 | 2.59k | else if( memory_compare( |
2330 | 2.59k | (void *) section->type_string, |
2331 | 2.59k | (void *) "header", |
2332 | 2.59k | 6 ) == 0 ) |
2333 | 1.09k | { |
2334 | 1.09k | read_count = libewf_section_compressed_string_read( |
2335 | 1.09k | section, |
2336 | 1.09k | internal_handle->io_handle, |
2337 | 1.09k | file_io_pool, |
2338 | 1.09k | file_io_pool_entry, |
2339 | 1.09k | internal_handle->io_handle->compression_method, |
2340 | 1.09k | &string_data, |
2341 | 1.09k | &string_data_size, |
2342 | 1.09k | error ); |
2343 | | |
2344 | 1.09k | if( read_count == -1 ) |
2345 | 59 | { |
2346 | 59 | libcerror_error_set( |
2347 | 59 | error, |
2348 | 59 | LIBCERROR_ERROR_DOMAIN_IO, |
2349 | 59 | LIBCERROR_IO_ERROR_READ_FAILED, |
2350 | 59 | "%s: unable to read header file object string.", |
2351 | 59 | function ); |
2352 | | |
2353 | 59 | goto on_error; |
2354 | 59 | } |
2355 | | #if defined( HAVE_DEBUG_OUTPUT ) |
2356 | | if( libcnotify_verbose != 0 ) |
2357 | | { |
2358 | | if( libewf_debug_byte_stream_print( |
2359 | | "Header", |
2360 | | string_data, |
2361 | | string_data_size, |
2362 | | error ) != 1 ) |
2363 | | { |
2364 | | libcerror_error_set( |
2365 | | error, |
2366 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2367 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
2368 | | "%s: unable to print header.", |
2369 | | function ); |
2370 | | |
2371 | | goto on_error; |
2372 | | } |
2373 | | } |
2374 | | #endif |
2375 | 1.03k | if( header_sections->header == NULL ) |
2376 | 1.03k | { |
2377 | 1.03k | header_sections->header = string_data; |
2378 | 1.03k | header_sections->header_size = string_data_size; |
2379 | 1.03k | } |
2380 | 0 | else |
2381 | 0 | { |
2382 | 0 | memory_free( |
2383 | 0 | string_data ); |
2384 | 0 | } |
2385 | 1.03k | string_data = NULL; |
2386 | | |
2387 | 1.03k | header_sections->number_of_header_sections += 1; |
2388 | | |
2389 | 1.03k | header_section_found = 1; |
2390 | | |
2391 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2392 | | known_section = 1; |
2393 | | #endif |
2394 | 1.03k | } |
2395 | 1.50k | else if( memory_compare( |
2396 | 1.50k | (void *) section->type_string, |
2397 | 1.50k | (void *) "table2", |
2398 | 1.50k | 6 ) == 0 ) |
2399 | 660 | { |
2400 | 660 | if( read_table_sections != 0 ) |
2401 | 659 | { |
2402 | 659 | read_count = libewf_segment_file_read_table2_section( |
2403 | 659 | segment_file, |
2404 | 659 | section, |
2405 | 659 | file_io_pool, |
2406 | 659 | file_io_pool_entry, |
2407 | 659 | error ); |
2408 | 659 | } |
2409 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2410 | | known_section = 1; |
2411 | | #endif |
2412 | 660 | } |
2413 | 843 | else if( memory_compare( |
2414 | 843 | (void *) section->type_string, |
2415 | 843 | (void *) "volume", |
2416 | 843 | 6 ) == 0 ) |
2417 | 806 | { |
2418 | 806 | read_count = libewf_segment_file_read_volume_section( |
2419 | 806 | segment_file, |
2420 | 806 | section, |
2421 | 806 | file_io_pool, |
2422 | 806 | file_io_pool_entry, |
2423 | 806 | internal_handle->media_values, |
2424 | 806 | error ); |
2425 | | |
2426 | 806 | initialize_chunk_values = 1; |
2427 | | |
2428 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2429 | | known_section = 1; |
2430 | | #endif |
2431 | 806 | } |
2432 | 2.60k | } |
2433 | 2.96k | else if( section->type_string_length == 7 ) |
2434 | 2.93k | { |
2435 | 2.93k | if( memory_compare( |
2436 | 2.93k | (void *) section->type_string, |
2437 | 2.93k | (void *) "header2", |
2438 | 2.93k | 7 ) == 0 ) |
2439 | 2.68k | { |
2440 | 2.68k | read_count = libewf_section_compressed_string_read( |
2441 | 2.68k | section, |
2442 | 2.68k | internal_handle->io_handle, |
2443 | 2.68k | file_io_pool, |
2444 | 2.68k | file_io_pool_entry, |
2445 | 2.68k | internal_handle->io_handle->compression_method, |
2446 | 2.68k | &string_data, |
2447 | 2.68k | &string_data_size, |
2448 | 2.68k | error ); |
2449 | | |
2450 | 2.68k | if( read_count == -1 ) |
2451 | 469 | { |
2452 | 469 | libcerror_error_set( |
2453 | 469 | error, |
2454 | 469 | LIBCERROR_ERROR_DOMAIN_IO, |
2455 | 469 | LIBCERROR_IO_ERROR_READ_FAILED, |
2456 | 469 | "%s: unable to read header2 file object string.", |
2457 | 469 | function ); |
2458 | | |
2459 | 469 | goto on_error; |
2460 | 469 | } |
2461 | | #if defined( HAVE_DEBUG_OUTPUT ) |
2462 | | if( libcnotify_verbose != 0 ) |
2463 | | { |
2464 | | if( libewf_debug_utf16_stream_print( |
2465 | | "Header2", |
2466 | | string_data, |
2467 | | string_data_size, |
2468 | | error ) != 1 ) |
2469 | | { |
2470 | | libcerror_error_set( |
2471 | | error, |
2472 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2473 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
2474 | | "%s: unable to print header2.", |
2475 | | function ); |
2476 | | |
2477 | | goto on_error; |
2478 | | } |
2479 | | } |
2480 | | #endif |
2481 | 2.21k | if( header_sections->header2 == NULL ) |
2482 | 1.30k | { |
2483 | 1.30k | header_sections->header2 = string_data; |
2484 | 1.30k | header_sections->header2_size = string_data_size; |
2485 | 1.30k | } |
2486 | 906 | else |
2487 | 906 | { |
2488 | 906 | memory_free( |
2489 | 906 | string_data ); |
2490 | 906 | } |
2491 | 2.21k | string_data = NULL; |
2492 | | |
2493 | 2.21k | header_sections->number_of_header_sections += 1; |
2494 | | |
2495 | 2.21k | header_section_found = 1; |
2496 | | |
2497 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2498 | | known_section = 1; |
2499 | | #endif |
2500 | 2.21k | } |
2501 | 247 | else if( memory_compare( |
2502 | 247 | (void *) section->type_string, |
2503 | 247 | (void *) "xheader", |
2504 | 247 | 7 ) == 0 ) |
2505 | 71 | { |
2506 | 71 | read_count = libewf_section_compressed_string_read( |
2507 | 71 | section, |
2508 | 71 | internal_handle->io_handle, |
2509 | 71 | file_io_pool, |
2510 | 71 | file_io_pool_entry, |
2511 | 71 | internal_handle->io_handle->compression_method, |
2512 | 71 | &string_data, |
2513 | 71 | &string_data_size, |
2514 | 71 | error ); |
2515 | | |
2516 | 71 | if( read_count == -1 ) |
2517 | 12 | { |
2518 | 12 | libcerror_error_set( |
2519 | 12 | error, |
2520 | 12 | LIBCERROR_ERROR_DOMAIN_IO, |
2521 | 12 | LIBCERROR_IO_ERROR_READ_FAILED, |
2522 | 12 | "%s: unable to read xheader string.", |
2523 | 12 | function ); |
2524 | | |
2525 | 12 | goto on_error; |
2526 | 12 | } |
2527 | | #if defined( HAVE_DEBUG_OUTPUT ) |
2528 | | if( libcnotify_verbose != 0 ) |
2529 | | { |
2530 | | if( libewf_debug_utf8_stream_print( |
2531 | | "XHeader", |
2532 | | string_data, |
2533 | | string_data_size, |
2534 | | error ) != 1 ) |
2535 | | { |
2536 | | libcerror_error_set( |
2537 | | error, |
2538 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2539 | | LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, |
2540 | | "%s: unable to print xheader.", |
2541 | | function ); |
2542 | | |
2543 | | goto on_error; |
2544 | | } |
2545 | | } |
2546 | | #endif |
2547 | 59 | if( header_sections->xheader == NULL ) |
2548 | 59 | { |
2549 | 59 | header_sections->xheader = string_data; |
2550 | 59 | header_sections->xheader_size = string_data_size; |
2551 | 59 | } |
2552 | 0 | else |
2553 | 0 | { |
2554 | 0 | memory_free( |
2555 | 0 | string_data ); |
2556 | 0 | } |
2557 | 59 | string_data = NULL; |
2558 | | |
2559 | 59 | header_sections->number_of_header_sections += 1; |
2560 | | |
2561 | 59 | header_section_found = 1; |
2562 | | |
2563 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2564 | | known_section = 1; |
2565 | | #endif |
2566 | 59 | } |
2567 | 2.93k | } |
2568 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
2569 | | if( libcnotify_verbose != 0 ) |
2570 | | { |
2571 | | if( known_section == 0 ) |
2572 | | { |
2573 | | if( segment_file->major_version == 1 ) |
2574 | | { |
2575 | | libcnotify_printf( |
2576 | | "%s: unsupported section type: %s.\n", |
2577 | | function, |
2578 | | (char *) section->type_string ); |
2579 | | } |
2580 | | else if( segment_file->major_version == 2 ) |
2581 | | { |
2582 | | libcnotify_printf( |
2583 | | "%s: unsupported section type: 0x%08" PRIx32 ".\n", |
2584 | | function, |
2585 | | section->type ); |
2586 | | } |
2587 | | } |
2588 | | } |
2589 | | #endif |
2590 | 7.54k | if( read_count == -1 ) |
2591 | 934 | { |
2592 | 934 | if( section->type_string_length > 0 ) |
2593 | 934 | { |
2594 | 934 | libcerror_error_set( |
2595 | 934 | error, |
2596 | 934 | LIBCERROR_ERROR_DOMAIN_IO, |
2597 | 934 | LIBCERROR_IO_ERROR_READ_FAILED, |
2598 | 934 | "%s: unable to read section: %s.", |
2599 | 934 | function, |
2600 | 934 | (char *) section->type_string ); |
2601 | 934 | } |
2602 | 0 | else |
2603 | 0 | { |
2604 | 0 | libcerror_error_set( |
2605 | 0 | error, |
2606 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
2607 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
2608 | 0 | "%s: unable to read section: 0x%08" PRIx32 ".", |
2609 | 0 | function, |
2610 | 0 | section->type ); |
2611 | 0 | } |
2612 | 934 | goto on_error; |
2613 | 934 | } |
2614 | 6.61k | if( initialize_chunk_values != 0 ) |
2615 | 753 | { |
2616 | 753 | if( segment_file->type == LIBEWF_SEGMENT_FILE_TYPE_EWF1_SMART ) |
2617 | 0 | { |
2618 | 0 | segment_file->io_handle->segment_file_type = LIBEWF_SEGMENT_FILE_TYPE_EWF1_SMART; |
2619 | 0 | segment_file->io_handle->format = LIBEWF_FORMAT_SMART; |
2620 | 0 | } |
2621 | 753 | if( libewf_media_values_calculate_chunk_size( |
2622 | 753 | internal_handle->media_values, |
2623 | 753 | error ) != 1 ) |
2624 | 6 | { |
2625 | 6 | libcerror_error_set( |
2626 | 6 | error, |
2627 | 6 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2628 | 6 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2629 | 6 | "%s: unable to calculate chunk size.", |
2630 | 6 | function ); |
2631 | | |
2632 | 6 | goto on_error; |
2633 | 6 | } |
2634 | | /* TODO refactor */ |
2635 | 747 | internal_handle->io_handle->chunk_size = internal_handle->media_values->chunk_size; |
2636 | | |
2637 | | /* Do a preliminary dection of the EWF format for reading the sector table section |
2638 | | */ |
2639 | 747 | if( internal_handle->io_handle->segment_file_type == LIBEWF_SEGMENT_FILE_TYPE_EWF1 ) |
2640 | 721 | { |
2641 | 721 | if( header_sections->number_of_header_sections == 1 ) |
2642 | 53 | { |
2643 | 53 | internal_handle->io_handle->format = LIBEWF_FORMAT_ENCASE1; |
2644 | 53 | } |
2645 | 668 | else if( internal_handle->media_values->error_granularity == 0 ) |
2646 | 2 | { |
2647 | 2 | internal_handle->io_handle->format = LIBEWF_FORMAT_ENCASE2; |
2648 | 2 | } |
2649 | 721 | } |
2650 | 747 | initialize_chunk_values = 0; |
2651 | 747 | } |
2652 | 6.61k | } |
2653 | 1.10k | if( header_section_found != 0 ) |
2654 | 768 | { |
2655 | 768 | if( libewf_header_sections_parse( |
2656 | 768 | header_sections, |
2657 | 768 | internal_handle->io_handle, |
2658 | 768 | internal_handle->header_values, |
2659 | 768 | &( internal_handle->io_handle->format ), |
2660 | 768 | error ) == -1 ) |
2661 | 1 | { |
2662 | 1 | libcerror_error_set( |
2663 | 1 | error, |
2664 | 1 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2665 | 1 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2666 | 1 | "%s: unable to parse header sections.", |
2667 | 1 | function ); |
2668 | | |
2669 | 1 | goto on_error; |
2670 | 1 | } |
2671 | 768 | } |
2672 | 1.10k | if( single_files_data != NULL ) |
2673 | 0 | { |
2674 | 0 | if( libewf_single_files_initialize( |
2675 | 0 | &( internal_handle->single_files ), |
2676 | 0 | error ) != 1 ) |
2677 | 0 | { |
2678 | 0 | libcerror_error_set( |
2679 | 0 | error, |
2680 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2681 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
2682 | 0 | "%s: unable to create single files.", |
2683 | 0 | function ); |
2684 | |
|
2685 | 0 | goto on_error; |
2686 | 0 | } |
2687 | 0 | if( libewf_single_files_read_data( |
2688 | 0 | internal_handle->single_files, |
2689 | 0 | single_files_data, |
2690 | 0 | single_files_data_size, |
2691 | 0 | &( internal_handle->media_values->media_size ), |
2692 | 0 | &( internal_handle->io_handle->format ), |
2693 | 0 | error ) != 1 ) |
2694 | 0 | { |
2695 | 0 | libcerror_error_set( |
2696 | 0 | error, |
2697 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2698 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2699 | 0 | "%s: unable to parse single files.", |
2700 | 0 | function ); |
2701 | |
|
2702 | 0 | goto on_error; |
2703 | 0 | } |
2704 | 0 | memory_free( |
2705 | 0 | single_files_section_data ); |
2706 | |
|
2707 | 0 | single_files_section_data = NULL; |
2708 | |
|
2709 | 0 | if( internal_handle->io_handle->segment_file_type != LIBEWF_SEGMENT_FILE_TYPE_EWF2_LOGICAL ) |
2710 | 0 | { |
2711 | 0 | if( internal_handle->io_handle->format == LIBEWF_FORMAT_LOGICAL_ENCASE7 ) |
2712 | 0 | { |
2713 | 0 | internal_handle->io_handle->format = LIBEWF_FORMAT_V2_LOGICAL_ENCASE7; |
2714 | 0 | } |
2715 | 0 | } |
2716 | 0 | internal_handle->media_values->number_of_sectors = internal_handle->media_values->media_size |
2717 | 0 | / internal_handle->media_values->bytes_per_sector; |
2718 | |
|
2719 | 0 | if( ( internal_handle->media_values->media_size % internal_handle->media_values->bytes_per_sector ) != 0 ) |
2720 | 0 | { |
2721 | 0 | internal_handle->media_values->number_of_sectors += 1; |
2722 | 0 | } |
2723 | 0 | } |
2724 | 1.10k | if( libewf_header_sections_free( |
2725 | 1.10k | &header_sections, |
2726 | 1.10k | error ) != 1 ) |
2727 | 0 | { |
2728 | 0 | libcerror_error_set( |
2729 | 0 | error, |
2730 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2731 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
2732 | 0 | "%s: unable to free header sections.", |
2733 | 0 | function ); |
2734 | |
|
2735 | 0 | goto on_error; |
2736 | 0 | } |
2737 | 1.10k | if( libfcache_cache_free( |
2738 | 1.10k | §ions_cache, |
2739 | 1.10k | error ) != 1 ) |
2740 | 0 | { |
2741 | 0 | libcerror_error_set( |
2742 | 0 | error, |
2743 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2744 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
2745 | 0 | "%s: unable to free sections cache.", |
2746 | 0 | function ); |
2747 | |
|
2748 | 0 | goto on_error; |
2749 | 0 | } |
2750 | 1.10k | return( 1 ); |
2751 | | |
2752 | 1.48k | on_error: |
2753 | 1.48k | if( internal_handle->single_files != NULL ) |
2754 | 0 | { |
2755 | 0 | libewf_single_files_free( |
2756 | 0 | &( internal_handle->single_files ), |
2757 | 0 | NULL ); |
2758 | 0 | } |
2759 | 1.48k | if( single_files_section_data != NULL ) |
2760 | 0 | { |
2761 | 0 | memory_free( |
2762 | 0 | single_files_section_data ); |
2763 | 0 | } |
2764 | 1.48k | if( string_data != NULL ) |
2765 | 0 | { |
2766 | 0 | memory_free( |
2767 | 0 | string_data ); |
2768 | 0 | } |
2769 | 1.48k | if( header_sections != NULL ) |
2770 | 1.48k | { |
2771 | 1.48k | libewf_header_sections_free( |
2772 | 1.48k | &header_sections, |
2773 | 1.48k | NULL ); |
2774 | 1.48k | } |
2775 | 1.48k | if( sections_cache != NULL ) |
2776 | 1.48k | { |
2777 | 1.48k | libfcache_cache_free( |
2778 | 1.48k | §ions_cache, |
2779 | 1.48k | NULL ); |
2780 | 1.48k | } |
2781 | 1.48k | return( -1 ); |
2782 | 1.10k | } |
2783 | | |
2784 | | /* Opens the segment files for reading |
2785 | | * Returns 1 if successful or -1 on error |
2786 | | */ |
2787 | | int libewf_internal_handle_open_read_segment_files( |
2788 | | libewf_internal_handle_t *internal_handle, |
2789 | | libbfio_pool_t *file_io_pool, |
2790 | | libewf_segment_table_t *segment_table, |
2791 | | libcerror_error_t **error ) |
2792 | 2.86k | { |
2793 | 2.86k | libewf_segment_file_t *segment_file = NULL; |
2794 | 2.86k | static char *function = "libewf_internal_handle_open_read_segment_files"; |
2795 | 2.86k | size64_t maximum_segment_size = 0; |
2796 | 2.86k | size64_t segment_file_size = 0; |
2797 | 2.86k | uint32_t number_of_segments = 0; |
2798 | 2.86k | uint32_t segment_number = 0; |
2799 | 2.86k | int file_io_pool_entry = 0; |
2800 | 2.86k | int last_segment_file = 0; |
2801 | | |
2802 | 2.86k | if( internal_handle == NULL ) |
2803 | 0 | { |
2804 | 0 | libcerror_error_set( |
2805 | 0 | error, |
2806 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2807 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2808 | 0 | "%s: invalid handle.", |
2809 | 0 | function ); |
2810 | |
|
2811 | 0 | return( -1 ); |
2812 | 0 | } |
2813 | 2.86k | if( internal_handle->io_handle == NULL ) |
2814 | 0 | { |
2815 | 0 | libcerror_error_set( |
2816 | 0 | error, |
2817 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2818 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
2819 | 0 | "%s: invalid handle - missing IO handle.", |
2820 | 0 | function ); |
2821 | |
|
2822 | 0 | return( -1 ); |
2823 | 0 | } |
2824 | 2.86k | if( internal_handle->read_io_handle == NULL ) |
2825 | 0 | { |
2826 | 0 | libcerror_error_set( |
2827 | 0 | error, |
2828 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2829 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
2830 | 0 | "%s: invalid handle - missing read IO handle.", |
2831 | 0 | function ); |
2832 | |
|
2833 | 0 | return( -1 ); |
2834 | 0 | } |
2835 | 2.86k | if( segment_table == NULL ) |
2836 | 0 | { |
2837 | 0 | libcerror_error_set( |
2838 | 0 | error, |
2839 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
2840 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
2841 | 0 | "%s: invalid segment table.", |
2842 | 0 | function ); |
2843 | |
|
2844 | 0 | return( -1 ); |
2845 | 0 | } |
2846 | 2.86k | if( libewf_segment_table_get_number_of_segments( |
2847 | 2.86k | segment_table, |
2848 | 2.86k | &number_of_segments, |
2849 | 2.86k | error ) != 1 ) |
2850 | 0 | { |
2851 | 0 | libcerror_error_set( |
2852 | 0 | error, |
2853 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2854 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2855 | 0 | "%s: unable to retrieve number of segments from segment table.", |
2856 | 0 | function ); |
2857 | |
|
2858 | 0 | return( -1 ); |
2859 | 0 | } |
2860 | | /* Make sure to read the device information section first so we |
2861 | | * have the correct chunk size when reading Lx01 files. |
2862 | | */ |
2863 | 2.86k | if( libewf_internal_handle_open_read_device_information( |
2864 | 2.86k | internal_handle, |
2865 | 2.86k | file_io_pool, |
2866 | 2.86k | segment_table, |
2867 | 2.86k | number_of_segments, |
2868 | 2.86k | error ) != 1 ) |
2869 | 277 | { |
2870 | 277 | libcerror_error_set( |
2871 | 277 | error, |
2872 | 277 | LIBCERROR_ERROR_DOMAIN_IO, |
2873 | 277 | LIBCERROR_IO_ERROR_READ_FAILED, |
2874 | 277 | "%s: unable to read device information.", |
2875 | 277 | function ); |
2876 | | |
2877 | 277 | return( -1 ); |
2878 | 277 | } |
2879 | 2.58k | for( segment_number = 0; |
2880 | 3.69k | segment_number < number_of_segments; |
2881 | 2.58k | segment_number++ ) |
2882 | 2.58k | { |
2883 | 2.58k | if( libewf_segment_table_get_segment_by_index( |
2884 | 2.58k | segment_table, |
2885 | 2.58k | segment_number, |
2886 | 2.58k | &file_io_pool_entry, |
2887 | 2.58k | &segment_file_size, |
2888 | 2.58k | error ) != 1 ) |
2889 | 0 | { |
2890 | 0 | libcerror_error_set( |
2891 | 0 | error, |
2892 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2893 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2894 | 0 | "%s: unable to retrieve segment: %" PRIu32 " from segment table.", |
2895 | 0 | function, |
2896 | 0 | segment_number ); |
2897 | |
|
2898 | 0 | return( -1 ); |
2899 | 0 | } |
2900 | 2.58k | if( ( segment_number == 0 ) |
2901 | 2.58k | && ( number_of_segments > 1 ) ) |
2902 | 0 | { |
2903 | | /* Round the maximum segment size to nearest number of KiB |
2904 | | */ |
2905 | 0 | maximum_segment_size = ( segment_file_size >> 10 ) << 10; |
2906 | |
|
2907 | 0 | if( libewf_segment_table_set_maximum_segment_size( |
2908 | 0 | segment_table, |
2909 | 0 | maximum_segment_size, |
2910 | 0 | error ) != 1 ) |
2911 | 0 | { |
2912 | 0 | libcerror_error_set( |
2913 | 0 | error, |
2914 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2915 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
2916 | 0 | "%s: unable to set maximum segment size in segment table.", |
2917 | 0 | function ); |
2918 | |
|
2919 | 0 | return( -1 ); |
2920 | 0 | } |
2921 | 0 | } |
2922 | 2.58k | if( libewf_segment_table_get_segment_file_by_index( |
2923 | 2.58k | segment_table, |
2924 | 2.58k | segment_number, |
2925 | 2.58k | file_io_pool, |
2926 | 2.58k | &segment_file, |
2927 | 2.58k | error ) != 1 ) |
2928 | 0 | { |
2929 | 0 | libcerror_error_set( |
2930 | 0 | error, |
2931 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2932 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
2933 | 0 | "%s: unable to retrieve segment file: %" PRIu32 " from segment table.", |
2934 | 0 | function, |
2935 | 0 | segment_number ); |
2936 | |
|
2937 | 0 | return( -1 ); |
2938 | 0 | } |
2939 | 2.58k | if( segment_file == NULL ) |
2940 | 0 | { |
2941 | 0 | libcerror_error_set( |
2942 | 0 | error, |
2943 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
2944 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
2945 | 0 | "%s: missing segment file: %" PRIu32 ".", |
2946 | 0 | function, |
2947 | 0 | segment_number ); |
2948 | |
|
2949 | 0 | return( -1 ); |
2950 | 0 | } |
2951 | 2.58k | if( segment_file->segment_number != ( segment_number + 1 ) ) |
2952 | 0 | { |
2953 | 0 | libcerror_error_set( |
2954 | 0 | error, |
2955 | 0 | LIBCERROR_ERROR_DOMAIN_INPUT, |
2956 | 0 | LIBCERROR_INPUT_ERROR_VALUE_MISMATCH, |
2957 | 0 | "%s: segment number mismatch ( stored: %" PRIu32 ", expected: %" PRIu32 " ).", |
2958 | 0 | function, |
2959 | 0 | segment_file->segment_number, |
2960 | 0 | segment_number + 1 ); |
2961 | |
|
2962 | 0 | return( -1 ); |
2963 | 0 | } |
2964 | 2.58k | if( segment_file->segment_number == 1 ) |
2965 | 2.58k | { |
2966 | 2.58k | internal_handle->io_handle->segment_file_type = segment_file->type; |
2967 | 2.58k | internal_handle->io_handle->major_version = segment_file->major_version; |
2968 | 2.58k | internal_handle->io_handle->minor_version = segment_file->minor_version; |
2969 | 2.58k | internal_handle->io_handle->compression_method = segment_file->compression_method; |
2970 | | |
2971 | 2.58k | if( segment_file->major_version == 2 ) |
2972 | 0 | { |
2973 | 0 | if( memory_copy( |
2974 | 0 | internal_handle->media_values->set_identifier, |
2975 | 0 | segment_file->set_identifier, |
2976 | 0 | 16 ) == NULL ) |
2977 | 0 | { |
2978 | 0 | libcerror_error_set( |
2979 | 0 | error, |
2980 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
2981 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
2982 | 0 | "%s: unable to copy segment file set identifier to media values.", |
2983 | 0 | function ); |
2984 | |
|
2985 | 0 | return( -1 ); |
2986 | 0 | } |
2987 | 0 | } |
2988 | 2.58k | } |
2989 | 0 | else |
2990 | 0 | { |
2991 | 0 | if( ( segment_file->major_version != internal_handle->io_handle->major_version ) |
2992 | 0 | || ( segment_file->minor_version != internal_handle->io_handle->minor_version ) ) |
2993 | 0 | { |
2994 | 0 | libcerror_error_set( |
2995 | 0 | error, |
2996 | 0 | LIBCERROR_ERROR_DOMAIN_INPUT, |
2997 | 0 | LIBCERROR_INPUT_ERROR_VALUE_MISMATCH, |
2998 | 0 | "%s: segment file format version value mismatch.", |
2999 | 0 | function ); |
3000 | |
|
3001 | 0 | return( -1 ); |
3002 | 0 | } |
3003 | 0 | if( internal_handle->io_handle->major_version == 2 ) |
3004 | 0 | { |
3005 | 0 | if( segment_file->compression_method != internal_handle->io_handle->compression_method ) |
3006 | 0 | { |
3007 | 0 | libcerror_error_set( |
3008 | 0 | error, |
3009 | 0 | LIBCERROR_ERROR_DOMAIN_INPUT, |
3010 | 0 | LIBCERROR_INPUT_ERROR_VALUE_MISMATCH, |
3011 | 0 | "%s: segment file compression method value mismatch.", |
3012 | 0 | function ); |
3013 | |
|
3014 | 0 | return( -1 ); |
3015 | 0 | } |
3016 | 0 | if( memory_compare( |
3017 | 0 | internal_handle->media_values->set_identifier, |
3018 | 0 | segment_file->set_identifier, |
3019 | 0 | 16 ) != 0 ) |
3020 | 0 | { |
3021 | 0 | libcerror_error_set( |
3022 | 0 | error, |
3023 | 0 | LIBCERROR_ERROR_DOMAIN_INPUT, |
3024 | 0 | LIBCERROR_INPUT_ERROR_VALUE_MISMATCH, |
3025 | 0 | "%s: segment file set identifier value mismatch.", |
3026 | 0 | function ); |
3027 | |
|
3028 | 0 | return( -1 ); |
3029 | 0 | } |
3030 | 0 | } |
3031 | 0 | } |
3032 | 2.58k | if( ( segment_file->flags & LIBEWF_SEGMENT_FILE_FLAG_IS_LAST ) != 0 ) |
3033 | 18 | { |
3034 | 18 | last_segment_file = 1; |
3035 | 18 | } |
3036 | 2.58k | if( ( segment_file->flags & LIBEWF_SEGMENT_FILE_FLAG_IS_ENCRYPTED ) != 0 ) |
3037 | 0 | { |
3038 | | /* TODO get key info */ |
3039 | 0 | internal_handle->io_handle->format = LIBEWF_FORMAT_V2_ENCASE7; |
3040 | 0 | internal_handle->io_handle->is_encrypted = 1; |
3041 | 0 | } |
3042 | 2.58k | if( libewf_internal_handle_open_read_segment_file_section_data( |
3043 | 2.58k | internal_handle, |
3044 | 2.58k | segment_file, |
3045 | 2.58k | file_io_pool, |
3046 | 2.58k | file_io_pool_entry, |
3047 | 2.58k | error ) != 1 ) |
3048 | 1.48k | { |
3049 | 1.48k | libcerror_error_set( |
3050 | 1.48k | error, |
3051 | 1.48k | LIBCERROR_ERROR_DOMAIN_IO, |
3052 | 1.48k | LIBCERROR_IO_ERROR_READ_FAILED, |
3053 | 1.48k | "%s: unable to read section data from segment file: %" PRIu32 ".", |
3054 | 1.48k | function, |
3055 | 1.48k | segment_number ); |
3056 | | |
3057 | 1.48k | return( -1 ); |
3058 | 1.48k | } |
3059 | 1.10k | if( ( segment_file->flags & LIBEWF_SEGMENT_FILE_FLAG_IS_CORRUPTED ) != 0 ) |
3060 | 1.10k | { |
3061 | 1.10k | segment_table->flags |= LIBEWF_SEGMENT_TABLE_FLAG_IS_CORRUPTED; |
3062 | 1.10k | } |
3063 | 1.10k | if( libewf_segment_table_set_segment_storage_media_size_by_index( |
3064 | 1.10k | segment_table, |
3065 | 1.10k | segment_number, |
3066 | 1.10k | segment_file->storage_media_size, |
3067 | 1.10k | error ) != 1 ) |
3068 | 0 | { |
3069 | 0 | libcerror_error_set( |
3070 | 0 | error, |
3071 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3072 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
3073 | 0 | "%s: unable to set mapped range of element: %" PRIu32 " in segment table.", |
3074 | 0 | function, |
3075 | 0 | segment_number ); |
3076 | |
|
3077 | 0 | return( -1 ); |
3078 | 0 | } |
3079 | 1.10k | internal_handle->read_io_handle->storage_media_size_read += segment_file->storage_media_size; |
3080 | 1.10k | internal_handle->read_io_handle->number_of_chunks_read += segment_file->number_of_chunks; |
3081 | 1.10k | } |
3082 | 1.10k | if( last_segment_file == 0 ) |
3083 | 1.09k | { |
3084 | 1.09k | libcerror_error_set( |
3085 | 1.09k | error, |
3086 | 1.09k | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3087 | 1.09k | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
3088 | 1.09k | "%s: missing done section.", |
3089 | 1.09k | function ); |
3090 | | |
3091 | | #if defined( HAVE_DEBUG_OUTPUT ) |
3092 | | if( libcnotify_verbose != 0 ) |
3093 | | { |
3094 | | if( ( error != NULL ) |
3095 | | && ( *error != NULL ) ) |
3096 | | { |
3097 | | libcnotify_print_error_backtrace( |
3098 | | *error ); |
3099 | | } |
3100 | | } |
3101 | | #endif |
3102 | 1.09k | libcerror_error_free( |
3103 | 1.09k | error ); |
3104 | | |
3105 | 1.09k | segment_table->flags |= LIBEWF_SEGMENT_TABLE_FLAG_IS_CORRUPTED; |
3106 | 1.09k | } |
3107 | 1.10k | return( 1 ); |
3108 | 2.58k | } |
3109 | | |
3110 | | /* Reads the device information from the segment files |
3111 | | * Returns 1 if successful or -1 on error |
3112 | | */ |
3113 | | int libewf_internal_handle_open_read_device_information( |
3114 | | libewf_internal_handle_t *internal_handle, |
3115 | | libbfio_pool_t *file_io_pool, |
3116 | | libewf_segment_table_t *segment_table, |
3117 | | uint32_t number_of_segments, |
3118 | | libcerror_error_t **error ) |
3119 | 2.86k | { |
3120 | 2.86k | libewf_section_descriptor_t *section_descriptor = NULL; |
3121 | 2.86k | libewf_segment_file_t *segment_file = NULL; |
3122 | 2.86k | libfcache_cache_t *sections_cache = NULL; |
3123 | 2.86k | static char *function = "libewf_internal_handle_open_read_device_information"; |
3124 | 2.86k | size64_t segment_file_size = 0; |
3125 | 2.86k | ssize_t read_count = 0; |
3126 | 2.86k | uint32_t segment_number = 0; |
3127 | 2.86k | int file_io_pool_entry = 0; |
3128 | | |
3129 | 2.86k | if( internal_handle == NULL ) |
3130 | 0 | { |
3131 | 0 | libcerror_error_set( |
3132 | 0 | error, |
3133 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3134 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3135 | 0 | "%s: invalid handle.", |
3136 | 0 | function ); |
3137 | |
|
3138 | 0 | return( -1 ); |
3139 | 0 | } |
3140 | 2.86k | if( number_of_segments == 0 ) |
3141 | 0 | { |
3142 | 0 | libcerror_error_set( |
3143 | 0 | error, |
3144 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3145 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
3146 | 0 | "%s: invalid number of segments value out of bounds.", |
3147 | 0 | function ); |
3148 | |
|
3149 | 0 | return( -1 ); |
3150 | 0 | } |
3151 | 2.86k | if( libewf_segment_table_get_segment_file_by_index( |
3152 | 2.86k | segment_table, |
3153 | 2.86k | segment_number, |
3154 | 2.86k | file_io_pool, |
3155 | 2.86k | &segment_file, |
3156 | 2.86k | error ) != 1 ) |
3157 | 94 | { |
3158 | 94 | libcerror_error_set( |
3159 | 94 | error, |
3160 | 94 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3161 | 94 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3162 | 94 | "%s: unable to retrieve segment file: %" PRIu32 " from segment table.", |
3163 | 94 | function, |
3164 | 94 | segment_number ); |
3165 | | |
3166 | 94 | goto on_error; |
3167 | 94 | } |
3168 | 2.77k | if( segment_file == NULL ) |
3169 | 0 | { |
3170 | 0 | libcerror_error_set( |
3171 | 0 | error, |
3172 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3173 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
3174 | 0 | "%s: missing segment file: %" PRIu32 ".", |
3175 | 0 | function, |
3176 | 0 | segment_number ); |
3177 | |
|
3178 | 0 | goto on_error; |
3179 | 0 | } |
3180 | 2.77k | if( segment_file->major_version != 2 ) |
3181 | 2.58k | { |
3182 | 2.58k | return( 1 ); |
3183 | 2.58k | } |
3184 | 183 | if( segment_file->device_information_section_index == -1 ) |
3185 | 183 | { |
3186 | | /* Lx01 stores the device information in the last segment file |
3187 | | */ |
3188 | 183 | segment_number = number_of_segments - 1; |
3189 | | |
3190 | 183 | if( libewf_segment_table_get_segment_file_by_index( |
3191 | 183 | segment_table, |
3192 | 183 | segment_number, |
3193 | 183 | file_io_pool, |
3194 | 183 | &segment_file, |
3195 | 183 | error ) != 1 ) |
3196 | 0 | { |
3197 | 0 | libcerror_error_set( |
3198 | 0 | error, |
3199 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3200 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3201 | 0 | "%s: unable to retrieve segment file: %" PRIu32 " from segment table.", |
3202 | 0 | function, |
3203 | 0 | segment_number ); |
3204 | |
|
3205 | 0 | goto on_error; |
3206 | 0 | } |
3207 | 183 | if( segment_file == NULL ) |
3208 | 0 | { |
3209 | 0 | libcerror_error_set( |
3210 | 0 | error, |
3211 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3212 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
3213 | 0 | "%s: missing segment file: %" PRIu32 ".", |
3214 | 0 | function, |
3215 | 0 | segment_number ); |
3216 | |
|
3217 | 0 | goto on_error; |
3218 | 0 | } |
3219 | 183 | } |
3220 | 183 | if( segment_file->device_information_section_index == -1 ) |
3221 | 183 | { |
3222 | 183 | libcerror_error_set( |
3223 | 183 | error, |
3224 | 183 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3225 | 183 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
3226 | 183 | "%s: unable to locate a device information section.", |
3227 | 183 | function ); |
3228 | | |
3229 | 183 | goto on_error; |
3230 | 183 | } |
3231 | 0 | if( libewf_segment_table_get_segment_by_index( |
3232 | 0 | segment_table, |
3233 | 0 | segment_number, |
3234 | 0 | &file_io_pool_entry, |
3235 | 0 | &segment_file_size, |
3236 | 0 | error ) != 1 ) |
3237 | 0 | { |
3238 | 0 | libcerror_error_set( |
3239 | 0 | error, |
3240 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3241 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3242 | 0 | "%s: unable to retrieve segment: %" PRIu32 " from segment table.", |
3243 | 0 | function, |
3244 | 0 | segment_number ); |
3245 | |
|
3246 | 0 | goto on_error; |
3247 | 0 | } |
3248 | 0 | if( libfcache_cache_initialize( |
3249 | 0 | §ions_cache, |
3250 | 0 | LIBEWF_MAXIMUM_CACHE_ENTRIES_SECTIONS, |
3251 | 0 | error ) != 1 ) |
3252 | 0 | { |
3253 | 0 | libcerror_error_set( |
3254 | 0 | error, |
3255 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3256 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
3257 | 0 | "%s: unable to create sections cache.", |
3258 | 0 | function ); |
3259 | |
|
3260 | 0 | goto on_error; |
3261 | 0 | } |
3262 | 0 | if( libfdata_list_get_element_value_by_index( |
3263 | 0 | segment_file->sections_list, |
3264 | 0 | (intptr_t *) file_io_pool, |
3265 | 0 | (libfdata_cache_t *) sections_cache, |
3266 | 0 | segment_file->device_information_section_index, |
3267 | 0 | (intptr_t **) §ion_descriptor, |
3268 | 0 | 0, |
3269 | 0 | error ) != 1 ) |
3270 | 0 | { |
3271 | 0 | libcerror_error_set( |
3272 | 0 | error, |
3273 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3274 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3275 | 0 | "%s: unable to retrieve section: %d from sections list.", |
3276 | 0 | function, |
3277 | 0 | segment_file->device_information_section_index ); |
3278 | |
|
3279 | 0 | goto on_error; |
3280 | 0 | } |
3281 | 0 | if( libewf_segment_file_seek_offset( |
3282 | 0 | segment_file, |
3283 | 0 | file_io_pool, |
3284 | 0 | file_io_pool_entry, |
3285 | 0 | section_descriptor->start_offset, |
3286 | 0 | error ) == -1 ) |
3287 | 0 | { |
3288 | 0 | libcerror_error_set( |
3289 | 0 | error, |
3290 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
3291 | 0 | LIBCERROR_IO_ERROR_OPEN_FAILED, |
3292 | 0 | "%s: unable to seek section: %d data offset: %" PRIu64 " (0x%08%" PRIx64 ").", |
3293 | 0 | function, |
3294 | 0 | segment_file->device_information_section_index, |
3295 | 0 | section_descriptor->start_offset ); |
3296 | |
|
3297 | 0 | goto on_error; |
3298 | 0 | } |
3299 | 0 | read_count = libewf_device_information_section_read_file_io_pool( |
3300 | 0 | section_descriptor, |
3301 | 0 | internal_handle->io_handle, |
3302 | 0 | file_io_pool, |
3303 | 0 | file_io_pool_entry, |
3304 | 0 | internal_handle->read_io_handle, |
3305 | 0 | internal_handle->media_values, |
3306 | 0 | internal_handle->header_values, |
3307 | 0 | error ); |
3308 | |
|
3309 | 0 | if( read_count == -1 ) |
3310 | 0 | { |
3311 | 0 | libcerror_error_set( |
3312 | 0 | error, |
3313 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
3314 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
3315 | 0 | "%s: unable to read device information section: %d.", |
3316 | 0 | function, |
3317 | 0 | segment_file->device_information_section_index ); |
3318 | |
|
3319 | 0 | goto on_error; |
3320 | 0 | } |
3321 | 0 | if( libfcache_cache_free( |
3322 | 0 | §ions_cache, |
3323 | 0 | error ) != 1 ) |
3324 | 0 | { |
3325 | 0 | libcerror_error_set( |
3326 | 0 | error, |
3327 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3328 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
3329 | 0 | "%s: unable to free sections cache.", |
3330 | 0 | function ); |
3331 | |
|
3332 | 0 | goto on_error; |
3333 | 0 | } |
3334 | 0 | return( 1 ); |
3335 | | |
3336 | 277 | on_error: |
3337 | 277 | if( sections_cache != NULL ) |
3338 | 0 | { |
3339 | 0 | libfcache_cache_free( |
3340 | 0 | §ions_cache, |
3341 | 0 | NULL ); |
3342 | 0 | } |
3343 | 277 | return( -1 ); |
3344 | 0 | } |
3345 | | |
3346 | | /* Opens a set of EWF file(s) using a Basic File IO (bfio) pool |
3347 | | * This function is not multi-thread safe acquire write lock before call |
3348 | | * Returns 1 if successful or -1 on error |
3349 | | */ |
3350 | | int libewf_internal_handle_open_file_io_pool( |
3351 | | libewf_internal_handle_t *internal_handle, |
3352 | | libbfio_pool_t *file_io_pool, |
3353 | | int access_flags, |
3354 | | libewf_segment_table_t *segment_table, |
3355 | | libcerror_error_t **error ) |
3356 | 3.03k | { |
3357 | 3.03k | libbfio_handle_t *file_io_handle = NULL; |
3358 | 3.03k | libewf_segment_file_t *segment_file = NULL; |
3359 | 3.03k | static char *function = "libewf_internal_handle_open_file_io_pool"; |
3360 | 3.03k | size64_t segment_file_size = 0; |
3361 | 3.03k | ssize_t read_count = 0; |
3362 | 3.03k | int file_io_pool_entry = 0; |
3363 | 3.03k | int number_of_file_io_handles = 0; |
3364 | | |
3365 | 3.03k | if( internal_handle == NULL ) |
3366 | 0 | { |
3367 | 0 | libcerror_error_set( |
3368 | 0 | error, |
3369 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3370 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3371 | 0 | "%s: invalid handle.", |
3372 | 0 | function ); |
3373 | |
|
3374 | 0 | return( -1 ); |
3375 | 0 | } |
3376 | 3.03k | if( internal_handle->io_handle == NULL ) |
3377 | 0 | { |
3378 | 0 | libcerror_error_set( |
3379 | 0 | error, |
3380 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3381 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
3382 | 0 | "%s: invalid handle - missing IO handle.", |
3383 | 0 | function ); |
3384 | |
|
3385 | 0 | return( -1 ); |
3386 | 0 | } |
3387 | 3.03k | if( internal_handle->file_io_pool != NULL ) |
3388 | 0 | { |
3389 | 0 | libcerror_error_set( |
3390 | 0 | error, |
3391 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3392 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
3393 | 0 | "%s: invalid handle - file IO pool value already set.", |
3394 | 0 | function ); |
3395 | |
|
3396 | 0 | return( -1 ); |
3397 | 0 | } |
3398 | 3.03k | if( internal_handle->chunk_table != NULL ) |
3399 | 0 | { |
3400 | 0 | libcerror_error_set( |
3401 | 0 | error, |
3402 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3403 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
3404 | 0 | "%s: invalid handle - chunk table value already set.", |
3405 | 0 | function ); |
3406 | |
|
3407 | 0 | return( -1 ); |
3408 | 0 | } |
3409 | 3.03k | if( internal_handle->hash_sections != NULL ) |
3410 | 0 | { |
3411 | 0 | libcerror_error_set( |
3412 | 0 | error, |
3413 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3414 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
3415 | 0 | "%s: invalid handle - hash sections value already set.", |
3416 | 0 | function ); |
3417 | |
|
3418 | 0 | return( -1 ); |
3419 | 0 | } |
3420 | 3.03k | if( internal_handle->single_files != NULL ) |
3421 | 0 | { |
3422 | 0 | libcerror_error_set( |
3423 | 0 | error, |
3424 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3425 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
3426 | 0 | "%s: invalid handle - single files value already set.", |
3427 | 0 | function ); |
3428 | |
|
3429 | 0 | return( -1 ); |
3430 | 0 | } |
3431 | 3.03k | if( file_io_pool == NULL ) |
3432 | 0 | { |
3433 | 0 | libcerror_error_set( |
3434 | 0 | error, |
3435 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3436 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3437 | 0 | "%s: invalid file IO pool.", |
3438 | 0 | function ); |
3439 | |
|
3440 | 0 | return( -1 ); |
3441 | 0 | } |
3442 | 3.03k | if( ( ( access_flags & ~( LIBEWF_ACCESS_FLAG_READ | LIBEWF_ACCESS_FLAG_WRITE | LIBEWF_ACCESS_FLAG_RESUME ) ) != 0 ) |
3443 | 3.03k | || ( ( ( access_flags & LIBEWF_ACCESS_FLAG_READ ) != 0 ) |
3444 | 3.03k | && ( ( access_flags & LIBEWF_ACCESS_FLAG_WRITE ) != 0 ) ) ) |
3445 | 0 | { |
3446 | 0 | libcerror_error_set( |
3447 | 0 | error, |
3448 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3449 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
3450 | 0 | "%s: unsupported access flags.", |
3451 | 0 | function ); |
3452 | |
|
3453 | 0 | return( -1 ); |
3454 | 0 | } |
3455 | 3.03k | if( ( ( access_flags & LIBEWF_ACCESS_FLAG_READ ) != 0 ) |
3456 | 3.03k | || ( ( access_flags & LIBEWF_ACCESS_FLAG_RESUME ) != 0 ) ) |
3457 | 3.03k | { |
3458 | 3.03k | if( libewf_read_io_handle_initialize( |
3459 | 3.03k | &( internal_handle->read_io_handle ), |
3460 | 3.03k | error ) != 1 ) |
3461 | 0 | { |
3462 | 0 | libcerror_error_set( |
3463 | 0 | error, |
3464 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3465 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
3466 | 0 | "%s: unable to create read IO handle.", |
3467 | 0 | function ); |
3468 | |
|
3469 | 0 | goto on_error; |
3470 | 0 | } |
3471 | 3.03k | } |
3472 | 3.03k | if( ( access_flags & LIBEWF_ACCESS_FLAG_WRITE ) != 0 ) |
3473 | 0 | { |
3474 | 0 | if( libewf_write_io_handle_initialize( |
3475 | 0 | &( internal_handle->write_io_handle ), |
3476 | 0 | internal_handle->io_handle, |
3477 | 0 | error ) != 1 ) |
3478 | 0 | { |
3479 | 0 | libcerror_error_set( |
3480 | 0 | error, |
3481 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3482 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
3483 | 0 | "%s: unable to create write IO handle.", |
3484 | 0 | function ); |
3485 | |
|
3486 | 0 | goto on_error; |
3487 | 0 | } |
3488 | 0 | } |
3489 | 3.03k | if( libewf_chunk_table_initialize( |
3490 | 3.03k | &( internal_handle->chunk_table ), |
3491 | 3.03k | internal_handle->io_handle, |
3492 | 3.03k | error ) != 1 ) |
3493 | 0 | { |
3494 | 0 | libcerror_error_set( |
3495 | 0 | error, |
3496 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3497 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
3498 | 0 | "%s: unable to create chunk table.", |
3499 | 0 | function ); |
3500 | |
|
3501 | 0 | goto on_error; |
3502 | 0 | } |
3503 | 3.03k | if( libewf_header_values_initialize( |
3504 | 3.03k | &( internal_handle->header_values ), |
3505 | 3.03k | error ) != 1 ) |
3506 | 0 | { |
3507 | 0 | libcerror_error_set( |
3508 | 0 | error, |
3509 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3510 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
3511 | 0 | "%s: unable to create header values.", |
3512 | 0 | function ); |
3513 | |
|
3514 | 0 | goto on_error; |
3515 | 0 | } |
3516 | 3.03k | if( libewf_hash_sections_initialize( |
3517 | 3.03k | &( internal_handle->hash_sections ), |
3518 | 3.03k | error ) != 1 ) |
3519 | 0 | { |
3520 | 0 | libcerror_error_set( |
3521 | 0 | error, |
3522 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3523 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
3524 | 0 | "%s: unable to create hash sections.", |
3525 | 0 | function ); |
3526 | |
|
3527 | 0 | goto on_error; |
3528 | 0 | } |
3529 | 3.03k | if( libcdata_array_empty( |
3530 | 3.03k | internal_handle->sessions, |
3531 | 3.03k | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_sector_range_free, |
3532 | 3.03k | error ) != 1 ) |
3533 | 0 | { |
3534 | 0 | libcerror_error_set( |
3535 | 0 | error, |
3536 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3537 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
3538 | 0 | "%s: unable to empty sessions array.", |
3539 | 0 | function ); |
3540 | |
|
3541 | 0 | goto on_error; |
3542 | 0 | } |
3543 | 3.03k | if( libcdata_array_empty( |
3544 | 3.03k | internal_handle->tracks, |
3545 | 3.03k | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_sector_range_free, |
3546 | 3.03k | error ) != 1 ) |
3547 | 0 | { |
3548 | 0 | libcerror_error_set( |
3549 | 0 | error, |
3550 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3551 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
3552 | 0 | "%s: unable to empty tracks array.", |
3553 | 0 | function ); |
3554 | |
|
3555 | 0 | goto on_error; |
3556 | 0 | } |
3557 | 3.03k | if( libcdata_range_list_empty( |
3558 | 3.03k | internal_handle->acquiry_errors, |
3559 | 3.03k | NULL, |
3560 | 3.03k | error ) != 1 ) |
3561 | 0 | { |
3562 | 0 | libcerror_error_set( |
3563 | 0 | error, |
3564 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3565 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
3566 | 0 | "%s: unable to empty acquiry errors range list.", |
3567 | 0 | function ); |
3568 | |
|
3569 | 0 | goto on_error; |
3570 | 0 | } |
3571 | 3.03k | if( ( ( access_flags & LIBEWF_ACCESS_FLAG_READ ) != 0 ) |
3572 | 3.03k | || ( ( access_flags & LIBEWF_ACCESS_FLAG_RESUME ) != 0 ) ) |
3573 | 3.03k | { |
3574 | 3.03k | if( libbfio_pool_get_number_of_handles( |
3575 | 3.03k | file_io_pool, |
3576 | 3.03k | &number_of_file_io_handles, |
3577 | 3.03k | error ) != 1 ) |
3578 | 0 | { |
3579 | 0 | libcerror_error_set( |
3580 | 0 | error, |
3581 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3582 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3583 | 0 | "%s: unable to retrieve the number of handles in the pool.", |
3584 | 0 | function ); |
3585 | |
|
3586 | 0 | goto on_error; |
3587 | 0 | } |
3588 | 3.03k | if( libewf_segment_file_initialize( |
3589 | 3.03k | &segment_file, |
3590 | 3.03k | internal_handle->io_handle, |
3591 | 3.03k | error ) != 1 ) |
3592 | 0 | { |
3593 | 0 | libcerror_error_set( |
3594 | 0 | error, |
3595 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3596 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
3597 | 0 | "%s: unable to create segment file.", |
3598 | 0 | function ); |
3599 | |
|
3600 | 0 | goto on_error; |
3601 | 0 | } |
3602 | 3.03k | for( file_io_pool_entry = 0; |
3603 | 5.89k | file_io_pool_entry < number_of_file_io_handles; |
3604 | 3.03k | file_io_pool_entry++ ) |
3605 | 3.03k | { |
3606 | 3.03k | if( libbfio_pool_get_size( |
3607 | 3.03k | file_io_pool, |
3608 | 3.03k | file_io_pool_entry, |
3609 | 3.03k | &segment_file_size, |
3610 | 3.03k | error ) != 1 ) |
3611 | 0 | { |
3612 | 0 | libcerror_error_set( |
3613 | 0 | error, |
3614 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3615 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3616 | 0 | "%s: unable to retrieve size of file IO pool entry: %d.", |
3617 | 0 | function, |
3618 | 0 | file_io_pool_entry ); |
3619 | |
|
3620 | 0 | goto on_error; |
3621 | 0 | } |
3622 | 3.03k | if( libbfio_pool_get_handle( |
3623 | 3.03k | file_io_pool, |
3624 | 3.03k | file_io_pool_entry, |
3625 | 3.03k | &file_io_handle, |
3626 | 3.03k | error ) != 1 ) |
3627 | 0 | { |
3628 | 0 | libcerror_error_set( |
3629 | 0 | error, |
3630 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3631 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
3632 | 0 | "%s: unable to retrieve file IO handle: %d from pool.", |
3633 | 0 | function, |
3634 | 0 | file_io_pool_entry ); |
3635 | |
|
3636 | 0 | goto on_error; |
3637 | 0 | } |
3638 | | #if defined( HAVE_DEBUG_OUTPUT ) |
3639 | | if( libcnotify_verbose != 0 ) |
3640 | | { |
3641 | | libcnotify_printf( |
3642 | | "%s: processing file IO pool entry: %d.\n", |
3643 | | function, |
3644 | | file_io_pool_entry ); |
3645 | | } |
3646 | | #endif |
3647 | 3.03k | read_count = libewf_segment_file_read_file_header_file_io_pool( |
3648 | 3.03k | segment_file, |
3649 | 3.03k | file_io_pool, |
3650 | 3.03k | file_io_pool_entry, |
3651 | 3.03k | error ); |
3652 | | |
3653 | 3.03k | if( read_count < 0 ) |
3654 | 97 | { |
3655 | 97 | libcerror_error_set( |
3656 | 97 | error, |
3657 | 97 | LIBCERROR_ERROR_DOMAIN_IO, |
3658 | 97 | LIBCERROR_IO_ERROR_READ_FAILED, |
3659 | 97 | "%s: unable to read segment file header.", |
3660 | 97 | function ); |
3661 | | |
3662 | 97 | goto on_error; |
3663 | 97 | } |
3664 | 2.93k | if( segment_file->segment_number == 0 ) |
3665 | 1 | { |
3666 | 1 | libcerror_error_set( |
3667 | 1 | error, |
3668 | 1 | LIBCERROR_ERROR_DOMAIN_INPUT, |
3669 | 1 | LIBCERROR_INPUT_ERROR_INVALID_DATA, |
3670 | 1 | "%s: invalid segment number: 0 in file IO pool entry: %d.", |
3671 | 1 | function, |
3672 | 1 | file_io_pool_entry ); |
3673 | | |
3674 | 1 | goto on_error; |
3675 | 1 | } |
3676 | 2.93k | if( libewf_segment_table_append_segment_by_segment_file( |
3677 | 2.93k | segment_table, |
3678 | 2.93k | segment_file, |
3679 | 2.93k | file_io_pool_entry, |
3680 | 2.93k | segment_file_size, |
3681 | 2.93k | error ) != 1 ) |
3682 | 71 | { |
3683 | 71 | libcerror_error_set( |
3684 | 71 | error, |
3685 | 71 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3686 | 71 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
3687 | 71 | "%s: unable to append segment: %" PRIu32 " to segment table.", |
3688 | 71 | function, |
3689 | 71 | segment_file->segment_number ); |
3690 | | |
3691 | 71 | goto on_error; |
3692 | 71 | } |
3693 | 2.93k | } |
3694 | 2.86k | if( libewf_segment_file_free( |
3695 | 2.86k | &segment_file, |
3696 | 2.86k | error ) != 1 ) |
3697 | 0 | { |
3698 | 0 | libcerror_error_set( |
3699 | 0 | error, |
3700 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3701 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
3702 | 0 | "%s: unable to free segment file.", |
3703 | 0 | function ); |
3704 | |
|
3705 | 0 | goto on_error; |
3706 | 0 | } |
3707 | 2.86k | if( libewf_internal_handle_open_read_segment_files( |
3708 | 2.86k | internal_handle, |
3709 | 2.86k | file_io_pool, |
3710 | 2.86k | segment_table, |
3711 | 2.86k | error ) != 1 ) |
3712 | 1.75k | { |
3713 | 1.75k | libcerror_error_set( |
3714 | 1.75k | error, |
3715 | 1.75k | LIBCERROR_ERROR_DOMAIN_IO, |
3716 | 1.75k | LIBCERROR_IO_ERROR_READ_FAILED, |
3717 | 1.75k | "%s: unable to read segment files.", |
3718 | 1.75k | function ); |
3719 | | |
3720 | 1.75k | if( ( access_flags & LIBEWF_ACCESS_FLAG_RESUME ) == 0 ) |
3721 | 1.75k | { |
3722 | 1.75k | goto on_error; |
3723 | 1.75k | } |
3724 | | #if defined( HAVE_DEBUG_OUTPUT ) |
3725 | | if( libcnotify_verbose != 0 ) |
3726 | | { |
3727 | | if( ( error != NULL ) |
3728 | | && ( *error != NULL ) ) |
3729 | | { |
3730 | | libcnotify_print_error_backtrace( |
3731 | | *error ); |
3732 | | } |
3733 | | } |
3734 | | #endif |
3735 | 0 | libcerror_error_free( |
3736 | 0 | error ); |
3737 | 0 | } |
3738 | 1.10k | if( internal_handle->media_values == NULL ) |
3739 | 0 | { |
3740 | 0 | libcerror_error_set( |
3741 | 0 | error, |
3742 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3743 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
3744 | 0 | "%s: invalid handle - missing media values.", |
3745 | 0 | function ); |
3746 | |
|
3747 | 0 | goto on_error; |
3748 | 0 | } |
3749 | | /* TODO refactor */ |
3750 | 1.10k | if( internal_handle->single_files == NULL ) |
3751 | 1.10k | { |
3752 | 1.10k | if( libewf_internal_handle_get_media_values( |
3753 | 1.10k | internal_handle, |
3754 | 1.10k | &( internal_handle->media_values->media_size ), |
3755 | 1.10k | error ) != 1 ) |
3756 | 0 | { |
3757 | 0 | libcerror_error_set( |
3758 | 0 | error, |
3759 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3760 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
3761 | 0 | "%s: unable to determine media values.", |
3762 | 0 | function ); |
3763 | |
|
3764 | 0 | goto on_error; |
3765 | 0 | } |
3766 | 1.10k | } |
3767 | 1.10k | } |
3768 | 1.10k | if( ( ( access_flags & LIBEWF_ACCESS_FLAG_WRITE ) != 0 ) |
3769 | 1.10k | && ( ( access_flags & LIBEWF_ACCESS_FLAG_RESUME ) != 0 ) ) |
3770 | 0 | { |
3771 | 0 | if( internal_handle->write_io_handle->values_initialized == 0 ) |
3772 | 0 | { |
3773 | 0 | if( libewf_write_io_handle_initialize_values( |
3774 | 0 | internal_handle->write_io_handle, |
3775 | 0 | internal_handle->io_handle, |
3776 | 0 | internal_handle->media_values, |
3777 | 0 | segment_table, |
3778 | 0 | error ) != 1 ) |
3779 | 0 | { |
3780 | 0 | libcerror_error_set( |
3781 | 0 | error, |
3782 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3783 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
3784 | 0 | "%s: unable to initialize write IO handle values.", |
3785 | 0 | function ); |
3786 | |
|
3787 | 0 | goto on_error; |
3788 | 0 | } |
3789 | 0 | } |
3790 | 0 | if( libewf_write_io_handle_initialize_resume( |
3791 | 0 | internal_handle->write_io_handle, |
3792 | 0 | internal_handle->io_handle, |
3793 | 0 | file_io_pool, |
3794 | 0 | internal_handle->media_values, |
3795 | 0 | segment_table, |
3796 | 0 | internal_handle->read_io_handle, |
3797 | 0 | &( internal_handle->current_offset ), |
3798 | 0 | error ) != 1 ) |
3799 | 0 | { |
3800 | 0 | libcerror_error_set( |
3801 | 0 | error, |
3802 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3803 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
3804 | 0 | "%s: unable to initialize write IO handle to resume.", |
3805 | 0 | function ); |
3806 | |
|
3807 | 0 | goto on_error; |
3808 | 0 | } |
3809 | 0 | } |
3810 | 1.10k | internal_handle->io_handle->chunk_size = internal_handle->media_values->chunk_size; |
3811 | 1.10k | internal_handle->io_handle->access_flags = access_flags; |
3812 | | |
3813 | 1.10k | return( 1 ); |
3814 | | |
3815 | 1.92k | on_error: |
3816 | 1.92k | if( segment_file != NULL ) |
3817 | 169 | { |
3818 | 169 | libewf_segment_file_free( |
3819 | 169 | &segment_file, |
3820 | 169 | NULL ); |
3821 | 169 | } |
3822 | 1.92k | if( internal_handle->single_files != NULL ) |
3823 | 0 | { |
3824 | 0 | libewf_single_files_free( |
3825 | 0 | &( internal_handle->single_files ), |
3826 | 0 | NULL ); |
3827 | 0 | } |
3828 | 1.92k | if( internal_handle->hash_sections != NULL ) |
3829 | 1.92k | { |
3830 | 1.92k | libewf_hash_sections_free( |
3831 | 1.92k | &( internal_handle->hash_sections ), |
3832 | 1.92k | NULL ); |
3833 | 1.92k | } |
3834 | 1.92k | if( internal_handle->header_values != NULL ) |
3835 | 1.92k | { |
3836 | 1.92k | libfvalue_table_free( |
3837 | 1.92k | &( internal_handle->header_values ), |
3838 | 1.92k | NULL ); |
3839 | 1.92k | } |
3840 | 1.92k | if( internal_handle->chunk_table != NULL ) |
3841 | 1.92k | { |
3842 | 1.92k | libewf_chunk_table_free( |
3843 | 1.92k | &( internal_handle->chunk_table ), |
3844 | 1.92k | NULL ); |
3845 | 1.92k | } |
3846 | 1.92k | if( internal_handle->write_io_handle != NULL ) |
3847 | 0 | { |
3848 | 0 | libewf_write_io_handle_free( |
3849 | 0 | &( internal_handle->write_io_handle ), |
3850 | 0 | error ); |
3851 | 0 | } |
3852 | 1.92k | if( internal_handle->read_io_handle != NULL ) |
3853 | 1.92k | { |
3854 | 1.92k | libewf_read_io_handle_free( |
3855 | 1.92k | &( internal_handle->read_io_handle ), |
3856 | 1.92k | error ); |
3857 | 1.92k | } |
3858 | 1.92k | return( -1 ); |
3859 | 1.10k | } |
3860 | | |
3861 | | /* Opens a set of EWF file(s) using a Basic File IO (bfio) pool |
3862 | | * Returns 1 if successful or -1 on error |
3863 | | */ |
3864 | | int libewf_handle_open_file_io_pool( |
3865 | | libewf_handle_t *handle, |
3866 | | libbfio_pool_t *file_io_pool, |
3867 | | int access_flags, |
3868 | | libcerror_error_t **error ) |
3869 | 3.03k | { |
3870 | 3.03k | libewf_internal_handle_t *internal_handle = NULL; |
3871 | 3.03k | static char *function = "libewf_handle_open_file_io_pool"; |
3872 | 3.03k | int result = 0; |
3873 | | |
3874 | 3.03k | if( handle == NULL ) |
3875 | 0 | { |
3876 | 0 | libcerror_error_set( |
3877 | 0 | error, |
3878 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3879 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3880 | 0 | "%s: invalid handle.", |
3881 | 0 | function ); |
3882 | |
|
3883 | 0 | return( -1 ); |
3884 | 0 | } |
3885 | 3.03k | internal_handle = (libewf_internal_handle_t *) handle; |
3886 | | |
3887 | 3.03k | if( internal_handle->file_io_pool != NULL ) |
3888 | 0 | { |
3889 | 0 | libcerror_error_set( |
3890 | 0 | error, |
3891 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3892 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
3893 | 0 | "%s: invalid handle - file IO pool value already set.", |
3894 | 0 | function ); |
3895 | |
|
3896 | 0 | return( -1 ); |
3897 | 0 | } |
3898 | 3.03k | #if !defined( HAVE_WRITE_SUPPORT ) |
3899 | 3.03k | if( ( access_flags & LIBEWF_ACCESS_FLAG_WRITE ) != 0 ) |
3900 | 0 | { |
3901 | 0 | libcerror_error_set( |
3902 | 0 | error, |
3903 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3904 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
3905 | 0 | "%s: write access currently not supported - compiled without zlib.", |
3906 | 0 | function ); |
3907 | |
|
3908 | 0 | return( -1 ); |
3909 | 0 | } |
3910 | 3.03k | #endif |
3911 | 3.03k | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
3912 | 3.03k | if( libcthreads_read_write_lock_grab_for_write( |
3913 | 3.03k | internal_handle->read_write_lock, |
3914 | 3.03k | error ) != 1 ) |
3915 | 0 | { |
3916 | 0 | libcerror_error_set( |
3917 | 0 | error, |
3918 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3919 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
3920 | 0 | "%s: unable to grab read/write lock for writing.", |
3921 | 0 | function ); |
3922 | |
|
3923 | 0 | return( -1 ); |
3924 | 0 | } |
3925 | 3.03k | #endif |
3926 | 3.03k | result = libewf_internal_handle_open_file_io_pool( |
3927 | 3.03k | internal_handle, |
3928 | 3.03k | file_io_pool, |
3929 | 3.03k | access_flags, |
3930 | 3.03k | internal_handle->segment_table, |
3931 | 3.03k | error ); |
3932 | | |
3933 | 3.03k | if( result != 1 ) |
3934 | 1.92k | { |
3935 | 1.92k | libcerror_error_set( |
3936 | 1.92k | error, |
3937 | 1.92k | LIBCERROR_ERROR_DOMAIN_IO, |
3938 | 1.92k | LIBCERROR_IO_ERROR_OPEN_FAILED, |
3939 | 1.92k | "%s: unable to open handle using a file IO pool.", |
3940 | 1.92k | function ); |
3941 | 1.92k | } |
3942 | 1.10k | else |
3943 | 1.10k | { |
3944 | 1.10k | internal_handle->file_io_pool = file_io_pool; |
3945 | 1.10k | } |
3946 | 3.03k | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
3947 | 3.03k | if( libcthreads_read_write_lock_release_for_write( |
3948 | 3.03k | internal_handle->read_write_lock, |
3949 | 3.03k | error ) != 1 ) |
3950 | 0 | { |
3951 | 0 | libcerror_error_set( |
3952 | 0 | error, |
3953 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
3954 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
3955 | 0 | "%s: unable to release read/write lock for writing.", |
3956 | 0 | function ); |
3957 | |
|
3958 | 0 | result = -1; |
3959 | 0 | } |
3960 | 3.03k | #endif |
3961 | 3.03k | if( result != 1 ) |
3962 | 1.92k | { |
3963 | 1.92k | goto on_error; |
3964 | 1.92k | } |
3965 | 1.10k | return( 1 ); |
3966 | | |
3967 | 1.92k | on_error: |
3968 | 1.92k | internal_handle->file_io_pool = NULL; |
3969 | | |
3970 | 1.92k | return( -1 ); |
3971 | 3.03k | } |
3972 | | |
3973 | | /* Closes the EWF handle |
3974 | | * Returns 0 if successful or -1 on error |
3975 | | */ |
3976 | | int libewf_handle_close( |
3977 | | libewf_handle_t *handle, |
3978 | | libcerror_error_t **error ) |
3979 | 1.10k | { |
3980 | 1.10k | libewf_internal_handle_t *internal_handle = NULL; |
3981 | 1.10k | static char *function = "libewf_handle_close"; |
3982 | 1.10k | ssize_t write_count = 0; |
3983 | 1.10k | int result = 0; |
3984 | | |
3985 | 1.10k | if( handle == NULL ) |
3986 | 0 | { |
3987 | 0 | libcerror_error_set( |
3988 | 0 | error, |
3989 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
3990 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
3991 | 0 | "%s: invalid handle.", |
3992 | 0 | function ); |
3993 | |
|
3994 | 0 | return( -1 ); |
3995 | 0 | } |
3996 | 1.10k | internal_handle = (libewf_internal_handle_t *) handle; |
3997 | | |
3998 | 1.10k | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
3999 | 1.10k | if( libcthreads_read_write_lock_grab_for_write( |
4000 | 1.10k | internal_handle->read_write_lock, |
4001 | 1.10k | error ) != 1 ) |
4002 | 0 | { |
4003 | 0 | libcerror_error_set( |
4004 | 0 | error, |
4005 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4006 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
4007 | 0 | "%s: unable to grab read/write lock for writing.", |
4008 | 0 | function ); |
4009 | |
|
4010 | 0 | return( -1 ); |
4011 | 0 | } |
4012 | 1.10k | #endif |
4013 | 1.10k | if( ( internal_handle->write_io_handle != NULL ) |
4014 | 1.10k | && ( internal_handle->write_io_handle->write_finalized == 0 ) ) |
4015 | 0 | { |
4016 | 0 | write_count = libewf_internal_handle_write_finalize_file_io_pool( |
4017 | 0 | internal_handle, |
4018 | 0 | internal_handle->file_io_pool, |
4019 | 0 | error ); |
4020 | |
|
4021 | 0 | if( write_count < 0 ) |
4022 | 0 | { |
4023 | 0 | libcerror_error_set( |
4024 | 0 | error, |
4025 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
4026 | 0 | LIBCERROR_IO_ERROR_WRITE_FAILED, |
4027 | 0 | "%s: unable to finalize write.", |
4028 | 0 | function ); |
4029 | |
|
4030 | 0 | result = -1; |
4031 | 0 | } |
4032 | 0 | } |
4033 | 1.10k | if( internal_handle->file_io_pool_created_in_library != 0 ) |
4034 | 0 | { |
4035 | 0 | if( libbfio_pool_close_all( |
4036 | 0 | internal_handle->file_io_pool, |
4037 | 0 | error ) != 0 ) |
4038 | 0 | { |
4039 | 0 | libcerror_error_set( |
4040 | 0 | error, |
4041 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
4042 | 0 | LIBCERROR_IO_ERROR_CLOSE_FAILED, |
4043 | 0 | "%s: unable to close all file IO pool handles.", |
4044 | 0 | function ); |
4045 | |
|
4046 | 0 | result = -1; |
4047 | 0 | } |
4048 | 0 | if( libbfio_pool_free( |
4049 | 0 | &( internal_handle->file_io_pool ), |
4050 | 0 | error ) != 1 ) |
4051 | 0 | { |
4052 | 0 | libcerror_error_set( |
4053 | 0 | error, |
4054 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4055 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
4056 | 0 | "%s: unable to free file IO pool.", |
4057 | 0 | function ); |
4058 | |
|
4059 | 0 | result = -1; |
4060 | 0 | } |
4061 | 0 | internal_handle->file_io_pool_created_in_library = 0; |
4062 | 0 | } |
4063 | 1.10k | internal_handle->file_io_pool = NULL; |
4064 | | |
4065 | 1.10k | if( libewf_io_handle_clear( |
4066 | 1.10k | internal_handle->io_handle, |
4067 | 1.10k | error ) != 1 ) |
4068 | 0 | { |
4069 | 0 | libcerror_error_set( |
4070 | 0 | error, |
4071 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4072 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
4073 | 0 | "%s: unable to clear IO handle.", |
4074 | 0 | function ); |
4075 | |
|
4076 | 0 | result = -1; |
4077 | 0 | } |
4078 | 1.10k | if( libewf_media_values_clear( |
4079 | 1.10k | internal_handle->media_values, |
4080 | 1.10k | error ) != 1 ) |
4081 | 0 | { |
4082 | 0 | libcerror_error_set( |
4083 | 0 | error, |
4084 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4085 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
4086 | 0 | "%s: unable to clear media values.", |
4087 | 0 | function ); |
4088 | |
|
4089 | 0 | result = -1; |
4090 | 0 | } |
4091 | 1.10k | if( internal_handle->read_io_handle != NULL ) |
4092 | 1.10k | { |
4093 | 1.10k | if( libewf_read_io_handle_free( |
4094 | 1.10k | &( internal_handle->read_io_handle ), |
4095 | 1.10k | error ) != 1 ) |
4096 | 0 | { |
4097 | 0 | libcerror_error_set( |
4098 | 0 | error, |
4099 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4100 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
4101 | 0 | "%s: unable to free read IO handle.", |
4102 | 0 | function ); |
4103 | |
|
4104 | 0 | result = -1; |
4105 | 0 | } |
4106 | 1.10k | } |
4107 | 1.10k | if( internal_handle->write_io_handle != NULL ) |
4108 | 0 | { |
4109 | 0 | if( libewf_write_io_handle_free( |
4110 | 0 | &( internal_handle->write_io_handle ), |
4111 | 0 | error ) != 1 ) |
4112 | 0 | { |
4113 | 0 | libcerror_error_set( |
4114 | 0 | error, |
4115 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4116 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
4117 | 0 | "%s: unable to free write IO handle.", |
4118 | 0 | function ); |
4119 | |
|
4120 | 0 | result = -1; |
4121 | 0 | } |
4122 | 0 | } |
4123 | | /* Free the chunk data if it could not be passed to libfcache_cache_set_value_by_index |
4124 | | */ |
4125 | 1.10k | if( internal_handle->chunk_data != NULL ) |
4126 | 0 | { |
4127 | 0 | if( libewf_chunk_data_free( |
4128 | 0 | &( internal_handle->chunk_data ), |
4129 | 0 | error ) != 1 ) |
4130 | 0 | { |
4131 | 0 | libcerror_error_set( |
4132 | 0 | error, |
4133 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4134 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
4135 | 0 | "%s: unable to free chunk data.", |
4136 | 0 | function ); |
4137 | |
|
4138 | 0 | result = -1; |
4139 | 0 | } |
4140 | 0 | } |
4141 | 1.10k | if( internal_handle->chunk_table != NULL ) |
4142 | 1.10k | { |
4143 | 1.10k | if( libewf_chunk_table_free( |
4144 | 1.10k | &( internal_handle->chunk_table ), |
4145 | 1.10k | error ) != 1 ) |
4146 | 0 | { |
4147 | 0 | libcerror_error_set( |
4148 | 0 | error, |
4149 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4150 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
4151 | 0 | "%s: unable to free chunk table.", |
4152 | 0 | function ); |
4153 | |
|
4154 | 0 | result = -1; |
4155 | 0 | } |
4156 | 1.10k | } |
4157 | 1.10k | if( internal_handle->hash_sections != NULL ) |
4158 | 1.10k | { |
4159 | 1.10k | if( libewf_hash_sections_free( |
4160 | 1.10k | &( internal_handle->hash_sections ), |
4161 | 1.10k | error ) != 1 ) |
4162 | 0 | { |
4163 | 0 | libcerror_error_set( |
4164 | 0 | error, |
4165 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4166 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
4167 | 0 | "%s: unable to free hash sections.", |
4168 | 0 | function ); |
4169 | |
|
4170 | 0 | result = -1; |
4171 | 0 | } |
4172 | 1.10k | } |
4173 | 1.10k | if( internal_handle->header_values != NULL ) |
4174 | 1.10k | { |
4175 | 1.10k | if( libfvalue_table_free( |
4176 | 1.10k | &( internal_handle->header_values ), |
4177 | 1.10k | error ) != 1 ) |
4178 | 0 | { |
4179 | 0 | libcerror_error_set( |
4180 | 0 | error, |
4181 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4182 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
4183 | 0 | "%s: unable to free header values.", |
4184 | 0 | function ); |
4185 | |
|
4186 | 0 | result = -1; |
4187 | 0 | } |
4188 | 1.10k | } |
4189 | 1.10k | if( internal_handle->hash_values != NULL ) |
4190 | 0 | { |
4191 | 0 | if( libfvalue_table_free( |
4192 | 0 | &( internal_handle->hash_values ), |
4193 | 0 | error ) != 1 ) |
4194 | 0 | { |
4195 | 0 | libcerror_error_set( |
4196 | 0 | error, |
4197 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4198 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
4199 | 0 | "%s: unable to free hash values.", |
4200 | 0 | function ); |
4201 | |
|
4202 | 0 | result = -1; |
4203 | 0 | } |
4204 | 0 | } |
4205 | 1.10k | if( internal_handle->single_files != NULL ) |
4206 | 0 | { |
4207 | 0 | if( libewf_single_files_free( |
4208 | 0 | &( internal_handle->single_files ), |
4209 | 0 | error ) != 1 ) |
4210 | 0 | { |
4211 | 0 | libcerror_error_set( |
4212 | 0 | error, |
4213 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4214 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
4215 | 0 | "%s: unable to free single files.", |
4216 | 0 | function ); |
4217 | |
|
4218 | 0 | result = -1; |
4219 | 0 | } |
4220 | 0 | } |
4221 | 1.10k | if( libcdata_array_empty( |
4222 | 1.10k | internal_handle->sessions, |
4223 | 1.10k | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_sector_range_free, |
4224 | 1.10k | error ) != 1 ) |
4225 | 0 | { |
4226 | 0 | libcerror_error_set( |
4227 | 0 | error, |
4228 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4229 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
4230 | 0 | "%s: unable to empty sessions array.", |
4231 | 0 | function ); |
4232 | |
|
4233 | 0 | result = -1; |
4234 | 0 | } |
4235 | 1.10k | if( libcdata_array_empty( |
4236 | 1.10k | internal_handle->tracks, |
4237 | 1.10k | (int (*)(intptr_t **, libcerror_error_t **)) &libewf_sector_range_free, |
4238 | 1.10k | error ) != 1 ) |
4239 | 0 | { |
4240 | 0 | libcerror_error_set( |
4241 | 0 | error, |
4242 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4243 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
4244 | 0 | "%s: unable to empty tracks array.", |
4245 | 0 | function ); |
4246 | |
|
4247 | 0 | result = -1; |
4248 | 0 | } |
4249 | 1.10k | if( libcdata_range_list_empty( |
4250 | 1.10k | internal_handle->acquiry_errors, |
4251 | 1.10k | NULL, |
4252 | 1.10k | error ) != 1 ) |
4253 | 0 | { |
4254 | 0 | libcerror_error_set( |
4255 | 0 | error, |
4256 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4257 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
4258 | 0 | "%s: unable to empty acquiry errors range list.", |
4259 | 0 | function ); |
4260 | |
|
4261 | 0 | result = -1; |
4262 | 0 | } |
4263 | 1.10k | if( libewf_segment_table_clear( |
4264 | 1.10k | internal_handle->segment_table, |
4265 | 1.10k | error ) != 1 ) |
4266 | 0 | { |
4267 | 0 | libcerror_error_set( |
4268 | 0 | error, |
4269 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4270 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
4271 | 0 | "%s: unable to clear segment table.", |
4272 | 0 | function ); |
4273 | |
|
4274 | 0 | result = -1; |
4275 | 0 | } |
4276 | 1.10k | if( libewf_io_handle_clear( |
4277 | 1.10k | internal_handle->io_handle, |
4278 | 1.10k | error ) != 1 ) |
4279 | 0 | { |
4280 | 0 | libcerror_error_set( |
4281 | 0 | error, |
4282 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4283 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
4284 | 0 | "%s: unable to clear IO handle.", |
4285 | 0 | function ); |
4286 | |
|
4287 | 0 | result = -1; |
4288 | 0 | } |
4289 | 1.10k | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
4290 | 1.10k | if( libcthreads_read_write_lock_release_for_write( |
4291 | 1.10k | internal_handle->read_write_lock, |
4292 | 1.10k | error ) != 1 ) |
4293 | 0 | { |
4294 | 0 | libcerror_error_set( |
4295 | 0 | error, |
4296 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4297 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
4298 | 0 | "%s: unable to release read/write lock for writing.", |
4299 | 0 | function ); |
4300 | |
|
4301 | 0 | result = -1; |
4302 | 0 | } |
4303 | 1.10k | #endif |
4304 | 1.10k | return( result ); |
4305 | 1.10k | } |
4306 | | |
4307 | | /* Reads (media) data from the last current into a buffer using a Basic File IO (bfio) pool |
4308 | | * This function is not multi-thread safe acquire write lock before call |
4309 | | * Returns the number of bytes read, 0 when no longer data can be read or -1 on error |
4310 | | */ |
4311 | | ssize_t libewf_internal_handle_read_buffer_from_file_io_pool( |
4312 | | libewf_internal_handle_t *internal_handle, |
4313 | | libbfio_pool_t *file_io_pool, |
4314 | | void *buffer, |
4315 | | size_t buffer_size, |
4316 | | libcerror_error_t **error ) |
4317 | 0 | { |
4318 | 0 | libewf_chunk_data_t *chunk_data = NULL; |
4319 | 0 | static char *function = "libewf_internal_handle_read_buffer_from_file_io_pool"; |
4320 | 0 | off64_t chunk_data_offset = 0; |
4321 | 0 | size_t buffer_offset = 0; |
4322 | 0 | size_t read_size = 0; |
4323 | |
|
4324 | 0 | if( internal_handle == NULL ) |
4325 | 0 | { |
4326 | 0 | libcerror_error_set( |
4327 | 0 | error, |
4328 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4329 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4330 | 0 | "%s: invalid handle.", |
4331 | 0 | function ); |
4332 | |
|
4333 | 0 | return( -1 ); |
4334 | 0 | } |
4335 | 0 | if( internal_handle->io_handle == NULL ) |
4336 | 0 | { |
4337 | 0 | libcerror_error_set( |
4338 | 0 | error, |
4339 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4340 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
4341 | 0 | "%s: invalid handle - missing IO handle.", |
4342 | 0 | function ); |
4343 | |
|
4344 | 0 | return( -1 ); |
4345 | 0 | } |
4346 | 0 | if( internal_handle->chunk_data != NULL ) |
4347 | 0 | { |
4348 | 0 | libcerror_error_set( |
4349 | 0 | error, |
4350 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4351 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
4352 | 0 | "%s: invalid handle - chunk data set.", |
4353 | 0 | function ); |
4354 | |
|
4355 | 0 | return( -1 ); |
4356 | 0 | } |
4357 | 0 | if( internal_handle->current_offset < 0 ) |
4358 | 0 | { |
4359 | 0 | libcerror_error_set( |
4360 | 0 | error, |
4361 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4362 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
4363 | 0 | "%s: invalid handle - invalid IO handle - current offset value out of bounds.", |
4364 | 0 | function ); |
4365 | |
|
4366 | 0 | return( -1 ); |
4367 | 0 | } |
4368 | 0 | if( internal_handle->media_values == NULL ) |
4369 | 0 | { |
4370 | 0 | libcerror_error_set( |
4371 | 0 | error, |
4372 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4373 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
4374 | 0 | "%s: invalid handle - missing media values.", |
4375 | 0 | function ); |
4376 | |
|
4377 | 0 | return( -1 ); |
4378 | 0 | } |
4379 | 0 | if( internal_handle->media_values->chunk_size == 0 ) |
4380 | 0 | { |
4381 | 0 | libcerror_error_set( |
4382 | 0 | error, |
4383 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4384 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
4385 | 0 | "%s: invalid handle - invalid media values - missing chunk size.", |
4386 | 0 | function ); |
4387 | |
|
4388 | 0 | return( -1 ); |
4389 | 0 | } |
4390 | 0 | if( buffer == NULL ) |
4391 | 0 | { |
4392 | 0 | libcerror_error_set( |
4393 | 0 | error, |
4394 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4395 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4396 | 0 | "%s: invalid buffer.", |
4397 | 0 | function ); |
4398 | |
|
4399 | 0 | return( -1 ); |
4400 | 0 | } |
4401 | 0 | if( buffer_size > (size_t) SSIZE_MAX ) |
4402 | 0 | { |
4403 | 0 | libcerror_error_set( |
4404 | 0 | error, |
4405 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4406 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
4407 | 0 | "%s: invalid buffer size value exceeds maximum.", |
4408 | 0 | function ); |
4409 | |
|
4410 | 0 | return( -1 ); |
4411 | 0 | } |
4412 | 0 | if( (size64_t) internal_handle->current_offset >= internal_handle->media_values->media_size ) |
4413 | 0 | { |
4414 | 0 | return( 0 ); |
4415 | 0 | } |
4416 | 0 | internal_handle->io_handle->abort = 0; |
4417 | |
|
4418 | 0 | if( (size64_t) ( internal_handle->current_offset + buffer_size ) >= internal_handle->media_values->media_size ) |
4419 | 0 | { |
4420 | 0 | buffer_size = (size_t) ( internal_handle->media_values->media_size - internal_handle->current_offset ); |
4421 | 0 | } |
4422 | 0 | while( buffer_size > 0 ) |
4423 | 0 | { |
4424 | 0 | if( libewf_chunk_table_get_chunk_data_by_offset( |
4425 | 0 | internal_handle->chunk_table, |
4426 | 0 | internal_handle->io_handle, |
4427 | 0 | file_io_pool, |
4428 | 0 | internal_handle->media_values, |
4429 | 0 | internal_handle->segment_table, |
4430 | 0 | internal_handle->current_offset, |
4431 | 0 | &chunk_data_offset, |
4432 | 0 | &chunk_data, |
4433 | 0 | error ) != 1 ) |
4434 | 0 | { |
4435 | 0 | libcerror_error_set( |
4436 | 0 | error, |
4437 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4438 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
4439 | 0 | "%s: unable to retrieve chunk data for offset: %" PRIi64 " (0x%08" PRIx64 ").", |
4440 | 0 | function, |
4441 | 0 | internal_handle->current_offset, |
4442 | 0 | internal_handle->current_offset ); |
4443 | |
|
4444 | 0 | return( -1 ); |
4445 | 0 | } |
4446 | 0 | if( chunk_data == NULL ) |
4447 | 0 | { |
4448 | 0 | libcerror_error_set( |
4449 | 0 | error, |
4450 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4451 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
4452 | 0 | "%s: missing chunk data for offset: %" PRIi64 " (0x%08" PRIx64 ").", |
4453 | 0 | function, |
4454 | 0 | internal_handle->current_offset, |
4455 | 0 | internal_handle->current_offset ); |
4456 | |
|
4457 | 0 | return( -1 ); |
4458 | 0 | } |
4459 | 0 | if( (off64_t) chunk_data_offset > (off64_t) chunk_data->data_size ) |
4460 | 0 | { |
4461 | 0 | libcerror_error_set( |
4462 | 0 | error, |
4463 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4464 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
4465 | 0 | "%s: chunk: %" PRIu64 " offset exceeds data size.", |
4466 | 0 | function, |
4467 | 0 | chunk_data->chunk_index ); |
4468 | |
|
4469 | 0 | return( -1 ); |
4470 | 0 | } |
4471 | 0 | read_size = (size_t) ( chunk_data->data_size - chunk_data_offset ); |
4472 | |
|
4473 | 0 | if( read_size > buffer_size ) |
4474 | 0 | { |
4475 | 0 | read_size = buffer_size; |
4476 | 0 | } |
4477 | 0 | if( read_size == 0 ) |
4478 | 0 | { |
4479 | 0 | break; |
4480 | 0 | } |
4481 | 0 | if( memory_copy( |
4482 | 0 | &( ( (uint8_t *) buffer )[ buffer_offset ] ), |
4483 | 0 | &( ( chunk_data->data )[ chunk_data_offset ] ), |
4484 | 0 | read_size ) == NULL ) |
4485 | 0 | { |
4486 | 0 | libcerror_error_set( |
4487 | 0 | error, |
4488 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
4489 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
4490 | 0 | "%s: unable to copy chunk: %" PRIu64 " data to buffer.", |
4491 | 0 | function, |
4492 | 0 | chunk_data->chunk_index ); |
4493 | |
|
4494 | 0 | return( -1 ); |
4495 | 0 | } |
4496 | 0 | buffer_offset += read_size; |
4497 | 0 | buffer_size -= read_size; |
4498 | |
|
4499 | 0 | internal_handle->current_offset += (off64_t) read_size; |
4500 | |
|
4501 | 0 | if( (size64_t) internal_handle->current_offset >= internal_handle->media_values->media_size ) |
4502 | 0 | { |
4503 | 0 | break; |
4504 | 0 | } |
4505 | 0 | if( internal_handle->io_handle->abort != 0 ) |
4506 | 0 | { |
4507 | 0 | break; |
4508 | 0 | } |
4509 | 0 | chunk_data = NULL; |
4510 | 0 | chunk_data_offset = 0; |
4511 | 0 | } |
4512 | 0 | internal_handle->io_handle->abort = 0; |
4513 | |
|
4514 | 0 | return( (ssize_t) buffer_offset ); |
4515 | 0 | } |
4516 | | |
4517 | | /* Reads (media) data at the current offset into a buffer |
4518 | | * Returns the number of bytes read, 0 when no longer data can be read or -1 on error |
4519 | | */ |
4520 | | ssize_t libewf_handle_read_buffer( |
4521 | | libewf_handle_t *handle, |
4522 | | void *buffer, |
4523 | | size_t buffer_size, |
4524 | | libcerror_error_t **error ) |
4525 | 0 | { |
4526 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
4527 | 0 | static char *function = "libewf_handle_read_buffer"; |
4528 | 0 | ssize_t read_count = 0; |
4529 | |
|
4530 | 0 | if( handle == NULL ) |
4531 | 0 | { |
4532 | 0 | libcerror_error_set( |
4533 | 0 | error, |
4534 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4535 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4536 | 0 | "%s: invalid handle.", |
4537 | 0 | function ); |
4538 | |
|
4539 | 0 | return( -1 ); |
4540 | 0 | } |
4541 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
4542 | |
|
4543 | 0 | if( internal_handle->file_io_pool == NULL ) |
4544 | 0 | { |
4545 | 0 | libcerror_error_set( |
4546 | 0 | error, |
4547 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4548 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
4549 | 0 | "%s: invalid handle - missing file IO pool.", |
4550 | 0 | function ); |
4551 | |
|
4552 | 0 | return( -1 ); |
4553 | 0 | } |
4554 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
4555 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
4556 | 0 | internal_handle->read_write_lock, |
4557 | 0 | error ) != 1 ) |
4558 | 0 | { |
4559 | 0 | libcerror_error_set( |
4560 | 0 | error, |
4561 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4562 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
4563 | 0 | "%s: unable to grab read/write lock for writing.", |
4564 | 0 | function ); |
4565 | |
|
4566 | 0 | return( -1 ); |
4567 | 0 | } |
4568 | 0 | #endif |
4569 | 0 | read_count = libewf_internal_handle_read_buffer_from_file_io_pool( |
4570 | 0 | internal_handle, |
4571 | 0 | internal_handle->file_io_pool, |
4572 | 0 | buffer, |
4573 | 0 | buffer_size, |
4574 | 0 | error ); |
4575 | |
|
4576 | 0 | if( read_count == -1 ) |
4577 | 0 | { |
4578 | 0 | libcerror_error_set( |
4579 | 0 | error, |
4580 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
4581 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
4582 | 0 | "%s: unable to read buffer.", |
4583 | 0 | function ); |
4584 | |
|
4585 | 0 | read_count = -1; |
4586 | 0 | } |
4587 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
4588 | 0 | if( libcthreads_read_write_lock_release_for_write( |
4589 | 0 | internal_handle->read_write_lock, |
4590 | 0 | error ) != 1 ) |
4591 | 0 | { |
4592 | 0 | libcerror_error_set( |
4593 | 0 | error, |
4594 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4595 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
4596 | 0 | "%s: unable to release read/write lock for writing.", |
4597 | 0 | function ); |
4598 | |
|
4599 | 0 | return( -1 ); |
4600 | 0 | } |
4601 | 0 | #endif |
4602 | 0 | return( read_count ); |
4603 | 0 | } |
4604 | | |
4605 | | /* Reads (media) data at a specific offset |
4606 | | * Returns the number of bytes read, 0 when no longer data can be read or -1 on error |
4607 | | */ |
4608 | | ssize_t libewf_handle_read_buffer_at_offset( |
4609 | | libewf_handle_t *handle, |
4610 | | void *buffer, |
4611 | | size_t buffer_size, |
4612 | | off64_t offset, |
4613 | | libcerror_error_t **error ) |
4614 | 0 | { |
4615 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
4616 | 0 | static char *function = "libewf_handle_read_buffer_at_offset"; |
4617 | 0 | ssize_t read_count = 0; |
4618 | |
|
4619 | 0 | if( handle == NULL ) |
4620 | 0 | { |
4621 | 0 | libcerror_error_set( |
4622 | 0 | error, |
4623 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4624 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4625 | 0 | "%s: invalid handle.", |
4626 | 0 | function ); |
4627 | |
|
4628 | 0 | return( -1 ); |
4629 | 0 | } |
4630 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
4631 | |
|
4632 | 0 | if( internal_handle->file_io_pool == NULL ) |
4633 | 0 | { |
4634 | 0 | libcerror_error_set( |
4635 | 0 | error, |
4636 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4637 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
4638 | 0 | "%s: invalid handle - missing file IO pool.", |
4639 | 0 | function ); |
4640 | |
|
4641 | 0 | return( -1 ); |
4642 | 0 | } |
4643 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
4644 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
4645 | 0 | internal_handle->read_write_lock, |
4646 | 0 | error ) != 1 ) |
4647 | 0 | { |
4648 | 0 | libcerror_error_set( |
4649 | 0 | error, |
4650 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4651 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
4652 | 0 | "%s: unable to grab read/write lock for writing.", |
4653 | 0 | function ); |
4654 | |
|
4655 | 0 | return( -1 ); |
4656 | 0 | } |
4657 | 0 | #endif |
4658 | 0 | if( libewf_internal_handle_seek_offset( |
4659 | 0 | internal_handle, |
4660 | 0 | offset, |
4661 | 0 | SEEK_SET, |
4662 | 0 | error ) == -1 ) |
4663 | 0 | { |
4664 | 0 | libcerror_error_set( |
4665 | 0 | error, |
4666 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
4667 | 0 | LIBCERROR_IO_ERROR_SEEK_FAILED, |
4668 | 0 | "%s: unable to seek offset.", |
4669 | 0 | function ); |
4670 | |
|
4671 | 0 | read_count = -1; |
4672 | 0 | } |
4673 | 0 | if( read_count != -1 ) |
4674 | 0 | { |
4675 | 0 | read_count = libewf_internal_handle_read_buffer_from_file_io_pool( |
4676 | 0 | internal_handle, |
4677 | 0 | internal_handle->file_io_pool, |
4678 | 0 | buffer, |
4679 | 0 | buffer_size, |
4680 | 0 | error ); |
4681 | |
|
4682 | 0 | if( read_count == -1 ) |
4683 | 0 | { |
4684 | 0 | libcerror_error_set( |
4685 | 0 | error, |
4686 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
4687 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
4688 | 0 | "%s: unable to read buffer.", |
4689 | 0 | function ); |
4690 | |
|
4691 | 0 | read_count = -1; |
4692 | 0 | } |
4693 | 0 | } |
4694 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
4695 | 0 | if( libcthreads_read_write_lock_release_for_write( |
4696 | 0 | internal_handle->read_write_lock, |
4697 | 0 | error ) != 1 ) |
4698 | 0 | { |
4699 | 0 | libcerror_error_set( |
4700 | 0 | error, |
4701 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4702 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
4703 | 0 | "%s: unable to release read/write lock for writing.", |
4704 | 0 | function ); |
4705 | |
|
4706 | 0 | return( -1 ); |
4707 | 0 | } |
4708 | 0 | #endif |
4709 | 0 | return( read_count ); |
4710 | 0 | } |
4711 | | |
4712 | | /* Writes (media) data at the current offset from a buffer using a Basic File IO (bfio) pool |
4713 | | * the necessary settings of the write values must have been made |
4714 | | * Will initialize write if necessary |
4715 | | * This function is not multi-thread safe acquire write lock before call |
4716 | | * Returns the number of bytes written, 0 when no longer data can be written or -1 on error |
4717 | | */ |
4718 | | ssize_t libewf_internal_handle_write_buffer_to_file_io_pool( |
4719 | | libewf_internal_handle_t *internal_handle, |
4720 | | libbfio_pool_t *file_io_pool, |
4721 | | const void *buffer, |
4722 | | size_t buffer_size, |
4723 | | libcerror_error_t **error ) |
4724 | 0 | { |
4725 | 0 | static char *function = "libewf_internal_handle_write_buffer_to_file_io_pool"; |
4726 | 0 | size_t buffer_offset = 0; |
4727 | 0 | size_t input_data_size = 0; |
4728 | 0 | size_t write_size = 0; |
4729 | 0 | ssize_t write_count = 0; |
4730 | 0 | off64_t chunk_data_offset = 0; |
4731 | 0 | uint64_t chunk_index = 0; |
4732 | 0 | int write_chunk = 0; |
4733 | |
|
4734 | 0 | if( internal_handle == NULL ) |
4735 | 0 | { |
4736 | 0 | libcerror_error_set( |
4737 | 0 | error, |
4738 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4739 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4740 | 0 | "%s: invalid handle.", |
4741 | 0 | function ); |
4742 | |
|
4743 | 0 | return( -1 ); |
4744 | 0 | } |
4745 | 0 | if( internal_handle->io_handle == NULL ) |
4746 | 0 | { |
4747 | 0 | libcerror_error_set( |
4748 | 0 | error, |
4749 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4750 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
4751 | 0 | "%s: invalid handle - missing IO handle.", |
4752 | 0 | function ); |
4753 | |
|
4754 | 0 | return( -1 ); |
4755 | 0 | } |
4756 | 0 | if( internal_handle->current_offset < 0 ) |
4757 | 0 | { |
4758 | 0 | libcerror_error_set( |
4759 | 0 | error, |
4760 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4761 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
4762 | 0 | "%s: invalid handle - invalid IO handle - current offset value out of bounds.", |
4763 | 0 | function ); |
4764 | |
|
4765 | 0 | return( -1 ); |
4766 | 0 | } |
4767 | 0 | if( ( ( internal_handle->io_handle->access_flags & LIBEWF_ACCESS_FLAG_READ ) != 0 ) |
4768 | 0 | && ( ( internal_handle->io_handle->access_flags & LIBEWF_ACCESS_FLAG_RESUME ) == 0 ) ) |
4769 | 0 | { |
4770 | 0 | if( internal_handle->chunk_data != NULL ) |
4771 | 0 | { |
4772 | 0 | libcerror_error_set( |
4773 | 0 | error, |
4774 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4775 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
4776 | 0 | "%s: invalid handle - chunk data set.", |
4777 | 0 | function ); |
4778 | |
|
4779 | 0 | return( -1 ); |
4780 | 0 | } |
4781 | 0 | } |
4782 | 0 | if( internal_handle->media_values == NULL ) |
4783 | 0 | { |
4784 | 0 | libcerror_error_set( |
4785 | 0 | error, |
4786 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4787 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
4788 | 0 | "%s: invalid handle - missing media values.", |
4789 | 0 | function ); |
4790 | |
|
4791 | 0 | return( -1 ); |
4792 | 0 | } |
4793 | 0 | if( internal_handle->media_values->chunk_size == 0 ) |
4794 | 0 | { |
4795 | 0 | libcerror_error_set( |
4796 | 0 | error, |
4797 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4798 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
4799 | 0 | "%s: invalid handle - invalid media values - missing chunk size.", |
4800 | 0 | function ); |
4801 | |
|
4802 | 0 | return( -1 ); |
4803 | 0 | } |
4804 | 0 | if( internal_handle->write_io_handle == NULL ) |
4805 | 0 | { |
4806 | 0 | libcerror_error_set( |
4807 | 0 | error, |
4808 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4809 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
4810 | 0 | "%s: invalid handle - missing subhandle write.", |
4811 | 0 | function ); |
4812 | |
|
4813 | 0 | return( -1 ); |
4814 | 0 | } |
4815 | 0 | if( buffer == NULL ) |
4816 | 0 | { |
4817 | 0 | libcerror_error_set( |
4818 | 0 | error, |
4819 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4820 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
4821 | 0 | "%s: invalid buffer.", |
4822 | 0 | function ); |
4823 | |
|
4824 | 0 | return( -1 ); |
4825 | 0 | } |
4826 | 0 | if( buffer_size > (size_t) SSIZE_MAX ) |
4827 | 0 | { |
4828 | 0 | libcerror_error_set( |
4829 | 0 | error, |
4830 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
4831 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
4832 | 0 | "%s: invalid buffer size value exceeds maximum.", |
4833 | 0 | function ); |
4834 | |
|
4835 | 0 | return( -1 ); |
4836 | 0 | } |
4837 | 0 | if( internal_handle->current_offset < 0 ) |
4838 | 0 | { |
4839 | 0 | libcerror_error_set( |
4840 | 0 | error, |
4841 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4842 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
4843 | 0 | "%s: invalid offset value out of bounds.", |
4844 | 0 | function ); |
4845 | |
|
4846 | 0 | return( -1 ); |
4847 | 0 | } |
4848 | 0 | if( ( internal_handle->media_values->media_size != 0 ) |
4849 | 0 | && ( (size64_t) internal_handle->current_offset >= internal_handle->media_values->media_size ) ) |
4850 | 0 | { |
4851 | 0 | return( 0 ); |
4852 | 0 | } |
4853 | 0 | internal_handle->io_handle->abort = 0; |
4854 | |
|
4855 | 0 | if( ( internal_handle->media_values->media_size != 0 ) |
4856 | 0 | && ( (size64_t) ( internal_handle->current_offset + buffer_size ) >= internal_handle->media_values->media_size ) ) |
4857 | 0 | { |
4858 | 0 | buffer_size = (size_t) ( internal_handle->media_values->media_size - internal_handle->current_offset ); |
4859 | 0 | } |
4860 | 0 | chunk_index = internal_handle->current_offset / internal_handle->media_values->chunk_size; |
4861 | |
|
4862 | 0 | if( chunk_index >= (uint64_t) INT_MAX ) |
4863 | 0 | { |
4864 | 0 | libcerror_error_set( |
4865 | 0 | error, |
4866 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4867 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
4868 | 0 | "%s: invalid chunk index value exceeds maximum.", |
4869 | 0 | function ); |
4870 | |
|
4871 | 0 | return( -1 ); |
4872 | 0 | } |
4873 | 0 | chunk_data_offset = chunk_index * internal_handle->media_values->chunk_size; |
4874 | 0 | chunk_data_offset = internal_handle->current_offset - chunk_data_offset; |
4875 | |
|
4876 | 0 | if( chunk_data_offset >= (off64_t) SSIZE_MAX ) |
4877 | 0 | { |
4878 | 0 | libcerror_error_set( |
4879 | 0 | error, |
4880 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4881 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
4882 | 0 | "%s: invalid chunk data offset value exceeds maximum.", |
4883 | 0 | function ); |
4884 | |
|
4885 | 0 | return( -1 ); |
4886 | 0 | } |
4887 | 0 | while( buffer_size > 0 ) |
4888 | 0 | { |
4889 | 0 | if( chunk_index < internal_handle->write_io_handle->number_of_chunks_written ) |
4890 | 0 | { |
4891 | 0 | libcerror_error_set( |
4892 | 0 | error, |
4893 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4894 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
4895 | 0 | "%s: chunk: %" PRIu64 " already exists.", |
4896 | 0 | function, |
4897 | 0 | chunk_index ); |
4898 | |
|
4899 | 0 | return( -1 ); |
4900 | 0 | } |
4901 | 0 | if( internal_handle->write_io_handle->write_finalized != 0 ) |
4902 | 0 | { |
4903 | 0 | break; |
4904 | 0 | } |
4905 | 0 | if( internal_handle->chunk_data == NULL ) |
4906 | 0 | { |
4907 | 0 | if( libewf_chunk_data_initialize( |
4908 | 0 | &( internal_handle->chunk_data ), |
4909 | 0 | internal_handle->media_values->chunk_size, |
4910 | 0 | 0, |
4911 | 0 | error ) != 1 ) |
4912 | 0 | { |
4913 | 0 | libcerror_error_set( |
4914 | 0 | error, |
4915 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4916 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
4917 | 0 | "%s: unable to create chunk: %" PRIu64 " data.", |
4918 | 0 | function, |
4919 | 0 | chunk_index ); |
4920 | |
|
4921 | 0 | return( -1 ); |
4922 | 0 | } |
4923 | 0 | } |
4924 | 0 | if( internal_handle->chunk_data == NULL ) |
4925 | 0 | { |
4926 | 0 | libcerror_error_set( |
4927 | 0 | error, |
4928 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4929 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
4930 | 0 | "%s: internal handle - missing chunk: %" PRIu64 " data.", |
4931 | 0 | function, |
4932 | 0 | chunk_index ); |
4933 | |
|
4934 | 0 | return( -1 ); |
4935 | 0 | } |
4936 | 0 | if( chunk_data_offset > internal_handle->media_values->chunk_size ) |
4937 | 0 | { |
4938 | 0 | libcerror_error_set( |
4939 | 0 | error, |
4940 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
4941 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
4942 | 0 | "%s: chunk offset exceeds chunk data size.", |
4943 | 0 | function ); |
4944 | |
|
4945 | 0 | return( -1 ); |
4946 | 0 | } |
4947 | 0 | write_size = (size_t) ( internal_handle->media_values->chunk_size - chunk_data_offset ); |
4948 | |
|
4949 | 0 | if( write_size > buffer_size ) |
4950 | 0 | { |
4951 | 0 | write_size = buffer_size; |
4952 | 0 | } |
4953 | 0 | if( write_size == 0 ) |
4954 | 0 | { |
4955 | 0 | break; |
4956 | 0 | } |
4957 | 0 | if( memory_copy( |
4958 | 0 | &( ( internal_handle->chunk_data->data )[ chunk_data_offset ] ), |
4959 | 0 | &( ( (uint8_t *) buffer )[ buffer_offset ] ), |
4960 | 0 | write_size ) == NULL ) |
4961 | 0 | { |
4962 | 0 | libcerror_error_set( |
4963 | 0 | error, |
4964 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
4965 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
4966 | 0 | "%s: unable to copy buffer to chunk data.", |
4967 | 0 | function ); |
4968 | |
|
4969 | 0 | return( -1 ); |
4970 | 0 | } |
4971 | 0 | internal_handle->chunk_data->data_size = (size_t) ( chunk_data_offset + write_size ); |
4972 | |
|
4973 | 0 | buffer_offset += write_size; |
4974 | 0 | buffer_size -= write_size; |
4975 | |
|
4976 | 0 | if( internal_handle->chunk_data->data_size == internal_handle->media_values->chunk_size ) |
4977 | 0 | { |
4978 | 0 | write_chunk = 1; |
4979 | 0 | } |
4980 | 0 | else if( ( internal_handle->media_values->media_size != 0 ) |
4981 | 0 | && ( ( (size64_t) internal_handle->current_offset + write_size ) == internal_handle->media_values->media_size ) ) |
4982 | 0 | { |
4983 | 0 | write_chunk = 1; |
4984 | 0 | } |
4985 | 0 | else |
4986 | 0 | { |
4987 | 0 | write_chunk = 0; |
4988 | 0 | } |
4989 | 0 | if( write_chunk != 0 ) |
4990 | 0 | { |
4991 | 0 | input_data_size = internal_handle->chunk_data->data_size; |
4992 | |
|
4993 | 0 | if( libewf_chunk_data_pack( |
4994 | 0 | internal_handle->chunk_data, |
4995 | 0 | internal_handle->io_handle, |
4996 | 0 | internal_handle->write_io_handle->compressed_zero_byte_empty_block, |
4997 | 0 | internal_handle->write_io_handle->compressed_zero_byte_empty_block_size, |
4998 | 0 | internal_handle->write_io_handle->pack_flags, |
4999 | 0 | error ) != 1 ) |
5000 | 0 | { |
5001 | 0 | libcerror_error_set( |
5002 | 0 | error, |
5003 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5004 | 0 | LIBCERROR_RUNTIME_ERROR_GENERIC, |
5005 | 0 | "%s: unable to pack chunk: %" PRIu64 " data.", |
5006 | 0 | function, |
5007 | 0 | chunk_index ); |
5008 | |
|
5009 | 0 | return( -1 ); |
5010 | 0 | } |
5011 | 0 | write_count = libewf_write_io_handle_write_new_chunk( |
5012 | 0 | internal_handle->write_io_handle, |
5013 | 0 | internal_handle->io_handle, |
5014 | 0 | file_io_pool, |
5015 | 0 | internal_handle->media_values, |
5016 | 0 | internal_handle->segment_table, |
5017 | 0 | internal_handle->header_values, |
5018 | 0 | internal_handle->hash_values, |
5019 | 0 | internal_handle->hash_sections, |
5020 | 0 | internal_handle->sessions, |
5021 | 0 | internal_handle->tracks, |
5022 | 0 | internal_handle->acquiry_errors, |
5023 | 0 | chunk_index, |
5024 | 0 | internal_handle->chunk_data, |
5025 | 0 | input_data_size, |
5026 | 0 | error ); |
5027 | |
|
5028 | 0 | if( write_count <= 0 ) |
5029 | 0 | { |
5030 | 0 | libcerror_error_set( |
5031 | 0 | error, |
5032 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
5033 | 0 | LIBCERROR_IO_ERROR_WRITE_FAILED, |
5034 | 0 | "%s: unable to write new chunk.", |
5035 | 0 | function ); |
5036 | |
|
5037 | 0 | return( -1 ); |
5038 | 0 | } |
5039 | 0 | if( libewf_chunk_data_free( |
5040 | 0 | &( internal_handle->chunk_data ), |
5041 | 0 | error ) != 1 ) |
5042 | 0 | { |
5043 | 0 | libcerror_error_set( |
5044 | 0 | error, |
5045 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5046 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
5047 | 0 | "%s: unable to free chunk data.", |
5048 | 0 | function ); |
5049 | |
|
5050 | 0 | return( -1 ); |
5051 | 0 | } |
5052 | 0 | } |
5053 | 0 | chunk_index += 1; |
5054 | 0 | chunk_data_offset = 0; |
5055 | |
|
5056 | 0 | internal_handle->current_offset += (off64_t) write_size; |
5057 | |
|
5058 | 0 | if( ( internal_handle->media_values->media_size != 0 ) |
5059 | 0 | && ( (size64_t) internal_handle->current_offset >= internal_handle->media_values->media_size ) ) |
5060 | 0 | { |
5061 | 0 | break; |
5062 | 0 | } |
5063 | 0 | if( internal_handle->io_handle->abort != 0 ) |
5064 | 0 | { |
5065 | 0 | break; |
5066 | 0 | } |
5067 | 0 | } |
5068 | 0 | internal_handle->io_handle->abort = 0; |
5069 | |
|
5070 | 0 | return( (ssize_t) buffer_offset ); |
5071 | 0 | } |
5072 | | |
5073 | | /* Writes (media) data at the current offset |
5074 | | * the necessary settings of the write values must have been made |
5075 | | * Will initialize write if necessary |
5076 | | * Returns the number of bytes written, 0 when no longer data can be written or -1 on error |
5077 | | */ |
5078 | | ssize_t libewf_handle_write_buffer( |
5079 | | libewf_handle_t *handle, |
5080 | | const void *buffer, |
5081 | | size_t buffer_size, |
5082 | | libcerror_error_t **error ) |
5083 | 0 | { |
5084 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
5085 | 0 | static char *function = "libewf_handle_write_buffer"; |
5086 | 0 | ssize_t write_count = 0; |
5087 | |
|
5088 | 0 | if( handle == NULL ) |
5089 | 0 | { |
5090 | 0 | libcerror_error_set( |
5091 | 0 | error, |
5092 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
5093 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
5094 | 0 | "%s: invalid handle.", |
5095 | 0 | function ); |
5096 | |
|
5097 | 0 | return( -1 ); |
5098 | 0 | } |
5099 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
5100 | |
|
5101 | 0 | if( internal_handle->file_io_pool == NULL ) |
5102 | 0 | { |
5103 | 0 | libcerror_error_set( |
5104 | 0 | error, |
5105 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5106 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
5107 | 0 | "%s: invalid handle - missing file IO pool.", |
5108 | 0 | function ); |
5109 | |
|
5110 | 0 | return( -1 ); |
5111 | 0 | } |
5112 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
5113 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
5114 | 0 | internal_handle->read_write_lock, |
5115 | 0 | error ) != 1 ) |
5116 | 0 | { |
5117 | 0 | libcerror_error_set( |
5118 | 0 | error, |
5119 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5120 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
5121 | 0 | "%s: unable to grab read/write lock for writing.", |
5122 | 0 | function ); |
5123 | |
|
5124 | 0 | return( -1 ); |
5125 | 0 | } |
5126 | 0 | #endif |
5127 | 0 | if( internal_handle->write_io_handle->values_initialized == 0 ) |
5128 | 0 | { |
5129 | 0 | if( libewf_write_io_handle_initialize_values( |
5130 | 0 | internal_handle->write_io_handle, |
5131 | 0 | internal_handle->io_handle, |
5132 | 0 | internal_handle->media_values, |
5133 | 0 | internal_handle->segment_table, |
5134 | 0 | error ) != 1 ) |
5135 | 0 | { |
5136 | 0 | libcerror_error_set( |
5137 | 0 | error, |
5138 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5139 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
5140 | 0 | "%s: unable to initialize write IO handle values.", |
5141 | 0 | function ); |
5142 | |
|
5143 | 0 | write_count = -1; |
5144 | 0 | } |
5145 | 0 | } |
5146 | 0 | if( write_count != -1 ) |
5147 | 0 | { |
5148 | 0 | write_count = libewf_internal_handle_write_buffer_to_file_io_pool( |
5149 | 0 | internal_handle, |
5150 | 0 | internal_handle->file_io_pool, |
5151 | 0 | buffer, |
5152 | 0 | buffer_size, |
5153 | 0 | error ); |
5154 | |
|
5155 | 0 | if( write_count == -1 ) |
5156 | 0 | { |
5157 | 0 | libcerror_error_set( |
5158 | 0 | error, |
5159 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
5160 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
5161 | 0 | "%s: unable to write buffer.", |
5162 | 0 | function ); |
5163 | |
|
5164 | 0 | write_count = -1; |
5165 | 0 | } |
5166 | 0 | } |
5167 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
5168 | 0 | if( libcthreads_read_write_lock_release_for_write( |
5169 | 0 | internal_handle->read_write_lock, |
5170 | 0 | error ) != 1 ) |
5171 | 0 | { |
5172 | 0 | libcerror_error_set( |
5173 | 0 | error, |
5174 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5175 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
5176 | 0 | "%s: unable to release read/write lock for writing.", |
5177 | 0 | function ); |
5178 | |
|
5179 | 0 | return( -1 ); |
5180 | 0 | } |
5181 | 0 | #endif |
5182 | 0 | return( write_count ); |
5183 | 0 | } |
5184 | | |
5185 | | /* Writes (media) data at a specific offset, |
5186 | | * the necessary settings of the write values must have been made |
5187 | | * Will initialize write if necessary |
5188 | | * Returns the number of bytes written, 0 when no longer data can be written or -1 on error |
5189 | | */ |
5190 | | ssize_t libewf_handle_write_buffer_at_offset( |
5191 | | libewf_handle_t *handle, |
5192 | | const void *buffer, |
5193 | | size_t buffer_size, |
5194 | | off64_t offset, |
5195 | | libcerror_error_t **error ) |
5196 | 0 | { |
5197 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
5198 | 0 | static char *function = "libewf_handle_write_buffer_at_offset"; |
5199 | 0 | ssize_t write_count = 0; |
5200 | |
|
5201 | 0 | if( handle == NULL ) |
5202 | 0 | { |
5203 | 0 | libcerror_error_set( |
5204 | 0 | error, |
5205 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
5206 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
5207 | 0 | "%s: invalid handle.", |
5208 | 0 | function ); |
5209 | |
|
5210 | 0 | return( -1 ); |
5211 | 0 | } |
5212 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
5213 | |
|
5214 | 0 | if( internal_handle->file_io_pool == NULL ) |
5215 | 0 | { |
5216 | 0 | libcerror_error_set( |
5217 | 0 | error, |
5218 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5219 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
5220 | 0 | "%s: invalid handle - missing file IO pool.", |
5221 | 0 | function ); |
5222 | |
|
5223 | 0 | return( -1 ); |
5224 | 0 | } |
5225 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
5226 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
5227 | 0 | internal_handle->read_write_lock, |
5228 | 0 | error ) != 1 ) |
5229 | 0 | { |
5230 | 0 | libcerror_error_set( |
5231 | 0 | error, |
5232 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5233 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
5234 | 0 | "%s: unable to grab read/write lock for writing.", |
5235 | 0 | function ); |
5236 | |
|
5237 | 0 | return( -1 ); |
5238 | 0 | } |
5239 | 0 | #endif |
5240 | 0 | if( internal_handle->write_io_handle->values_initialized == 0 ) |
5241 | 0 | { |
5242 | 0 | if( libewf_write_io_handle_initialize_values( |
5243 | 0 | internal_handle->write_io_handle, |
5244 | 0 | internal_handle->io_handle, |
5245 | 0 | internal_handle->media_values, |
5246 | 0 | internal_handle->segment_table, |
5247 | 0 | error ) != 1 ) |
5248 | 0 | { |
5249 | 0 | libcerror_error_set( |
5250 | 0 | error, |
5251 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5252 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
5253 | 0 | "%s: unable to initialize write IO handle values.", |
5254 | 0 | function ); |
5255 | |
|
5256 | 0 | write_count = -1; |
5257 | 0 | } |
5258 | 0 | } |
5259 | 0 | if( write_count != -1 ) |
5260 | 0 | { |
5261 | 0 | if( libewf_internal_handle_seek_offset( |
5262 | 0 | internal_handle, |
5263 | 0 | offset, |
5264 | 0 | SEEK_SET, |
5265 | 0 | error ) == -1 ) |
5266 | 0 | { |
5267 | 0 | libcerror_error_set( |
5268 | 0 | error, |
5269 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
5270 | 0 | LIBCERROR_IO_ERROR_SEEK_FAILED, |
5271 | 0 | "%s: unable to seek offset.", |
5272 | 0 | function ); |
5273 | |
|
5274 | 0 | write_count = -1; |
5275 | 0 | } |
5276 | 0 | } |
5277 | 0 | if( write_count != -1 ) |
5278 | 0 | { |
5279 | 0 | write_count = libewf_internal_handle_write_buffer_to_file_io_pool( |
5280 | 0 | internal_handle, |
5281 | 0 | internal_handle->file_io_pool, |
5282 | 0 | buffer, |
5283 | 0 | buffer_size, |
5284 | 0 | error ); |
5285 | |
|
5286 | 0 | if( write_count == -1 ) |
5287 | 0 | { |
5288 | 0 | libcerror_error_set( |
5289 | 0 | error, |
5290 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
5291 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
5292 | 0 | "%s: unable to write buffer.", |
5293 | 0 | function ); |
5294 | |
|
5295 | 0 | write_count = -1; |
5296 | 0 | } |
5297 | 0 | } |
5298 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
5299 | 0 | if( libcthreads_read_write_lock_release_for_write( |
5300 | 0 | internal_handle->read_write_lock, |
5301 | 0 | error ) != 1 ) |
5302 | 0 | { |
5303 | 0 | libcerror_error_set( |
5304 | 0 | error, |
5305 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5306 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
5307 | 0 | "%s: unable to release read/write lock for writing.", |
5308 | 0 | function ); |
5309 | |
|
5310 | 0 | return( -1 ); |
5311 | 0 | } |
5312 | 0 | #endif |
5313 | 0 | return( write_count ); |
5314 | 0 | } |
5315 | | |
5316 | | /* Retrieves a (media) data chunk |
5317 | | * Returns 1 if successful or -1 on error |
5318 | | */ |
5319 | | int libewf_handle_get_data_chunk( |
5320 | | libewf_handle_t *handle, |
5321 | | libewf_data_chunk_t **data_chunk, |
5322 | | libcerror_error_t **error ) |
5323 | 0 | { |
5324 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
5325 | 0 | static char *function = "libewf_handle_get_data_chunk"; |
5326 | 0 | int result = 1; |
5327 | |
|
5328 | 0 | if( handle == NULL ) |
5329 | 0 | { |
5330 | 0 | libcerror_error_set( |
5331 | 0 | error, |
5332 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
5333 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
5334 | 0 | "%s: invalid handle.", |
5335 | 0 | function ); |
5336 | |
|
5337 | 0 | return( -1 ); |
5338 | 0 | } |
5339 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
5340 | |
|
5341 | 0 | if( internal_handle->media_values == NULL ) |
5342 | 0 | { |
5343 | 0 | libcerror_error_set( |
5344 | 0 | error, |
5345 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5346 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
5347 | 0 | "%s: invalid handle - missing media values.", |
5348 | 0 | function ); |
5349 | |
|
5350 | 0 | return( -1 ); |
5351 | 0 | } |
5352 | 0 | if( data_chunk == NULL ) |
5353 | 0 | { |
5354 | 0 | libcerror_error_set( |
5355 | 0 | error, |
5356 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
5357 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
5358 | 0 | "%s: invalid data chunk.", |
5359 | 0 | function ); |
5360 | |
|
5361 | 0 | return( -1 ); |
5362 | 0 | } |
5363 | 0 | if( *data_chunk != NULL ) |
5364 | 0 | { |
5365 | 0 | libcerror_error_set( |
5366 | 0 | error, |
5367 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5368 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
5369 | 0 | "%s: data chunk value already set.", |
5370 | 0 | function ); |
5371 | |
|
5372 | 0 | return( -1 ); |
5373 | 0 | } |
5374 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
5375 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
5376 | 0 | internal_handle->read_write_lock, |
5377 | 0 | error ) != 1 ) |
5378 | 0 | { |
5379 | 0 | libcerror_error_set( |
5380 | 0 | error, |
5381 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5382 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
5383 | 0 | "%s: unable to grab read/write lock for writing.", |
5384 | 0 | function ); |
5385 | |
|
5386 | 0 | return( -1 ); |
5387 | 0 | } |
5388 | 0 | #endif |
5389 | 0 | if( ( internal_handle->write_io_handle != NULL ) |
5390 | 0 | && ( internal_handle->write_io_handle->values_initialized == 0 ) ) |
5391 | 0 | { |
5392 | 0 | if( libewf_write_io_handle_initialize_values( |
5393 | 0 | internal_handle->write_io_handle, |
5394 | 0 | internal_handle->io_handle, |
5395 | 0 | internal_handle->media_values, |
5396 | 0 | internal_handle->segment_table, |
5397 | 0 | error ) != 1 ) |
5398 | 0 | { |
5399 | 0 | libcerror_error_set( |
5400 | 0 | error, |
5401 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5402 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
5403 | 0 | "%s: unable to initialize write IO handle values.", |
5404 | 0 | function ); |
5405 | |
|
5406 | 0 | result = -1; |
5407 | 0 | } |
5408 | 0 | } |
5409 | 0 | if( result != -1 ) |
5410 | 0 | { |
5411 | 0 | if( libewf_data_chunk_initialize( |
5412 | 0 | data_chunk, |
5413 | 0 | internal_handle->io_handle, |
5414 | 0 | internal_handle->write_io_handle, |
5415 | 0 | error ) != 1 ) |
5416 | 0 | { |
5417 | 0 | libcerror_error_set( |
5418 | 0 | error, |
5419 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5420 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
5421 | 0 | "%s: unable to create data chunk.", |
5422 | 0 | function ); |
5423 | |
|
5424 | 0 | result = -1; |
5425 | 0 | } |
5426 | 0 | } |
5427 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
5428 | 0 | if( libcthreads_read_write_lock_release_for_write( |
5429 | 0 | internal_handle->read_write_lock, |
5430 | 0 | error ) != 1 ) |
5431 | 0 | { |
5432 | 0 | libcerror_error_set( |
5433 | 0 | error, |
5434 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5435 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
5436 | 0 | "%s: unable to release read/write lock for writing.", |
5437 | 0 | function ); |
5438 | |
|
5439 | 0 | return( -1 ); |
5440 | 0 | } |
5441 | 0 | #endif |
5442 | 0 | return( result ); |
5443 | 0 | } |
5444 | | |
5445 | | /* Reads a (media) data chunk at the current offset |
5446 | | * This function is not multi-thread safe acquire write lock before call |
5447 | | * Returns the number of bytes in the data chunk, 0 when no longer data can be read or -1 on error |
5448 | | */ |
5449 | | ssize_t libewf_internal_handle_read_data_chunk_from_file_io_pool( |
5450 | | libewf_internal_handle_t *internal_handle, |
5451 | | libbfio_pool_t *file_io_pool, |
5452 | | libewf_internal_data_chunk_t *internal_data_chunk, |
5453 | | libcerror_error_t **error ) |
5454 | 0 | { |
5455 | 0 | libewf_chunk_data_t *chunk_data = NULL; |
5456 | 0 | static char *function = "libewf_internal_handle_read_data_chunk_from_file_io_pool"; |
5457 | 0 | off64_t chunk_data_offset = 0; |
5458 | 0 | size_t read_count = 0; |
5459 | |
|
5460 | 0 | if( internal_handle == NULL ) |
5461 | 0 | { |
5462 | 0 | libcerror_error_set( |
5463 | 0 | error, |
5464 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
5465 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
5466 | 0 | "%s: invalid handle.", |
5467 | 0 | function ); |
5468 | |
|
5469 | 0 | return( -1 ); |
5470 | 0 | } |
5471 | 0 | if( internal_handle->io_handle == NULL ) |
5472 | 0 | { |
5473 | 0 | libcerror_error_set( |
5474 | 0 | error, |
5475 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5476 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
5477 | 0 | "%s: invalid handle - missing IO handle.", |
5478 | 0 | function ); |
5479 | |
|
5480 | 0 | return( -1 ); |
5481 | 0 | } |
5482 | 0 | if( internal_handle->chunk_data != NULL ) |
5483 | 0 | { |
5484 | 0 | libcerror_error_set( |
5485 | 0 | error, |
5486 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5487 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
5488 | 0 | "%s: invalid handle - chunk data set.", |
5489 | 0 | function ); |
5490 | |
|
5491 | 0 | return( -1 ); |
5492 | 0 | } |
5493 | 0 | if( internal_handle->current_offset < 0 ) |
5494 | 0 | { |
5495 | 0 | libcerror_error_set( |
5496 | 0 | error, |
5497 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5498 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
5499 | 0 | "%s: invalid handle - invalid IO handle - current offset value out of bounds.", |
5500 | 0 | function ); |
5501 | |
|
5502 | 0 | return( -1 ); |
5503 | 0 | } |
5504 | 0 | if( internal_handle->media_values == NULL ) |
5505 | 0 | { |
5506 | 0 | libcerror_error_set( |
5507 | 0 | error, |
5508 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5509 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
5510 | 0 | "%s: invalid handle - missing media values.", |
5511 | 0 | function ); |
5512 | |
|
5513 | 0 | return( -1 ); |
5514 | 0 | } |
5515 | 0 | if( (size64_t) internal_handle->current_offset >= internal_handle->media_values->media_size ) |
5516 | 0 | { |
5517 | 0 | return( 0 ); |
5518 | 0 | } |
5519 | 0 | if( libewf_chunk_table_get_chunk_data_by_offset_no_cache( |
5520 | 0 | internal_handle->chunk_table, |
5521 | 0 | internal_handle->io_handle, |
5522 | 0 | file_io_pool, |
5523 | 0 | internal_handle->media_values, |
5524 | 0 | internal_handle->segment_table, |
5525 | 0 | internal_handle->current_offset, |
5526 | 0 | &chunk_data_offset, |
5527 | 0 | &chunk_data, |
5528 | 0 | error ) != 1 ) |
5529 | 0 | { |
5530 | 0 | libcerror_error_set( |
5531 | 0 | error, |
5532 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5533 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
5534 | 0 | "%s: unable to retrieve chunk data for offset: %" PRIi64 " (0x%08" PRIx64 ").", |
5535 | 0 | function, |
5536 | 0 | internal_handle->current_offset, |
5537 | 0 | internal_handle->current_offset ); |
5538 | |
|
5539 | 0 | goto on_error; |
5540 | 0 | } |
5541 | 0 | if( chunk_data == NULL ) |
5542 | 0 | { |
5543 | 0 | libcerror_error_set( |
5544 | 0 | error, |
5545 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5546 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
5547 | 0 | "%s: missing chunk data for offset: %" PRIi64 " (0x%08" PRIx64 ").", |
5548 | 0 | function, |
5549 | 0 | internal_handle->current_offset, |
5550 | 0 | internal_handle->current_offset ); |
5551 | |
|
5552 | 0 | goto on_error; |
5553 | 0 | } |
5554 | | /* data_chunk takes over management of chunk_data |
5555 | | */ |
5556 | 0 | if( libewf_internal_data_chunk_set_chunk_data( |
5557 | 0 | internal_data_chunk, |
5558 | 0 | chunk_data, |
5559 | 0 | error ) != 1 ) |
5560 | 0 | { |
5561 | 0 | libcerror_error_set( |
5562 | 0 | error, |
5563 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5564 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
5565 | 0 | "%s: unable to set chunk: %" PRIu64 " data in data chunk.", |
5566 | 0 | function, |
5567 | 0 | chunk_data->chunk_index ); |
5568 | |
|
5569 | 0 | goto on_error; |
5570 | 0 | } |
5571 | 0 | internal_handle->current_offset = chunk_data->range_end_offset; |
5572 | |
|
5573 | 0 | read_count = (ssize_t) ( chunk_data->range_end_offset - chunk_data->range_start_offset ); |
5574 | |
|
5575 | 0 | return( read_count ); |
5576 | | |
5577 | 0 | on_error: |
5578 | 0 | if( chunk_data != NULL ) |
5579 | 0 | { |
5580 | 0 | libewf_chunk_data_free( |
5581 | 0 | &chunk_data, |
5582 | 0 | NULL ); |
5583 | 0 | } |
5584 | 0 | return( -1 ); |
5585 | 0 | } |
5586 | | |
5587 | | /* Reads a (media) data chunk at the current offset |
5588 | | * Returns the number of bytes read, 0 when no longer data can be read or -1 on error |
5589 | | * Returns the number of bytes in the data chunk, 0 when no longer data can be read or -1 on error |
5590 | | */ |
5591 | | ssize_t libewf_handle_read_data_chunk( |
5592 | | libewf_handle_t *handle, |
5593 | | libewf_data_chunk_t *data_chunk, |
5594 | | libcerror_error_t **error ) |
5595 | 0 | { |
5596 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
5597 | 0 | static char *function = "libewf_handle_read_data_chunk"; |
5598 | 0 | ssize_t read_count = 0; |
5599 | |
|
5600 | 0 | if( handle == NULL ) |
5601 | 0 | { |
5602 | 0 | libcerror_error_set( |
5603 | 0 | error, |
5604 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
5605 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
5606 | 0 | "%s: invalid handle.", |
5607 | 0 | function ); |
5608 | |
|
5609 | 0 | return( -1 ); |
5610 | 0 | } |
5611 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
5612 | |
|
5613 | 0 | if( internal_handle->file_io_pool == NULL ) |
5614 | 0 | { |
5615 | 0 | libcerror_error_set( |
5616 | 0 | error, |
5617 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5618 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
5619 | 0 | "%s: invalid handle - missing file IO pool.", |
5620 | 0 | function ); |
5621 | |
|
5622 | 0 | return( -1 ); |
5623 | 0 | } |
5624 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
5625 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
5626 | 0 | internal_handle->read_write_lock, |
5627 | 0 | error ) != 1 ) |
5628 | 0 | { |
5629 | 0 | libcerror_error_set( |
5630 | 0 | error, |
5631 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5632 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
5633 | 0 | "%s: unable to grab read/write lock for writing.", |
5634 | 0 | function ); |
5635 | |
|
5636 | 0 | return( -1 ); |
5637 | 0 | } |
5638 | 0 | #endif |
5639 | 0 | read_count = libewf_internal_handle_read_data_chunk_from_file_io_pool( |
5640 | 0 | internal_handle, |
5641 | 0 | internal_handle->file_io_pool, |
5642 | 0 | (libewf_internal_data_chunk_t *) data_chunk, |
5643 | 0 | error ); |
5644 | |
|
5645 | 0 | if( read_count < 0 ) |
5646 | 0 | { |
5647 | 0 | libcerror_error_set( |
5648 | 0 | error, |
5649 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
5650 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
5651 | 0 | "%s: unable to read data chunk.", |
5652 | 0 | function ); |
5653 | |
|
5654 | 0 | read_count = -1; |
5655 | 0 | } |
5656 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
5657 | 0 | if( libcthreads_read_write_lock_release_for_write( |
5658 | 0 | internal_handle->read_write_lock, |
5659 | 0 | error ) != 1 ) |
5660 | 0 | { |
5661 | 0 | libcerror_error_set( |
5662 | 0 | error, |
5663 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5664 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
5665 | 0 | "%s: unable to release read/write lock for writing.", |
5666 | 0 | function ); |
5667 | |
|
5668 | 0 | return( -1 ); |
5669 | 0 | } |
5670 | 0 | #endif |
5671 | 0 | return( read_count ); |
5672 | 0 | } |
5673 | | |
5674 | | /* Writes a (media) data chunk at the current offset |
5675 | | * This function is not multi-thread safe acquire write lock before call |
5676 | | * Returns the number of bytes written, 0 when no longer data can be written or -1 on error |
5677 | | */ |
5678 | | ssize_t libewf_internal_handle_write_data_chunk_to_file_io_pool( |
5679 | | libewf_internal_handle_t *internal_handle, |
5680 | | libbfio_pool_t *file_io_pool, |
5681 | | libewf_internal_data_chunk_t *internal_data_chunk, |
5682 | | libcerror_error_t **error ) |
5683 | 0 | { |
5684 | 0 | static char *function = "libewf_internal_handle_write_data_chunk_to_file_io_pool"; |
5685 | 0 | size_t data_size = 0; |
5686 | 0 | ssize_t write_count = 0; |
5687 | 0 | uint64_t current_chunk_index = 0; |
5688 | |
|
5689 | 0 | if( internal_handle == NULL ) |
5690 | 0 | { |
5691 | 0 | libcerror_error_set( |
5692 | 0 | error, |
5693 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
5694 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
5695 | 0 | "%s: invalid handle.", |
5696 | 0 | function ); |
5697 | |
|
5698 | 0 | return( -1 ); |
5699 | 0 | } |
5700 | 0 | if( internal_handle->io_handle == NULL ) |
5701 | 0 | { |
5702 | 0 | libcerror_error_set( |
5703 | 0 | error, |
5704 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5705 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
5706 | 0 | "%s: invalid handle - missing IO handle.", |
5707 | 0 | function ); |
5708 | |
|
5709 | 0 | return( -1 ); |
5710 | 0 | } |
5711 | 0 | if( internal_handle->chunk_data != NULL ) |
5712 | 0 | { |
5713 | 0 | libcerror_error_set( |
5714 | 0 | error, |
5715 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5716 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
5717 | 0 | "%s: invalid handle - chunk data set.", |
5718 | 0 | function ); |
5719 | |
|
5720 | 0 | return( -1 ); |
5721 | 0 | } |
5722 | 0 | if( internal_handle->current_offset < 0 ) |
5723 | 0 | { |
5724 | 0 | libcerror_error_set( |
5725 | 0 | error, |
5726 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5727 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
5728 | 0 | "%s: invalid handle - invalid IO handle - current offset value out of bounds.", |
5729 | 0 | function ); |
5730 | |
|
5731 | 0 | return( -1 ); |
5732 | 0 | } |
5733 | 0 | if( internal_handle->media_values == NULL ) |
5734 | 0 | { |
5735 | 0 | libcerror_error_set( |
5736 | 0 | error, |
5737 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5738 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
5739 | 0 | "%s: invalid handle - missing media values.", |
5740 | 0 | function ); |
5741 | |
|
5742 | 0 | return( -1 ); |
5743 | 0 | } |
5744 | 0 | if( internal_handle->media_values->chunk_size == 0 ) |
5745 | 0 | { |
5746 | 0 | libcerror_error_set( |
5747 | 0 | error, |
5748 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5749 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
5750 | 0 | "%s: invalid handle - invalid media values - missing chunk size.", |
5751 | 0 | function ); |
5752 | |
|
5753 | 0 | return( -1 ); |
5754 | 0 | } |
5755 | 0 | if( internal_handle->write_io_handle == NULL ) |
5756 | 0 | { |
5757 | 0 | libcerror_error_set( |
5758 | 0 | error, |
5759 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5760 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
5761 | 0 | "%s: invalid handle - missing subhandle write.", |
5762 | 0 | function ); |
5763 | |
|
5764 | 0 | return( -1 ); |
5765 | 0 | } |
5766 | 0 | if( internal_data_chunk == NULL ) |
5767 | 0 | { |
5768 | 0 | libcerror_error_set( |
5769 | 0 | error, |
5770 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
5771 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
5772 | 0 | "%s: invalid data chunk.", |
5773 | 0 | function ); |
5774 | |
|
5775 | 0 | return( -1 ); |
5776 | 0 | } |
5777 | 0 | if( ( internal_handle->media_values->media_size != 0 ) |
5778 | 0 | && ( (size64_t) internal_handle->current_offset >= internal_handle->media_values->media_size ) ) |
5779 | 0 | { |
5780 | 0 | return( 0 ); |
5781 | 0 | } |
5782 | 0 | data_size = internal_data_chunk->data_size; |
5783 | |
|
5784 | 0 | if( internal_handle->media_values->media_size != 0 ) |
5785 | 0 | { |
5786 | 0 | if( (size64_t) ( internal_handle->current_offset + data_size ) > internal_handle->media_values->media_size ) |
5787 | 0 | { |
5788 | 0 | libcerror_error_set( |
5789 | 0 | error, |
5790 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5791 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
5792 | 0 | "%s: last data chunk size value out of bounds.", |
5793 | 0 | function ); |
5794 | |
|
5795 | 0 | return( -1 ); |
5796 | 0 | } |
5797 | 0 | } |
5798 | | /* TODO remove need to calculate */ |
5799 | 0 | current_chunk_index = internal_handle->current_offset / internal_handle->media_values->chunk_size; |
5800 | |
|
5801 | 0 | internal_handle->current_offset = (off64_t) current_chunk_index * (off64_t) internal_handle->media_values->chunk_size; |
5802 | |
|
5803 | | #if defined( HAVE_DEBUG_OUTPUT ) |
5804 | | if( libcnotify_verbose != 0 ) |
5805 | | { |
5806 | | libcnotify_printf( |
5807 | | "%s: writing chunk: %" PRIu64 " of size: %" PRIzd ".\n", |
5808 | | function, |
5809 | | current_chunk_index, |
5810 | | data_size ); |
5811 | | } |
5812 | | #endif |
5813 | 0 | if( current_chunk_index < internal_handle->write_io_handle->number_of_chunks_written ) |
5814 | 0 | { |
5815 | 0 | libcerror_error_set( |
5816 | 0 | error, |
5817 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5818 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
5819 | 0 | "%s: chunk: %" PRIu64 " already exists.", |
5820 | 0 | function, |
5821 | 0 | current_chunk_index ); |
5822 | |
|
5823 | 0 | return( -1 ); |
5824 | 0 | } |
5825 | 0 | write_count = libewf_write_io_handle_write_new_chunk( |
5826 | 0 | internal_handle->write_io_handle, |
5827 | 0 | internal_handle->io_handle, |
5828 | 0 | file_io_pool, |
5829 | 0 | internal_handle->media_values, |
5830 | 0 | internal_handle->segment_table, |
5831 | 0 | internal_handle->header_values, |
5832 | 0 | internal_handle->hash_values, |
5833 | 0 | internal_handle->hash_sections, |
5834 | 0 | internal_handle->sessions, |
5835 | 0 | internal_handle->tracks, |
5836 | 0 | internal_handle->acquiry_errors, |
5837 | 0 | current_chunk_index, |
5838 | 0 | internal_data_chunk->chunk_data, |
5839 | 0 | data_size, |
5840 | 0 | error ); |
5841 | |
|
5842 | 0 | if( write_count < 0 ) |
5843 | 0 | { |
5844 | 0 | libcerror_error_set( |
5845 | 0 | error, |
5846 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
5847 | 0 | LIBCERROR_IO_ERROR_WRITE_FAILED, |
5848 | 0 | "%s: unable to write chunk data.", |
5849 | 0 | function ); |
5850 | |
|
5851 | 0 | return( -1 ); |
5852 | 0 | } |
5853 | 0 | internal_handle->current_offset += (off64_t) data_size; |
5854 | |
|
5855 | 0 | return( write_count ); |
5856 | 0 | } |
5857 | | |
5858 | | /* Writes a (media) data chunk at the current offset |
5859 | | * Returns the number of bytes written, 0 when no longer data can be written or -1 on error |
5860 | | */ |
5861 | | ssize_t libewf_handle_write_data_chunk( |
5862 | | libewf_handle_t *handle, |
5863 | | libewf_data_chunk_t *data_chunk, |
5864 | | libcerror_error_t **error ) |
5865 | 0 | { |
5866 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
5867 | 0 | static char *function = "libewf_handle_write_data_chunk"; |
5868 | 0 | ssize_t write_count = 0; |
5869 | |
|
5870 | 0 | if( handle == NULL ) |
5871 | 0 | { |
5872 | 0 | libcerror_error_set( |
5873 | 0 | error, |
5874 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
5875 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
5876 | 0 | "%s: invalid handle.", |
5877 | 0 | function ); |
5878 | |
|
5879 | 0 | return( -1 ); |
5880 | 0 | } |
5881 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
5882 | |
|
5883 | 0 | if( internal_handle->file_io_pool == NULL ) |
5884 | 0 | { |
5885 | 0 | libcerror_error_set( |
5886 | 0 | error, |
5887 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5888 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
5889 | 0 | "%s: invalid handle - missing file IO pool.", |
5890 | 0 | function ); |
5891 | |
|
5892 | 0 | return( -1 ); |
5893 | 0 | } |
5894 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
5895 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
5896 | 0 | internal_handle->read_write_lock, |
5897 | 0 | error ) != 1 ) |
5898 | 0 | { |
5899 | 0 | libcerror_error_set( |
5900 | 0 | error, |
5901 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5902 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
5903 | 0 | "%s: unable to grab read/write lock for writing.", |
5904 | 0 | function ); |
5905 | |
|
5906 | 0 | return( -1 ); |
5907 | 0 | } |
5908 | 0 | #endif |
5909 | 0 | write_count = libewf_internal_handle_write_data_chunk_to_file_io_pool( |
5910 | 0 | internal_handle, |
5911 | 0 | internal_handle->file_io_pool, |
5912 | 0 | (libewf_internal_data_chunk_t *) data_chunk, |
5913 | 0 | error ); |
5914 | |
|
5915 | 0 | if( write_count < 0 ) |
5916 | 0 | { |
5917 | 0 | libcerror_error_set( |
5918 | 0 | error, |
5919 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
5920 | 0 | LIBCERROR_IO_ERROR_WRITE_FAILED, |
5921 | 0 | "%s: unable to write data chunk.", |
5922 | 0 | function ); |
5923 | |
|
5924 | 0 | write_count = -1; |
5925 | 0 | } |
5926 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
5927 | 0 | if( libcthreads_read_write_lock_release_for_write( |
5928 | 0 | internal_handle->read_write_lock, |
5929 | 0 | error ) != 1 ) |
5930 | 0 | { |
5931 | 0 | libcerror_error_set( |
5932 | 0 | error, |
5933 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5934 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
5935 | 0 | "%s: unable to release read/write lock for writing.", |
5936 | 0 | function ); |
5937 | |
|
5938 | 0 | return( -1 ); |
5939 | 0 | } |
5940 | 0 | #endif |
5941 | 0 | return( write_count ); |
5942 | 0 | } |
5943 | | |
5944 | | /* Finalizes the write by correcting the EWF the meta data in the segment files |
5945 | | * This function is required after write from stream |
5946 | | * Returns the number of bytes written or -1 on error |
5947 | | */ |
5948 | | ssize_t libewf_internal_handle_write_finalize_file_io_pool( |
5949 | | libewf_internal_handle_t *internal_handle, |
5950 | | libbfio_pool_t *file_io_pool, |
5951 | | libcerror_error_t **error ) |
5952 | 0 | { |
5953 | 0 | libewf_segment_file_t *segment_file = NULL; |
5954 | 0 | static char *function = "libewf_internal_handle_write_finalize_file_io_pool"; |
5955 | 0 | size64_t segment_file_size = 0; |
5956 | 0 | size_t input_data_size = 0; |
5957 | 0 | ssize_t write_count = 0; |
5958 | 0 | ssize_t write_finalize_count = 0; |
5959 | 0 | uint64_t chunk_index = 0; |
5960 | 0 | uint32_t number_of_segments = 0; |
5961 | 0 | int file_io_pool_entry = -1; |
5962 | |
|
5963 | 0 | if( internal_handle == NULL ) |
5964 | 0 | { |
5965 | 0 | libcerror_error_set( |
5966 | 0 | error, |
5967 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
5968 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
5969 | 0 | "%s: invalid handle.", |
5970 | 0 | function ); |
5971 | |
|
5972 | 0 | return( -1 ); |
5973 | 0 | } |
5974 | 0 | if( internal_handle->io_handle == NULL ) |
5975 | 0 | { |
5976 | 0 | libcerror_error_set( |
5977 | 0 | error, |
5978 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5979 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
5980 | 0 | "%s: invalid handle - missing IO handle.", |
5981 | 0 | function ); |
5982 | |
|
5983 | 0 | return( -1 ); |
5984 | 0 | } |
5985 | 0 | if( internal_handle->current_offset < 0 ) |
5986 | 0 | { |
5987 | 0 | libcerror_error_set( |
5988 | 0 | error, |
5989 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
5990 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
5991 | 0 | "%s: invalid handle - invalid IO handle - current offset value out of bounds.", |
5992 | 0 | function ); |
5993 | |
|
5994 | 0 | return( -1 ); |
5995 | 0 | } |
5996 | 0 | if( ( ( internal_handle->io_handle->access_flags & LIBEWF_ACCESS_FLAG_READ ) != 0 ) |
5997 | 0 | && ( ( internal_handle->io_handle->access_flags & LIBEWF_ACCESS_FLAG_RESUME ) == 0 ) ) |
5998 | 0 | { |
5999 | 0 | if( internal_handle->chunk_data != NULL ) |
6000 | 0 | { |
6001 | 0 | libcerror_error_set( |
6002 | 0 | error, |
6003 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6004 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
6005 | 0 | "%s: invalid handle - chunk data set.", |
6006 | 0 | function ); |
6007 | |
|
6008 | 0 | return( -1 ); |
6009 | 0 | } |
6010 | 0 | } |
6011 | 0 | if( internal_handle->write_io_handle == NULL ) |
6012 | 0 | { |
6013 | 0 | libcerror_error_set( |
6014 | 0 | error, |
6015 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6016 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
6017 | 0 | "%s: invalid handle - missing write IO handle.", |
6018 | 0 | function ); |
6019 | |
|
6020 | 0 | return( -1 ); |
6021 | 0 | } |
6022 | 0 | if( internal_handle->media_values == NULL ) |
6023 | 0 | { |
6024 | 0 | libcerror_error_set( |
6025 | 0 | error, |
6026 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6027 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
6028 | 0 | "%s: invalid handle - missing media values.", |
6029 | 0 | function ); |
6030 | |
|
6031 | 0 | return( -1 ); |
6032 | 0 | } |
6033 | 0 | if( internal_handle->media_values->chunk_size == 0 ) |
6034 | 0 | { |
6035 | 0 | libcerror_error_set( |
6036 | 0 | error, |
6037 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6038 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
6039 | 0 | "%s: invalid handle - invalid media values - missing chunk size.", |
6040 | 0 | function ); |
6041 | |
|
6042 | 0 | return( -1 ); |
6043 | 0 | } |
6044 | 0 | if( internal_handle->write_io_handle->write_finalized != 0 ) |
6045 | 0 | { |
6046 | 0 | return( 0 ); |
6047 | 0 | } |
6048 | 0 | if( ( ( internal_handle->io_handle->access_flags & LIBEWF_ACCESS_FLAG_READ ) != 0 ) |
6049 | 0 | && ( ( internal_handle->io_handle->access_flags & LIBEWF_ACCESS_FLAG_RESUME ) == 0 ) ) |
6050 | 0 | { |
6051 | 0 | return( 0 ); |
6052 | 0 | } |
6053 | 0 | if( internal_handle->chunk_data != NULL ) |
6054 | 0 | { |
6055 | 0 | chunk_index = internal_handle->current_offset / internal_handle->media_values->chunk_size; |
6056 | |
|
6057 | 0 | if( chunk_index < internal_handle->write_io_handle->number_of_chunks_written ) |
6058 | 0 | { |
6059 | 0 | libcerror_error_set( |
6060 | 0 | error, |
6061 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6062 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
6063 | 0 | "%s: chunk: %" PRIu64 " already exists.", |
6064 | 0 | function, |
6065 | 0 | chunk_index ); |
6066 | |
|
6067 | 0 | return( -1 ); |
6068 | 0 | } |
6069 | 0 | input_data_size = internal_handle->chunk_data->data_size; |
6070 | |
|
6071 | 0 | if( libewf_chunk_data_pack( |
6072 | 0 | internal_handle->chunk_data, |
6073 | 0 | internal_handle->io_handle, |
6074 | 0 | internal_handle->write_io_handle->compressed_zero_byte_empty_block, |
6075 | 0 | internal_handle->write_io_handle->compressed_zero_byte_empty_block_size, |
6076 | 0 | internal_handle->write_io_handle->pack_flags, |
6077 | 0 | error ) != 1 ) |
6078 | 0 | { |
6079 | 0 | libcerror_error_set( |
6080 | 0 | error, |
6081 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6082 | 0 | LIBCERROR_RUNTIME_ERROR_GENERIC, |
6083 | 0 | "%s: unable to pack chunk: %" PRIu64 " data.", |
6084 | 0 | function, |
6085 | 0 | chunk_index ); |
6086 | |
|
6087 | 0 | return( -1 ); |
6088 | 0 | } |
6089 | 0 | write_count = libewf_write_io_handle_write_new_chunk( |
6090 | 0 | internal_handle->write_io_handle, |
6091 | 0 | internal_handle->io_handle, |
6092 | 0 | file_io_pool, |
6093 | 0 | internal_handle->media_values, |
6094 | 0 | internal_handle->segment_table, |
6095 | 0 | internal_handle->header_values, |
6096 | 0 | internal_handle->hash_values, |
6097 | 0 | internal_handle->hash_sections, |
6098 | 0 | internal_handle->sessions, |
6099 | 0 | internal_handle->tracks, |
6100 | 0 | internal_handle->acquiry_errors, |
6101 | 0 | chunk_index, |
6102 | 0 | internal_handle->chunk_data, |
6103 | 0 | input_data_size, |
6104 | 0 | error ); |
6105 | |
|
6106 | 0 | if( write_count <= 0 ) |
6107 | 0 | { |
6108 | 0 | libcerror_error_set( |
6109 | 0 | error, |
6110 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
6111 | 0 | LIBCERROR_IO_ERROR_WRITE_FAILED, |
6112 | 0 | "%s: unable to write new chunk.", |
6113 | 0 | function ); |
6114 | |
|
6115 | 0 | return( -1 ); |
6116 | 0 | } |
6117 | 0 | write_finalize_count += write_count; |
6118 | |
|
6119 | 0 | if( libewf_chunk_data_free( |
6120 | 0 | &( internal_handle->chunk_data ), |
6121 | 0 | error ) != 1 ) |
6122 | 0 | { |
6123 | 0 | libcerror_error_set( |
6124 | 0 | error, |
6125 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6126 | 0 | LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, |
6127 | 0 | "%s: unable to free chunk data.", |
6128 | 0 | function ); |
6129 | |
|
6130 | 0 | return( -1 ); |
6131 | 0 | } |
6132 | 0 | } |
6133 | | /* Check if all media data has been written |
6134 | | */ |
6135 | 0 | if( ( internal_handle->media_values->media_size != 0 ) |
6136 | 0 | && ( internal_handle->write_io_handle->input_write_count < (ssize64_t) internal_handle->media_values->media_size ) ) |
6137 | 0 | { |
6138 | 0 | return( write_finalize_count ); |
6139 | 0 | } |
6140 | 0 | if( libewf_segment_table_get_number_of_segments( |
6141 | 0 | internal_handle->segment_table, |
6142 | 0 | &number_of_segments, |
6143 | 0 | error ) != 1 ) |
6144 | 0 | { |
6145 | 0 | libcerror_error_set( |
6146 | 0 | error, |
6147 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6148 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
6149 | 0 | "%s: unable to retrieve number of segments.", |
6150 | 0 | function ); |
6151 | |
|
6152 | 0 | return( -1 ); |
6153 | 0 | } |
6154 | 0 | if( number_of_segments == 0 ) |
6155 | 0 | { |
6156 | | /* No segment file needs to be created |
6157 | | */ |
6158 | | /* TODO clean up this logic: when is this triggered? */ |
6159 | 0 | if( internal_handle->media_values->media_size != 0 ) |
6160 | 0 | { |
6161 | 0 | return( write_finalize_count ); |
6162 | 0 | } |
6163 | | /* Create the segment file if required |
6164 | | */ |
6165 | 0 | if( libewf_write_io_handle_create_segment_file( |
6166 | 0 | internal_handle->io_handle, |
6167 | 0 | file_io_pool, |
6168 | 0 | internal_handle->segment_table, |
6169 | 0 | internal_handle->io_handle->segment_file_type, |
6170 | 0 | 0, |
6171 | 0 | internal_handle->write_io_handle->maximum_number_of_segments, |
6172 | 0 | internal_handle->media_values->set_identifier, |
6173 | 0 | &file_io_pool_entry, |
6174 | 0 | &segment_file, |
6175 | 0 | error ) != 1 ) |
6176 | 0 | { |
6177 | 0 | libcerror_error_set( |
6178 | 0 | error, |
6179 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
6180 | 0 | LIBCERROR_IO_ERROR_OPEN_FAILED, |
6181 | 0 | "%s: unable to create segment file: 0.", |
6182 | 0 | function ); |
6183 | |
|
6184 | 0 | return( -1 ); |
6185 | 0 | } |
6186 | 0 | write_count = libewf_segment_file_write_start( |
6187 | 0 | segment_file, |
6188 | 0 | file_io_pool, |
6189 | 0 | file_io_pool_entry, |
6190 | 0 | &( internal_handle->write_io_handle->case_data ), |
6191 | 0 | &( internal_handle->write_io_handle->case_data_size ), |
6192 | 0 | &( internal_handle->write_io_handle->device_information ), |
6193 | 0 | &( internal_handle->write_io_handle->device_information_size ), |
6194 | 0 | &( internal_handle->write_io_handle->data_section ), |
6195 | 0 | internal_handle->media_values, |
6196 | 0 | internal_handle->header_values, |
6197 | 0 | internal_handle->write_io_handle->timestamp, |
6198 | 0 | error ); |
6199 | |
|
6200 | 0 | if( write_count == -1 ) |
6201 | 0 | { |
6202 | 0 | libcerror_error_set( |
6203 | 0 | error, |
6204 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
6205 | 0 | LIBCERROR_IO_ERROR_WRITE_FAILED, |
6206 | 0 | "%s: unable to write segment file: 0 start.", |
6207 | 0 | function ); |
6208 | |
|
6209 | 0 | return( -1 ); |
6210 | 0 | } |
6211 | 0 | write_finalize_count += write_count; |
6212 | 0 | } |
6213 | | /* Check if the last segment file is still open for writing |
6214 | | */ |
6215 | 0 | else if( internal_handle->write_io_handle->current_segment_file != NULL ) |
6216 | 0 | { |
6217 | 0 | if( libewf_segment_table_get_segment_by_index( |
6218 | 0 | internal_handle->segment_table, |
6219 | 0 | internal_handle->write_io_handle->current_segment_number, |
6220 | 0 | &file_io_pool_entry, |
6221 | 0 | &segment_file_size, |
6222 | 0 | error ) != 1 ) |
6223 | 0 | { |
6224 | 0 | libcerror_error_set( |
6225 | 0 | error, |
6226 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6227 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
6228 | 0 | "%s: unable to retrieve segment: %" PRIu32 " from segment table.", |
6229 | 0 | function, |
6230 | 0 | internal_handle->write_io_handle->current_segment_number ); |
6231 | |
|
6232 | 0 | return( -1 ); |
6233 | 0 | } |
6234 | | /* Check if chunks section needs to be corrected |
6235 | | */ |
6236 | 0 | if( internal_handle->write_io_handle->chunks_section_offset != 0 ) |
6237 | 0 | { |
6238 | 0 | write_count = libewf_write_io_handle_write_chunks_section_end( |
6239 | 0 | internal_handle->write_io_handle, |
6240 | 0 | internal_handle->io_handle, |
6241 | 0 | file_io_pool, |
6242 | 0 | file_io_pool_entry, |
6243 | 0 | internal_handle->write_io_handle->current_segment_file, |
6244 | 0 | error ); |
6245 | |
|
6246 | 0 | if( write_count == -1 ) |
6247 | 0 | { |
6248 | 0 | libcerror_error_set( |
6249 | 0 | error, |
6250 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
6251 | 0 | LIBCERROR_IO_ERROR_WRITE_FAILED, |
6252 | 0 | "%s: unable to write chunks section end: %" PRIu32 ".", |
6253 | 0 | function, |
6254 | 0 | internal_handle->write_io_handle->current_segment_number ); |
6255 | |
|
6256 | 0 | return( -1 ); |
6257 | 0 | } |
6258 | 0 | write_finalize_count += write_count; |
6259 | 0 | } |
6260 | | /* Close the segment file |
6261 | | */ |
6262 | | #if defined( HAVE_DEBUG_OUTPUT ) |
6263 | | if( libcnotify_verbose != 0 ) |
6264 | | { |
6265 | | libcnotify_printf( |
6266 | | "%s: closing last segment file: %" PRIu32 ".\n", |
6267 | | function, |
6268 | | internal_handle->write_io_handle->current_segment_number ); |
6269 | | } |
6270 | | #endif |
6271 | 0 | write_count = libewf_segment_file_write_close( |
6272 | 0 | internal_handle->write_io_handle->current_segment_file, |
6273 | 0 | file_io_pool, |
6274 | 0 | file_io_pool_entry, |
6275 | 0 | internal_handle->write_io_handle->number_of_chunks_written_to_segment_file, |
6276 | 0 | 1, |
6277 | 0 | internal_handle->hash_sections, |
6278 | 0 | internal_handle->hash_values, |
6279 | 0 | internal_handle->media_values, |
6280 | 0 | internal_handle->sessions, |
6281 | 0 | internal_handle->tracks, |
6282 | 0 | internal_handle->acquiry_errors, |
6283 | 0 | &( internal_handle->write_io_handle->data_section ), |
6284 | 0 | error ); |
6285 | |
|
6286 | 0 | if( write_count == -1 ) |
6287 | 0 | { |
6288 | 0 | libcerror_error_set( |
6289 | 0 | error, |
6290 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
6291 | 0 | LIBCERROR_IO_ERROR_WRITE_FAILED, |
6292 | 0 | "%s: unable to close segment file: %" PRIu32 ".", |
6293 | 0 | function, |
6294 | 0 | internal_handle->write_io_handle->current_segment_number ); |
6295 | |
|
6296 | 0 | return( -1 ); |
6297 | 0 | } |
6298 | 0 | write_finalize_count += write_count; |
6299 | |
|
6300 | 0 | internal_handle->write_io_handle->current_segment_file = NULL; |
6301 | 0 | } |
6302 | | /* Correct the media values if streamed write was used |
6303 | | */ |
6304 | 0 | if( internal_handle->media_values->media_size == 0 ) |
6305 | 0 | { |
6306 | | /* Determine the media values |
6307 | | */ |
6308 | 0 | internal_handle->media_values->number_of_chunks = internal_handle->write_io_handle->number_of_chunks_written; |
6309 | 0 | internal_handle->media_values->number_of_sectors = (uint64_t) ( internal_handle->write_io_handle->input_write_count / internal_handle->media_values->bytes_per_sector ); |
6310 | 0 | internal_handle->media_values->media_size = (size64_t) internal_handle->write_io_handle->input_write_count; |
6311 | | |
6312 | | /* Flush the section write caches |
6313 | | */ |
6314 | 0 | if( internal_handle->write_io_handle->case_data != NULL ) |
6315 | 0 | { |
6316 | 0 | memory_free( |
6317 | 0 | internal_handle->write_io_handle->case_data ); |
6318 | |
|
6319 | 0 | internal_handle->write_io_handle->case_data = NULL; |
6320 | 0 | internal_handle->write_io_handle->case_data_size = 0; |
6321 | 0 | } |
6322 | 0 | if( internal_handle->write_io_handle->device_information != NULL ) |
6323 | 0 | { |
6324 | 0 | memory_free( |
6325 | 0 | internal_handle->write_io_handle->device_information ); |
6326 | |
|
6327 | 0 | internal_handle->write_io_handle->device_information = NULL; |
6328 | 0 | internal_handle->write_io_handle->device_information_size = 0; |
6329 | 0 | } |
6330 | 0 | if( internal_handle->write_io_handle->data_section != NULL ) |
6331 | 0 | { |
6332 | 0 | memory_free( |
6333 | 0 | internal_handle->write_io_handle->data_section ); |
6334 | |
|
6335 | 0 | internal_handle->write_io_handle->data_section = NULL; |
6336 | 0 | } |
6337 | | /* Correct the sections in the segment files |
6338 | | */ |
6339 | 0 | if( libewf_write_io_handle_finalize_write_sections_corrections( |
6340 | 0 | internal_handle->write_io_handle, |
6341 | 0 | file_io_pool, |
6342 | 0 | internal_handle->media_values, |
6343 | 0 | internal_handle->segment_table, |
6344 | 0 | internal_handle->header_values, |
6345 | 0 | internal_handle->hash_values, |
6346 | 0 | internal_handle->hash_sections, |
6347 | 0 | internal_handle->sessions, |
6348 | 0 | internal_handle->tracks, |
6349 | 0 | internal_handle->acquiry_errors, |
6350 | 0 | error ) != 1 ) |
6351 | 0 | { |
6352 | 0 | libcerror_error_set( |
6353 | 0 | error, |
6354 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
6355 | 0 | LIBCERROR_IO_ERROR_WRITE_FAILED, |
6356 | 0 | "%s: unable to write sections corrections to segment files.", |
6357 | 0 | function ); |
6358 | |
|
6359 | 0 | return( -1 ); |
6360 | 0 | } |
6361 | 0 | } |
6362 | 0 | internal_handle->write_io_handle->write_finalized = 1; |
6363 | |
|
6364 | 0 | return( write_finalize_count ); |
6365 | 0 | } |
6366 | | |
6367 | | /* Finalizes the write by correcting the EWF the meta data in the segment files |
6368 | | * This function is required after write from stream |
6369 | | * Returns the number of bytes written or -1 on error |
6370 | | */ |
6371 | | ssize_t libewf_handle_write_finalize( |
6372 | | libewf_handle_t *handle, |
6373 | | libcerror_error_t **error ) |
6374 | 0 | { |
6375 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
6376 | 0 | static char *function = "libewf_handle_write_finalize"; |
6377 | 0 | ssize_t write_count = 0; |
6378 | |
|
6379 | 0 | if( handle == NULL ) |
6380 | 0 | { |
6381 | 0 | libcerror_error_set( |
6382 | 0 | error, |
6383 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6384 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
6385 | 0 | "%s: invalid handle.", |
6386 | 0 | function ); |
6387 | |
|
6388 | 0 | return( -1 ); |
6389 | 0 | } |
6390 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
6391 | |
|
6392 | 0 | if( internal_handle->file_io_pool == NULL ) |
6393 | 0 | { |
6394 | 0 | libcerror_error_set( |
6395 | 0 | error, |
6396 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6397 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
6398 | 0 | "%s: invalid handle - missing file IO pool.", |
6399 | 0 | function ); |
6400 | |
|
6401 | 0 | return( -1 ); |
6402 | 0 | } |
6403 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
6404 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
6405 | 0 | internal_handle->read_write_lock, |
6406 | 0 | error ) != 1 ) |
6407 | 0 | { |
6408 | 0 | libcerror_error_set( |
6409 | 0 | error, |
6410 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6411 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
6412 | 0 | "%s: unable to grab read/write lock for writing.", |
6413 | 0 | function ); |
6414 | |
|
6415 | 0 | return( -1 ); |
6416 | 0 | } |
6417 | 0 | #endif |
6418 | 0 | write_count = libewf_internal_handle_write_finalize_file_io_pool( |
6419 | 0 | internal_handle, |
6420 | 0 | internal_handle->file_io_pool, |
6421 | 0 | error ); |
6422 | |
|
6423 | 0 | if( write_count == -1 ) |
6424 | 0 | { |
6425 | 0 | libcerror_error_set( |
6426 | 0 | error, |
6427 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
6428 | 0 | LIBCERROR_IO_ERROR_READ_FAILED, |
6429 | 0 | "%s: unable to write finalize.", |
6430 | 0 | function ); |
6431 | |
|
6432 | 0 | write_count = -1; |
6433 | 0 | } |
6434 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
6435 | 0 | if( libcthreads_read_write_lock_release_for_write( |
6436 | 0 | internal_handle->read_write_lock, |
6437 | 0 | error ) != 1 ) |
6438 | 0 | { |
6439 | 0 | libcerror_error_set( |
6440 | 0 | error, |
6441 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6442 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
6443 | 0 | "%s: unable to release read/write lock for writing.", |
6444 | 0 | function ); |
6445 | |
|
6446 | 0 | return( -1 ); |
6447 | 0 | } |
6448 | 0 | #endif |
6449 | 0 | return( write_count ); |
6450 | 0 | } |
6451 | | |
6452 | | /* Seeks a certain offset of the (media) data |
6453 | | * This function is not multi-thread safe acquire write lock before call |
6454 | | * Returns the offset if seek is successful or -1 on error |
6455 | | */ |
6456 | | off64_t libewf_internal_handle_seek_offset( |
6457 | | libewf_internal_handle_t *internal_handle, |
6458 | | off64_t offset, |
6459 | | int whence, |
6460 | | libcerror_error_t **error ) |
6461 | 0 | { |
6462 | 0 | static char *function = "libewf_internal_handle_seek_offset"; |
6463 | |
|
6464 | 0 | if( internal_handle == NULL ) |
6465 | 0 | { |
6466 | 0 | libcerror_error_set( |
6467 | 0 | error, |
6468 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6469 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
6470 | 0 | "%s: invalid handle.", |
6471 | 0 | function ); |
6472 | |
|
6473 | 0 | return( -1 ); |
6474 | 0 | } |
6475 | 0 | if( internal_handle->chunk_data != NULL ) |
6476 | 0 | { |
6477 | 0 | libcerror_error_set( |
6478 | 0 | error, |
6479 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6480 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
6481 | 0 | "%s: invalid handle - chunk data set.", |
6482 | 0 | function ); |
6483 | |
|
6484 | 0 | return( -1 ); |
6485 | 0 | } |
6486 | 0 | if( internal_handle->media_values == NULL ) |
6487 | 0 | { |
6488 | 0 | libcerror_error_set( |
6489 | 0 | error, |
6490 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6491 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
6492 | 0 | "%s: invalid handle - missing media values.", |
6493 | 0 | function ); |
6494 | |
|
6495 | 0 | return( -1 ); |
6496 | 0 | } |
6497 | 0 | if( internal_handle->media_values->chunk_size == 0 ) |
6498 | 0 | { |
6499 | 0 | libcerror_error_set( |
6500 | 0 | error, |
6501 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6502 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
6503 | 0 | "%s: invalid handle - invalid media values - missing chunk size.", |
6504 | 0 | function ); |
6505 | |
|
6506 | 0 | return( -1 ); |
6507 | 0 | } |
6508 | 0 | if( ( whence != SEEK_CUR ) |
6509 | 0 | && ( whence != SEEK_END ) |
6510 | 0 | && ( whence != SEEK_SET ) ) |
6511 | 0 | { |
6512 | 0 | libcerror_error_set( |
6513 | 0 | error, |
6514 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6515 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
6516 | 0 | "%s: unsupported whence.", |
6517 | 0 | function ); |
6518 | |
|
6519 | 0 | return( -1 ); |
6520 | 0 | } |
6521 | 0 | if( whence == SEEK_CUR ) |
6522 | 0 | { |
6523 | 0 | offset += internal_handle->current_offset; |
6524 | 0 | } |
6525 | 0 | else if( whence == SEEK_END ) |
6526 | 0 | { |
6527 | 0 | offset += (off64_t) internal_handle->media_values->media_size; |
6528 | 0 | } |
6529 | | #if defined( HAVE_DEBUG_OUTPUT ) |
6530 | | if( libcnotify_verbose != 0 ) |
6531 | | { |
6532 | | libcnotify_printf( |
6533 | | "%s: seeking media data offset: %" PRIi64 ".\n", |
6534 | | function, |
6535 | | offset ); |
6536 | | } |
6537 | | #endif |
6538 | 0 | if( offset < 0 ) |
6539 | 0 | { |
6540 | 0 | libcerror_error_set( |
6541 | 0 | error, |
6542 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6543 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
6544 | 0 | "%s: invalid offset value out of bounds.", |
6545 | 0 | function ); |
6546 | |
|
6547 | 0 | return( -1 ); |
6548 | 0 | } |
6549 | 0 | internal_handle->current_offset = offset; |
6550 | |
|
6551 | 0 | return( offset ); |
6552 | 0 | } |
6553 | | |
6554 | | /* Seeks a certain offset of the (media) data |
6555 | | * Returns the offset if seek is successful or -1 on error |
6556 | | */ |
6557 | | off64_t libewf_handle_seek_offset( |
6558 | | libewf_handle_t *handle, |
6559 | | off64_t offset, |
6560 | | int whence, |
6561 | | libcerror_error_t **error ) |
6562 | 0 | { |
6563 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
6564 | 0 | static char *function = "libewf_handle_seek_offset"; |
6565 | |
|
6566 | 0 | if( handle == NULL ) |
6567 | 0 | { |
6568 | 0 | libcerror_error_set( |
6569 | 0 | error, |
6570 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6571 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
6572 | 0 | "%s: invalid handle.", |
6573 | 0 | function ); |
6574 | |
|
6575 | 0 | return( -1 ); |
6576 | 0 | } |
6577 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
6578 | |
|
6579 | 0 | if( internal_handle->file_io_pool == NULL ) |
6580 | 0 | { |
6581 | 0 | libcerror_error_set( |
6582 | 0 | error, |
6583 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6584 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
6585 | 0 | "%s: invalid handle - missing file IO pool.", |
6586 | 0 | function ); |
6587 | |
|
6588 | 0 | return( -1 ); |
6589 | 0 | } |
6590 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
6591 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
6592 | 0 | internal_handle->read_write_lock, |
6593 | 0 | error ) != 1 ) |
6594 | 0 | { |
6595 | 0 | libcerror_error_set( |
6596 | 0 | error, |
6597 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6598 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
6599 | 0 | "%s: unable to grab read/write lock for writing.", |
6600 | 0 | function ); |
6601 | |
|
6602 | 0 | return( -1 ); |
6603 | 0 | } |
6604 | 0 | #endif |
6605 | 0 | offset = libewf_internal_handle_seek_offset( |
6606 | 0 | internal_handle, |
6607 | 0 | offset, |
6608 | 0 | whence, |
6609 | 0 | error ); |
6610 | |
|
6611 | 0 | if( offset == -1 ) |
6612 | 0 | { |
6613 | 0 | libcerror_error_set( |
6614 | 0 | error, |
6615 | 0 | LIBCERROR_ERROR_DOMAIN_IO, |
6616 | 0 | LIBCERROR_IO_ERROR_SEEK_FAILED, |
6617 | 0 | "%s: unable to seek offset.", |
6618 | 0 | function ); |
6619 | 0 | } |
6620 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
6621 | 0 | if( libcthreads_read_write_lock_release_for_write( |
6622 | 0 | internal_handle->read_write_lock, |
6623 | 0 | error ) != 1 ) |
6624 | 0 | { |
6625 | 0 | libcerror_error_set( |
6626 | 0 | error, |
6627 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6628 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
6629 | 0 | "%s: unable to release read/write lock for writing.", |
6630 | 0 | function ); |
6631 | |
|
6632 | 0 | return( -1 ); |
6633 | 0 | } |
6634 | 0 | #endif |
6635 | 0 | return( offset ); |
6636 | 0 | } |
6637 | | |
6638 | | /* Retrieves the current offset of the (media) data |
6639 | | * Returns 1 if successful or -1 on error |
6640 | | */ |
6641 | | int libewf_handle_get_offset( |
6642 | | libewf_handle_t *handle, |
6643 | | off64_t *offset, |
6644 | | libcerror_error_t **error ) |
6645 | 0 | { |
6646 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
6647 | 0 | static char *function = "libewf_handle_get_offset"; |
6648 | |
|
6649 | 0 | if( handle == NULL ) |
6650 | 0 | { |
6651 | 0 | libcerror_error_set( |
6652 | 0 | error, |
6653 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6654 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
6655 | 0 | "%s: invalid handle.", |
6656 | 0 | function ); |
6657 | |
|
6658 | 0 | return( -1 ); |
6659 | 0 | } |
6660 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
6661 | |
|
6662 | 0 | if( offset == NULL ) |
6663 | 0 | { |
6664 | 0 | libcerror_error_set( |
6665 | 0 | error, |
6666 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6667 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
6668 | 0 | "%s: invalid offset.", |
6669 | 0 | function ); |
6670 | |
|
6671 | 0 | return( -1 ); |
6672 | 0 | } |
6673 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
6674 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
6675 | 0 | internal_handle->read_write_lock, |
6676 | 0 | error ) != 1 ) |
6677 | 0 | { |
6678 | 0 | libcerror_error_set( |
6679 | 0 | error, |
6680 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6681 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
6682 | 0 | "%s: unable to grab read/write lock for reading.", |
6683 | 0 | function ); |
6684 | |
|
6685 | 0 | return( -1 ); |
6686 | 0 | } |
6687 | 0 | #endif |
6688 | 0 | *offset = internal_handle->current_offset; |
6689 | |
|
6690 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
6691 | 0 | if( libcthreads_read_write_lock_release_for_read( |
6692 | 0 | internal_handle->read_write_lock, |
6693 | 0 | error ) != 1 ) |
6694 | 0 | { |
6695 | 0 | libcerror_error_set( |
6696 | 0 | error, |
6697 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6698 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
6699 | 0 | "%s: unable to release read/write lock for reading.", |
6700 | 0 | function ); |
6701 | |
|
6702 | 0 | return( -1 ); |
6703 | 0 | } |
6704 | 0 | #endif |
6705 | 0 | return( 1 ); |
6706 | 0 | } |
6707 | | |
6708 | | /* Sets the maximum number of (concurrent) open file handles |
6709 | | * Returns 1 if successful or -1 on error |
6710 | | */ |
6711 | | int libewf_handle_set_maximum_number_of_open_handles( |
6712 | | libewf_handle_t *handle, |
6713 | | int maximum_number_of_open_handles, |
6714 | | libcerror_error_t **error ) |
6715 | 0 | { |
6716 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
6717 | 0 | static char *function = "libewf_handle_set_maximum_number_of_open_handles"; |
6718 | 0 | int result = 1; |
6719 | |
|
6720 | 0 | if( handle == NULL ) |
6721 | 0 | { |
6722 | 0 | libcerror_error_set( |
6723 | 0 | error, |
6724 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6725 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
6726 | 0 | "%s: invalid handle.", |
6727 | 0 | function ); |
6728 | |
|
6729 | 0 | return( -1 ); |
6730 | 0 | } |
6731 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
6732 | |
|
6733 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
6734 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
6735 | 0 | internal_handle->read_write_lock, |
6736 | 0 | error ) != 1 ) |
6737 | 0 | { |
6738 | 0 | libcerror_error_set( |
6739 | 0 | error, |
6740 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6741 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
6742 | 0 | "%s: unable to grab read/write lock for writing.", |
6743 | 0 | function ); |
6744 | |
|
6745 | 0 | return( -1 ); |
6746 | 0 | } |
6747 | 0 | #endif |
6748 | 0 | if( internal_handle->file_io_pool != NULL ) |
6749 | 0 | { |
6750 | 0 | result = libbfio_pool_set_maximum_number_of_open_handles( |
6751 | 0 | internal_handle->file_io_pool, |
6752 | 0 | maximum_number_of_open_handles, |
6753 | 0 | error ); |
6754 | |
|
6755 | 0 | if( result != 1 ) |
6756 | 0 | { |
6757 | 0 | libcerror_error_set( |
6758 | 0 | error, |
6759 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6760 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
6761 | 0 | "%s: unable to set maximum number of open handles in file IO pool.", |
6762 | 0 | function ); |
6763 | 0 | } |
6764 | 0 | } |
6765 | 0 | if( result == 1 ) |
6766 | 0 | { |
6767 | 0 | internal_handle->maximum_number_of_open_handles = maximum_number_of_open_handles; |
6768 | 0 | } |
6769 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
6770 | 0 | if( libcthreads_read_write_lock_release_for_write( |
6771 | 0 | internal_handle->read_write_lock, |
6772 | 0 | error ) != 1 ) |
6773 | 0 | { |
6774 | 0 | libcerror_error_set( |
6775 | 0 | error, |
6776 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6777 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
6778 | 0 | "%s: unable to release read/write lock for writing.", |
6779 | 0 | function ); |
6780 | |
|
6781 | 0 | return( -1 ); |
6782 | 0 | } |
6783 | 0 | #endif |
6784 | 0 | return( result ); |
6785 | 0 | } |
6786 | | |
6787 | | /* Determine if the segment files are corrupted |
6788 | | * Returns 1 if corrupted, 0 if not or -1 on error |
6789 | | */ |
6790 | | int libewf_handle_segment_files_corrupted( |
6791 | | libewf_handle_t *handle, |
6792 | | libcerror_error_t **error ) |
6793 | 0 | { |
6794 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
6795 | 0 | static char *function = "libewf_handle_segment_files_corrupted"; |
6796 | 0 | int result = 0; |
6797 | |
|
6798 | 0 | if( handle == NULL ) |
6799 | 0 | { |
6800 | 0 | libcerror_error_set( |
6801 | 0 | error, |
6802 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6803 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
6804 | 0 | "%s: invalid handle.", |
6805 | 0 | function ); |
6806 | |
|
6807 | 0 | return( -1 ); |
6808 | 0 | } |
6809 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
6810 | |
|
6811 | 0 | if( internal_handle->segment_table == NULL ) |
6812 | 0 | { |
6813 | 0 | libcerror_error_set( |
6814 | 0 | error, |
6815 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6816 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
6817 | 0 | "%s: invalid handle - missing segment table.", |
6818 | 0 | function ); |
6819 | |
|
6820 | 0 | return( -1 ); |
6821 | 0 | } |
6822 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
6823 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
6824 | 0 | internal_handle->read_write_lock, |
6825 | 0 | error ) != 1 ) |
6826 | 0 | { |
6827 | 0 | libcerror_error_set( |
6828 | 0 | error, |
6829 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6830 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
6831 | 0 | "%s: unable to grab read/write lock for reading.", |
6832 | 0 | function ); |
6833 | |
|
6834 | 0 | return( -1 ); |
6835 | 0 | } |
6836 | 0 | #endif |
6837 | 0 | result = ( internal_handle->segment_table->flags & LIBEWF_SEGMENT_TABLE_FLAG_IS_CORRUPTED ) != 0; |
6838 | |
|
6839 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
6840 | 0 | if( libcthreads_read_write_lock_release_for_read( |
6841 | 0 | internal_handle->read_write_lock, |
6842 | 0 | error ) != 1 ) |
6843 | 0 | { |
6844 | 0 | libcerror_error_set( |
6845 | 0 | error, |
6846 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6847 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
6848 | 0 | "%s: unable to release read/write lock for reading.", |
6849 | 0 | function ); |
6850 | |
|
6851 | 0 | return( -1 ); |
6852 | 0 | } |
6853 | 0 | #endif |
6854 | 0 | return( result ); |
6855 | 0 | } |
6856 | | |
6857 | | /* Determine if the segment files are encrypted |
6858 | | * Returns 1 if encrypted, 0 if not or -1 on error |
6859 | | */ |
6860 | | int libewf_handle_segment_files_encrypted( |
6861 | | libewf_handle_t *handle, |
6862 | | libcerror_error_t **error ) |
6863 | 0 | { |
6864 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
6865 | 0 | static char *function = "libewf_handle_segment_files_encrypted"; |
6866 | 0 | int result = 0; |
6867 | |
|
6868 | 0 | if( handle == NULL ) |
6869 | 0 | { |
6870 | 0 | libcerror_error_set( |
6871 | 0 | error, |
6872 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6873 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
6874 | 0 | "%s: invalid handle.", |
6875 | 0 | function ); |
6876 | |
|
6877 | 0 | return( -1 ); |
6878 | 0 | } |
6879 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
6880 | |
|
6881 | 0 | if( internal_handle->io_handle == NULL ) |
6882 | 0 | { |
6883 | 0 | libcerror_error_set( |
6884 | 0 | error, |
6885 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6886 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
6887 | 0 | "%s: invalid handle - missing IO handle.", |
6888 | 0 | function ); |
6889 | |
|
6890 | 0 | return( -1 ); |
6891 | 0 | } |
6892 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
6893 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
6894 | 0 | internal_handle->read_write_lock, |
6895 | 0 | error ) != 1 ) |
6896 | 0 | { |
6897 | 0 | libcerror_error_set( |
6898 | 0 | error, |
6899 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6900 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
6901 | 0 | "%s: unable to grab read/write lock for reading.", |
6902 | 0 | function ); |
6903 | |
|
6904 | 0 | return( -1 ); |
6905 | 0 | } |
6906 | 0 | #endif |
6907 | 0 | result = (int) internal_handle->io_handle->is_encrypted; |
6908 | |
|
6909 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
6910 | 0 | if( libcthreads_read_write_lock_release_for_read( |
6911 | 0 | internal_handle->read_write_lock, |
6912 | 0 | error ) != 1 ) |
6913 | 0 | { |
6914 | 0 | libcerror_error_set( |
6915 | 0 | error, |
6916 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6917 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
6918 | 0 | "%s: unable to release read/write lock for reading.", |
6919 | 0 | function ); |
6920 | |
|
6921 | 0 | return( -1 ); |
6922 | 0 | } |
6923 | 0 | #endif |
6924 | 0 | return( result ); |
6925 | 0 | } |
6926 | | |
6927 | | /* Retrieves the segment filename size |
6928 | | * The filename size should include the end of string character |
6929 | | * Returns 1 if successful, 0 if not set or -1 on error |
6930 | | */ |
6931 | | int libewf_handle_get_segment_filename_size( |
6932 | | libewf_handle_t *handle, |
6933 | | size_t *filename_size, |
6934 | | libcerror_error_t **error ) |
6935 | 0 | { |
6936 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
6937 | 0 | static char *function = "libewf_handle_get_segment_filename_size"; |
6938 | 0 | int result = 0; |
6939 | |
|
6940 | 0 | if( handle == NULL ) |
6941 | 0 | { |
6942 | 0 | libcerror_error_set( |
6943 | 0 | error, |
6944 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
6945 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
6946 | 0 | "%s: invalid handle.", |
6947 | 0 | function ); |
6948 | |
|
6949 | 0 | return( -1 ); |
6950 | 0 | } |
6951 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
6952 | |
|
6953 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
6954 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
6955 | 0 | internal_handle->read_write_lock, |
6956 | 0 | error ) != 1 ) |
6957 | 0 | { |
6958 | 0 | libcerror_error_set( |
6959 | 0 | error, |
6960 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6961 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
6962 | 0 | "%s: unable to grab read/write lock for reading.", |
6963 | 0 | function ); |
6964 | |
|
6965 | 0 | return( -1 ); |
6966 | 0 | } |
6967 | 0 | #endif |
6968 | 0 | result = libewf_segment_table_get_basename_size( |
6969 | 0 | internal_handle->segment_table, |
6970 | 0 | filename_size, |
6971 | 0 | error ); |
6972 | |
|
6973 | 0 | if( result == -1 ) |
6974 | 0 | { |
6975 | 0 | libcerror_error_set( |
6976 | 0 | error, |
6977 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6978 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
6979 | 0 | "%s: unable to retrieve segment table basename size.", |
6980 | 0 | function ); |
6981 | 0 | } |
6982 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
6983 | 0 | if( libcthreads_read_write_lock_release_for_read( |
6984 | 0 | internal_handle->read_write_lock, |
6985 | 0 | error ) != 1 ) |
6986 | 0 | { |
6987 | 0 | libcerror_error_set( |
6988 | 0 | error, |
6989 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
6990 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
6991 | 0 | "%s: unable to release read/write lock for reading.", |
6992 | 0 | function ); |
6993 | |
|
6994 | 0 | return( -1 ); |
6995 | 0 | } |
6996 | 0 | #endif |
6997 | 0 | return( result ); |
6998 | 0 | } |
6999 | | |
7000 | | /* Retrieves the segment filename |
7001 | | * The filename size should include the end of string character |
7002 | | * Returns 1 if successful, 0 if not set or -1 on error |
7003 | | */ |
7004 | | int libewf_handle_get_segment_filename( |
7005 | | libewf_handle_t *handle, |
7006 | | char *filename, |
7007 | | size_t filename_size, |
7008 | | libcerror_error_t **error ) |
7009 | 0 | { |
7010 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
7011 | 0 | static char *function = "libewf_handle_get_segment_filename"; |
7012 | 0 | int result = 0; |
7013 | |
|
7014 | 0 | if( handle == NULL ) |
7015 | 0 | { |
7016 | 0 | libcerror_error_set( |
7017 | 0 | error, |
7018 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
7019 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
7020 | 0 | "%s: invalid handle.", |
7021 | 0 | function ); |
7022 | |
|
7023 | 0 | return( -1 ); |
7024 | 0 | } |
7025 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
7026 | |
|
7027 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7028 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
7029 | 0 | internal_handle->read_write_lock, |
7030 | 0 | error ) != 1 ) |
7031 | 0 | { |
7032 | 0 | libcerror_error_set( |
7033 | 0 | error, |
7034 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7035 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7036 | 0 | "%s: unable to grab read/write lock for reading.", |
7037 | 0 | function ); |
7038 | |
|
7039 | 0 | return( -1 ); |
7040 | 0 | } |
7041 | 0 | #endif |
7042 | 0 | result = libewf_segment_table_get_basename( |
7043 | 0 | internal_handle->segment_table, |
7044 | 0 | filename, |
7045 | 0 | filename_size, |
7046 | 0 | error ); |
7047 | |
|
7048 | 0 | if( result == -1 ) |
7049 | 0 | { |
7050 | 0 | libcerror_error_set( |
7051 | 0 | error, |
7052 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7053 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
7054 | 0 | "%s: unable to retrieve segment table basename.", |
7055 | 0 | function ); |
7056 | 0 | } |
7057 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7058 | 0 | if( libcthreads_read_write_lock_release_for_read( |
7059 | 0 | internal_handle->read_write_lock, |
7060 | 0 | error ) != 1 ) |
7061 | 0 | { |
7062 | 0 | libcerror_error_set( |
7063 | 0 | error, |
7064 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7065 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7066 | 0 | "%s: unable to release read/write lock for reading.", |
7067 | 0 | function ); |
7068 | |
|
7069 | 0 | return( -1 ); |
7070 | 0 | } |
7071 | 0 | #endif |
7072 | 0 | return( result ); |
7073 | 0 | } |
7074 | | |
7075 | | /* Sets the segment file |
7076 | | * Returns 1 if successful or -1 on error |
7077 | | */ |
7078 | | int libewf_handle_set_segment_filename( |
7079 | | libewf_handle_t *handle, |
7080 | | const char *filename, |
7081 | | size_t filename_length, |
7082 | | libcerror_error_t **error ) |
7083 | 0 | { |
7084 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
7085 | 0 | static char *function = "libewf_handle_set_segment_filename"; |
7086 | 0 | int result = 0; |
7087 | |
|
7088 | 0 | if( handle == NULL ) |
7089 | 0 | { |
7090 | 0 | libcerror_error_set( |
7091 | 0 | error, |
7092 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
7093 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
7094 | 0 | "%s: invalid handle.", |
7095 | 0 | function ); |
7096 | |
|
7097 | 0 | return( -1 ); |
7098 | 0 | } |
7099 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
7100 | |
|
7101 | 0 | if( internal_handle->write_io_handle == NULL ) |
7102 | 0 | { |
7103 | 0 | libcerror_error_set( |
7104 | 0 | error, |
7105 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7106 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7107 | 0 | "%s: segment filename cannot be changed.", |
7108 | 0 | function ); |
7109 | |
|
7110 | 0 | return( -1 ); |
7111 | 0 | } |
7112 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7113 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
7114 | 0 | internal_handle->read_write_lock, |
7115 | 0 | error ) != 1 ) |
7116 | 0 | { |
7117 | 0 | libcerror_error_set( |
7118 | 0 | error, |
7119 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7120 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7121 | 0 | "%s: unable to grab read/write lock for writing.", |
7122 | 0 | function ); |
7123 | |
|
7124 | 0 | return( -1 ); |
7125 | 0 | } |
7126 | 0 | #endif |
7127 | 0 | result = libewf_segment_table_set_basename( |
7128 | 0 | internal_handle->segment_table, |
7129 | 0 | filename, |
7130 | 0 | filename_length, |
7131 | 0 | error ); |
7132 | |
|
7133 | 0 | if( result != 1 ) |
7134 | 0 | { |
7135 | 0 | libcerror_error_set( |
7136 | 0 | error, |
7137 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7138 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7139 | 0 | "%s: unable to set segment table basename.", |
7140 | 0 | function ); |
7141 | 0 | } |
7142 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7143 | 0 | if( libcthreads_read_write_lock_release_for_write( |
7144 | 0 | internal_handle->read_write_lock, |
7145 | 0 | error ) != 1 ) |
7146 | 0 | { |
7147 | 0 | libcerror_error_set( |
7148 | 0 | error, |
7149 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7150 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7151 | 0 | "%s: unable to release read/write lock for writing.", |
7152 | 0 | function ); |
7153 | |
|
7154 | 0 | return( -1 ); |
7155 | 0 | } |
7156 | 0 | #endif |
7157 | 0 | return( result ); |
7158 | 0 | } |
7159 | | |
7160 | | #if defined( HAVE_WIDE_CHARACTER_TYPE ) |
7161 | | |
7162 | | /* Retrieves the segment filename size |
7163 | | * The filename size includes the end of string character |
7164 | | * Returns 1 if successful, 0 if not set or -1 on error |
7165 | | */ |
7166 | | int libewf_handle_get_segment_filename_size_wide( |
7167 | | libewf_handle_t *handle, |
7168 | | size_t *filename_size, |
7169 | | libcerror_error_t **error ) |
7170 | | { |
7171 | | libewf_internal_handle_t *internal_handle = NULL; |
7172 | | static char *function = "libewf_handle_get_segment_filename_size_wide"; |
7173 | | int result = 0; |
7174 | | |
7175 | | if( handle == NULL ) |
7176 | | { |
7177 | | libcerror_error_set( |
7178 | | error, |
7179 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
7180 | | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
7181 | | "%s: invalid handle.", |
7182 | | function ); |
7183 | | |
7184 | | return( -1 ); |
7185 | | } |
7186 | | internal_handle = (libewf_internal_handle_t *) handle; |
7187 | | |
7188 | | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7189 | | if( libcthreads_read_write_lock_grab_for_read( |
7190 | | internal_handle->read_write_lock, |
7191 | | error ) != 1 ) |
7192 | | { |
7193 | | libcerror_error_set( |
7194 | | error, |
7195 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7196 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7197 | | "%s: unable to grab read/write lock for reading.", |
7198 | | function ); |
7199 | | |
7200 | | return( -1 ); |
7201 | | } |
7202 | | #endif |
7203 | | result = libewf_segment_table_get_basename_size_wide( |
7204 | | internal_handle->segment_table, |
7205 | | filename_size, |
7206 | | error ); |
7207 | | |
7208 | | if( result == -1 ) |
7209 | | { |
7210 | | libcerror_error_set( |
7211 | | error, |
7212 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7213 | | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
7214 | | "%s: unable to retrieve segment table basename size.", |
7215 | | function ); |
7216 | | } |
7217 | | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7218 | | if( libcthreads_read_write_lock_release_for_read( |
7219 | | internal_handle->read_write_lock, |
7220 | | error ) != 1 ) |
7221 | | { |
7222 | | libcerror_error_set( |
7223 | | error, |
7224 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7225 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7226 | | "%s: unable to release read/write lock for reading.", |
7227 | | function ); |
7228 | | |
7229 | | return( -1 ); |
7230 | | } |
7231 | | #endif |
7232 | | return( result ); |
7233 | | } |
7234 | | |
7235 | | /* Retrieves the segment filename |
7236 | | * The filename size should include the end of string character |
7237 | | * Returns 1 if successful, 0 if not set or -1 on error |
7238 | | */ |
7239 | | int libewf_handle_get_segment_filename_wide( |
7240 | | libewf_handle_t *handle, |
7241 | | wchar_t *filename, |
7242 | | size_t filename_size, |
7243 | | libcerror_error_t **error ) |
7244 | | { |
7245 | | libewf_internal_handle_t *internal_handle = NULL; |
7246 | | static char *function = "libewf_handle_get_segment_filename_wide"; |
7247 | | int result = 0; |
7248 | | |
7249 | | if( handle == NULL ) |
7250 | | { |
7251 | | libcerror_error_set( |
7252 | | error, |
7253 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
7254 | | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
7255 | | "%s: invalid handle.", |
7256 | | function ); |
7257 | | |
7258 | | return( -1 ); |
7259 | | } |
7260 | | internal_handle = (libewf_internal_handle_t *) handle; |
7261 | | |
7262 | | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7263 | | if( libcthreads_read_write_lock_grab_for_read( |
7264 | | internal_handle->read_write_lock, |
7265 | | error ) != 1 ) |
7266 | | { |
7267 | | libcerror_error_set( |
7268 | | error, |
7269 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7270 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7271 | | "%s: unable to grab read/write lock for reading.", |
7272 | | function ); |
7273 | | |
7274 | | return( -1 ); |
7275 | | } |
7276 | | #endif |
7277 | | result = libewf_segment_table_get_basename_wide( |
7278 | | internal_handle->segment_table, |
7279 | | filename, |
7280 | | filename_size, |
7281 | | error ); |
7282 | | |
7283 | | if( result == -1 ) |
7284 | | { |
7285 | | libcerror_error_set( |
7286 | | error, |
7287 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7288 | | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
7289 | | "%s: unable to retrieve segment table basename.", |
7290 | | function ); |
7291 | | } |
7292 | | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7293 | | if( libcthreads_read_write_lock_release_for_read( |
7294 | | internal_handle->read_write_lock, |
7295 | | error ) != 1 ) |
7296 | | { |
7297 | | libcerror_error_set( |
7298 | | error, |
7299 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7300 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7301 | | "%s: unable to release read/write lock for reading.", |
7302 | | function ); |
7303 | | |
7304 | | return( -1 ); |
7305 | | } |
7306 | | #endif |
7307 | | return( result ); |
7308 | | } |
7309 | | |
7310 | | /* Sets the segment file |
7311 | | * Returns 1 if successful or -1 on error |
7312 | | */ |
7313 | | int libewf_handle_set_segment_filename_wide( |
7314 | | libewf_handle_t *handle, |
7315 | | const wchar_t *filename, |
7316 | | size_t filename_length, |
7317 | | libcerror_error_t **error ) |
7318 | | { |
7319 | | libewf_internal_handle_t *internal_handle = NULL; |
7320 | | static char *function = "libewf_handle_set_segment_filename_wide"; |
7321 | | int result = 0; |
7322 | | |
7323 | | if( handle == NULL ) |
7324 | | { |
7325 | | libcerror_error_set( |
7326 | | error, |
7327 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
7328 | | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
7329 | | "%s: invalid handle.", |
7330 | | function ); |
7331 | | |
7332 | | return( -1 ); |
7333 | | } |
7334 | | internal_handle = (libewf_internal_handle_t *) handle; |
7335 | | |
7336 | | if( internal_handle->write_io_handle == NULL ) |
7337 | | { |
7338 | | libcerror_error_set( |
7339 | | error, |
7340 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7341 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7342 | | "%s: segment filename cannot be changed.", |
7343 | | function ); |
7344 | | |
7345 | | return( -1 ); |
7346 | | } |
7347 | | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7348 | | if( libcthreads_read_write_lock_grab_for_write( |
7349 | | internal_handle->read_write_lock, |
7350 | | error ) != 1 ) |
7351 | | { |
7352 | | libcerror_error_set( |
7353 | | error, |
7354 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7355 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7356 | | "%s: unable to grab read/write lock for writing.", |
7357 | | function ); |
7358 | | |
7359 | | return( -1 ); |
7360 | | } |
7361 | | #endif |
7362 | | result = libewf_segment_table_set_basename_wide( |
7363 | | internal_handle->segment_table, |
7364 | | filename, |
7365 | | filename_length, |
7366 | | error ); |
7367 | | |
7368 | | if( result != 1 ) |
7369 | | { |
7370 | | libcerror_error_set( |
7371 | | error, |
7372 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7373 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7374 | | "%s: unable to set segment table basename.", |
7375 | | function ); |
7376 | | } |
7377 | | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7378 | | if( libcthreads_read_write_lock_release_for_write( |
7379 | | internal_handle->read_write_lock, |
7380 | | error ) != 1 ) |
7381 | | { |
7382 | | libcerror_error_set( |
7383 | | error, |
7384 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7385 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7386 | | "%s: unable to release read/write lock for writing.", |
7387 | | function ); |
7388 | | |
7389 | | return( -1 ); |
7390 | | } |
7391 | | #endif |
7392 | | return( result ); |
7393 | | } |
7394 | | |
7395 | | #endif /* defined( HAVE_WIDE_CHARACTER_TYPE ) */ |
7396 | | |
7397 | | /* Retrieves the maximum segment file size |
7398 | | * Returns 1 if successful or -1 on error |
7399 | | */ |
7400 | | int libewf_handle_get_maximum_segment_size( |
7401 | | libewf_handle_t *handle, |
7402 | | size64_t *maximum_segment_size, |
7403 | | libcerror_error_t **error ) |
7404 | 0 | { |
7405 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
7406 | 0 | static char *function = "libewf_handle_get_maximum_segment_size"; |
7407 | |
|
7408 | 0 | if( handle == NULL ) |
7409 | 0 | { |
7410 | 0 | libcerror_error_set( |
7411 | 0 | error, |
7412 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
7413 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
7414 | 0 | "%s: invalid handle.", |
7415 | 0 | function ); |
7416 | |
|
7417 | 0 | return( -1 ); |
7418 | 0 | } |
7419 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
7420 | |
|
7421 | 0 | if( internal_handle->segment_table == NULL ) |
7422 | 0 | { |
7423 | 0 | libcerror_error_set( |
7424 | 0 | error, |
7425 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7426 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
7427 | 0 | "%s: invalid handle - missing segment table.", |
7428 | 0 | function ); |
7429 | |
|
7430 | 0 | return( -1 ); |
7431 | 0 | } |
7432 | 0 | if( maximum_segment_size == NULL ) |
7433 | 0 | { |
7434 | 0 | libcerror_error_set( |
7435 | 0 | error, |
7436 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
7437 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
7438 | 0 | "%s: invalid maximum segment size.", |
7439 | 0 | function ); |
7440 | |
|
7441 | 0 | return( -1 ); |
7442 | 0 | } |
7443 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7444 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
7445 | 0 | internal_handle->read_write_lock, |
7446 | 0 | error ) != 1 ) |
7447 | 0 | { |
7448 | 0 | libcerror_error_set( |
7449 | 0 | error, |
7450 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7451 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7452 | 0 | "%s: unable to grab read/write lock for reading.", |
7453 | 0 | function ); |
7454 | |
|
7455 | 0 | return( -1 ); |
7456 | 0 | } |
7457 | 0 | #endif |
7458 | 0 | *maximum_segment_size = internal_handle->segment_table->maximum_segment_size; |
7459 | |
|
7460 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7461 | 0 | if( libcthreads_read_write_lock_release_for_read( |
7462 | 0 | internal_handle->read_write_lock, |
7463 | 0 | error ) != 1 ) |
7464 | 0 | { |
7465 | 0 | libcerror_error_set( |
7466 | 0 | error, |
7467 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7468 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7469 | 0 | "%s: unable to release read/write lock for reading.", |
7470 | 0 | function ); |
7471 | |
|
7472 | 0 | return( -1 ); |
7473 | 0 | } |
7474 | 0 | #endif |
7475 | 0 | return( 1 ); |
7476 | 0 | } |
7477 | | |
7478 | | /* Sets the maximum segment file size |
7479 | | * A maximum segment file size of 0 represents the maximum possible size for the format |
7480 | | * If the maximum segment file size is smaller than the size needed to store a single chunk |
7481 | | * the size off the latter is enforced and not the maximum segment file size |
7482 | | * Returns 1 if successful or -1 on error |
7483 | | */ |
7484 | | int libewf_handle_set_maximum_segment_size( |
7485 | | libewf_handle_t *handle, |
7486 | | size64_t maximum_segment_size, |
7487 | | libcerror_error_t **error ) |
7488 | 0 | { |
7489 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
7490 | 0 | static char *function = "libewf_handle_set_maximum_segment_size"; |
7491 | 0 | int result = 1; |
7492 | |
|
7493 | 0 | if( handle == NULL ) |
7494 | 0 | { |
7495 | 0 | libcerror_error_set( |
7496 | 0 | error, |
7497 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
7498 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
7499 | 0 | "%s: invalid handle.", |
7500 | 0 | function ); |
7501 | |
|
7502 | 0 | return( -1 ); |
7503 | 0 | } |
7504 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
7505 | |
|
7506 | 0 | if( internal_handle->media_values == NULL ) |
7507 | 0 | { |
7508 | 0 | libcerror_error_set( |
7509 | 0 | error, |
7510 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7511 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
7512 | 0 | "%s: invalid handle - missing media values.", |
7513 | 0 | function ); |
7514 | |
|
7515 | 0 | return( -1 ); |
7516 | 0 | } |
7517 | 0 | if( internal_handle->segment_table == NULL ) |
7518 | 0 | { |
7519 | 0 | libcerror_error_set( |
7520 | 0 | error, |
7521 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7522 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
7523 | 0 | "%s: invalid handle - missing segment table.", |
7524 | 0 | function ); |
7525 | |
|
7526 | 0 | return( -1 ); |
7527 | 0 | } |
7528 | 0 | if( maximum_segment_size > (size64_t) INT64_MAX ) |
7529 | 0 | { |
7530 | 0 | libcerror_error_set( |
7531 | 0 | error, |
7532 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
7533 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
7534 | 0 | "%s: invalid maximum segment size value exceeds maximum.", |
7535 | 0 | function ); |
7536 | |
|
7537 | 0 | return( -1 ); |
7538 | 0 | } |
7539 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7540 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
7541 | 0 | internal_handle->read_write_lock, |
7542 | 0 | error ) != 1 ) |
7543 | 0 | { |
7544 | 0 | libcerror_error_set( |
7545 | 0 | error, |
7546 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7547 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7548 | 0 | "%s: unable to grab read/write lock for writing.", |
7549 | 0 | function ); |
7550 | |
|
7551 | 0 | return( -1 ); |
7552 | 0 | } |
7553 | 0 | #endif |
7554 | 0 | if( ( internal_handle->read_io_handle != NULL ) |
7555 | 0 | || ( internal_handle->write_io_handle == NULL ) |
7556 | 0 | || ( internal_handle->write_io_handle->values_initialized != 0 ) ) |
7557 | 0 | { |
7558 | 0 | libcerror_error_set( |
7559 | 0 | error, |
7560 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7561 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7562 | 0 | "%s: maximum segment size cannot be changed.", |
7563 | 0 | function ); |
7564 | |
|
7565 | 0 | result = -1; |
7566 | 0 | } |
7567 | 0 | else if( maximum_segment_size > internal_handle->write_io_handle->maximum_segment_file_size ) |
7568 | 0 | { |
7569 | 0 | libcerror_error_set( |
7570 | 0 | error, |
7571 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7572 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
7573 | 0 | "%s: invalid segment file size value out of bounds.", |
7574 | 0 | function ); |
7575 | |
|
7576 | 0 | result = -1; |
7577 | 0 | } |
7578 | 0 | else |
7579 | 0 | { |
7580 | 0 | internal_handle->segment_table->maximum_segment_size = maximum_segment_size; |
7581 | 0 | } |
7582 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7583 | 0 | if( libcthreads_read_write_lock_release_for_write( |
7584 | 0 | internal_handle->read_write_lock, |
7585 | 0 | error ) != 1 ) |
7586 | 0 | { |
7587 | 0 | libcerror_error_set( |
7588 | 0 | error, |
7589 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7590 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7591 | 0 | "%s: unable to release read/write lock for writing.", |
7592 | 0 | function ); |
7593 | |
|
7594 | 0 | return( -1 ); |
7595 | 0 | } |
7596 | 0 | #endif |
7597 | 0 | return( result ); |
7598 | 0 | } |
7599 | | |
7600 | | /* Retrieves the filename size of the segment file of the current chunk |
7601 | | * The filename size should include the end of string character |
7602 | | * Returns 1 if successful, 0 if no such filename or -1 on error |
7603 | | */ |
7604 | | int libewf_handle_get_filename_size( |
7605 | | libewf_handle_t *handle, |
7606 | | size_t *filename_size, |
7607 | | libcerror_error_t **error ) |
7608 | 0 | { |
7609 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
7610 | 0 | libbfio_handle_t *file_io_handle = NULL; |
7611 | 0 | static char *function = "libewf_handle_get_filename_size"; |
7612 | 0 | int result = 0; |
7613 | |
|
7614 | 0 | if( handle == NULL ) |
7615 | 0 | { |
7616 | 0 | libcerror_error_set( |
7617 | 0 | error, |
7618 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
7619 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
7620 | 0 | "%s: invalid handle.", |
7621 | 0 | function ); |
7622 | |
|
7623 | 0 | return( -1 ); |
7624 | 0 | } |
7625 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
7626 | |
|
7627 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7628 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
7629 | 0 | internal_handle->read_write_lock, |
7630 | 0 | error ) != 1 ) |
7631 | 0 | { |
7632 | 0 | libcerror_error_set( |
7633 | 0 | error, |
7634 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7635 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7636 | 0 | "%s: unable to grab read/write lock for reading.", |
7637 | 0 | function ); |
7638 | |
|
7639 | 0 | return( -1 ); |
7640 | 0 | } |
7641 | 0 | #endif |
7642 | 0 | result = libewf_internal_handle_get_file_io_handle( |
7643 | 0 | internal_handle, |
7644 | 0 | &file_io_handle, |
7645 | 0 | error ); |
7646 | |
|
7647 | 0 | if( result == -1 ) |
7648 | 0 | { |
7649 | 0 | libcerror_error_set( |
7650 | 0 | error, |
7651 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7652 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
7653 | 0 | "%s: unable to retrieve file IO handle for current chunk.", |
7654 | 0 | function ); |
7655 | 0 | } |
7656 | 0 | else if( result != 0 ) |
7657 | 0 | { |
7658 | 0 | result = libbfio_file_get_name_size( |
7659 | 0 | file_io_handle, |
7660 | 0 | filename_size, |
7661 | 0 | error ); |
7662 | |
|
7663 | 0 | if( result != 1 ) |
7664 | 0 | { |
7665 | 0 | libcerror_error_set( |
7666 | 0 | error, |
7667 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7668 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
7669 | 0 | "%s: unable to retrieve filename size.", |
7670 | 0 | function ); |
7671 | 0 | } |
7672 | 0 | } |
7673 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7674 | 0 | if( libcthreads_read_write_lock_release_for_read( |
7675 | 0 | internal_handle->read_write_lock, |
7676 | 0 | error ) != 1 ) |
7677 | 0 | { |
7678 | 0 | libcerror_error_set( |
7679 | 0 | error, |
7680 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7681 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7682 | 0 | "%s: unable to release read/write lock for reading.", |
7683 | 0 | function ); |
7684 | |
|
7685 | 0 | return( -1 ); |
7686 | 0 | } |
7687 | 0 | #endif |
7688 | 0 | return( result ); |
7689 | 0 | } |
7690 | | |
7691 | | /* Retrieves the filename of the segment file of the current chunk |
7692 | | * The filename size should include the end of string character |
7693 | | * Returns 1 if successful, 0 if no such filename or -1 on error |
7694 | | */ |
7695 | | int libewf_handle_get_filename( |
7696 | | libewf_handle_t *handle, |
7697 | | char *filename, |
7698 | | size_t filename_size, |
7699 | | libcerror_error_t **error ) |
7700 | 0 | { |
7701 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
7702 | 0 | libbfio_handle_t *file_io_handle = NULL; |
7703 | 0 | static char *function = "libewf_handle_get_filename"; |
7704 | 0 | int result = 0; |
7705 | |
|
7706 | 0 | if( handle == NULL ) |
7707 | 0 | { |
7708 | 0 | libcerror_error_set( |
7709 | 0 | error, |
7710 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
7711 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
7712 | 0 | "%s: invalid handle.", |
7713 | 0 | function ); |
7714 | |
|
7715 | 0 | return( -1 ); |
7716 | 0 | } |
7717 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
7718 | |
|
7719 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7720 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
7721 | 0 | internal_handle->read_write_lock, |
7722 | 0 | error ) != 1 ) |
7723 | 0 | { |
7724 | 0 | libcerror_error_set( |
7725 | 0 | error, |
7726 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7727 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7728 | 0 | "%s: unable to grab read/write lock for reading.", |
7729 | 0 | function ); |
7730 | |
|
7731 | 0 | return( -1 ); |
7732 | 0 | } |
7733 | 0 | #endif |
7734 | 0 | result = libewf_internal_handle_get_file_io_handle( |
7735 | 0 | internal_handle, |
7736 | 0 | &file_io_handle, |
7737 | 0 | error ); |
7738 | |
|
7739 | 0 | if( result == -1 ) |
7740 | 0 | { |
7741 | 0 | libcerror_error_set( |
7742 | 0 | error, |
7743 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7744 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
7745 | 0 | "%s: unable to retrieve file IO handle for current chunk.", |
7746 | 0 | function ); |
7747 | 0 | } |
7748 | 0 | else if( result != 0 ) |
7749 | 0 | { |
7750 | 0 | result = libbfio_file_get_name( |
7751 | 0 | file_io_handle, |
7752 | 0 | filename, |
7753 | 0 | filename_size, |
7754 | 0 | error ); |
7755 | |
|
7756 | 0 | if( result != 1 ) |
7757 | 0 | { |
7758 | 0 | libcerror_error_set( |
7759 | 0 | error, |
7760 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7761 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
7762 | 0 | "%s: unable to retrieve filename.", |
7763 | 0 | function ); |
7764 | 0 | } |
7765 | 0 | } |
7766 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7767 | 0 | if( libcthreads_read_write_lock_release_for_read( |
7768 | 0 | internal_handle->read_write_lock, |
7769 | 0 | error ) != 1 ) |
7770 | 0 | { |
7771 | 0 | libcerror_error_set( |
7772 | 0 | error, |
7773 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7774 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7775 | 0 | "%s: unable to release read/write lock for reading.", |
7776 | 0 | function ); |
7777 | |
|
7778 | 0 | return( -1 ); |
7779 | 0 | } |
7780 | 0 | #endif |
7781 | 0 | return( result ); |
7782 | 0 | } |
7783 | | |
7784 | | #if defined( HAVE_WIDE_CHARACTER_TYPE ) |
7785 | | |
7786 | | /* Retrieves the filename size of the segment file of the current chunk |
7787 | | * The filename size includes the end of string character |
7788 | | * Returns 1 if successful, 0 if no such filename or -1 on error |
7789 | | */ |
7790 | | int libewf_handle_get_filename_size_wide( |
7791 | | libewf_handle_t *handle, |
7792 | | size_t *filename_size, |
7793 | | libcerror_error_t **error ) |
7794 | | { |
7795 | | libewf_internal_handle_t *internal_handle = NULL; |
7796 | | libbfio_handle_t *file_io_handle = NULL; |
7797 | | static char *function = "libewf_handle_get_filename_size_wide"; |
7798 | | int result = 0; |
7799 | | |
7800 | | if( handle == NULL ) |
7801 | | { |
7802 | | libcerror_error_set( |
7803 | | error, |
7804 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
7805 | | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
7806 | | "%s: invalid handle.", |
7807 | | function ); |
7808 | | |
7809 | | return( -1 ); |
7810 | | } |
7811 | | internal_handle = (libewf_internal_handle_t *) handle; |
7812 | | |
7813 | | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7814 | | if( libcthreads_read_write_lock_grab_for_read( |
7815 | | internal_handle->read_write_lock, |
7816 | | error ) != 1 ) |
7817 | | { |
7818 | | libcerror_error_set( |
7819 | | error, |
7820 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7821 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7822 | | "%s: unable to grab read/write lock for reading.", |
7823 | | function ); |
7824 | | |
7825 | | return( -1 ); |
7826 | | } |
7827 | | #endif |
7828 | | result = libewf_internal_handle_get_file_io_handle( |
7829 | | internal_handle, |
7830 | | &file_io_handle, |
7831 | | error ); |
7832 | | |
7833 | | if( result == -1 ) |
7834 | | { |
7835 | | libcerror_error_set( |
7836 | | error, |
7837 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7838 | | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
7839 | | "%s: unable to retrieve file IO handle for current chunk.", |
7840 | | function ); |
7841 | | } |
7842 | | else if( result != 0 ) |
7843 | | { |
7844 | | result = libbfio_file_get_name_size_wide( |
7845 | | file_io_handle, |
7846 | | filename_size, |
7847 | | error ); |
7848 | | |
7849 | | if( result != 1 ) |
7850 | | { |
7851 | | libcerror_error_set( |
7852 | | error, |
7853 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7854 | | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
7855 | | "%s: unable to retrieve filename size.", |
7856 | | function ); |
7857 | | } |
7858 | | } |
7859 | | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7860 | | if( libcthreads_read_write_lock_release_for_read( |
7861 | | internal_handle->read_write_lock, |
7862 | | error ) != 1 ) |
7863 | | { |
7864 | | libcerror_error_set( |
7865 | | error, |
7866 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7867 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7868 | | "%s: unable to release read/write lock for reading.", |
7869 | | function ); |
7870 | | |
7871 | | return( -1 ); |
7872 | | } |
7873 | | #endif |
7874 | | return( result ); |
7875 | | } |
7876 | | |
7877 | | /* Retrieves the filename of the segment file of the current chunk |
7878 | | * The filename size should include the end of string character |
7879 | | * Returns 1 if successful, 0 if no such filename or -1 on error |
7880 | | */ |
7881 | | int libewf_handle_get_filename_wide( |
7882 | | libewf_handle_t *handle, |
7883 | | wchar_t *filename, |
7884 | | size_t filename_size, |
7885 | | libcerror_error_t **error ) |
7886 | | { |
7887 | | libewf_internal_handle_t *internal_handle = NULL; |
7888 | | libbfio_handle_t *file_io_handle = NULL; |
7889 | | static char *function = "libewf_handle_get_filename_wide"; |
7890 | | int result = 0; |
7891 | | |
7892 | | if( handle == NULL ) |
7893 | | { |
7894 | | libcerror_error_set( |
7895 | | error, |
7896 | | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
7897 | | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
7898 | | "%s: invalid handle.", |
7899 | | function ); |
7900 | | |
7901 | | return( -1 ); |
7902 | | } |
7903 | | internal_handle = (libewf_internal_handle_t *) handle; |
7904 | | |
7905 | | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7906 | | if( libcthreads_read_write_lock_grab_for_read( |
7907 | | internal_handle->read_write_lock, |
7908 | | error ) != 1 ) |
7909 | | { |
7910 | | libcerror_error_set( |
7911 | | error, |
7912 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7913 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7914 | | "%s: unable to grab read/write lock for reading.", |
7915 | | function ); |
7916 | | |
7917 | | return( -1 ); |
7918 | | } |
7919 | | #endif |
7920 | | result = libewf_internal_handle_get_file_io_handle( |
7921 | | internal_handle, |
7922 | | &file_io_handle, |
7923 | | error ); |
7924 | | |
7925 | | if( result == -1 ) |
7926 | | { |
7927 | | libcerror_error_set( |
7928 | | error, |
7929 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7930 | | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
7931 | | "%s: unable to retrieve file IO handle for current chunk.", |
7932 | | function ); |
7933 | | } |
7934 | | else if( result != 0 ) |
7935 | | { |
7936 | | result = libbfio_file_get_name_wide( |
7937 | | file_io_handle, |
7938 | | filename, |
7939 | | filename_size, |
7940 | | error ); |
7941 | | |
7942 | | if( result != 1 ) |
7943 | | { |
7944 | | libcerror_error_set( |
7945 | | error, |
7946 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7947 | | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
7948 | | "%s: unable to retrieve filename.", |
7949 | | function ); |
7950 | | } |
7951 | | } |
7952 | | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
7953 | | if( libcthreads_read_write_lock_release_for_read( |
7954 | | internal_handle->read_write_lock, |
7955 | | error ) != 1 ) |
7956 | | { |
7957 | | libcerror_error_set( |
7958 | | error, |
7959 | | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
7960 | | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
7961 | | "%s: unable to release read/write lock for reading.", |
7962 | | function ); |
7963 | | |
7964 | | return( -1 ); |
7965 | | } |
7966 | | #endif |
7967 | | return( result ); |
7968 | | } |
7969 | | |
7970 | | #endif |
7971 | | |
7972 | | /* Retrieves the file IO handle of the segment file of the current chunk |
7973 | | * This function is not multi-thread safe acquire write lock before call |
7974 | | * Returns 1 if successful, 0 if no such file IO handle or -1 on error |
7975 | | */ |
7976 | | int libewf_internal_handle_get_file_io_handle( |
7977 | | libewf_internal_handle_t *internal_handle, |
7978 | | libbfio_handle_t **file_io_handle, |
7979 | | libcerror_error_t **error ) |
7980 | 0 | { |
7981 | 0 | static char *function = "libewf_internal_handle_get_file_io_handle"; |
7982 | 0 | size64_t segment_file_size = 0; |
7983 | 0 | uint64_t chunk_index = 0; |
7984 | 0 | int file_io_pool_entry = 0; |
7985 | 0 | int result = 0; |
7986 | |
|
7987 | 0 | if( internal_handle == NULL ) |
7988 | 0 | { |
7989 | 0 | libcerror_error_set( |
7990 | 0 | error, |
7991 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
7992 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
7993 | 0 | "%s: invalid handle.", |
7994 | 0 | function ); |
7995 | |
|
7996 | 0 | return( -1 ); |
7997 | 0 | } |
7998 | 0 | if( internal_handle->io_handle == NULL ) |
7999 | 0 | { |
8000 | 0 | libcerror_error_set( |
8001 | 0 | error, |
8002 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8003 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
8004 | 0 | "%s: invalid handle - missing IO handle.", |
8005 | 0 | function ); |
8006 | |
|
8007 | 0 | return( -1 ); |
8008 | 0 | } |
8009 | 0 | if( internal_handle->current_offset < 0 ) |
8010 | 0 | { |
8011 | 0 | libcerror_error_set( |
8012 | 0 | error, |
8013 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8014 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
8015 | 0 | "%s: invalid handle - invalid IO handle - current offset value out of bounds.", |
8016 | 0 | function ); |
8017 | |
|
8018 | 0 | return( -1 ); |
8019 | 0 | } |
8020 | 0 | if( internal_handle->media_values == NULL ) |
8021 | 0 | { |
8022 | 0 | libcerror_error_set( |
8023 | 0 | error, |
8024 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8025 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
8026 | 0 | "%s: invalid handle - missing media values.", |
8027 | 0 | function ); |
8028 | |
|
8029 | 0 | return( -1 ); |
8030 | 0 | } |
8031 | 0 | if( internal_handle->media_values->chunk_size == 0 ) |
8032 | 0 | { |
8033 | 0 | libcerror_error_set( |
8034 | 0 | error, |
8035 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8036 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
8037 | 0 | "%s: invalid handle - invalid media values - missing chunk size.", |
8038 | 0 | function ); |
8039 | |
|
8040 | 0 | return( -1 ); |
8041 | 0 | } |
8042 | 0 | chunk_index = internal_handle->current_offset / internal_handle->media_values->chunk_size; |
8043 | |
|
8044 | 0 | result = libewf_segment_table_get_segment_at_offset( |
8045 | 0 | internal_handle->segment_table, |
8046 | 0 | internal_handle->current_offset, |
8047 | 0 | &file_io_pool_entry, |
8048 | 0 | &segment_file_size, |
8049 | 0 | error ); |
8050 | |
|
8051 | 0 | if( result == -1 ) |
8052 | 0 | { |
8053 | 0 | libcerror_error_set( |
8054 | 0 | error, |
8055 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8056 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
8057 | 0 | "%s: unable to retrieve segment at offset: %" PRIi64 " (0x%08" PRIx64 ") from segment table.", |
8058 | 0 | function, |
8059 | 0 | internal_handle->current_offset, |
8060 | 0 | internal_handle->current_offset ); |
8061 | |
|
8062 | 0 | return( -1 ); |
8063 | 0 | } |
8064 | 0 | else if( result != 0 ) |
8065 | 0 | { |
8066 | 0 | if( file_io_pool_entry == -1 ) |
8067 | 0 | { |
8068 | 0 | return( 0 ); |
8069 | 0 | } |
8070 | 0 | if( libbfio_pool_get_handle( |
8071 | 0 | internal_handle->file_io_pool, |
8072 | 0 | file_io_pool_entry, |
8073 | 0 | file_io_handle, |
8074 | 0 | error ) != 1 ) |
8075 | 0 | { |
8076 | 0 | libcerror_error_set( |
8077 | 0 | error, |
8078 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8079 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
8080 | 0 | "%s: unable to retrieve file IO handle: %d from pool (chunk: %" PRIu64 ").", |
8081 | 0 | function, |
8082 | 0 | file_io_pool_entry, |
8083 | 0 | chunk_index ); |
8084 | |
|
8085 | 0 | return( -1 ); |
8086 | 0 | } |
8087 | 0 | } |
8088 | 0 | return( result ); |
8089 | 0 | } |
8090 | | |
8091 | | /* Retrieves the file IO handle of the segment file of the current chunk |
8092 | | * Returns 1 if successful, 0 if no such file IO handle or -1 on error |
8093 | | */ |
8094 | | int libewf_handle_get_file_io_handle( |
8095 | | libewf_handle_t *handle, |
8096 | | libbfio_handle_t **file_io_handle, |
8097 | | libcerror_error_t **error ) |
8098 | 0 | { |
8099 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
8100 | 0 | static char *function = "libewf_handle_get_file_io_handle"; |
8101 | 0 | int result = 0; |
8102 | |
|
8103 | 0 | if( handle == NULL ) |
8104 | 0 | { |
8105 | 0 | libcerror_error_set( |
8106 | 0 | error, |
8107 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
8108 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
8109 | 0 | "%s: invalid handle.", |
8110 | 0 | function ); |
8111 | |
|
8112 | 0 | return( -1 ); |
8113 | 0 | } |
8114 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
8115 | |
|
8116 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
8117 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
8118 | 0 | internal_handle->read_write_lock, |
8119 | 0 | error ) != 1 ) |
8120 | 0 | { |
8121 | 0 | libcerror_error_set( |
8122 | 0 | error, |
8123 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8124 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
8125 | 0 | "%s: unable to grab read/write lock for reading.", |
8126 | 0 | function ); |
8127 | |
|
8128 | 0 | return( -1 ); |
8129 | 0 | } |
8130 | 0 | #endif |
8131 | 0 | result = libewf_internal_handle_get_file_io_handle( |
8132 | 0 | internal_handle, |
8133 | 0 | file_io_handle, |
8134 | 0 | error ); |
8135 | |
|
8136 | 0 | if( result == -1 ) |
8137 | 0 | { |
8138 | 0 | libcerror_error_set( |
8139 | 0 | error, |
8140 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8141 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
8142 | 0 | "%s: unable to retrieve file IO handle for current chunk.", |
8143 | 0 | function ); |
8144 | 0 | } |
8145 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
8146 | 0 | if( libcthreads_read_write_lock_release_for_read( |
8147 | 0 | internal_handle->read_write_lock, |
8148 | 0 | error ) != 1 ) |
8149 | 0 | { |
8150 | 0 | libcerror_error_set( |
8151 | 0 | error, |
8152 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8153 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
8154 | 0 | "%s: unable to release read/write lock for reading.", |
8155 | 0 | function ); |
8156 | |
|
8157 | 0 | return( -1 ); |
8158 | 0 | } |
8159 | 0 | #endif |
8160 | 0 | return( result ); |
8161 | 0 | } |
8162 | | |
8163 | | /* Retrieves the media values |
8164 | | * Returns 1 if successful or -1 on error |
8165 | | */ |
8166 | | int libewf_internal_handle_get_media_values( |
8167 | | libewf_internal_handle_t *internal_handle, |
8168 | | size64_t *media_size, |
8169 | | libcerror_error_t **error ) |
8170 | 1.10k | { |
8171 | 1.10k | libewf_chunk_data_t *chunk_data = NULL; |
8172 | 1.10k | static char *function = "libewf_internal_handle_get_media_values"; |
8173 | 1.10k | size64_t chunks_data_size = 0; |
8174 | 1.10k | size64_t sector_data_size = 0; |
8175 | 1.10k | size32_t chunk_size = 0; |
8176 | 1.10k | off64_t chunk_data_offset = 0; |
8177 | 1.10k | uint64_t chunk_index = 0; |
8178 | | |
8179 | 1.10k | if( internal_handle == NULL ) |
8180 | 0 | { |
8181 | 0 | libcerror_error_set( |
8182 | 0 | error, |
8183 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
8184 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
8185 | 0 | "%s: invalid handle.", |
8186 | 0 | function ); |
8187 | |
|
8188 | 0 | return( -1 ); |
8189 | 0 | } |
8190 | 1.10k | if( internal_handle->media_values == NULL ) |
8191 | 0 | { |
8192 | 0 | libcerror_error_set( |
8193 | 0 | error, |
8194 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8195 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
8196 | 0 | "%s: invalid handle - missing media values.", |
8197 | 0 | function ); |
8198 | |
|
8199 | 0 | return( -1 ); |
8200 | 0 | } |
8201 | 1.10k | if( media_size == NULL ) |
8202 | 0 | { |
8203 | 0 | libcerror_error_set( |
8204 | 0 | error, |
8205 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
8206 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
8207 | 0 | "%s: invalid media size.", |
8208 | 0 | function ); |
8209 | |
|
8210 | 0 | return( -1 ); |
8211 | 0 | } |
8212 | 1.10k | sector_data_size = (size64_t) internal_handle->media_values->number_of_sectors * internal_handle->media_values->bytes_per_sector; |
8213 | | |
8214 | 1.10k | if( ( ( internal_handle->io_handle->access_flags & LIBEWF_ACCESS_FLAG_READ ) != 0 ) |
8215 | 1.10k | && ( ( internal_handle->io_handle->access_flags & LIBEWF_ACCESS_FLAG_RESUME ) == 0 ) ) |
8216 | 0 | { |
8217 | 0 | chunk_size = (size32_t) internal_handle->media_values->sectors_per_chunk * internal_handle->media_values->bytes_per_sector; |
8218 | |
|
8219 | 0 | if( internal_handle->media_values->number_of_chunks > 0 ) |
8220 | 0 | { |
8221 | 0 | internal_handle->current_offset = ( (off64_t) internal_handle->media_values->number_of_chunks - 1 ) * chunk_size; |
8222 | |
|
8223 | 0 | if( libewf_chunk_table_get_chunk_data_by_offset( |
8224 | 0 | internal_handle->chunk_table, |
8225 | 0 | internal_handle->io_handle, |
8226 | 0 | internal_handle->file_io_pool, |
8227 | 0 | internal_handle->media_values, |
8228 | 0 | internal_handle->segment_table, |
8229 | 0 | internal_handle->current_offset, |
8230 | 0 | &chunk_data_offset, |
8231 | 0 | &chunk_data, |
8232 | 0 | error ) != 1 ) |
8233 | 0 | { |
8234 | 0 | libcerror_error_set( |
8235 | 0 | error, |
8236 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8237 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
8238 | 0 | "%s: unable to retrieve chunk data for offset: %" PRIi64 " (0x%08" PRIx64 ").", |
8239 | 0 | function, |
8240 | 0 | internal_handle->current_offset, |
8241 | 0 | internal_handle->current_offset ); |
8242 | |
|
8243 | 0 | return( -1 ); |
8244 | 0 | } |
8245 | 0 | if( chunk_data == NULL ) |
8246 | 0 | { |
8247 | 0 | libcerror_error_set( |
8248 | 0 | error, |
8249 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8250 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
8251 | 0 | "%s: missing chunk data for offset: %" PRIi64 " (0x%08" PRIx64 ").", |
8252 | 0 | function, |
8253 | 0 | internal_handle->current_offset, |
8254 | 0 | internal_handle->current_offset ); |
8255 | |
|
8256 | 0 | return( -1 ); |
8257 | 0 | } |
8258 | | /* The only way to determine the size of the last compressed chunk is to unpack it |
8259 | | */ |
8260 | 0 | if( libewf_chunk_data_unpack( |
8261 | 0 | chunk_data, |
8262 | 0 | internal_handle->io_handle, |
8263 | 0 | error ) != 1 ) |
8264 | 0 | { |
8265 | 0 | libcerror_error_set( |
8266 | 0 | error, |
8267 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8268 | 0 | LIBCERROR_RUNTIME_ERROR_GENERIC, |
8269 | 0 | "%s: unable to unpack chunk: %" PRIu64 " data.", |
8270 | 0 | function, |
8271 | 0 | chunk_index ); |
8272 | |
|
8273 | 0 | return( -1 ); |
8274 | 0 | } |
8275 | 0 | chunks_data_size = chunk_index * chunk_size; |
8276 | |
|
8277 | 0 | if( ( chunk_data->range_flags & LIBEWF_RANGE_FLAG_IS_CORRUPTED ) == 0 ) |
8278 | 0 | { |
8279 | 0 | chunks_data_size += chunk_data->data_size; |
8280 | 0 | } |
8281 | 0 | if( sector_data_size != chunks_data_size ) |
8282 | 0 | { |
8283 | | #if defined( HAVE_VERBOSE_OUTPUT ) |
8284 | | if( libcnotify_verbose != 0 ) |
8285 | | { |
8286 | | libcnotify_printf( |
8287 | | "%s: mismatch of media data size in volume: %" PRIu64 " and chunk table: %" PRIu64 "\n", |
8288 | | function, |
8289 | | sector_data_size, |
8290 | | chunks_data_size ); |
8291 | | } |
8292 | | #endif |
8293 | 0 | if( sector_data_size < chunks_data_size ) |
8294 | 0 | { |
8295 | 0 | sector_data_size = chunks_data_size; |
8296 | 0 | } |
8297 | 0 | } |
8298 | 0 | } |
8299 | 0 | } |
8300 | 1.10k | *media_size = sector_data_size; |
8301 | | |
8302 | 1.10k | return( 1 ); |
8303 | 1.10k | } |
8304 | | |
8305 | | /* Sets the media values |
8306 | | * Returns 1 if successful or -1 on error |
8307 | | */ |
8308 | | int libewf_internal_handle_set_media_values( |
8309 | | libewf_internal_handle_t *internal_handle, |
8310 | | uint32_t sectors_per_chunk, |
8311 | | uint32_t bytes_per_sector, |
8312 | | size64_t media_size, |
8313 | | libcerror_error_t **error ) |
8314 | 0 | { |
8315 | 0 | static char *function = "libewf_internal_handle_set_media_values"; |
8316 | 0 | size32_t chunk_size = 0; |
8317 | 0 | size64_t maximum_input_file_size = 0; |
8318 | 0 | uint64_t number_of_chunks = 0; |
8319 | 0 | uint64_t number_of_sectors = 0; |
8320 | |
|
8321 | 0 | if( internal_handle == NULL ) |
8322 | 0 | { |
8323 | 0 | libcerror_error_set( |
8324 | 0 | error, |
8325 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
8326 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
8327 | 0 | "%s: invalid handle.", |
8328 | 0 | function ); |
8329 | |
|
8330 | 0 | return( -1 ); |
8331 | 0 | } |
8332 | 0 | if( internal_handle->media_values == NULL ) |
8333 | 0 | { |
8334 | 0 | libcerror_error_set( |
8335 | 0 | error, |
8336 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8337 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
8338 | 0 | "%s: invalid handle - missing media values.", |
8339 | 0 | function ); |
8340 | |
|
8341 | 0 | return( -1 ); |
8342 | 0 | } |
8343 | 0 | if( ( sectors_per_chunk == 0 ) |
8344 | 0 | || ( sectors_per_chunk > (uint32_t) INT32_MAX ) ) |
8345 | 0 | { |
8346 | 0 | libcerror_error_set( |
8347 | 0 | error, |
8348 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
8349 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
8350 | 0 | "%s: invalid sectors per chunk.", |
8351 | 0 | function ); |
8352 | |
|
8353 | 0 | return( -1 ); |
8354 | 0 | } |
8355 | 0 | if( ( bytes_per_sector == 0 ) |
8356 | 0 | || ( bytes_per_sector > (uint32_t) INT32_MAX ) ) |
8357 | 0 | { |
8358 | 0 | libcerror_error_set( |
8359 | 0 | error, |
8360 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
8361 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_OUT_OF_BOUNDS, |
8362 | 0 | "%s: invalid bytes per sector.", |
8363 | 0 | function ); |
8364 | |
|
8365 | 0 | return( -1 ); |
8366 | 0 | } |
8367 | 0 | if( media_size > (size64_t) INT64_MAX ) |
8368 | 0 | { |
8369 | 0 | libcerror_error_set( |
8370 | 0 | error, |
8371 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
8372 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
8373 | 0 | "%s: invalid media size value exceeds maximum.", |
8374 | 0 | function ); |
8375 | |
|
8376 | 0 | return( -1 ); |
8377 | 0 | } |
8378 | | /* Determine the chunk size |
8379 | | */ |
8380 | 0 | chunk_size = sectors_per_chunk * bytes_per_sector; |
8381 | |
|
8382 | 0 | if( ( chunk_size == 0 ) |
8383 | 0 | || ( chunk_size > (size32_t) INT32_MAX ) ) |
8384 | 0 | { |
8385 | 0 | libcerror_error_set( |
8386 | 0 | error, |
8387 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8388 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
8389 | 0 | "%s: invalid chunk size.", |
8390 | 0 | function ); |
8391 | |
|
8392 | 0 | return( -1 ); |
8393 | 0 | } |
8394 | | /* Check if the input file size does not exceed the maximum possible input file size |
8395 | | * for the chunk size |
8396 | | */ |
8397 | 0 | maximum_input_file_size = (size64_t) chunk_size * (size64_t) UINT32_MAX; |
8398 | |
|
8399 | 0 | if( media_size > maximum_input_file_size ) |
8400 | 0 | { |
8401 | 0 | libcerror_error_set( |
8402 | 0 | error, |
8403 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8404 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
8405 | 0 | "%s: media size cannot be larger than size: %" PRIu64 " with a chunk size of: %" PRIu32 ".", |
8406 | 0 | function, |
8407 | 0 | maximum_input_file_size, |
8408 | 0 | chunk_size ); |
8409 | |
|
8410 | 0 | return( -1 ); |
8411 | 0 | } |
8412 | 0 | internal_handle->media_values->sectors_per_chunk = sectors_per_chunk; |
8413 | 0 | internal_handle->media_values->bytes_per_sector = bytes_per_sector; |
8414 | 0 | internal_handle->media_values->chunk_size = chunk_size; |
8415 | 0 | internal_handle->media_values->media_size = media_size; |
8416 | | |
8417 | | /* If a media size was provided |
8418 | | */ |
8419 | 0 | if( media_size > 0 ) |
8420 | 0 | { |
8421 | | /* Determine the number of chunks to write |
8422 | | */ |
8423 | 0 | number_of_chunks = (uint64_t) media_size / (uint64_t) chunk_size; |
8424 | |
|
8425 | 0 | if( ( (uint64_t) media_size % (uint64_t) chunk_size ) != 0 ) |
8426 | 0 | { |
8427 | 0 | number_of_chunks += 1; |
8428 | 0 | } |
8429 | 0 | if( number_of_chunks > (uint64_t) UINT32_MAX ) |
8430 | 0 | { |
8431 | 0 | libcerror_error_set( |
8432 | 0 | error, |
8433 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8434 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
8435 | 0 | "%s: invalid number of chunks value exceeds maximum.", |
8436 | 0 | function ); |
8437 | |
|
8438 | 0 | return( -1 ); |
8439 | 0 | } |
8440 | 0 | internal_handle->media_values->number_of_chunks = (uint64_t) number_of_chunks; |
8441 | | |
8442 | | /* Determine the number of sectors to write |
8443 | | */ |
8444 | 0 | number_of_sectors = (uint64_t) media_size / (uint64_t) bytes_per_sector; |
8445 | |
|
8446 | 0 | if( number_of_sectors > (uint64_t) INT64_MAX ) |
8447 | 0 | { |
8448 | 0 | libcerror_error_set( |
8449 | 0 | error, |
8450 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8451 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
8452 | 0 | "%s: invalid number of sectors value exceeds maximum.", |
8453 | 0 | function ); |
8454 | |
|
8455 | 0 | return( -1 ); |
8456 | 0 | } |
8457 | 0 | internal_handle->media_values->number_of_sectors = number_of_sectors; |
8458 | 0 | } |
8459 | 0 | return( 1 ); |
8460 | 0 | } |
8461 | | |
8462 | | /* Retrieves the root (single) file entry |
8463 | | * Returns 1 if successful, 0 if no file entries are present or -1 on error |
8464 | | */ |
8465 | | int libewf_handle_get_root_file_entry( |
8466 | | libewf_handle_t *handle, |
8467 | | libewf_file_entry_t **root_file_entry, |
8468 | | libcerror_error_t **error ) |
8469 | 0 | { |
8470 | 0 | libcdata_tree_node_t *root_node = NULL; |
8471 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
8472 | 0 | static char *function = "libewf_handle_get_root_file_entry"; |
8473 | 0 | int result = 0; |
8474 | |
|
8475 | 0 | if( handle == NULL ) |
8476 | 0 | { |
8477 | 0 | libcerror_error_set( |
8478 | 0 | error, |
8479 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
8480 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
8481 | 0 | "%s: invalid handle.", |
8482 | 0 | function ); |
8483 | |
|
8484 | 0 | return( -1 ); |
8485 | 0 | } |
8486 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
8487 | |
|
8488 | 0 | if( internal_handle->single_files == NULL ) |
8489 | 0 | { |
8490 | 0 | libcerror_error_set( |
8491 | 0 | error, |
8492 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8493 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
8494 | 0 | "%s: invalid handle - missing single files.", |
8495 | 0 | function ); |
8496 | |
|
8497 | 0 | return( -1 ); |
8498 | 0 | } |
8499 | 0 | if( root_file_entry == NULL ) |
8500 | 0 | { |
8501 | 0 | libcerror_error_set( |
8502 | 0 | error, |
8503 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
8504 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
8505 | 0 | "%s: invalid root file entry.", |
8506 | 0 | function ); |
8507 | |
|
8508 | 0 | return( -1 ); |
8509 | 0 | } |
8510 | 0 | if( *root_file_entry != NULL ) |
8511 | 0 | { |
8512 | 0 | libcerror_error_set( |
8513 | 0 | error, |
8514 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8515 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
8516 | 0 | "%s: root file entry value already set.", |
8517 | 0 | function ); |
8518 | |
|
8519 | 0 | return( -1 ); |
8520 | 0 | } |
8521 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
8522 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
8523 | 0 | internal_handle->read_write_lock, |
8524 | 0 | error ) != 1 ) |
8525 | 0 | { |
8526 | 0 | libcerror_error_set( |
8527 | 0 | error, |
8528 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8529 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
8530 | 0 | "%s: unable to grab read/write lock for reading.", |
8531 | 0 | function ); |
8532 | |
|
8533 | 0 | return( -1 ); |
8534 | 0 | } |
8535 | 0 | #endif |
8536 | 0 | if( libewf_single_files_get_file_entry_tree_root_node( |
8537 | 0 | internal_handle->single_files, |
8538 | 0 | &root_node, |
8539 | 0 | error ) != 1 ) |
8540 | 0 | { |
8541 | 0 | libcerror_error_set( |
8542 | 0 | error, |
8543 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8544 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
8545 | 0 | "%s: unable to retrieve file entry tree root node.", |
8546 | 0 | function ); |
8547 | |
|
8548 | 0 | result = -1; |
8549 | 0 | } |
8550 | 0 | else if( root_node != NULL ) |
8551 | 0 | { |
8552 | 0 | result = libewf_file_entry_initialize( |
8553 | 0 | root_file_entry, |
8554 | 0 | handle, |
8555 | 0 | internal_handle->single_files, |
8556 | 0 | root_node, |
8557 | 0 | error ); |
8558 | |
|
8559 | 0 | if( result != 1 ) |
8560 | 0 | { |
8561 | 0 | libcerror_error_set( |
8562 | 0 | error, |
8563 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8564 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
8565 | 0 | "%s: unable to create root file entry.", |
8566 | 0 | function ); |
8567 | |
|
8568 | 0 | result = -1; |
8569 | 0 | } |
8570 | 0 | } |
8571 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
8572 | 0 | if( libcthreads_read_write_lock_release_for_read( |
8573 | 0 | internal_handle->read_write_lock, |
8574 | 0 | error ) != 1 ) |
8575 | 0 | { |
8576 | 0 | libcerror_error_set( |
8577 | 0 | error, |
8578 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8579 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
8580 | 0 | "%s: unable to release read/write lock for reading.", |
8581 | 0 | function ); |
8582 | |
|
8583 | 0 | return( -1 ); |
8584 | 0 | } |
8585 | 0 | #endif |
8586 | 0 | return( result ); |
8587 | 0 | } |
8588 | | |
8589 | | /* Retrieves the (single) file entry for the specific UTF-8 encoded path |
8590 | | * The path separator is the \ character |
8591 | | * This function is not multi-thread safe acquire write lock before call |
8592 | | * Returns 1 if successful, 0 if no such file entry or -1 on error |
8593 | | */ |
8594 | | int libewf_internal_handle_get_file_entry_by_utf8_path( |
8595 | | libewf_internal_handle_t *internal_handle, |
8596 | | const uint8_t *utf8_string, |
8597 | | size_t utf8_string_length, |
8598 | | libewf_file_entry_t **file_entry, |
8599 | | libcerror_error_t **error ) |
8600 | 0 | { |
8601 | 0 | libcdata_tree_node_t *node = NULL; |
8602 | 0 | libcdata_tree_node_t *root_node = NULL; |
8603 | 0 | libcdata_tree_node_t *sub_node = NULL; |
8604 | 0 | libewf_lef_file_entry_t *lef_file_entry = NULL; |
8605 | 0 | libewf_lef_file_entry_t *sub_lef_file_entry = NULL; |
8606 | 0 | uint8_t *utf8_string_segment = NULL; |
8607 | 0 | static char *function = "libewf_handle_get_file_entry_by_utf8_path"; |
8608 | 0 | size_t utf8_string_index = 0; |
8609 | 0 | size_t utf8_string_segment_length = 0; |
8610 | 0 | int result = 0; |
8611 | |
|
8612 | 0 | if( internal_handle == NULL ) |
8613 | 0 | { |
8614 | 0 | libcerror_error_set( |
8615 | 0 | error, |
8616 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
8617 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
8618 | 0 | "%s: invalid handle.", |
8619 | 0 | function ); |
8620 | |
|
8621 | 0 | return( -1 ); |
8622 | 0 | } |
8623 | 0 | if( internal_handle->single_files == NULL ) |
8624 | 0 | { |
8625 | 0 | libcerror_error_set( |
8626 | 0 | error, |
8627 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8628 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
8629 | 0 | "%s: invalid handle - missing single files.", |
8630 | 0 | function ); |
8631 | |
|
8632 | 0 | return( -1 ); |
8633 | 0 | } |
8634 | 0 | if( utf8_string == NULL ) |
8635 | 0 | { |
8636 | 0 | libcerror_error_set( |
8637 | 0 | error, |
8638 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
8639 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
8640 | 0 | "%s: invalid UTF-8 string.", |
8641 | 0 | function ); |
8642 | |
|
8643 | 0 | return( -1 ); |
8644 | 0 | } |
8645 | 0 | if( utf8_string_length > (size_t) SSIZE_MAX ) |
8646 | 0 | { |
8647 | 0 | libcerror_error_set( |
8648 | 0 | error, |
8649 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8650 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
8651 | 0 | "%s: invalid UTF-8 string length value exceeds maximum.", |
8652 | 0 | function ); |
8653 | |
|
8654 | 0 | return( -1 ); |
8655 | 0 | } |
8656 | 0 | if( file_entry == NULL ) |
8657 | 0 | { |
8658 | 0 | libcerror_error_set( |
8659 | 0 | error, |
8660 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
8661 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
8662 | 0 | "%s: invalid file entry.", |
8663 | 0 | function ); |
8664 | |
|
8665 | 0 | return( -1 ); |
8666 | 0 | } |
8667 | 0 | if( *file_entry != NULL ) |
8668 | 0 | { |
8669 | 0 | libcerror_error_set( |
8670 | 0 | error, |
8671 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8672 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
8673 | 0 | "%s: file entry value already set.", |
8674 | 0 | function ); |
8675 | |
|
8676 | 0 | return( -1 ); |
8677 | 0 | } |
8678 | 0 | if( libewf_single_files_get_file_entry_tree_root_node( |
8679 | 0 | internal_handle->single_files, |
8680 | 0 | &root_node, |
8681 | 0 | error ) != 1 ) |
8682 | 0 | { |
8683 | 0 | libcerror_error_set( |
8684 | 0 | error, |
8685 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8686 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
8687 | 0 | "%s: unable to retrieve file entry tree root node.", |
8688 | 0 | function ); |
8689 | |
|
8690 | 0 | result = -1; |
8691 | 0 | } |
8692 | 0 | else if( root_node == NULL ) |
8693 | 0 | { |
8694 | 0 | return( 0 ); |
8695 | 0 | } |
8696 | 0 | if( libcdata_tree_node_get_value( |
8697 | 0 | root_node, |
8698 | 0 | (intptr_t **) &lef_file_entry, |
8699 | 0 | error ) != 1 ) |
8700 | 0 | { |
8701 | 0 | libcerror_error_set( |
8702 | 0 | error, |
8703 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8704 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
8705 | 0 | "%s: unable to retrieve value from root file entry node.", |
8706 | 0 | function ); |
8707 | |
|
8708 | 0 | return( -1 ); |
8709 | 0 | } |
8710 | 0 | if( lef_file_entry == NULL ) |
8711 | 0 | { |
8712 | 0 | libcerror_error_set( |
8713 | 0 | error, |
8714 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8715 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
8716 | 0 | "%s: missing root file entry values.", |
8717 | 0 | function ); |
8718 | |
|
8719 | 0 | return( -1 ); |
8720 | 0 | } |
8721 | 0 | if( utf8_string_length > 0 ) |
8722 | 0 | { |
8723 | | /* Ignore a leading separator |
8724 | | */ |
8725 | 0 | if( utf8_string[ utf8_string_index ] == (uint8_t) LIBEWF_SEPARATOR ) |
8726 | 0 | { |
8727 | 0 | utf8_string_index++; |
8728 | 0 | } |
8729 | 0 | } |
8730 | 0 | node = root_node; |
8731 | |
|
8732 | 0 | if( ( utf8_string_length == 0 ) |
8733 | 0 | || ( utf8_string_length == 1 ) ) |
8734 | 0 | { |
8735 | 0 | result = 1; |
8736 | 0 | } |
8737 | 0 | else while( utf8_string_index < utf8_string_length ) |
8738 | 0 | { |
8739 | 0 | utf8_string_segment = (uint8_t *) &( utf8_string[ utf8_string_index ] ); |
8740 | 0 | utf8_string_segment_length = 0; |
8741 | |
|
8742 | 0 | while( utf8_string_index < utf8_string_length ) |
8743 | 0 | { |
8744 | 0 | if( ( utf8_string[ utf8_string_index ] == (uint8_t) LIBEWF_SEPARATOR ) |
8745 | 0 | || ( utf8_string[ utf8_string_index ] == (uint8_t) 0 ) ) |
8746 | 0 | { |
8747 | 0 | utf8_string_index++; |
8748 | |
|
8749 | 0 | break; |
8750 | 0 | } |
8751 | 0 | utf8_string_index++; |
8752 | |
|
8753 | 0 | utf8_string_segment_length++; |
8754 | 0 | } |
8755 | 0 | if( utf8_string_segment_length == 0 ) |
8756 | 0 | { |
8757 | 0 | libcerror_error_set( |
8758 | 0 | error, |
8759 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8760 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
8761 | 0 | "%s: missing sub file entry name.", |
8762 | 0 | function ); |
8763 | |
|
8764 | 0 | return( -1 ); |
8765 | 0 | } |
8766 | 0 | result = libewf_single_file_tree_get_sub_node_by_utf8_name( |
8767 | 0 | node, |
8768 | 0 | utf8_string_segment, |
8769 | 0 | utf8_string_segment_length, |
8770 | 0 | &sub_node, |
8771 | 0 | &sub_lef_file_entry, |
8772 | 0 | error ); |
8773 | |
|
8774 | 0 | if( result == -1 ) |
8775 | 0 | { |
8776 | 0 | libcerror_error_set( |
8777 | 0 | error, |
8778 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8779 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
8780 | 0 | "%s: unable to retrieve file entry sub node by name.", |
8781 | 0 | function ); |
8782 | |
|
8783 | 0 | return( -1 ); |
8784 | 0 | } |
8785 | 0 | else if( result == 0 ) |
8786 | 0 | { |
8787 | 0 | break; |
8788 | 0 | } |
8789 | 0 | node = sub_node; |
8790 | 0 | } |
8791 | 0 | if( result != 0 ) |
8792 | 0 | { |
8793 | 0 | if( libewf_file_entry_initialize( |
8794 | 0 | file_entry, |
8795 | 0 | (libewf_handle_t *) internal_handle, |
8796 | 0 | internal_handle->single_files, |
8797 | 0 | node, |
8798 | 0 | error ) != 1 ) |
8799 | 0 | { |
8800 | 0 | libcerror_error_set( |
8801 | 0 | error, |
8802 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8803 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
8804 | 0 | "%s: unable to create file entry.", |
8805 | 0 | function ); |
8806 | |
|
8807 | 0 | return( -1 ); |
8808 | 0 | } |
8809 | 0 | } |
8810 | 0 | return( result ); |
8811 | 0 | } |
8812 | | |
8813 | | /* Retrieves the (single) file entry for the specific UTF-8 encoded path |
8814 | | * The path separator is the \ character |
8815 | | * Returns 1 if successful, 0 if no such file entry or -1 on error |
8816 | | */ |
8817 | | int libewf_handle_get_file_entry_by_utf8_path( |
8818 | | libewf_handle_t *handle, |
8819 | | const uint8_t *utf8_string, |
8820 | | size_t utf8_string_length, |
8821 | | libewf_file_entry_t **file_entry, |
8822 | | libcerror_error_t **error ) |
8823 | 0 | { |
8824 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
8825 | 0 | static char *function = "libewf_handle_get_file_entry_by_utf8_path"; |
8826 | 0 | int result = 0; |
8827 | |
|
8828 | 0 | if( handle == NULL ) |
8829 | 0 | { |
8830 | 0 | libcerror_error_set( |
8831 | 0 | error, |
8832 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
8833 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
8834 | 0 | "%s: invalid handle.", |
8835 | 0 | function ); |
8836 | |
|
8837 | 0 | return( -1 ); |
8838 | 0 | } |
8839 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
8840 | |
|
8841 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
8842 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
8843 | 0 | internal_handle->read_write_lock, |
8844 | 0 | error ) != 1 ) |
8845 | 0 | { |
8846 | 0 | libcerror_error_set( |
8847 | 0 | error, |
8848 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8849 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
8850 | 0 | "%s: unable to grab read/write lock for reading.", |
8851 | 0 | function ); |
8852 | |
|
8853 | 0 | return( -1 ); |
8854 | 0 | } |
8855 | 0 | #endif |
8856 | 0 | result = libewf_internal_handle_get_file_entry_by_utf8_path( |
8857 | 0 | internal_handle, |
8858 | 0 | utf8_string, |
8859 | 0 | utf8_string_length, |
8860 | 0 | file_entry, |
8861 | 0 | error ); |
8862 | |
|
8863 | 0 | if( result == -1 ) |
8864 | 0 | { |
8865 | 0 | libcerror_error_set( |
8866 | 0 | error, |
8867 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8868 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
8869 | 0 | "%s: unable to retrieve file entry by UTF-8 path.", |
8870 | 0 | function ); |
8871 | 0 | } |
8872 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
8873 | 0 | if( libcthreads_read_write_lock_release_for_read( |
8874 | 0 | internal_handle->read_write_lock, |
8875 | 0 | error ) != 1 ) |
8876 | 0 | { |
8877 | 0 | libcerror_error_set( |
8878 | 0 | error, |
8879 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8880 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
8881 | 0 | "%s: unable to release read/write lock for reading.", |
8882 | 0 | function ); |
8883 | |
|
8884 | 0 | return( -1 ); |
8885 | 0 | } |
8886 | 0 | #endif |
8887 | 0 | return( result ); |
8888 | 0 | } |
8889 | | |
8890 | | /* Retrieves the (single) file entry for the specific UTF-16 encoded path |
8891 | | * The path separator is the \ character |
8892 | | * This function is not multi-thread safe acquire write lock before call |
8893 | | * Returns 1 if successful, 0 if no such file entry or -1 on error |
8894 | | */ |
8895 | | int libewf_internal_handle_get_file_entry_by_utf16_path( |
8896 | | libewf_internal_handle_t *internal_handle, |
8897 | | const uint16_t *utf16_string, |
8898 | | size_t utf16_string_length, |
8899 | | libewf_file_entry_t **file_entry, |
8900 | | libcerror_error_t **error ) |
8901 | 0 | { |
8902 | 0 | libcdata_tree_node_t *node = NULL; |
8903 | 0 | libcdata_tree_node_t *root_node = NULL; |
8904 | 0 | libcdata_tree_node_t *sub_node = NULL; |
8905 | 0 | libewf_lef_file_entry_t *lef_file_entry = NULL; |
8906 | 0 | libewf_lef_file_entry_t *sub_lef_file_entry = NULL; |
8907 | 0 | uint16_t *utf16_string_segment = NULL; |
8908 | 0 | static char *function = "libewf_handle_get_file_entry_by_utf16_path"; |
8909 | 0 | size_t utf16_string_index = 0; |
8910 | 0 | size_t utf16_string_segment_length = 0; |
8911 | 0 | int result = 0; |
8912 | |
|
8913 | 0 | if( internal_handle == NULL ) |
8914 | 0 | { |
8915 | 0 | libcerror_error_set( |
8916 | 0 | error, |
8917 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
8918 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
8919 | 0 | "%s: invalid handle.", |
8920 | 0 | function ); |
8921 | |
|
8922 | 0 | return( -1 ); |
8923 | 0 | } |
8924 | 0 | if( internal_handle->single_files == NULL ) |
8925 | 0 | { |
8926 | 0 | libcerror_error_set( |
8927 | 0 | error, |
8928 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8929 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
8930 | 0 | "%s: invalid handle - missing single files.", |
8931 | 0 | function ); |
8932 | |
|
8933 | 0 | return( -1 ); |
8934 | 0 | } |
8935 | 0 | if( utf16_string == NULL ) |
8936 | 0 | { |
8937 | 0 | libcerror_error_set( |
8938 | 0 | error, |
8939 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
8940 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
8941 | 0 | "%s: invalid UTF-16 string.", |
8942 | 0 | function ); |
8943 | |
|
8944 | 0 | return( -1 ); |
8945 | 0 | } |
8946 | 0 | if( utf16_string_length > (size_t) SSIZE_MAX ) |
8947 | 0 | { |
8948 | 0 | libcerror_error_set( |
8949 | 0 | error, |
8950 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8951 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
8952 | 0 | "%s: invalid UTF-16 string length value exceeds maximum.", |
8953 | 0 | function ); |
8954 | |
|
8955 | 0 | return( -1 ); |
8956 | 0 | } |
8957 | 0 | if( file_entry == NULL ) |
8958 | 0 | { |
8959 | 0 | libcerror_error_set( |
8960 | 0 | error, |
8961 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
8962 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
8963 | 0 | "%s: invalid file entry.", |
8964 | 0 | function ); |
8965 | |
|
8966 | 0 | return( -1 ); |
8967 | 0 | } |
8968 | 0 | if( *file_entry != NULL ) |
8969 | 0 | { |
8970 | 0 | libcerror_error_set( |
8971 | 0 | error, |
8972 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8973 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
8974 | 0 | "%s: file entry value already set.", |
8975 | 0 | function ); |
8976 | |
|
8977 | 0 | return( -1 ); |
8978 | 0 | } |
8979 | 0 | if( libewf_single_files_get_file_entry_tree_root_node( |
8980 | 0 | internal_handle->single_files, |
8981 | 0 | &root_node, |
8982 | 0 | error ) != 1 ) |
8983 | 0 | { |
8984 | 0 | libcerror_error_set( |
8985 | 0 | error, |
8986 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
8987 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
8988 | 0 | "%s: unable to retrieve file entry tree root node.", |
8989 | 0 | function ); |
8990 | |
|
8991 | 0 | result = -1; |
8992 | 0 | } |
8993 | 0 | else if( root_node == NULL ) |
8994 | 0 | { |
8995 | 0 | return( 0 ); |
8996 | 0 | } |
8997 | 0 | if( libcdata_tree_node_get_value( |
8998 | 0 | root_node, |
8999 | 0 | (intptr_t **) &lef_file_entry, |
9000 | 0 | error ) != 1 ) |
9001 | 0 | { |
9002 | 0 | libcerror_error_set( |
9003 | 0 | error, |
9004 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9005 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
9006 | 0 | "%s: unable to retrieve value from root file entry node.", |
9007 | 0 | function ); |
9008 | |
|
9009 | 0 | return( -1 ); |
9010 | 0 | } |
9011 | 0 | if( lef_file_entry == NULL ) |
9012 | 0 | { |
9013 | 0 | libcerror_error_set( |
9014 | 0 | error, |
9015 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9016 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
9017 | 0 | "%s: missing root file entry values.", |
9018 | 0 | function ); |
9019 | |
|
9020 | 0 | return( -1 ); |
9021 | 0 | } |
9022 | 0 | if( utf16_string_length > 0 ) |
9023 | 0 | { |
9024 | | /* Ignore a leading separator |
9025 | | */ |
9026 | 0 | if( utf16_string[ utf16_string_index ] == (uint16_t) LIBEWF_SEPARATOR ) |
9027 | 0 | { |
9028 | 0 | utf16_string_index++; |
9029 | 0 | } |
9030 | 0 | } |
9031 | 0 | node = root_node; |
9032 | |
|
9033 | 0 | if( ( utf16_string_length == 0 ) |
9034 | 0 | || ( utf16_string_length == 1 ) ) |
9035 | 0 | { |
9036 | 0 | result = 1; |
9037 | 0 | } |
9038 | 0 | else while( utf16_string_index < utf16_string_length ) |
9039 | 0 | { |
9040 | 0 | utf16_string_segment = (uint16_t *) &( utf16_string[ utf16_string_index ] ); |
9041 | 0 | utf16_string_segment_length = 0; |
9042 | |
|
9043 | 0 | while( utf16_string_index < utf16_string_length ) |
9044 | 0 | { |
9045 | 0 | if( ( utf16_string[ utf16_string_index ] == (uint16_t) LIBEWF_SEPARATOR ) |
9046 | 0 | || ( utf16_string[ utf16_string_index ] == (uint16_t) 0 ) ) |
9047 | 0 | { |
9048 | 0 | utf16_string_index++; |
9049 | |
|
9050 | 0 | break; |
9051 | 0 | } |
9052 | 0 | utf16_string_index++; |
9053 | |
|
9054 | 0 | utf16_string_segment_length++; |
9055 | 0 | } |
9056 | 0 | if( utf16_string_segment_length == 0 ) |
9057 | 0 | { |
9058 | 0 | libcerror_error_set( |
9059 | 0 | error, |
9060 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9061 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
9062 | 0 | "%s: missing sub file entry name.", |
9063 | 0 | function ); |
9064 | |
|
9065 | 0 | return( -1 ); |
9066 | 0 | } |
9067 | 0 | result = libewf_single_file_tree_get_sub_node_by_utf16_name( |
9068 | 0 | node, |
9069 | 0 | utf16_string_segment, |
9070 | 0 | utf16_string_segment_length, |
9071 | 0 | &sub_node, |
9072 | 0 | &sub_lef_file_entry, |
9073 | 0 | error ); |
9074 | |
|
9075 | 0 | if( result == -1 ) |
9076 | 0 | { |
9077 | 0 | libcerror_error_set( |
9078 | 0 | error, |
9079 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9080 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
9081 | 0 | "%s: unable to retrieve file entry sub node by name.", |
9082 | 0 | function ); |
9083 | |
|
9084 | 0 | return( -1 ); |
9085 | 0 | } |
9086 | 0 | else if( result == 0 ) |
9087 | 0 | { |
9088 | 0 | break; |
9089 | 0 | } |
9090 | 0 | node = sub_node; |
9091 | 0 | } |
9092 | 0 | if( result != 0 ) |
9093 | 0 | { |
9094 | 0 | if( libewf_file_entry_initialize( |
9095 | 0 | file_entry, |
9096 | 0 | (libewf_handle_t *) internal_handle, |
9097 | 0 | internal_handle->single_files, |
9098 | 0 | node, |
9099 | 0 | error ) != 1 ) |
9100 | 0 | { |
9101 | 0 | libcerror_error_set( |
9102 | 0 | error, |
9103 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9104 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
9105 | 0 | "%s: unable to create file entry.", |
9106 | 0 | function ); |
9107 | |
|
9108 | 0 | return( -1 ); |
9109 | 0 | } |
9110 | 0 | } |
9111 | 0 | return( result ); |
9112 | 0 | } |
9113 | | |
9114 | | /* Retrieves the (single) file entry for the specific UTF-16 encoded path |
9115 | | * The path separator is the \ character |
9116 | | * Returns 1 if successful, 0 if no such file entry or -1 on error |
9117 | | */ |
9118 | | int libewf_handle_get_file_entry_by_utf16_path( |
9119 | | libewf_handle_t *handle, |
9120 | | const uint16_t *utf16_string, |
9121 | | size_t utf16_string_length, |
9122 | | libewf_file_entry_t **file_entry, |
9123 | | libcerror_error_t **error ) |
9124 | 0 | { |
9125 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
9126 | 0 | static char *function = "libewf_handle_get_file_entry_by_utf16_path"; |
9127 | 0 | int result = 0; |
9128 | |
|
9129 | 0 | if( handle == NULL ) |
9130 | 0 | { |
9131 | 0 | libcerror_error_set( |
9132 | 0 | error, |
9133 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
9134 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
9135 | 0 | "%s: invalid handle.", |
9136 | 0 | function ); |
9137 | |
|
9138 | 0 | return( -1 ); |
9139 | 0 | } |
9140 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
9141 | |
|
9142 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9143 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
9144 | 0 | internal_handle->read_write_lock, |
9145 | 0 | error ) != 1 ) |
9146 | 0 | { |
9147 | 0 | libcerror_error_set( |
9148 | 0 | error, |
9149 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9150 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9151 | 0 | "%s: unable to grab read/write lock for reading.", |
9152 | 0 | function ); |
9153 | |
|
9154 | 0 | return( -1 ); |
9155 | 0 | } |
9156 | 0 | #endif |
9157 | 0 | result = libewf_internal_handle_get_file_entry_by_utf16_path( |
9158 | 0 | internal_handle, |
9159 | 0 | utf16_string, |
9160 | 0 | utf16_string_length, |
9161 | 0 | file_entry, |
9162 | 0 | error ); |
9163 | |
|
9164 | 0 | if( result == -1 ) |
9165 | 0 | { |
9166 | 0 | libcerror_error_set( |
9167 | 0 | error, |
9168 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9169 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
9170 | 0 | "%s: unable to retrieve file entry by UTF-16 path.", |
9171 | 0 | function ); |
9172 | 0 | } |
9173 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9174 | 0 | if( libcthreads_read_write_lock_release_for_read( |
9175 | 0 | internal_handle->read_write_lock, |
9176 | 0 | error ) != 1 ) |
9177 | 0 | { |
9178 | 0 | libcerror_error_set( |
9179 | 0 | error, |
9180 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9181 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9182 | 0 | "%s: unable to release read/write lock for reading.", |
9183 | 0 | function ); |
9184 | |
|
9185 | 0 | return( -1 ); |
9186 | 0 | } |
9187 | 0 | #endif |
9188 | 0 | return( result ); |
9189 | 0 | } |
9190 | | |
9191 | | /* Retrieves the number of sectors per chunk |
9192 | | * Returns 1 if successful or -1 on error |
9193 | | */ |
9194 | | int libewf_handle_get_sectors_per_chunk( |
9195 | | libewf_handle_t *handle, |
9196 | | uint32_t *sectors_per_chunk, |
9197 | | libcerror_error_t **error ) |
9198 | 0 | { |
9199 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
9200 | 0 | static char *function = "libewf_handle_get_sectors_per_chunk"; |
9201 | |
|
9202 | 0 | if( handle == NULL ) |
9203 | 0 | { |
9204 | 0 | libcerror_error_set( |
9205 | 0 | error, |
9206 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
9207 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
9208 | 0 | "%s: invalid handle.", |
9209 | 0 | function ); |
9210 | |
|
9211 | 0 | return( -1 ); |
9212 | 0 | } |
9213 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
9214 | |
|
9215 | 0 | if( internal_handle->media_values == NULL ) |
9216 | 0 | { |
9217 | 0 | libcerror_error_set( |
9218 | 0 | error, |
9219 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9220 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
9221 | 0 | "%s: invalid handle - missing media values.", |
9222 | 0 | function ); |
9223 | |
|
9224 | 0 | return( -1 ); |
9225 | 0 | } |
9226 | 0 | if( sectors_per_chunk == NULL ) |
9227 | 0 | { |
9228 | 0 | libcerror_error_set( |
9229 | 0 | error, |
9230 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
9231 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
9232 | 0 | "%s: invalid sectors per chunk.", |
9233 | 0 | function ); |
9234 | |
|
9235 | 0 | return( -1 ); |
9236 | 0 | } |
9237 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9238 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
9239 | 0 | internal_handle->read_write_lock, |
9240 | 0 | error ) != 1 ) |
9241 | 0 | { |
9242 | 0 | libcerror_error_set( |
9243 | 0 | error, |
9244 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9245 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9246 | 0 | "%s: unable to grab read/write lock for reading.", |
9247 | 0 | function ); |
9248 | |
|
9249 | 0 | return( -1 ); |
9250 | 0 | } |
9251 | 0 | #endif |
9252 | 0 | if( internal_handle->media_values->sectors_per_chunk > (uint32_t) INT32_MAX ) |
9253 | 0 | { |
9254 | 0 | libcerror_error_set( |
9255 | 0 | error, |
9256 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9257 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
9258 | 0 | "%s: invalid sectors per chunk value exceeds maximum.", |
9259 | 0 | function ); |
9260 | |
|
9261 | 0 | goto on_error; |
9262 | 0 | } |
9263 | 0 | *sectors_per_chunk = internal_handle->media_values->sectors_per_chunk; |
9264 | |
|
9265 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9266 | 0 | if( libcthreads_read_write_lock_release_for_read( |
9267 | 0 | internal_handle->read_write_lock, |
9268 | 0 | error ) != 1 ) |
9269 | 0 | { |
9270 | 0 | libcerror_error_set( |
9271 | 0 | error, |
9272 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9273 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9274 | 0 | "%s: unable to release read/write lock for reading.", |
9275 | 0 | function ); |
9276 | |
|
9277 | 0 | return( -1 ); |
9278 | 0 | } |
9279 | 0 | #endif |
9280 | 0 | return( 1 ); |
9281 | | |
9282 | 0 | on_error: |
9283 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9284 | 0 | libcthreads_read_write_lock_release_for_read( |
9285 | 0 | internal_handle->read_write_lock, |
9286 | 0 | NULL ); |
9287 | 0 | #endif |
9288 | 0 | return( -1 ); |
9289 | 0 | } |
9290 | | |
9291 | | /* Sets the number of sectors per chunk |
9292 | | * Returns 1 if successful or -1 on error |
9293 | | */ |
9294 | | int libewf_handle_set_sectors_per_chunk( |
9295 | | libewf_handle_t *handle, |
9296 | | uint32_t sectors_per_chunk, |
9297 | | libcerror_error_t **error ) |
9298 | 0 | { |
9299 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
9300 | 0 | static char *function = "libewf_handle_set_sectors_per_chunk"; |
9301 | |
|
9302 | 0 | if( handle == NULL ) |
9303 | 0 | { |
9304 | 0 | libcerror_error_set( |
9305 | 0 | error, |
9306 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
9307 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
9308 | 0 | "%s: invalid handle.", |
9309 | 0 | function ); |
9310 | |
|
9311 | 0 | return( -1 ); |
9312 | 0 | } |
9313 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
9314 | |
|
9315 | 0 | if( internal_handle->media_values == NULL ) |
9316 | 0 | { |
9317 | 0 | libcerror_error_set( |
9318 | 0 | error, |
9319 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9320 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
9321 | 0 | "%s: invalid handle - missing media values.", |
9322 | 0 | function ); |
9323 | |
|
9324 | 0 | return( -1 ); |
9325 | 0 | } |
9326 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9327 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
9328 | 0 | internal_handle->read_write_lock, |
9329 | 0 | error ) != 1 ) |
9330 | 0 | { |
9331 | 0 | libcerror_error_set( |
9332 | 0 | error, |
9333 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9334 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9335 | 0 | "%s: unable to grab read/write lock for writing.", |
9336 | 0 | function ); |
9337 | |
|
9338 | 0 | return( -1 ); |
9339 | 0 | } |
9340 | 0 | #endif |
9341 | 0 | if( ( internal_handle->read_io_handle != NULL ) |
9342 | 0 | || ( internal_handle->write_io_handle == NULL ) |
9343 | 0 | || ( internal_handle->write_io_handle->values_initialized != 0 ) ) |
9344 | 0 | { |
9345 | 0 | libcerror_error_set( |
9346 | 0 | error, |
9347 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9348 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9349 | 0 | "%s: sectors per chunk cannot be changed.", |
9350 | 0 | function ); |
9351 | |
|
9352 | 0 | goto on_error; |
9353 | 0 | } |
9354 | 0 | if( libewf_internal_handle_set_media_values( |
9355 | 0 | internal_handle, |
9356 | 0 | sectors_per_chunk, |
9357 | 0 | internal_handle->media_values->bytes_per_sector, |
9358 | 0 | internal_handle->media_values->media_size, |
9359 | 0 | error ) != 1 ) |
9360 | 0 | { |
9361 | 0 | libcerror_error_set( |
9362 | 0 | error, |
9363 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9364 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9365 | 0 | "%s: unable to set media values.", |
9366 | 0 | function ); |
9367 | |
|
9368 | 0 | goto on_error; |
9369 | 0 | } |
9370 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9371 | 0 | if( libcthreads_read_write_lock_release_for_write( |
9372 | 0 | internal_handle->read_write_lock, |
9373 | 0 | error ) != 1 ) |
9374 | 0 | { |
9375 | 0 | libcerror_error_set( |
9376 | 0 | error, |
9377 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9378 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9379 | 0 | "%s: unable to release read/write lock for writing.", |
9380 | 0 | function ); |
9381 | |
|
9382 | 0 | return( -1 ); |
9383 | 0 | } |
9384 | 0 | #endif |
9385 | 0 | return( 1 ); |
9386 | | |
9387 | 0 | on_error: |
9388 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9389 | 0 | libcthreads_read_write_lock_release_for_write( |
9390 | 0 | internal_handle->read_write_lock, |
9391 | 0 | NULL ); |
9392 | 0 | #endif |
9393 | 0 | return( -1 ); |
9394 | 0 | } |
9395 | | |
9396 | | /* Retrieves the number of bytes per sector |
9397 | | * Returns 1 if successful or -1 on error |
9398 | | */ |
9399 | | int libewf_handle_get_bytes_per_sector( |
9400 | | libewf_handle_t *handle, |
9401 | | uint32_t *bytes_per_sector, |
9402 | | libcerror_error_t **error ) |
9403 | 0 | { |
9404 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
9405 | 0 | static char *function = "libewf_handle_get_bytes_per_sector"; |
9406 | |
|
9407 | 0 | if( handle == NULL ) |
9408 | 0 | { |
9409 | 0 | libcerror_error_set( |
9410 | 0 | error, |
9411 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
9412 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
9413 | 0 | "%s: invalid handle.", |
9414 | 0 | function ); |
9415 | |
|
9416 | 0 | return( -1 ); |
9417 | 0 | } |
9418 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
9419 | |
|
9420 | 0 | if( internal_handle->media_values == NULL ) |
9421 | 0 | { |
9422 | 0 | libcerror_error_set( |
9423 | 0 | error, |
9424 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9425 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
9426 | 0 | "%s: invalid handle - missing media values.", |
9427 | 0 | function ); |
9428 | |
|
9429 | 0 | return( -1 ); |
9430 | 0 | } |
9431 | 0 | if( bytes_per_sector == NULL ) |
9432 | 0 | { |
9433 | 0 | libcerror_error_set( |
9434 | 0 | error, |
9435 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
9436 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
9437 | 0 | "%s: invalid bytes per sector.", |
9438 | 0 | function ); |
9439 | |
|
9440 | 0 | return( -1 ); |
9441 | 0 | } |
9442 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9443 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
9444 | 0 | internal_handle->read_write_lock, |
9445 | 0 | error ) != 1 ) |
9446 | 0 | { |
9447 | 0 | libcerror_error_set( |
9448 | 0 | error, |
9449 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9450 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9451 | 0 | "%s: unable to grab read/write lock for reading.", |
9452 | 0 | function ); |
9453 | |
|
9454 | 0 | return( -1 ); |
9455 | 0 | } |
9456 | 0 | #endif |
9457 | 0 | if( internal_handle->media_values->bytes_per_sector > (uint32_t) INT32_MAX ) |
9458 | 0 | { |
9459 | 0 | libcerror_error_set( |
9460 | 0 | error, |
9461 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9462 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
9463 | 0 | "%s: invalid bytes per sector value exceeds maximum.", |
9464 | 0 | function ); |
9465 | |
|
9466 | 0 | goto on_error; |
9467 | 0 | } |
9468 | 0 | *bytes_per_sector = internal_handle->media_values->bytes_per_sector; |
9469 | |
|
9470 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9471 | 0 | if( libcthreads_read_write_lock_release_for_read( |
9472 | 0 | internal_handle->read_write_lock, |
9473 | 0 | error ) != 1 ) |
9474 | 0 | { |
9475 | 0 | libcerror_error_set( |
9476 | 0 | error, |
9477 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9478 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9479 | 0 | "%s: unable to release read/write lock for reading.", |
9480 | 0 | function ); |
9481 | |
|
9482 | 0 | return( -1 ); |
9483 | 0 | } |
9484 | 0 | #endif |
9485 | 0 | return( 1 ); |
9486 | | |
9487 | 0 | on_error: |
9488 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9489 | 0 | libcthreads_read_write_lock_release_for_read( |
9490 | 0 | internal_handle->read_write_lock, |
9491 | 0 | NULL ); |
9492 | 0 | #endif |
9493 | 0 | return( -1 ); |
9494 | 0 | } |
9495 | | |
9496 | | /* Sets the number of bytes per sector |
9497 | | * Returns 1 if successful or -1 on error |
9498 | | */ |
9499 | | int libewf_handle_set_bytes_per_sector( |
9500 | | libewf_handle_t *handle, |
9501 | | uint32_t bytes_per_sector, |
9502 | | libcerror_error_t **error ) |
9503 | 0 | { |
9504 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
9505 | 0 | static char *function = "libewf_handle_set_bytes_per_sector"; |
9506 | |
|
9507 | 0 | if( handle == NULL ) |
9508 | 0 | { |
9509 | 0 | libcerror_error_set( |
9510 | 0 | error, |
9511 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
9512 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
9513 | 0 | "%s: invalid handle.", |
9514 | 0 | function ); |
9515 | |
|
9516 | 0 | return( -1 ); |
9517 | 0 | } |
9518 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
9519 | |
|
9520 | 0 | if( internal_handle->media_values == NULL ) |
9521 | 0 | { |
9522 | 0 | libcerror_error_set( |
9523 | 0 | error, |
9524 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9525 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
9526 | 0 | "%s: invalid handle - missing media values.", |
9527 | 0 | function ); |
9528 | |
|
9529 | 0 | return( -1 ); |
9530 | 0 | } |
9531 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9532 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
9533 | 0 | internal_handle->read_write_lock, |
9534 | 0 | error ) != 1 ) |
9535 | 0 | { |
9536 | 0 | libcerror_error_set( |
9537 | 0 | error, |
9538 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9539 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9540 | 0 | "%s: unable to grab read/write lock for writing.", |
9541 | 0 | function ); |
9542 | |
|
9543 | 0 | return( -1 ); |
9544 | 0 | } |
9545 | 0 | #endif |
9546 | 0 | if( ( internal_handle->read_io_handle != NULL ) |
9547 | 0 | || ( internal_handle->write_io_handle == NULL ) |
9548 | 0 | || ( internal_handle->write_io_handle->values_initialized != 0 ) ) |
9549 | 0 | { |
9550 | 0 | libcerror_error_set( |
9551 | 0 | error, |
9552 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9553 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9554 | 0 | "%s: bytes per sector cannot be changed.", |
9555 | 0 | function ); |
9556 | |
|
9557 | 0 | goto on_error; |
9558 | 0 | } |
9559 | 0 | if( libewf_internal_handle_set_media_values( |
9560 | 0 | internal_handle, |
9561 | 0 | internal_handle->media_values->sectors_per_chunk, |
9562 | 0 | bytes_per_sector, |
9563 | 0 | internal_handle->media_values->media_size, |
9564 | 0 | error ) != 1 ) |
9565 | 0 | { |
9566 | 0 | libcerror_error_set( |
9567 | 0 | error, |
9568 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9569 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9570 | 0 | "%s: unable to set media values.", |
9571 | 0 | function ); |
9572 | |
|
9573 | 0 | goto on_error; |
9574 | 0 | } |
9575 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9576 | 0 | if( libcthreads_read_write_lock_release_for_write( |
9577 | 0 | internal_handle->read_write_lock, |
9578 | 0 | error ) != 1 ) |
9579 | 0 | { |
9580 | 0 | libcerror_error_set( |
9581 | 0 | error, |
9582 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9583 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9584 | 0 | "%s: unable to release read/write lock for writing.", |
9585 | 0 | function ); |
9586 | |
|
9587 | 0 | return( -1 ); |
9588 | 0 | } |
9589 | 0 | #endif |
9590 | 0 | return( 1 ); |
9591 | | |
9592 | 0 | on_error: |
9593 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9594 | 0 | libcthreads_read_write_lock_release_for_write( |
9595 | 0 | internal_handle->read_write_lock, |
9596 | 0 | NULL ); |
9597 | 0 | #endif |
9598 | 0 | return( -1 ); |
9599 | 0 | } |
9600 | | |
9601 | | /* Retrieves the number of sectors |
9602 | | * Returns 1 if successful or -1 on error |
9603 | | */ |
9604 | | int libewf_handle_get_number_of_sectors( |
9605 | | libewf_handle_t *handle, |
9606 | | uint64_t *number_of_sectors, |
9607 | | libcerror_error_t **error ) |
9608 | 0 | { |
9609 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
9610 | 0 | static char *function = "libewf_handle_get_number_of_sectors"; |
9611 | |
|
9612 | 0 | if( handle == NULL ) |
9613 | 0 | { |
9614 | 0 | libcerror_error_set( |
9615 | 0 | error, |
9616 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
9617 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
9618 | 0 | "%s: invalid handle.", |
9619 | 0 | function ); |
9620 | |
|
9621 | 0 | return( -1 ); |
9622 | 0 | } |
9623 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
9624 | |
|
9625 | 0 | if( internal_handle->media_values == NULL ) |
9626 | 0 | { |
9627 | 0 | libcerror_error_set( |
9628 | 0 | error, |
9629 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9630 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
9631 | 0 | "%s: invalid handle - missing media values.", |
9632 | 0 | function ); |
9633 | |
|
9634 | 0 | return( -1 ); |
9635 | 0 | } |
9636 | 0 | if( number_of_sectors == NULL ) |
9637 | 0 | { |
9638 | 0 | libcerror_error_set( |
9639 | 0 | error, |
9640 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
9641 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
9642 | 0 | "%s: invalid bytes per sector.", |
9643 | 0 | function ); |
9644 | |
|
9645 | 0 | return( -1 ); |
9646 | 0 | } |
9647 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9648 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
9649 | 0 | internal_handle->read_write_lock, |
9650 | 0 | error ) != 1 ) |
9651 | 0 | { |
9652 | 0 | libcerror_error_set( |
9653 | 0 | error, |
9654 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9655 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9656 | 0 | "%s: unable to grab read/write lock for reading.", |
9657 | 0 | function ); |
9658 | |
|
9659 | 0 | return( -1 ); |
9660 | 0 | } |
9661 | 0 | #endif |
9662 | 0 | if( internal_handle->media_values->number_of_sectors > (uint64_t) INT64_MAX ) |
9663 | 0 | { |
9664 | 0 | libcerror_error_set( |
9665 | 0 | error, |
9666 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9667 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
9668 | 0 | "%s: invalid number of sectors value exceeds maximum.", |
9669 | 0 | function ); |
9670 | |
|
9671 | 0 | goto on_error; |
9672 | 0 | } |
9673 | 0 | *number_of_sectors = internal_handle->media_values->number_of_sectors; |
9674 | |
|
9675 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9676 | 0 | if( libcthreads_read_write_lock_release_for_read( |
9677 | 0 | internal_handle->read_write_lock, |
9678 | 0 | error ) != 1 ) |
9679 | 0 | { |
9680 | 0 | libcerror_error_set( |
9681 | 0 | error, |
9682 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9683 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9684 | 0 | "%s: unable to release read/write lock for reading.", |
9685 | 0 | function ); |
9686 | |
|
9687 | 0 | return( -1 ); |
9688 | 0 | } |
9689 | 0 | #endif |
9690 | 0 | return( 1 ); |
9691 | | |
9692 | 0 | on_error: |
9693 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9694 | 0 | libcthreads_read_write_lock_release_for_read( |
9695 | 0 | internal_handle->read_write_lock, |
9696 | 0 | NULL ); |
9697 | 0 | #endif |
9698 | 0 | return( -1 ); |
9699 | 0 | } |
9700 | | |
9701 | | /* Retrieves the chunk size |
9702 | | * Returns 1 if successful or -1 on error |
9703 | | */ |
9704 | | int libewf_handle_get_chunk_size( |
9705 | | libewf_handle_t *handle, |
9706 | | size32_t *chunk_size, |
9707 | | libcerror_error_t **error ) |
9708 | 0 | { |
9709 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
9710 | 0 | static char *function = "libewf_handle_get_chunk_size"; |
9711 | |
|
9712 | 0 | if( handle == NULL ) |
9713 | 0 | { |
9714 | 0 | libcerror_error_set( |
9715 | 0 | error, |
9716 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
9717 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
9718 | 0 | "%s: invalid handle.", |
9719 | 0 | function ); |
9720 | |
|
9721 | 0 | return( -1 ); |
9722 | 0 | } |
9723 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
9724 | |
|
9725 | 0 | if( internal_handle->media_values == NULL ) |
9726 | 0 | { |
9727 | 0 | libcerror_error_set( |
9728 | 0 | error, |
9729 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9730 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
9731 | 0 | "%s: invalid handle - missing media values.", |
9732 | 0 | function ); |
9733 | |
|
9734 | 0 | return( -1 ); |
9735 | 0 | } |
9736 | 0 | if( chunk_size == NULL ) |
9737 | 0 | { |
9738 | 0 | libcerror_error_set( |
9739 | 0 | error, |
9740 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
9741 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
9742 | 0 | "%s: invalid chunk size.", |
9743 | 0 | function ); |
9744 | |
|
9745 | 0 | return( -1 ); |
9746 | 0 | } |
9747 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9748 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
9749 | 0 | internal_handle->read_write_lock, |
9750 | 0 | error ) != 1 ) |
9751 | 0 | { |
9752 | 0 | libcerror_error_set( |
9753 | 0 | error, |
9754 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9755 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9756 | 0 | "%s: unable to grab read/write lock for reading.", |
9757 | 0 | function ); |
9758 | |
|
9759 | 0 | return( -1 ); |
9760 | 0 | } |
9761 | 0 | #endif |
9762 | 0 | if( internal_handle->media_values->chunk_size > (size32_t) INT32_MAX ) |
9763 | 0 | { |
9764 | 0 | libcerror_error_set( |
9765 | 0 | error, |
9766 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9767 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
9768 | 0 | "%s: invalid chunk size value exceeds maximum.", |
9769 | 0 | function ); |
9770 | |
|
9771 | 0 | goto on_error; |
9772 | 0 | } |
9773 | 0 | *chunk_size = internal_handle->media_values->chunk_size; |
9774 | |
|
9775 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9776 | 0 | if( libcthreads_read_write_lock_release_for_read( |
9777 | 0 | internal_handle->read_write_lock, |
9778 | 0 | error ) != 1 ) |
9779 | 0 | { |
9780 | 0 | libcerror_error_set( |
9781 | 0 | error, |
9782 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9783 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9784 | 0 | "%s: unable to release read/write lock for reading.", |
9785 | 0 | function ); |
9786 | |
|
9787 | 0 | return( -1 ); |
9788 | 0 | } |
9789 | 0 | #endif |
9790 | 0 | return( 1 ); |
9791 | | |
9792 | 0 | on_error: |
9793 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9794 | 0 | libcthreads_read_write_lock_release_for_read( |
9795 | 0 | internal_handle->read_write_lock, |
9796 | 0 | NULL ); |
9797 | 0 | #endif |
9798 | 0 | return( -1 ); |
9799 | 0 | } |
9800 | | |
9801 | | /* Retrieves the error granularity |
9802 | | * Returns 1 if successful or -1 on error |
9803 | | */ |
9804 | | int libewf_handle_get_error_granularity( |
9805 | | libewf_handle_t *handle, |
9806 | | uint32_t *error_granularity, |
9807 | | libcerror_error_t **error ) |
9808 | 0 | { |
9809 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
9810 | 0 | static char *function = "libewf_handle_get_error_granularity"; |
9811 | |
|
9812 | 0 | if( handle == NULL ) |
9813 | 0 | { |
9814 | 0 | libcerror_error_set( |
9815 | 0 | error, |
9816 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
9817 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
9818 | 0 | "%s: invalid handle.", |
9819 | 0 | function ); |
9820 | |
|
9821 | 0 | return( -1 ); |
9822 | 0 | } |
9823 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
9824 | |
|
9825 | 0 | if( internal_handle->media_values == NULL ) |
9826 | 0 | { |
9827 | 0 | libcerror_error_set( |
9828 | 0 | error, |
9829 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9830 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
9831 | 0 | "%s: invalid handle - missing media values.", |
9832 | 0 | function ); |
9833 | |
|
9834 | 0 | return( -1 ); |
9835 | 0 | } |
9836 | 0 | if( error_granularity == NULL ) |
9837 | 0 | { |
9838 | 0 | libcerror_error_set( |
9839 | 0 | error, |
9840 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
9841 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
9842 | 0 | "%s: invalid error granularity.", |
9843 | 0 | function ); |
9844 | |
|
9845 | 0 | return( -1 ); |
9846 | 0 | } |
9847 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9848 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
9849 | 0 | internal_handle->read_write_lock, |
9850 | 0 | error ) != 1 ) |
9851 | 0 | { |
9852 | 0 | libcerror_error_set( |
9853 | 0 | error, |
9854 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9855 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9856 | 0 | "%s: unable to grab read/write lock for reading.", |
9857 | 0 | function ); |
9858 | |
|
9859 | 0 | return( -1 ); |
9860 | 0 | } |
9861 | 0 | #endif |
9862 | 0 | if( internal_handle->media_values->error_granularity > (uint32_t) INT32_MAX ) |
9863 | 0 | { |
9864 | 0 | libcerror_error_set( |
9865 | 0 | error, |
9866 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9867 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
9868 | 0 | "%s: invalid error granularity value exceeds maximum.", |
9869 | 0 | function ); |
9870 | |
|
9871 | 0 | goto on_error; |
9872 | 0 | } |
9873 | 0 | *error_granularity = internal_handle->media_values->error_granularity; |
9874 | |
|
9875 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9876 | 0 | if( libcthreads_read_write_lock_release_for_read( |
9877 | 0 | internal_handle->read_write_lock, |
9878 | 0 | error ) != 1 ) |
9879 | 0 | { |
9880 | 0 | libcerror_error_set( |
9881 | 0 | error, |
9882 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9883 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9884 | 0 | "%s: unable to release read/write lock for reading.", |
9885 | 0 | function ); |
9886 | |
|
9887 | 0 | return( -1 ); |
9888 | 0 | } |
9889 | 0 | #endif |
9890 | 0 | return( 1 ); |
9891 | | |
9892 | 0 | on_error: |
9893 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9894 | 0 | libcthreads_read_write_lock_release_for_read( |
9895 | 0 | internal_handle->read_write_lock, |
9896 | 0 | NULL ); |
9897 | 0 | #endif |
9898 | 0 | return( -1 ); |
9899 | 0 | } |
9900 | | |
9901 | | /* Sets the error granularity |
9902 | | * Returns 1 if successful or -1 on error |
9903 | | */ |
9904 | | int libewf_handle_set_error_granularity( |
9905 | | libewf_handle_t *handle, |
9906 | | uint32_t error_granularity, |
9907 | | libcerror_error_t **error ) |
9908 | 0 | { |
9909 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
9910 | 0 | static char *function = "libewf_handle_set_error_granularity"; |
9911 | |
|
9912 | 0 | if( handle == NULL ) |
9913 | 0 | { |
9914 | 0 | libcerror_error_set( |
9915 | 0 | error, |
9916 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
9917 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
9918 | 0 | "%s: invalid handle.", |
9919 | 0 | function ); |
9920 | |
|
9921 | 0 | return( -1 ); |
9922 | 0 | } |
9923 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
9924 | |
|
9925 | 0 | if( internal_handle->media_values == NULL ) |
9926 | 0 | { |
9927 | 0 | libcerror_error_set( |
9928 | 0 | error, |
9929 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9930 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
9931 | 0 | "%s: invalid handle - missing media values.", |
9932 | 0 | function ); |
9933 | |
|
9934 | 0 | return( -1 ); |
9935 | 0 | } |
9936 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9937 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
9938 | 0 | internal_handle->read_write_lock, |
9939 | 0 | error ) != 1 ) |
9940 | 0 | { |
9941 | 0 | libcerror_error_set( |
9942 | 0 | error, |
9943 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9944 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9945 | 0 | "%s: unable to grab read/write lock for writing.", |
9946 | 0 | function ); |
9947 | |
|
9948 | 0 | return( -1 ); |
9949 | 0 | } |
9950 | 0 | #endif |
9951 | 0 | if( ( internal_handle->write_io_handle == NULL ) |
9952 | 0 | || ( internal_handle->write_io_handle->values_initialized != 0 ) ) |
9953 | 0 | { |
9954 | 0 | libcerror_error_set( |
9955 | 0 | error, |
9956 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9957 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9958 | 0 | "%s: error granularity cannot be changed.", |
9959 | 0 | function ); |
9960 | |
|
9961 | 0 | goto on_error; |
9962 | 0 | } |
9963 | 0 | internal_handle->media_values->error_granularity = error_granularity; |
9964 | |
|
9965 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9966 | 0 | if( libcthreads_read_write_lock_release_for_write( |
9967 | 0 | internal_handle->read_write_lock, |
9968 | 0 | error ) != 1 ) |
9969 | 0 | { |
9970 | 0 | libcerror_error_set( |
9971 | 0 | error, |
9972 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
9973 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
9974 | 0 | "%s: unable to release read/write lock for writing.", |
9975 | 0 | function ); |
9976 | |
|
9977 | 0 | return( -1 ); |
9978 | 0 | } |
9979 | 0 | #endif |
9980 | 0 | return( 1 ); |
9981 | | |
9982 | 0 | on_error: |
9983 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
9984 | 0 | libcthreads_read_write_lock_release_for_write( |
9985 | 0 | internal_handle->read_write_lock, |
9986 | 0 | NULL ); |
9987 | 0 | #endif |
9988 | 0 | return( -1 ); |
9989 | 0 | } |
9990 | | |
9991 | | /* Retrieves the compression method |
9992 | | * Returns 1 if successful or -1 on error |
9993 | | */ |
9994 | | int libewf_handle_get_compression_method( |
9995 | | libewf_handle_t *handle, |
9996 | | uint16_t *compression_method, |
9997 | | libcerror_error_t **error ) |
9998 | 0 | { |
9999 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
10000 | 0 | static char *function = "libewf_handle_get_compression_method"; |
10001 | |
|
10002 | 0 | if( handle == NULL ) |
10003 | 0 | { |
10004 | 0 | libcerror_error_set( |
10005 | 0 | error, |
10006 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
10007 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
10008 | 0 | "%s: invalid handle.", |
10009 | 0 | function ); |
10010 | |
|
10011 | 0 | return( -1 ); |
10012 | 0 | } |
10013 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
10014 | |
|
10015 | 0 | if( internal_handle->io_handle == NULL ) |
10016 | 0 | { |
10017 | 0 | libcerror_error_set( |
10018 | 0 | error, |
10019 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10020 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
10021 | 0 | "%s: invalid handle - missing IO handle.", |
10022 | 0 | function ); |
10023 | |
|
10024 | 0 | return( -1 ); |
10025 | 0 | } |
10026 | 0 | if( compression_method == NULL ) |
10027 | 0 | { |
10028 | 0 | libcerror_error_set( |
10029 | 0 | error, |
10030 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
10031 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
10032 | 0 | "%s: invalid compression method.", |
10033 | 0 | function ); |
10034 | |
|
10035 | 0 | return( -1 ); |
10036 | 0 | } |
10037 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10038 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
10039 | 0 | internal_handle->read_write_lock, |
10040 | 0 | error ) != 1 ) |
10041 | 0 | { |
10042 | 0 | libcerror_error_set( |
10043 | 0 | error, |
10044 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10045 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10046 | 0 | "%s: unable to grab read/write lock for reading.", |
10047 | 0 | function ); |
10048 | |
|
10049 | 0 | return( -1 ); |
10050 | 0 | } |
10051 | 0 | #endif |
10052 | 0 | *compression_method = internal_handle->io_handle->compression_method; |
10053 | |
|
10054 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10055 | 0 | if( libcthreads_read_write_lock_release_for_read( |
10056 | 0 | internal_handle->read_write_lock, |
10057 | 0 | error ) != 1 ) |
10058 | 0 | { |
10059 | 0 | libcerror_error_set( |
10060 | 0 | error, |
10061 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10062 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10063 | 0 | "%s: unable to release read/write lock for reading.", |
10064 | 0 | function ); |
10065 | |
|
10066 | 0 | return( -1 ); |
10067 | 0 | } |
10068 | 0 | #endif |
10069 | 0 | return( 1 ); |
10070 | 0 | } |
10071 | | |
10072 | | /* Sets the compression method |
10073 | | * Returns 1 if successful or -1 on error |
10074 | | */ |
10075 | | int libewf_handle_set_compression_method( |
10076 | | libewf_handle_t *handle, |
10077 | | uint16_t compression_method, |
10078 | | libcerror_error_t **error ) |
10079 | 0 | { |
10080 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
10081 | 0 | static char *function = "libewf_handle_set_compression_method"; |
10082 | |
|
10083 | 0 | if( handle == NULL ) |
10084 | 0 | { |
10085 | 0 | libcerror_error_set( |
10086 | 0 | error, |
10087 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
10088 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
10089 | 0 | "%s: invalid handle.", |
10090 | 0 | function ); |
10091 | |
|
10092 | 0 | return( -1 ); |
10093 | 0 | } |
10094 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
10095 | |
|
10096 | 0 | if( internal_handle->io_handle == NULL ) |
10097 | 0 | { |
10098 | 0 | libcerror_error_set( |
10099 | 0 | error, |
10100 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10101 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
10102 | 0 | "%s: invalid handle - missing IO handle.", |
10103 | 0 | function ); |
10104 | |
|
10105 | 0 | return( -1 ); |
10106 | 0 | } |
10107 | 0 | if( ( compression_method != LIBEWF_COMPRESSION_METHOD_DEFLATE ) |
10108 | 0 | && ( compression_method != LIBEWF_COMPRESSION_METHOD_BZIP2 ) ) |
10109 | 0 | { |
10110 | 0 | libcerror_error_set( |
10111 | 0 | error, |
10112 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
10113 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
10114 | 0 | "%s: unsupported compression method.", |
10115 | 0 | function ); |
10116 | |
|
10117 | 0 | return( -1 ); |
10118 | 0 | } |
10119 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10120 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
10121 | 0 | internal_handle->read_write_lock, |
10122 | 0 | error ) != 1 ) |
10123 | 0 | { |
10124 | 0 | libcerror_error_set( |
10125 | 0 | error, |
10126 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10127 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10128 | 0 | "%s: unable to grab read/write lock for writing.", |
10129 | 0 | function ); |
10130 | |
|
10131 | 0 | return( -1 ); |
10132 | 0 | } |
10133 | 0 | #endif |
10134 | 0 | if( ( internal_handle->write_io_handle == NULL ) |
10135 | 0 | || ( internal_handle->write_io_handle->values_initialized != 0 ) ) |
10136 | 0 | { |
10137 | 0 | libcerror_error_set( |
10138 | 0 | error, |
10139 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10140 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10141 | 0 | "%s: compression values cannot be changed.", |
10142 | 0 | function ); |
10143 | |
|
10144 | 0 | goto on_error; |
10145 | 0 | } |
10146 | 0 | if( ( compression_method == LIBEWF_COMPRESSION_METHOD_BZIP2 ) |
10147 | 0 | && ( internal_handle->io_handle->segment_file_type != LIBEWF_SEGMENT_FILE_TYPE_EWF2 ) |
10148 | 0 | && ( internal_handle->io_handle->segment_file_type != LIBEWF_SEGMENT_FILE_TYPE_EWF2_LOGICAL ) ) |
10149 | 0 | { |
10150 | 0 | libcerror_error_set( |
10151 | 0 | error, |
10152 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10153 | 0 | LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, |
10154 | 0 | "%s: compression method not supported by format.", |
10155 | 0 | function ); |
10156 | |
|
10157 | 0 | goto on_error; |
10158 | 0 | } |
10159 | 0 | internal_handle->io_handle->compression_method = compression_method; |
10160 | |
|
10161 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10162 | 0 | if( libcthreads_read_write_lock_release_for_write( |
10163 | 0 | internal_handle->read_write_lock, |
10164 | 0 | error ) != 1 ) |
10165 | 0 | { |
10166 | 0 | libcerror_error_set( |
10167 | 0 | error, |
10168 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10169 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10170 | 0 | "%s: unable to release read/write lock for writing.", |
10171 | 0 | function ); |
10172 | |
|
10173 | 0 | return( -1 ); |
10174 | 0 | } |
10175 | 0 | #endif |
10176 | 0 | return( 1 ); |
10177 | | |
10178 | 0 | on_error: |
10179 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10180 | 0 | libcthreads_read_write_lock_release_for_write( |
10181 | 0 | internal_handle->read_write_lock, |
10182 | 0 | NULL ); |
10183 | 0 | #endif |
10184 | 0 | return( -1 ); |
10185 | 0 | } |
10186 | | |
10187 | | /* Retrieves the compression values |
10188 | | * Returns 1 if successful or -1 on error |
10189 | | */ |
10190 | | int libewf_handle_get_compression_values( |
10191 | | libewf_handle_t *handle, |
10192 | | int8_t *compression_level, |
10193 | | uint8_t *compression_flags, |
10194 | | libcerror_error_t **error ) |
10195 | 0 | { |
10196 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
10197 | 0 | static char *function = "libewf_handle_get_compression_values"; |
10198 | |
|
10199 | 0 | if( handle == NULL ) |
10200 | 0 | { |
10201 | 0 | libcerror_error_set( |
10202 | 0 | error, |
10203 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
10204 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
10205 | 0 | "%s: invalid handle.", |
10206 | 0 | function ); |
10207 | |
|
10208 | 0 | return( -1 ); |
10209 | 0 | } |
10210 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
10211 | |
|
10212 | 0 | if( internal_handle->io_handle == NULL ) |
10213 | 0 | { |
10214 | 0 | libcerror_error_set( |
10215 | 0 | error, |
10216 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10217 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
10218 | 0 | "%s: invalid handle - missing IO handle.", |
10219 | 0 | function ); |
10220 | |
|
10221 | 0 | return( -1 ); |
10222 | 0 | } |
10223 | 0 | if( compression_level == NULL ) |
10224 | 0 | { |
10225 | 0 | libcerror_error_set( |
10226 | 0 | error, |
10227 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
10228 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
10229 | 0 | "%s: invalid compression level.", |
10230 | 0 | function ); |
10231 | |
|
10232 | 0 | return( -1 ); |
10233 | 0 | } |
10234 | 0 | if( compression_flags == NULL ) |
10235 | 0 | { |
10236 | 0 | libcerror_error_set( |
10237 | 0 | error, |
10238 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
10239 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
10240 | 0 | "%s: invalid compression flags.", |
10241 | 0 | function ); |
10242 | |
|
10243 | 0 | return( -1 ); |
10244 | 0 | } |
10245 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10246 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
10247 | 0 | internal_handle->read_write_lock, |
10248 | 0 | error ) != 1 ) |
10249 | 0 | { |
10250 | 0 | libcerror_error_set( |
10251 | 0 | error, |
10252 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10253 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10254 | 0 | "%s: unable to grab read/write lock for reading.", |
10255 | 0 | function ); |
10256 | |
|
10257 | 0 | return( -1 ); |
10258 | 0 | } |
10259 | 0 | #endif |
10260 | 0 | *compression_level = internal_handle->io_handle->compression_level; |
10261 | 0 | *compression_flags = internal_handle->io_handle->compression_flags; |
10262 | |
|
10263 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10264 | 0 | if( libcthreads_read_write_lock_release_for_read( |
10265 | 0 | internal_handle->read_write_lock, |
10266 | 0 | error ) != 1 ) |
10267 | 0 | { |
10268 | 0 | libcerror_error_set( |
10269 | 0 | error, |
10270 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10271 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10272 | 0 | "%s: unable to release read/write lock for reading.", |
10273 | 0 | function ); |
10274 | |
|
10275 | 0 | return( -1 ); |
10276 | 0 | } |
10277 | 0 | #endif |
10278 | 0 | return( 1 ); |
10279 | 0 | } |
10280 | | |
10281 | | /* Sets the compression values |
10282 | | * Returns 1 if successful or -1 on error |
10283 | | */ |
10284 | | int libewf_handle_set_compression_values( |
10285 | | libewf_handle_t *handle, |
10286 | | int8_t compression_level, |
10287 | | uint8_t compression_flags, |
10288 | | libcerror_error_t **error ) |
10289 | 0 | { |
10290 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
10291 | 0 | static char *function = "libewf_handle_set_compression_values"; |
10292 | |
|
10293 | 0 | if( handle == NULL ) |
10294 | 0 | { |
10295 | 0 | libcerror_error_set( |
10296 | 0 | error, |
10297 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
10298 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
10299 | 0 | "%s: invalid handle.", |
10300 | 0 | function ); |
10301 | |
|
10302 | 0 | return( -1 ); |
10303 | 0 | } |
10304 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
10305 | |
|
10306 | 0 | if( internal_handle->io_handle == NULL ) |
10307 | 0 | { |
10308 | 0 | libcerror_error_set( |
10309 | 0 | error, |
10310 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10311 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
10312 | 0 | "%s: invalid handle - missing IO handle.", |
10313 | 0 | function ); |
10314 | |
|
10315 | 0 | return( -1 ); |
10316 | 0 | } |
10317 | 0 | if( ( compression_level != LIBEWF_COMPRESSION_LEVEL_NONE ) |
10318 | 0 | && ( compression_level != LIBEWF_COMPRESSION_LEVEL_FAST ) |
10319 | 0 | && ( compression_level != LIBEWF_COMPRESSION_LEVEL_BEST ) ) |
10320 | 0 | { |
10321 | 0 | libcerror_error_set( |
10322 | 0 | error, |
10323 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
10324 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
10325 | 0 | "%s: unsupported compression level.", |
10326 | 0 | function ); |
10327 | |
|
10328 | 0 | return( -1 ); |
10329 | 0 | } |
10330 | 0 | if( ( compression_flags & ~( LIBEWF_COMPRESS_FLAG_USE_EMPTY_BLOCK_COMPRESSION ) ) != 0 ) |
10331 | 0 | { |
10332 | 0 | libcerror_error_set( |
10333 | 0 | error, |
10334 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
10335 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
10336 | 0 | "%s: unsupported compression flags.", |
10337 | 0 | function ); |
10338 | |
|
10339 | 0 | return( -1 ); |
10340 | 0 | } |
10341 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10342 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
10343 | 0 | internal_handle->read_write_lock, |
10344 | 0 | error ) != 1 ) |
10345 | 0 | { |
10346 | 0 | libcerror_error_set( |
10347 | 0 | error, |
10348 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10349 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10350 | 0 | "%s: unable to grab read/write lock for writing.", |
10351 | 0 | function ); |
10352 | |
|
10353 | 0 | return( -1 ); |
10354 | 0 | } |
10355 | 0 | #endif |
10356 | 0 | if( ( internal_handle->write_io_handle == NULL ) |
10357 | 0 | || ( internal_handle->write_io_handle->values_initialized != 0 ) ) |
10358 | 0 | { |
10359 | 0 | libcerror_error_set( |
10360 | 0 | error, |
10361 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10362 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10363 | 0 | "%s: compression values cannot be changed.", |
10364 | 0 | function ); |
10365 | |
|
10366 | 0 | goto on_error; |
10367 | 0 | } |
10368 | 0 | if( ( internal_handle->io_handle->segment_file_type == LIBEWF_SEGMENT_FILE_TYPE_EWF2 ) |
10369 | 0 | && ( internal_handle->io_handle->segment_file_type == LIBEWF_SEGMENT_FILE_TYPE_EWF2_LOGICAL ) ) |
10370 | 0 | { |
10371 | 0 | compression_flags |= LIBEWF_COMPRESS_FLAG_USE_PATTERN_FILL_COMPRESSION; |
10372 | 0 | } |
10373 | 0 | internal_handle->io_handle->compression_level = compression_level; |
10374 | 0 | internal_handle->io_handle->compression_flags = compression_flags; |
10375 | |
|
10376 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10377 | 0 | if( libcthreads_read_write_lock_release_for_write( |
10378 | 0 | internal_handle->read_write_lock, |
10379 | 0 | error ) != 1 ) |
10380 | 0 | { |
10381 | 0 | libcerror_error_set( |
10382 | 0 | error, |
10383 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10384 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10385 | 0 | "%s: unable to release read/write lock for writing.", |
10386 | 0 | function ); |
10387 | |
|
10388 | 0 | return( -1 ); |
10389 | 0 | } |
10390 | 0 | #endif |
10391 | 0 | return( 1 ); |
10392 | | |
10393 | 0 | on_error: |
10394 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10395 | 0 | libcthreads_read_write_lock_release_for_write( |
10396 | 0 | internal_handle->read_write_lock, |
10397 | 0 | NULL ); |
10398 | 0 | #endif |
10399 | 0 | return( -1 ); |
10400 | 0 | } |
10401 | | |
10402 | | /* Retrieves the size of the contained media data |
10403 | | * Returns 1 if successful or -1 on error |
10404 | | */ |
10405 | | int libewf_handle_get_media_size( |
10406 | | libewf_handle_t *handle, |
10407 | | size64_t *media_size, |
10408 | | libcerror_error_t **error ) |
10409 | 0 | { |
10410 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
10411 | 0 | static char *function = "libewf_handle_get_media_size"; |
10412 | |
|
10413 | 0 | if( handle == NULL ) |
10414 | 0 | { |
10415 | 0 | libcerror_error_set( |
10416 | 0 | error, |
10417 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
10418 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
10419 | 0 | "%s: invalid handle.", |
10420 | 0 | function ); |
10421 | |
|
10422 | 0 | return( -1 ); |
10423 | 0 | } |
10424 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
10425 | |
|
10426 | 0 | if( internal_handle->media_values == NULL ) |
10427 | 0 | { |
10428 | 0 | libcerror_error_set( |
10429 | 0 | error, |
10430 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10431 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
10432 | 0 | "%s: invalid handle - missing media values.", |
10433 | 0 | function ); |
10434 | |
|
10435 | 0 | return( -1 ); |
10436 | 0 | } |
10437 | 0 | if( media_size == NULL ) |
10438 | 0 | { |
10439 | 0 | libcerror_error_set( |
10440 | 0 | error, |
10441 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
10442 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
10443 | 0 | "%s: invalid media size.", |
10444 | 0 | function ); |
10445 | |
|
10446 | 0 | return( -1 ); |
10447 | 0 | } |
10448 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10449 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
10450 | 0 | internal_handle->read_write_lock, |
10451 | 0 | error ) != 1 ) |
10452 | 0 | { |
10453 | 0 | libcerror_error_set( |
10454 | 0 | error, |
10455 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10456 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10457 | 0 | "%s: unable to grab read/write lock for reading.", |
10458 | 0 | function ); |
10459 | |
|
10460 | 0 | return( -1 ); |
10461 | 0 | } |
10462 | 0 | #endif |
10463 | 0 | *media_size = internal_handle->media_values->media_size; |
10464 | |
|
10465 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10466 | 0 | if( libcthreads_read_write_lock_release_for_read( |
10467 | 0 | internal_handle->read_write_lock, |
10468 | 0 | error ) != 1 ) |
10469 | 0 | { |
10470 | 0 | libcerror_error_set( |
10471 | 0 | error, |
10472 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10473 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10474 | 0 | "%s: unable to release read/write lock for reading.", |
10475 | 0 | function ); |
10476 | |
|
10477 | 0 | return( -1 ); |
10478 | 0 | } |
10479 | 0 | #endif |
10480 | 0 | return( 1 ); |
10481 | 0 | } |
10482 | | |
10483 | | /* Sets the media size |
10484 | | * Returns 1 if successful or -1 on error |
10485 | | */ |
10486 | | int libewf_handle_set_media_size( |
10487 | | libewf_handle_t *handle, |
10488 | | size64_t media_size, |
10489 | | libcerror_error_t **error ) |
10490 | 0 | { |
10491 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
10492 | 0 | static char *function = "libewf_handle_set_media_size"; |
10493 | |
|
10494 | 0 | if( handle == NULL ) |
10495 | 0 | { |
10496 | 0 | libcerror_error_set( |
10497 | 0 | error, |
10498 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
10499 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
10500 | 0 | "%s: invalid handle.", |
10501 | 0 | function ); |
10502 | |
|
10503 | 0 | return( -1 ); |
10504 | 0 | } |
10505 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
10506 | |
|
10507 | 0 | if( internal_handle->media_values == NULL ) |
10508 | 0 | { |
10509 | 0 | libcerror_error_set( |
10510 | 0 | error, |
10511 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10512 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
10513 | 0 | "%s: invalid handle - missing media values.", |
10514 | 0 | function ); |
10515 | |
|
10516 | 0 | return( -1 ); |
10517 | 0 | } |
10518 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10519 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
10520 | 0 | internal_handle->read_write_lock, |
10521 | 0 | error ) != 1 ) |
10522 | 0 | { |
10523 | 0 | libcerror_error_set( |
10524 | 0 | error, |
10525 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10526 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10527 | 0 | "%s: unable to grab read/write lock for writing.", |
10528 | 0 | function ); |
10529 | |
|
10530 | 0 | return( -1 ); |
10531 | 0 | } |
10532 | 0 | #endif |
10533 | 0 | if( ( internal_handle->read_io_handle != NULL ) |
10534 | 0 | || ( internal_handle->write_io_handle == NULL ) |
10535 | 0 | || ( internal_handle->write_io_handle->values_initialized != 0 ) ) |
10536 | 0 | { |
10537 | 0 | libcerror_error_set( |
10538 | 0 | error, |
10539 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10540 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10541 | 0 | "%s: media size cannot be changed.", |
10542 | 0 | function ); |
10543 | |
|
10544 | 0 | goto on_error; |
10545 | 0 | } |
10546 | 0 | if( libewf_internal_handle_set_media_values( |
10547 | 0 | internal_handle, |
10548 | 0 | internal_handle->media_values->sectors_per_chunk, |
10549 | 0 | internal_handle->media_values->bytes_per_sector, |
10550 | 0 | media_size, |
10551 | 0 | error ) != 1 ) |
10552 | 0 | { |
10553 | 0 | libcerror_error_set( |
10554 | 0 | error, |
10555 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10556 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10557 | 0 | "%s: unable to set media values.", |
10558 | 0 | function ); |
10559 | |
|
10560 | 0 | goto on_error; |
10561 | 0 | } |
10562 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10563 | 0 | if( libcthreads_read_write_lock_release_for_write( |
10564 | 0 | internal_handle->read_write_lock, |
10565 | 0 | error ) != 1 ) |
10566 | 0 | { |
10567 | 0 | libcerror_error_set( |
10568 | 0 | error, |
10569 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10570 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10571 | 0 | "%s: unable to release read/write lock for writing.", |
10572 | 0 | function ); |
10573 | |
|
10574 | 0 | return( -1 ); |
10575 | 0 | } |
10576 | 0 | #endif |
10577 | 0 | return( 1 ); |
10578 | | |
10579 | 0 | on_error: |
10580 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10581 | 0 | libcthreads_read_write_lock_release_for_write( |
10582 | 0 | internal_handle->read_write_lock, |
10583 | 0 | NULL ); |
10584 | 0 | #endif |
10585 | 0 | return( -1 ); |
10586 | 0 | } |
10587 | | |
10588 | | /* Retrieves the media type value |
10589 | | * Returns 1 if successful or -1 on error |
10590 | | */ |
10591 | | int libewf_handle_get_media_type( |
10592 | | libewf_handle_t *handle, |
10593 | | uint8_t *media_type, |
10594 | | libcerror_error_t **error ) |
10595 | 0 | { |
10596 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
10597 | 0 | static char *function = "libewf_handle_get_media_type"; |
10598 | |
|
10599 | 0 | if( handle == NULL ) |
10600 | 0 | { |
10601 | 0 | libcerror_error_set( |
10602 | 0 | error, |
10603 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
10604 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
10605 | 0 | "%s: invalid handle.", |
10606 | 0 | function ); |
10607 | |
|
10608 | 0 | return( -1 ); |
10609 | 0 | } |
10610 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
10611 | |
|
10612 | 0 | if( internal_handle->media_values == NULL ) |
10613 | 0 | { |
10614 | 0 | libcerror_error_set( |
10615 | 0 | error, |
10616 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10617 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
10618 | 0 | "%s: invalid handle - missing media values.", |
10619 | 0 | function ); |
10620 | |
|
10621 | 0 | return( -1 ); |
10622 | 0 | } |
10623 | 0 | if( internal_handle->media_values->media_type > (uint8_t) INT8_MAX ) |
10624 | 0 | { |
10625 | 0 | libcerror_error_set( |
10626 | 0 | error, |
10627 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10628 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
10629 | 0 | "%s: invalid media type value exceeds maximum.", |
10630 | 0 | function ); |
10631 | |
|
10632 | 0 | return( -1 ); |
10633 | 0 | } |
10634 | 0 | if( media_type == NULL ) |
10635 | 0 | { |
10636 | 0 | libcerror_error_set( |
10637 | 0 | error, |
10638 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
10639 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
10640 | 0 | "%s: invalid media type.", |
10641 | 0 | function ); |
10642 | |
|
10643 | 0 | return( -1 ); |
10644 | 0 | } |
10645 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10646 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
10647 | 0 | internal_handle->read_write_lock, |
10648 | 0 | error ) != 1 ) |
10649 | 0 | { |
10650 | 0 | libcerror_error_set( |
10651 | 0 | error, |
10652 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10653 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10654 | 0 | "%s: unable to grab read/write lock for reading.", |
10655 | 0 | function ); |
10656 | |
|
10657 | 0 | return( -1 ); |
10658 | 0 | } |
10659 | 0 | #endif |
10660 | 0 | *media_type = internal_handle->media_values->media_type; |
10661 | |
|
10662 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10663 | 0 | if( libcthreads_read_write_lock_release_for_read( |
10664 | 0 | internal_handle->read_write_lock, |
10665 | 0 | error ) != 1 ) |
10666 | 0 | { |
10667 | 0 | libcerror_error_set( |
10668 | 0 | error, |
10669 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10670 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10671 | 0 | "%s: unable to release read/write lock for reading.", |
10672 | 0 | function ); |
10673 | |
|
10674 | 0 | return( -1 ); |
10675 | 0 | } |
10676 | 0 | #endif |
10677 | 0 | return( 1 ); |
10678 | 0 | } |
10679 | | |
10680 | | /* Sets the media type |
10681 | | * Returns 1 if successful or -1 on error |
10682 | | */ |
10683 | | int libewf_handle_set_media_type( |
10684 | | libewf_handle_t *handle, |
10685 | | uint8_t media_type, |
10686 | | libcerror_error_t **error ) |
10687 | 0 | { |
10688 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
10689 | 0 | static char *function = "libewf_handle_set_media_type"; |
10690 | |
|
10691 | 0 | if( handle == NULL ) |
10692 | 0 | { |
10693 | 0 | libcerror_error_set( |
10694 | 0 | error, |
10695 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
10696 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
10697 | 0 | "%s: invalid handle.", |
10698 | 0 | function ); |
10699 | |
|
10700 | 0 | return( -1 ); |
10701 | 0 | } |
10702 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
10703 | |
|
10704 | 0 | if( internal_handle->media_values == NULL ) |
10705 | 0 | { |
10706 | 0 | libcerror_error_set( |
10707 | 0 | error, |
10708 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10709 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
10710 | 0 | "%s: invalid handle - missing media values.", |
10711 | 0 | function ); |
10712 | |
|
10713 | 0 | return( -1 ); |
10714 | 0 | } |
10715 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10716 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
10717 | 0 | internal_handle->read_write_lock, |
10718 | 0 | error ) != 1 ) |
10719 | 0 | { |
10720 | 0 | libcerror_error_set( |
10721 | 0 | error, |
10722 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10723 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10724 | 0 | "%s: unable to grab read/write lock for writing.", |
10725 | 0 | function ); |
10726 | |
|
10727 | 0 | return( -1 ); |
10728 | 0 | } |
10729 | 0 | #endif |
10730 | 0 | if( ( internal_handle->read_io_handle != NULL ) |
10731 | 0 | || ( internal_handle->write_io_handle == NULL ) |
10732 | 0 | || ( internal_handle->write_io_handle->values_initialized != 0 ) ) |
10733 | 0 | { |
10734 | 0 | libcerror_error_set( |
10735 | 0 | error, |
10736 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10737 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10738 | 0 | "%s: media type cannot be changed.", |
10739 | 0 | function ); |
10740 | |
|
10741 | 0 | goto on_error; |
10742 | 0 | } |
10743 | 0 | internal_handle->media_values->media_type = media_type; |
10744 | |
|
10745 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10746 | 0 | if( libcthreads_read_write_lock_release_for_write( |
10747 | 0 | internal_handle->read_write_lock, |
10748 | 0 | error ) != 1 ) |
10749 | 0 | { |
10750 | 0 | libcerror_error_set( |
10751 | 0 | error, |
10752 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10753 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10754 | 0 | "%s: unable to release read/write lock for writing.", |
10755 | 0 | function ); |
10756 | |
|
10757 | 0 | return( -1 ); |
10758 | 0 | } |
10759 | 0 | #endif |
10760 | 0 | return( 1 ); |
10761 | | |
10762 | 0 | on_error: |
10763 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10764 | 0 | libcthreads_read_write_lock_release_for_write( |
10765 | 0 | internal_handle->read_write_lock, |
10766 | 0 | NULL ); |
10767 | 0 | #endif |
10768 | 0 | return( -1 ); |
10769 | 0 | } |
10770 | | |
10771 | | /* Retrieves the media flags |
10772 | | * Returns 1 if successful or -1 on error |
10773 | | */ |
10774 | | int libewf_handle_get_media_flags( |
10775 | | libewf_handle_t *handle, |
10776 | | uint8_t *media_flags, |
10777 | | libcerror_error_t **error ) |
10778 | 0 | { |
10779 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
10780 | 0 | static char *function = "libewf_handle_get_media_flags"; |
10781 | |
|
10782 | 0 | if( handle == NULL ) |
10783 | 0 | { |
10784 | 0 | libcerror_error_set( |
10785 | 0 | error, |
10786 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
10787 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
10788 | 0 | "%s: invalid handle.", |
10789 | 0 | function ); |
10790 | |
|
10791 | 0 | return( -1 ); |
10792 | 0 | } |
10793 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
10794 | |
|
10795 | 0 | if( internal_handle->media_values == NULL ) |
10796 | 0 | { |
10797 | 0 | libcerror_error_set( |
10798 | 0 | error, |
10799 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10800 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
10801 | 0 | "%s: invalid handle - missing media values.", |
10802 | 0 | function ); |
10803 | |
|
10804 | 0 | return( -1 ); |
10805 | 0 | } |
10806 | 0 | if( media_flags == NULL ) |
10807 | 0 | { |
10808 | 0 | libcerror_error_set( |
10809 | 0 | error, |
10810 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
10811 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
10812 | 0 | "%s: invalid media flags.", |
10813 | 0 | function ); |
10814 | |
|
10815 | 0 | return( -1 ); |
10816 | 0 | } |
10817 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10818 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
10819 | 0 | internal_handle->read_write_lock, |
10820 | 0 | error ) != 1 ) |
10821 | 0 | { |
10822 | 0 | libcerror_error_set( |
10823 | 0 | error, |
10824 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10825 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10826 | 0 | "%s: unable to grab read/write lock for reading.", |
10827 | 0 | function ); |
10828 | |
|
10829 | 0 | return( -1 ); |
10830 | 0 | } |
10831 | 0 | #endif |
10832 | 0 | if( internal_handle->media_values->media_flags > (uint8_t) INT8_MAX ) |
10833 | 0 | { |
10834 | 0 | libcerror_error_set( |
10835 | 0 | error, |
10836 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10837 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
10838 | 0 | "%s: invalid media flags value exceeds maximum.", |
10839 | 0 | function ); |
10840 | |
|
10841 | 0 | goto on_error; |
10842 | 0 | } |
10843 | 0 | *media_flags = internal_handle->media_values->media_flags; |
10844 | |
|
10845 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10846 | 0 | if( libcthreads_read_write_lock_release_for_read( |
10847 | 0 | internal_handle->read_write_lock, |
10848 | 0 | error ) != 1 ) |
10849 | 0 | { |
10850 | 0 | libcerror_error_set( |
10851 | 0 | error, |
10852 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10853 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10854 | 0 | "%s: unable to release read/write lock for reading.", |
10855 | 0 | function ); |
10856 | |
|
10857 | 0 | return( -1 ); |
10858 | 0 | } |
10859 | 0 | #endif |
10860 | 0 | return( 1 ); |
10861 | | |
10862 | 0 | on_error: |
10863 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10864 | 0 | libcthreads_read_write_lock_release_for_read( |
10865 | 0 | internal_handle->read_write_lock, |
10866 | 0 | NULL ); |
10867 | 0 | #endif |
10868 | 0 | return( -1 ); |
10869 | 0 | } |
10870 | | |
10871 | | /* Sets the media flags |
10872 | | * Returns 1 if successful or -1 on error |
10873 | | */ |
10874 | | int libewf_handle_set_media_flags( |
10875 | | libewf_handle_t *handle, |
10876 | | uint8_t media_flags, |
10877 | | libcerror_error_t **error ) |
10878 | 0 | { |
10879 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
10880 | 0 | static char *function = "libewf_handle_set_media_flags"; |
10881 | |
|
10882 | 0 | if( handle == NULL ) |
10883 | 0 | { |
10884 | 0 | libcerror_error_set( |
10885 | 0 | error, |
10886 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
10887 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
10888 | 0 | "%s: invalid handle.", |
10889 | 0 | function ); |
10890 | |
|
10891 | 0 | return( -1 ); |
10892 | 0 | } |
10893 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
10894 | |
|
10895 | 0 | if( internal_handle->media_values == NULL ) |
10896 | 0 | { |
10897 | 0 | libcerror_error_set( |
10898 | 0 | error, |
10899 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10900 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
10901 | 0 | "%s: invalid handle - missing media values.", |
10902 | 0 | function ); |
10903 | |
|
10904 | 0 | return( -1 ); |
10905 | 0 | } |
10906 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10907 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
10908 | 0 | internal_handle->read_write_lock, |
10909 | 0 | error ) != 1 ) |
10910 | 0 | { |
10911 | 0 | libcerror_error_set( |
10912 | 0 | error, |
10913 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10914 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10915 | 0 | "%s: unable to grab read/write lock for writing.", |
10916 | 0 | function ); |
10917 | |
|
10918 | 0 | return( -1 ); |
10919 | 0 | } |
10920 | 0 | #endif |
10921 | 0 | if( ( internal_handle->read_io_handle != NULL ) |
10922 | 0 | || ( internal_handle->write_io_handle == NULL ) |
10923 | 0 | || ( internal_handle->write_io_handle->values_initialized != 0 ) ) |
10924 | 0 | { |
10925 | 0 | libcerror_error_set( |
10926 | 0 | error, |
10927 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10928 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10929 | 0 | "%s: media flags cannot be changed.", |
10930 | 0 | function ); |
10931 | |
|
10932 | 0 | goto on_error; |
10933 | 0 | } |
10934 | 0 | internal_handle->media_values->media_flags = media_flags; |
10935 | | |
10936 | | /* Make sure the lowest bit is always set |
10937 | | */ |
10938 | 0 | internal_handle->media_values->media_flags |= 0x01; |
10939 | |
|
10940 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10941 | 0 | if( libcthreads_read_write_lock_release_for_write( |
10942 | 0 | internal_handle->read_write_lock, |
10943 | 0 | error ) != 1 ) |
10944 | 0 | { |
10945 | 0 | libcerror_error_set( |
10946 | 0 | error, |
10947 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10948 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
10949 | 0 | "%s: unable to release read/write lock for writing.", |
10950 | 0 | function ); |
10951 | |
|
10952 | 0 | return( -1 ); |
10953 | 0 | } |
10954 | 0 | #endif |
10955 | 0 | return( 1 ); |
10956 | | |
10957 | 0 | on_error: |
10958 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
10959 | 0 | libcthreads_read_write_lock_release_for_write( |
10960 | 0 | internal_handle->read_write_lock, |
10961 | 0 | NULL ); |
10962 | 0 | #endif |
10963 | 0 | return( -1 ); |
10964 | 0 | } |
10965 | | |
10966 | | /* Retrieves the format type value |
10967 | | * Returns 1 if successful or -1 on error |
10968 | | */ |
10969 | | int libewf_handle_get_format( |
10970 | | libewf_handle_t *handle, |
10971 | | uint8_t *format, |
10972 | | libcerror_error_t **error ) |
10973 | 0 | { |
10974 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
10975 | 0 | static char *function = "libewf_handle_get_format"; |
10976 | 0 | int result = 1; |
10977 | |
|
10978 | 0 | if( handle == NULL ) |
10979 | 0 | { |
10980 | 0 | libcerror_error_set( |
10981 | 0 | error, |
10982 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
10983 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
10984 | 0 | "%s: invalid handle.", |
10985 | 0 | function ); |
10986 | |
|
10987 | 0 | return( -1 ); |
10988 | 0 | } |
10989 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
10990 | |
|
10991 | 0 | if( internal_handle->io_handle == NULL ) |
10992 | 0 | { |
10993 | 0 | libcerror_error_set( |
10994 | 0 | error, |
10995 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
10996 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
10997 | 0 | "%s: invalid handle - missing IO handle.", |
10998 | 0 | function ); |
10999 | |
|
11000 | 0 | return( -1 ); |
11001 | 0 | } |
11002 | 0 | if( internal_handle->media_values == NULL ) |
11003 | 0 | { |
11004 | 0 | libcerror_error_set( |
11005 | 0 | error, |
11006 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11007 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
11008 | 0 | "%s: invalid handle - missing media values.", |
11009 | 0 | function ); |
11010 | |
|
11011 | 0 | return( -1 ); |
11012 | 0 | } |
11013 | 0 | if( format == NULL ) |
11014 | 0 | { |
11015 | 0 | libcerror_error_set( |
11016 | 0 | error, |
11017 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
11018 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
11019 | 0 | "%s: invalid format.", |
11020 | 0 | function ); |
11021 | |
|
11022 | 0 | return( -1 ); |
11023 | 0 | } |
11024 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
11025 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
11026 | 0 | internal_handle->read_write_lock, |
11027 | 0 | error ) != 1 ) |
11028 | 0 | { |
11029 | 0 | libcerror_error_set( |
11030 | 0 | error, |
11031 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11032 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
11033 | 0 | "%s: unable to grab read/write lock for reading.", |
11034 | 0 | function ); |
11035 | |
|
11036 | 0 | return( -1 ); |
11037 | 0 | } |
11038 | 0 | #endif |
11039 | 0 | if( internal_handle->io_handle->format > (uint8_t) INT8_MAX ) |
11040 | 0 | { |
11041 | 0 | libcerror_error_set( |
11042 | 0 | error, |
11043 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11044 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM, |
11045 | 0 | "%s: invalid format value exceeds maximum.", |
11046 | 0 | function ); |
11047 | |
|
11048 | 0 | result = -1; |
11049 | 0 | } |
11050 | 0 | else |
11051 | 0 | { |
11052 | 0 | *format = internal_handle->io_handle->format; |
11053 | 0 | } |
11054 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
11055 | 0 | if( libcthreads_read_write_lock_release_for_read( |
11056 | 0 | internal_handle->read_write_lock, |
11057 | 0 | error ) != 1 ) |
11058 | 0 | { |
11059 | 0 | libcerror_error_set( |
11060 | 0 | error, |
11061 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11062 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
11063 | 0 | "%s: unable to release read/write lock for reading.", |
11064 | 0 | function ); |
11065 | |
|
11066 | 0 | return( -1 ); |
11067 | 0 | } |
11068 | 0 | #endif |
11069 | 0 | return( result ); |
11070 | 0 | } |
11071 | | |
11072 | | /* Sets the output format |
11073 | | * Returns 1 if successful or -1 on error |
11074 | | */ |
11075 | | int libewf_handle_set_format( |
11076 | | libewf_handle_t *handle, |
11077 | | uint8_t format, |
11078 | | libcerror_error_t **error ) |
11079 | 0 | { |
11080 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
11081 | 0 | static char *function = "libewf_handle_set_format"; |
11082 | |
|
11083 | 0 | if( handle == NULL ) |
11084 | 0 | { |
11085 | 0 | libcerror_error_set( |
11086 | 0 | error, |
11087 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
11088 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
11089 | 0 | "%s: invalid handle.", |
11090 | 0 | function ); |
11091 | |
|
11092 | 0 | return( -1 ); |
11093 | 0 | } |
11094 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
11095 | |
|
11096 | 0 | if( internal_handle->io_handle == NULL ) |
11097 | 0 | { |
11098 | 0 | libcerror_error_set( |
11099 | 0 | error, |
11100 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11101 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
11102 | 0 | "%s: invalid handle - missing IO handle.", |
11103 | 0 | function ); |
11104 | |
|
11105 | 0 | return( -1 ); |
11106 | 0 | } |
11107 | 0 | if( ( format != LIBEWF_FORMAT_ENCASE1 ) |
11108 | 0 | && ( format != LIBEWF_FORMAT_ENCASE2 ) |
11109 | 0 | && ( format != LIBEWF_FORMAT_ENCASE3 ) |
11110 | 0 | && ( format != LIBEWF_FORMAT_ENCASE4 ) |
11111 | 0 | && ( format != LIBEWF_FORMAT_ENCASE5 ) |
11112 | 0 | && ( format != LIBEWF_FORMAT_ENCASE6 ) |
11113 | 0 | && ( format != LIBEWF_FORMAT_ENCASE7 ) |
11114 | 0 | && ( format != LIBEWF_FORMAT_SMART ) |
11115 | 0 | && ( format != LIBEWF_FORMAT_FTK_IMAGER ) |
11116 | 0 | && ( format != LIBEWF_FORMAT_LINEN5 ) |
11117 | 0 | && ( format != LIBEWF_FORMAT_LINEN6 ) |
11118 | 0 | && ( format != LIBEWF_FORMAT_LINEN7 ) |
11119 | 0 | && ( format != LIBEWF_FORMAT_V2_ENCASE7 ) |
11120 | | /* TODO add support for: L01, Lx01: |
11121 | | && ( format != LIBEWF_FORMAT_LOGICAL_ENCASE5 ) |
11122 | | && ( format != LIBEWF_FORMAT_LOGICAL_ENCASE6 ) |
11123 | | && ( format != LIBEWF_FORMAT_LOGICAL_ENCASE7 ) |
11124 | | && ( format != LIBEWF_FORMAT_V2_LOGICAL_ENCASE7 ) |
11125 | | */ |
11126 | 0 | && ( format != LIBEWF_FORMAT_EWF ) |
11127 | 0 | && ( format != LIBEWF_FORMAT_EWFX ) ) |
11128 | 0 | { |
11129 | 0 | libcerror_error_set( |
11130 | 0 | error, |
11131 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
11132 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
11133 | 0 | "%s: unsupported format: %d.", |
11134 | 0 | function, |
11135 | 0 | format ); |
11136 | |
|
11137 | 0 | return( -1 ); |
11138 | 0 | } |
11139 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
11140 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
11141 | 0 | internal_handle->read_write_lock, |
11142 | 0 | error ) != 1 ) |
11143 | 0 | { |
11144 | 0 | libcerror_error_set( |
11145 | 0 | error, |
11146 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11147 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
11148 | 0 | "%s: unable to grab read/write lock for writing.", |
11149 | 0 | function ); |
11150 | |
|
11151 | 0 | return( -1 ); |
11152 | 0 | } |
11153 | 0 | #endif |
11154 | 0 | if( ( internal_handle->read_io_handle != NULL ) |
11155 | 0 | || ( internal_handle->write_io_handle == NULL ) |
11156 | 0 | || ( internal_handle->write_io_handle->values_initialized != 0 ) ) |
11157 | 0 | { |
11158 | 0 | libcerror_error_set( |
11159 | 0 | error, |
11160 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11161 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
11162 | 0 | "%s: format cannot be changed.", |
11163 | 0 | function ); |
11164 | |
|
11165 | 0 | goto on_error; |
11166 | 0 | } |
11167 | | /* TODO refactor into separate function */ |
11168 | 0 | internal_handle->io_handle->format = format; |
11169 | |
|
11170 | 0 | if( format == LIBEWF_FORMAT_V2_ENCASE7 ) |
11171 | 0 | { |
11172 | 0 | internal_handle->io_handle->major_version = 2; |
11173 | 0 | internal_handle->io_handle->minor_version = 1; |
11174 | 0 | } |
11175 | 0 | else |
11176 | 0 | { |
11177 | 0 | internal_handle->io_handle->major_version = 1; |
11178 | 0 | internal_handle->io_handle->minor_version = 0; |
11179 | 0 | } |
11180 | 0 | if( ( format == LIBEWF_FORMAT_EWF ) |
11181 | 0 | || ( format == LIBEWF_FORMAT_SMART ) ) |
11182 | 0 | { |
11183 | | /* Wraps .s01 to .s99 and then to .saa up to .zzz |
11184 | | * ( ( ( 's' to 'z' = 8 ) * 26 * 26 ) + 99 ) = 5507 |
11185 | | */ |
11186 | 0 | internal_handle->write_io_handle->maximum_number_of_segments = (uint32_t) 5507; |
11187 | 0 | internal_handle->io_handle->segment_file_type = LIBEWF_SEGMENT_FILE_TYPE_EWF1_SMART; |
11188 | 0 | } |
11189 | 0 | else if( format == LIBEWF_FORMAT_V2_ENCASE7 ) |
11190 | 0 | { |
11191 | | /* Wraps .Ex01 to .Ex99 and then to .ExAA up to .EzZZ |
11192 | | * ( ( ( 'x' to 'z' = 3 ) * 26 * 26 ) + 99 ) = 2127 |
11193 | | */ |
11194 | 0 | internal_handle->write_io_handle->maximum_number_of_segments = (uint32_t) 2127; |
11195 | 0 | internal_handle->io_handle->segment_file_type = LIBEWF_SEGMENT_FILE_TYPE_EWF2; |
11196 | 0 | } |
11197 | 0 | else |
11198 | 0 | { |
11199 | | /* Wraps .E01 to .E99 and then to .EAA up to .ZZZ |
11200 | | * ( ( ( 'E' to 'Z' or 'e' to 'z' = 22 ) * 26 * 26 ) + 99 ) = 14971 |
11201 | | */ |
11202 | 0 | internal_handle->write_io_handle->maximum_number_of_segments = (uint32_t) 14971; |
11203 | 0 | internal_handle->io_handle->segment_file_type = LIBEWF_SEGMENT_FILE_TYPE_EWF1; |
11204 | 0 | } |
11205 | | /* Determine the maximum number of table entries |
11206 | | */ |
11207 | 0 | if( ( format == LIBEWF_FORMAT_ENCASE6 ) |
11208 | 0 | || ( format == LIBEWF_FORMAT_ENCASE7 ) ) |
11209 | 0 | { |
11210 | 0 | internal_handle->write_io_handle->maximum_segment_file_size = INT64_MAX; |
11211 | 0 | internal_handle->write_io_handle->maximum_chunks_per_section = LIBEWF_MAXIMUM_TABLE_ENTRIES_ENCASE6; |
11212 | 0 | } |
11213 | 0 | else if( format == LIBEWF_FORMAT_V2_ENCASE7 ) |
11214 | 0 | { |
11215 | 0 | internal_handle->write_io_handle->maximum_segment_file_size = INT64_MAX; |
11216 | 0 | internal_handle->write_io_handle->maximum_chunks_per_section = LIBEWF_MAXIMUM_TABLE_ENTRIES; |
11217 | 0 | } |
11218 | 0 | else if( format == LIBEWF_FORMAT_EWFX ) |
11219 | 0 | { |
11220 | 0 | internal_handle->write_io_handle->maximum_segment_file_size = INT32_MAX; |
11221 | 0 | internal_handle->write_io_handle->maximum_chunks_per_section = LIBEWF_MAXIMUM_TABLE_ENTRIES; |
11222 | 0 | } |
11223 | 0 | else |
11224 | 0 | { |
11225 | 0 | internal_handle->write_io_handle->maximum_segment_file_size = INT32_MAX; |
11226 | 0 | internal_handle->write_io_handle->maximum_chunks_per_section = LIBEWF_MAXIMUM_TABLE_ENTRIES_EWF; |
11227 | 0 | } |
11228 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
11229 | 0 | if( libcthreads_read_write_lock_release_for_write( |
11230 | 0 | internal_handle->read_write_lock, |
11231 | 0 | error ) != 1 ) |
11232 | 0 | { |
11233 | 0 | libcerror_error_set( |
11234 | 0 | error, |
11235 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11236 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
11237 | 0 | "%s: unable to release read/write lock for writing.", |
11238 | 0 | function ); |
11239 | |
|
11240 | 0 | return( -1 ); |
11241 | 0 | } |
11242 | 0 | #endif |
11243 | 0 | return( 1 ); |
11244 | | |
11245 | 0 | on_error: |
11246 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
11247 | 0 | libcthreads_read_write_lock_release_for_write( |
11248 | 0 | internal_handle->read_write_lock, |
11249 | 0 | NULL ); |
11250 | 0 | #endif |
11251 | 0 | return( -1 ); |
11252 | 0 | } |
11253 | | |
11254 | | /* Retrieves the segment file version |
11255 | | * Returns 1 if successful or -1 on error |
11256 | | */ |
11257 | | int libewf_handle_get_segment_file_version( |
11258 | | libewf_handle_t *handle, |
11259 | | uint8_t *major_version, |
11260 | | uint8_t *minor_version, |
11261 | | libcerror_error_t **error ) |
11262 | 0 | { |
11263 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
11264 | 0 | static char *function = "libewf_handle_get_segment_file_version"; |
11265 | |
|
11266 | 0 | if( handle == NULL ) |
11267 | 0 | { |
11268 | 0 | libcerror_error_set( |
11269 | 0 | error, |
11270 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
11271 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
11272 | 0 | "%s: invalid handle.", |
11273 | 0 | function ); |
11274 | |
|
11275 | 0 | return( -1 ); |
11276 | 0 | } |
11277 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
11278 | |
|
11279 | 0 | if( internal_handle->io_handle == NULL ) |
11280 | 0 | { |
11281 | 0 | libcerror_error_set( |
11282 | 0 | error, |
11283 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11284 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
11285 | 0 | "%s: invalid handle - missing IO handle.", |
11286 | 0 | function ); |
11287 | |
|
11288 | 0 | return( -1 ); |
11289 | 0 | } |
11290 | 0 | if( major_version == NULL ) |
11291 | 0 | { |
11292 | 0 | libcerror_error_set( |
11293 | 0 | error, |
11294 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
11295 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
11296 | 0 | "%s: invalid major version.", |
11297 | 0 | function ); |
11298 | |
|
11299 | 0 | return( -1 ); |
11300 | 0 | } |
11301 | 0 | if( minor_version == NULL ) |
11302 | 0 | { |
11303 | 0 | libcerror_error_set( |
11304 | 0 | error, |
11305 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
11306 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
11307 | 0 | "%s: invalid minor version.", |
11308 | 0 | function ); |
11309 | |
|
11310 | 0 | return( -1 ); |
11311 | 0 | } |
11312 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
11313 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
11314 | 0 | internal_handle->read_write_lock, |
11315 | 0 | error ) != 1 ) |
11316 | 0 | { |
11317 | 0 | libcerror_error_set( |
11318 | 0 | error, |
11319 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11320 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
11321 | 0 | "%s: unable to grab read/write lock for reading.", |
11322 | 0 | function ); |
11323 | |
|
11324 | 0 | return( -1 ); |
11325 | 0 | } |
11326 | 0 | #endif |
11327 | 0 | *major_version = internal_handle->io_handle->major_version; |
11328 | 0 | *minor_version = internal_handle->io_handle->minor_version; |
11329 | |
|
11330 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
11331 | 0 | if( libcthreads_read_write_lock_release_for_read( |
11332 | 0 | internal_handle->read_write_lock, |
11333 | 0 | error ) != 1 ) |
11334 | 0 | { |
11335 | 0 | libcerror_error_set( |
11336 | 0 | error, |
11337 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11338 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
11339 | 0 | "%s: unable to release read/write lock for reading.", |
11340 | 0 | function ); |
11341 | |
|
11342 | 0 | return( -1 ); |
11343 | 0 | } |
11344 | 0 | #endif |
11345 | 0 | return( 1 ); |
11346 | 0 | } |
11347 | | |
11348 | | /* Retrieves the segment file set identifier |
11349 | | * The identifier is a GUID and is 16 bytes of size |
11350 | | * Returns 1 if successful or -1 on error |
11351 | | */ |
11352 | | int libewf_handle_get_segment_file_set_identifier( |
11353 | | libewf_handle_t *handle, |
11354 | | uint8_t *set_identifier, |
11355 | | size_t size, |
11356 | | libcerror_error_t **error ) |
11357 | 0 | { |
11358 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
11359 | 0 | static char *function = "libewf_handle_get_segment_file_set_identifier"; |
11360 | |
|
11361 | 0 | if( handle == NULL ) |
11362 | 0 | { |
11363 | 0 | libcerror_error_set( |
11364 | 0 | error, |
11365 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
11366 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
11367 | 0 | "%s: invalid handle.", |
11368 | 0 | function ); |
11369 | |
|
11370 | 0 | return( -1 ); |
11371 | 0 | } |
11372 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
11373 | |
|
11374 | 0 | if( internal_handle->media_values == NULL ) |
11375 | 0 | { |
11376 | 0 | libcerror_error_set( |
11377 | 0 | error, |
11378 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11379 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
11380 | 0 | "%s: invalid handle - missing media values.", |
11381 | 0 | function ); |
11382 | |
|
11383 | 0 | return( -1 ); |
11384 | 0 | } |
11385 | 0 | if( set_identifier == NULL ) |
11386 | 0 | { |
11387 | 0 | libcerror_error_set( |
11388 | 0 | error, |
11389 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
11390 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
11391 | 0 | "%s: invalid set identifier.", |
11392 | 0 | function ); |
11393 | |
|
11394 | 0 | return( -1 ); |
11395 | 0 | } |
11396 | 0 | if( size < 16 ) |
11397 | 0 | { |
11398 | 0 | libcerror_error_set( |
11399 | 0 | error, |
11400 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
11401 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
11402 | 0 | "%s: set identifier too small.", |
11403 | 0 | function ); |
11404 | |
|
11405 | 0 | return( -1 ); |
11406 | 0 | } |
11407 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
11408 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
11409 | 0 | internal_handle->read_write_lock, |
11410 | 0 | error ) != 1 ) |
11411 | 0 | { |
11412 | 0 | libcerror_error_set( |
11413 | 0 | error, |
11414 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11415 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
11416 | 0 | "%s: unable to grab read/write lock for reading.", |
11417 | 0 | function ); |
11418 | |
|
11419 | 0 | return( -1 ); |
11420 | 0 | } |
11421 | 0 | #endif |
11422 | 0 | if( memory_copy( |
11423 | 0 | set_identifier, |
11424 | 0 | internal_handle->media_values->set_identifier, |
11425 | 0 | 16 ) == NULL ) |
11426 | 0 | { |
11427 | 0 | libcerror_error_set( |
11428 | 0 | error, |
11429 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
11430 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
11431 | 0 | "%s: unable to set set identifier.", |
11432 | 0 | function ); |
11433 | |
|
11434 | 0 | goto on_error; |
11435 | 0 | } |
11436 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
11437 | 0 | if( libcthreads_read_write_lock_release_for_read( |
11438 | 0 | internal_handle->read_write_lock, |
11439 | 0 | error ) != 1 ) |
11440 | 0 | { |
11441 | 0 | libcerror_error_set( |
11442 | 0 | error, |
11443 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11444 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
11445 | 0 | "%s: unable to release read/write lock for reading.", |
11446 | 0 | function ); |
11447 | |
|
11448 | 0 | return( -1 ); |
11449 | 0 | } |
11450 | 0 | #endif |
11451 | 0 | return( 1 ); |
11452 | | |
11453 | 0 | on_error: |
11454 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
11455 | 0 | libcthreads_read_write_lock_release_for_read( |
11456 | 0 | internal_handle->read_write_lock, |
11457 | 0 | NULL ); |
11458 | 0 | #endif |
11459 | 0 | return( -1 ); |
11460 | 0 | } |
11461 | | |
11462 | | /* Sets the segment file set identifier |
11463 | | * The identifier is a GUID and is 16 bytes of size |
11464 | | * Returns 1 if successful or -1 on error |
11465 | | */ |
11466 | | int libewf_handle_set_segment_file_set_identifier( |
11467 | | libewf_handle_t *handle, |
11468 | | const uint8_t *set_identifier, |
11469 | | size_t size, |
11470 | | libcerror_error_t **error ) |
11471 | 0 | { |
11472 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
11473 | 0 | static char *function = "libewf_handle_set_segment_file_set_identifier"; |
11474 | |
|
11475 | 0 | if( handle == NULL ) |
11476 | 0 | { |
11477 | 0 | libcerror_error_set( |
11478 | 0 | error, |
11479 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
11480 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
11481 | 0 | "%s: invalid handle.", |
11482 | 0 | function ); |
11483 | |
|
11484 | 0 | return( -1 ); |
11485 | 0 | } |
11486 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
11487 | |
|
11488 | 0 | if( internal_handle->media_values == NULL ) |
11489 | 0 | { |
11490 | 0 | libcerror_error_set( |
11491 | 0 | error, |
11492 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11493 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
11494 | 0 | "%s: invalid handle - missing media values.", |
11495 | 0 | function ); |
11496 | |
|
11497 | 0 | return( -1 ); |
11498 | 0 | } |
11499 | 0 | if( set_identifier == NULL ) |
11500 | 0 | { |
11501 | 0 | libcerror_error_set( |
11502 | 0 | error, |
11503 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
11504 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
11505 | 0 | "%s: invalid set identifier.", |
11506 | 0 | function ); |
11507 | |
|
11508 | 0 | return( -1 ); |
11509 | 0 | } |
11510 | 0 | if( size < 16 ) |
11511 | 0 | { |
11512 | 0 | libcerror_error_set( |
11513 | 0 | error, |
11514 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
11515 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
11516 | 0 | "%s: set identifier too small.", |
11517 | 0 | function ); |
11518 | |
|
11519 | 0 | return( -1 ); |
11520 | 0 | } |
11521 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
11522 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
11523 | 0 | internal_handle->read_write_lock, |
11524 | 0 | error ) != 1 ) |
11525 | 0 | { |
11526 | 0 | libcerror_error_set( |
11527 | 0 | error, |
11528 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11529 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
11530 | 0 | "%s: unable to grab read/write lock for writing.", |
11531 | 0 | function ); |
11532 | |
|
11533 | 0 | return( -1 ); |
11534 | 0 | } |
11535 | 0 | #endif |
11536 | 0 | if( ( internal_handle->read_io_handle != NULL ) |
11537 | 0 | || ( internal_handle->write_io_handle == NULL ) |
11538 | 0 | || ( internal_handle->write_io_handle->values_initialized != 0 ) ) |
11539 | 0 | { |
11540 | 0 | libcerror_error_set( |
11541 | 0 | error, |
11542 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11543 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
11544 | 0 | "%s: set identifier cannot be changed.", |
11545 | 0 | function ); |
11546 | |
|
11547 | 0 | goto on_error; |
11548 | 0 | } |
11549 | 0 | if( memory_copy( |
11550 | 0 | internal_handle->media_values->set_identifier, |
11551 | 0 | set_identifier, |
11552 | 0 | 16 ) == NULL ) |
11553 | 0 | { |
11554 | 0 | libcerror_error_set( |
11555 | 0 | error, |
11556 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
11557 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
11558 | 0 | "%s: unable to copy set indentifier.", |
11559 | 0 | function ); |
11560 | |
|
11561 | 0 | goto on_error; |
11562 | 0 | } |
11563 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
11564 | 0 | if( libcthreads_read_write_lock_release_for_write( |
11565 | 0 | internal_handle->read_write_lock, |
11566 | 0 | error ) != 1 ) |
11567 | 0 | { |
11568 | 0 | libcerror_error_set( |
11569 | 0 | error, |
11570 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11571 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
11572 | 0 | "%s: unable to release read/write lock for writing.", |
11573 | 0 | function ); |
11574 | |
|
11575 | 0 | return( -1 ); |
11576 | 0 | } |
11577 | 0 | #endif |
11578 | 0 | return( 1 ); |
11579 | | |
11580 | 0 | on_error: |
11581 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
11582 | 0 | libcthreads_read_write_lock_release_for_write( |
11583 | 0 | internal_handle->read_write_lock, |
11584 | 0 | NULL ); |
11585 | 0 | #endif |
11586 | 0 | return( -1 ); |
11587 | 0 | } |
11588 | | |
11589 | | /* Retrieves the MD5 hash |
11590 | | * Returns 1 if successful, 0 if not set or -1 on error |
11591 | | */ |
11592 | | int libewf_handle_get_md5_hash( |
11593 | | libewf_handle_t *handle, |
11594 | | uint8_t *md5_hash, |
11595 | | size_t size, |
11596 | | libcerror_error_t **error ) |
11597 | 0 | { |
11598 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
11599 | 0 | static char *function = "libewf_handle_get_md5_hash"; |
11600 | 0 | int result = 0; |
11601 | |
|
11602 | 0 | if( handle == NULL ) |
11603 | 0 | { |
11604 | 0 | libcerror_error_set( |
11605 | 0 | error, |
11606 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
11607 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
11608 | 0 | "%s: invalid handle.", |
11609 | 0 | function ); |
11610 | |
|
11611 | 0 | return( -1 ); |
11612 | 0 | } |
11613 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
11614 | |
|
11615 | 0 | if( internal_handle->hash_sections == NULL ) |
11616 | 0 | { |
11617 | 0 | libcerror_error_set( |
11618 | 0 | error, |
11619 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11620 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
11621 | 0 | "%s: invalid handle - missing hash sections.", |
11622 | 0 | function ); |
11623 | |
|
11624 | 0 | return( -1 ); |
11625 | 0 | } |
11626 | 0 | if( md5_hash == NULL ) |
11627 | 0 | { |
11628 | 0 | libcerror_error_set( |
11629 | 0 | error, |
11630 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
11631 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
11632 | 0 | "%s: invalid MD5 hash.", |
11633 | 0 | function ); |
11634 | |
|
11635 | 0 | return( -1 ); |
11636 | 0 | } |
11637 | 0 | if( size < 16 ) |
11638 | 0 | { |
11639 | 0 | libcerror_error_set( |
11640 | 0 | error, |
11641 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
11642 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
11643 | 0 | "%s: MD5 hash too small.", |
11644 | 0 | function ); |
11645 | |
|
11646 | 0 | return( -1 ); |
11647 | 0 | } |
11648 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
11649 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
11650 | 0 | internal_handle->read_write_lock, |
11651 | 0 | error ) != 1 ) |
11652 | 0 | { |
11653 | 0 | libcerror_error_set( |
11654 | 0 | error, |
11655 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11656 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
11657 | 0 | "%s: unable to grab read/write lock for writing.", |
11658 | 0 | function ); |
11659 | |
|
11660 | 0 | return( -1 ); |
11661 | 0 | } |
11662 | 0 | #endif |
11663 | 0 | if( ( internal_handle->hash_sections->md5_hash_set == 0 ) |
11664 | 0 | && ( internal_handle->hash_values != NULL ) ) |
11665 | 0 | { |
11666 | 0 | if( libewf_hash_values_generate_md5_hash( |
11667 | 0 | internal_handle->hash_values, |
11668 | 0 | internal_handle->hash_sections->md5_hash, |
11669 | 0 | 16, |
11670 | 0 | &( internal_handle->hash_sections->md5_hash_set ), |
11671 | 0 | error ) != 1 ) |
11672 | 0 | { |
11673 | 0 | libcerror_error_set( |
11674 | 0 | error, |
11675 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11676 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
11677 | 0 | "%s: unable to parse MD5 hash value for its value.", |
11678 | 0 | function ); |
11679 | |
|
11680 | 0 | goto on_error; |
11681 | 0 | } |
11682 | 0 | } |
11683 | 0 | if( internal_handle->hash_sections->md5_digest_set != 0 ) |
11684 | 0 | { |
11685 | 0 | if( memory_copy( |
11686 | 0 | md5_hash, |
11687 | 0 | internal_handle->hash_sections->md5_digest, |
11688 | 0 | 16 ) == NULL ) |
11689 | 0 | { |
11690 | 0 | libcerror_error_set( |
11691 | 0 | error, |
11692 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
11693 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
11694 | 0 | "%s: unable to copy MD5 digest.", |
11695 | 0 | function ); |
11696 | |
|
11697 | 0 | goto on_error; |
11698 | 0 | } |
11699 | 0 | result = 1; |
11700 | 0 | } |
11701 | 0 | else if( internal_handle->hash_sections->md5_hash_set != 0 ) |
11702 | 0 | { |
11703 | 0 | if( memory_copy( |
11704 | 0 | md5_hash, |
11705 | 0 | internal_handle->hash_sections->md5_hash, |
11706 | 0 | 16 ) == NULL ) |
11707 | 0 | { |
11708 | 0 | libcerror_error_set( |
11709 | 0 | error, |
11710 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
11711 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
11712 | 0 | "%s: unable to copy MD5 hash.", |
11713 | 0 | function ); |
11714 | |
|
11715 | 0 | goto on_error; |
11716 | 0 | } |
11717 | 0 | result = 1; |
11718 | 0 | } |
11719 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
11720 | 0 | if( libcthreads_read_write_lock_release_for_write( |
11721 | 0 | internal_handle->read_write_lock, |
11722 | 0 | error ) != 1 ) |
11723 | 0 | { |
11724 | 0 | libcerror_error_set( |
11725 | 0 | error, |
11726 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11727 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
11728 | 0 | "%s: unable to release read/write lock for writing.", |
11729 | 0 | function ); |
11730 | |
|
11731 | 0 | return( -1 ); |
11732 | 0 | } |
11733 | 0 | #endif |
11734 | 0 | return( result ); |
11735 | | |
11736 | 0 | on_error: |
11737 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
11738 | 0 | libcthreads_read_write_lock_release_for_write( |
11739 | 0 | internal_handle->read_write_lock, |
11740 | 0 | NULL ); |
11741 | 0 | #endif |
11742 | 0 | return( -1 ); |
11743 | 0 | } |
11744 | | |
11745 | | /* Sets the MD5 hash |
11746 | | * Returns 1 if successful or -1 on error |
11747 | | */ |
11748 | | int libewf_handle_set_md5_hash( |
11749 | | libewf_handle_t *handle, |
11750 | | const uint8_t *md5_hash, |
11751 | | size_t size, |
11752 | | libcerror_error_t **error ) |
11753 | 0 | { |
11754 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
11755 | 0 | static char *function = "libewf_handle_set_md5_hash"; |
11756 | |
|
11757 | 0 | if( handle == NULL ) |
11758 | 0 | { |
11759 | 0 | libcerror_error_set( |
11760 | 0 | error, |
11761 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
11762 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
11763 | 0 | "%s: invalid handle.", |
11764 | 0 | function ); |
11765 | |
|
11766 | 0 | return( -1 ); |
11767 | 0 | } |
11768 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
11769 | |
|
11770 | 0 | if( internal_handle->hash_sections == NULL ) |
11771 | 0 | { |
11772 | 0 | libcerror_error_set( |
11773 | 0 | error, |
11774 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11775 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
11776 | 0 | "%s: invalid handle - missing hash sections.", |
11777 | 0 | function ); |
11778 | |
|
11779 | 0 | return( -1 ); |
11780 | 0 | } |
11781 | 0 | if( md5_hash == NULL ) |
11782 | 0 | { |
11783 | 0 | libcerror_error_set( |
11784 | 0 | error, |
11785 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
11786 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
11787 | 0 | "%s: invalid MD5 hash.", |
11788 | 0 | function ); |
11789 | |
|
11790 | 0 | return( -1 ); |
11791 | 0 | } |
11792 | 0 | if( size < 16 ) |
11793 | 0 | { |
11794 | 0 | libcerror_error_set( |
11795 | 0 | error, |
11796 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
11797 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
11798 | 0 | "%s: MD5 hash too small.", |
11799 | 0 | function ); |
11800 | |
|
11801 | 0 | return( -1 ); |
11802 | 0 | } |
11803 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
11804 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
11805 | 0 | internal_handle->read_write_lock, |
11806 | 0 | error ) != 1 ) |
11807 | 0 | { |
11808 | 0 | libcerror_error_set( |
11809 | 0 | error, |
11810 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11811 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
11812 | 0 | "%s: unable to grab read/write lock for writing.", |
11813 | 0 | function ); |
11814 | |
|
11815 | 0 | return( -1 ); |
11816 | 0 | } |
11817 | 0 | #endif |
11818 | 0 | if( ( internal_handle->read_io_handle != NULL ) |
11819 | 0 | || ( internal_handle->hash_sections->md5_hash_set != 0 ) |
11820 | 0 | || ( internal_handle->hash_sections->md5_digest_set != 0 ) ) |
11821 | 0 | { |
11822 | 0 | libcerror_error_set( |
11823 | 0 | error, |
11824 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11825 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
11826 | 0 | "%s: MD5 hash cannot be changed.", |
11827 | 0 | function ); |
11828 | |
|
11829 | 0 | goto on_error; |
11830 | 0 | } |
11831 | 0 | if( internal_handle->hash_values == NULL ) |
11832 | 0 | { |
11833 | 0 | if( libewf_hash_values_initialize( |
11834 | 0 | &( internal_handle->hash_values ), |
11835 | 0 | error ) != 1 ) |
11836 | 0 | { |
11837 | 0 | libcerror_error_set( |
11838 | 0 | error, |
11839 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11840 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
11841 | 0 | "%s: unable to create hash values.", |
11842 | 0 | function ); |
11843 | |
|
11844 | 0 | goto on_error; |
11845 | 0 | } |
11846 | 0 | internal_handle->hash_values_parsed = 1; |
11847 | 0 | } |
11848 | 0 | if( memory_copy( |
11849 | 0 | internal_handle->hash_sections->md5_hash, |
11850 | 0 | md5_hash, |
11851 | 0 | 16 ) == NULL ) |
11852 | 0 | { |
11853 | 0 | libcerror_error_set( |
11854 | 0 | error, |
11855 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
11856 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
11857 | 0 | "%s: unable to set MD5 hash.", |
11858 | 0 | function ); |
11859 | |
|
11860 | 0 | goto on_error; |
11861 | 0 | } |
11862 | 0 | internal_handle->hash_sections->md5_hash_set = 1; |
11863 | |
|
11864 | 0 | if( memory_copy( |
11865 | 0 | internal_handle->hash_sections->md5_digest, |
11866 | 0 | md5_hash, |
11867 | 0 | 16 ) == NULL ) |
11868 | 0 | { |
11869 | 0 | libcerror_error_set( |
11870 | 0 | error, |
11871 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
11872 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
11873 | 0 | "%s: unable to set MD5 hash.", |
11874 | 0 | function ); |
11875 | |
|
11876 | 0 | goto on_error; |
11877 | 0 | } |
11878 | 0 | internal_handle->hash_sections->md5_digest_set = 1; |
11879 | |
|
11880 | 0 | if( libewf_hash_values_parse_md5_hash( |
11881 | 0 | internal_handle->hash_values, |
11882 | 0 | md5_hash, |
11883 | 0 | 16, |
11884 | 0 | error ) != 1 ) |
11885 | 0 | { |
11886 | 0 | libcerror_error_set( |
11887 | 0 | error, |
11888 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11889 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
11890 | 0 | "%s: unable to parse MD5 hash for its value.", |
11891 | 0 | function ); |
11892 | |
|
11893 | 0 | goto on_error; |
11894 | 0 | } |
11895 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
11896 | 0 | if( libcthreads_read_write_lock_release_for_write( |
11897 | 0 | internal_handle->read_write_lock, |
11898 | 0 | error ) != 1 ) |
11899 | 0 | { |
11900 | 0 | libcerror_error_set( |
11901 | 0 | error, |
11902 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11903 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
11904 | 0 | "%s: unable to release read/write lock for writing.", |
11905 | 0 | function ); |
11906 | |
|
11907 | 0 | return( -1 ); |
11908 | 0 | } |
11909 | 0 | #endif |
11910 | 0 | return( 1 ); |
11911 | | |
11912 | 0 | on_error: |
11913 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
11914 | 0 | libcthreads_read_write_lock_release_for_write( |
11915 | 0 | internal_handle->read_write_lock, |
11916 | 0 | NULL ); |
11917 | 0 | #endif |
11918 | 0 | return( -1 ); |
11919 | 0 | } |
11920 | | |
11921 | | /* Retrieves the SHA1 hash |
11922 | | * Returns 1 if successful, 0 if not set or -1 on error |
11923 | | */ |
11924 | | int libewf_handle_get_sha1_hash( |
11925 | | libewf_handle_t *handle, |
11926 | | uint8_t *sha1_hash, |
11927 | | size_t size, |
11928 | | libcerror_error_t **error ) |
11929 | 0 | { |
11930 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
11931 | 0 | static char *function = "libewf_handle_get_sha1_hash"; |
11932 | 0 | int result = 0; |
11933 | |
|
11934 | 0 | if( handle == NULL ) |
11935 | 0 | { |
11936 | 0 | libcerror_error_set( |
11937 | 0 | error, |
11938 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
11939 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
11940 | 0 | "%s: invalid handle.", |
11941 | 0 | function ); |
11942 | |
|
11943 | 0 | return( -1 ); |
11944 | 0 | } |
11945 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
11946 | |
|
11947 | 0 | if( internal_handle->hash_sections == NULL ) |
11948 | 0 | { |
11949 | 0 | libcerror_error_set( |
11950 | 0 | error, |
11951 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11952 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
11953 | 0 | "%s: invalid handle - missing hash sections.", |
11954 | 0 | function ); |
11955 | |
|
11956 | 0 | return( -1 ); |
11957 | 0 | } |
11958 | 0 | if( sha1_hash == NULL ) |
11959 | 0 | { |
11960 | 0 | libcerror_error_set( |
11961 | 0 | error, |
11962 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
11963 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
11964 | 0 | "%s: invalid SHA1 hash.", |
11965 | 0 | function ); |
11966 | |
|
11967 | 0 | return( -1 ); |
11968 | 0 | } |
11969 | 0 | if( size < 20 ) |
11970 | 0 | { |
11971 | 0 | libcerror_error_set( |
11972 | 0 | error, |
11973 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
11974 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
11975 | 0 | "%s: SHA1 hash too small.", |
11976 | 0 | function ); |
11977 | |
|
11978 | 0 | return( -1 ); |
11979 | 0 | } |
11980 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
11981 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
11982 | 0 | internal_handle->read_write_lock, |
11983 | 0 | error ) != 1 ) |
11984 | 0 | { |
11985 | 0 | libcerror_error_set( |
11986 | 0 | error, |
11987 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
11988 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
11989 | 0 | "%s: unable to grab read/write lock for writing.", |
11990 | 0 | function ); |
11991 | |
|
11992 | 0 | return( -1 ); |
11993 | 0 | } |
11994 | 0 | #endif |
11995 | 0 | if( ( internal_handle->hash_sections->sha1_digest_set == 0 ) |
11996 | 0 | && ( internal_handle->hash_values != NULL ) ) |
11997 | 0 | { |
11998 | 0 | if( libewf_hash_values_generate_sha1_hash( |
11999 | 0 | internal_handle->hash_values, |
12000 | 0 | internal_handle->hash_sections->sha1_digest, |
12001 | 0 | 20, |
12002 | 0 | &( internal_handle->hash_sections->sha1_digest_set ), |
12003 | 0 | error ) != 1 ) |
12004 | 0 | { |
12005 | 0 | libcerror_error_set( |
12006 | 0 | error, |
12007 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12008 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
12009 | 0 | "%s: unable to parse MD5 hash value for its value.", |
12010 | 0 | function ); |
12011 | |
|
12012 | 0 | goto on_error; |
12013 | 0 | } |
12014 | 0 | } |
12015 | 0 | if( internal_handle->hash_sections->sha1_digest_set != 0 ) |
12016 | 0 | { |
12017 | 0 | if( memory_copy( |
12018 | 0 | sha1_hash, |
12019 | 0 | internal_handle->hash_sections->sha1_digest, |
12020 | 0 | 20 ) == NULL ) |
12021 | 0 | { |
12022 | 0 | libcerror_error_set( |
12023 | 0 | error, |
12024 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
12025 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
12026 | 0 | "%s: unable to copy SHA1 digest.", |
12027 | 0 | function ); |
12028 | |
|
12029 | 0 | goto on_error; |
12030 | 0 | } |
12031 | 0 | result = 1; |
12032 | 0 | } |
12033 | 0 | else if( internal_handle->hash_sections->sha1_hash_set != 0 ) |
12034 | 0 | { |
12035 | 0 | if( memory_copy( |
12036 | 0 | sha1_hash, |
12037 | 0 | internal_handle->hash_sections->sha1_hash, |
12038 | 0 | 20 ) == NULL ) |
12039 | 0 | { |
12040 | 0 | libcerror_error_set( |
12041 | 0 | error, |
12042 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
12043 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
12044 | 0 | "%s: unable to copy SHA1 hash.", |
12045 | 0 | function ); |
12046 | |
|
12047 | 0 | goto on_error; |
12048 | 0 | } |
12049 | 0 | result = 1; |
12050 | 0 | } |
12051 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12052 | 0 | if( libcthreads_read_write_lock_release_for_write( |
12053 | 0 | internal_handle->read_write_lock, |
12054 | 0 | error ) != 1 ) |
12055 | 0 | { |
12056 | 0 | libcerror_error_set( |
12057 | 0 | error, |
12058 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12059 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
12060 | 0 | "%s: unable to release read/write lock for writing.", |
12061 | 0 | function ); |
12062 | |
|
12063 | 0 | return( -1 ); |
12064 | 0 | } |
12065 | 0 | #endif |
12066 | 0 | return( result ); |
12067 | | |
12068 | 0 | on_error: |
12069 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12070 | 0 | libcthreads_read_write_lock_release_for_write( |
12071 | 0 | internal_handle->read_write_lock, |
12072 | 0 | NULL ); |
12073 | 0 | #endif |
12074 | 0 | return( -1 ); |
12075 | 0 | } |
12076 | | |
12077 | | /* Sets the SHA1 hash |
12078 | | * Returns 1 if successful or -1 on error |
12079 | | */ |
12080 | | int libewf_handle_set_sha1_hash( |
12081 | | libewf_handle_t *handle, |
12082 | | const uint8_t *sha1_hash, |
12083 | | size_t size, |
12084 | | libcerror_error_t **error ) |
12085 | 0 | { |
12086 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
12087 | 0 | static char *function = "libewf_handle_set_sha1_hash"; |
12088 | |
|
12089 | 0 | if( handle == NULL ) |
12090 | 0 | { |
12091 | 0 | libcerror_error_set( |
12092 | 0 | error, |
12093 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
12094 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
12095 | 0 | "%s: invalid handle.", |
12096 | 0 | function ); |
12097 | |
|
12098 | 0 | return( -1 ); |
12099 | 0 | } |
12100 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
12101 | |
|
12102 | 0 | if( internal_handle->hash_sections == NULL ) |
12103 | 0 | { |
12104 | 0 | libcerror_error_set( |
12105 | 0 | error, |
12106 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12107 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
12108 | 0 | "%s: invalid handle - missing hash sections.", |
12109 | 0 | function ); |
12110 | |
|
12111 | 0 | return( -1 ); |
12112 | 0 | } |
12113 | 0 | if( sha1_hash == NULL ) |
12114 | 0 | { |
12115 | 0 | libcerror_error_set( |
12116 | 0 | error, |
12117 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
12118 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
12119 | 0 | "%s: invalid SHA1 hash.", |
12120 | 0 | function ); |
12121 | |
|
12122 | 0 | return( -1 ); |
12123 | 0 | } |
12124 | 0 | if( size < 20 ) |
12125 | 0 | { |
12126 | 0 | libcerror_error_set( |
12127 | 0 | error, |
12128 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
12129 | 0 | LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
12130 | 0 | "%s: SHA1 hash too small.", |
12131 | 0 | function ); |
12132 | |
|
12133 | 0 | return( -1 ); |
12134 | 0 | } |
12135 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12136 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
12137 | 0 | internal_handle->read_write_lock, |
12138 | 0 | error ) != 1 ) |
12139 | 0 | { |
12140 | 0 | libcerror_error_set( |
12141 | 0 | error, |
12142 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12143 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
12144 | 0 | "%s: unable to grab read/write lock for writing.", |
12145 | 0 | function ); |
12146 | |
|
12147 | 0 | return( -1 ); |
12148 | 0 | } |
12149 | 0 | #endif |
12150 | 0 | if( ( internal_handle->read_io_handle != NULL ) |
12151 | 0 | || ( internal_handle->hash_sections->sha1_hash_set != 0 ) |
12152 | 0 | || ( internal_handle->hash_sections->sha1_digest_set != 0 ) ) |
12153 | 0 | { |
12154 | 0 | libcerror_error_set( |
12155 | 0 | error, |
12156 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12157 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
12158 | 0 | "%s: SHA1 hash cannot be changed.", |
12159 | 0 | function ); |
12160 | |
|
12161 | 0 | goto on_error; |
12162 | 0 | } |
12163 | 0 | if( internal_handle->hash_values == NULL ) |
12164 | 0 | { |
12165 | 0 | if( libewf_hash_values_initialize( |
12166 | 0 | &( internal_handle->hash_values ), |
12167 | 0 | error ) != 1 ) |
12168 | 0 | { |
12169 | 0 | libcerror_error_set( |
12170 | 0 | error, |
12171 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12172 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
12173 | 0 | "%s: unable to create hash values.", |
12174 | 0 | function ); |
12175 | |
|
12176 | 0 | goto on_error; |
12177 | 0 | } |
12178 | 0 | internal_handle->hash_values_parsed = 1; |
12179 | 0 | } |
12180 | 0 | if( memory_copy( |
12181 | 0 | internal_handle->hash_sections->sha1_hash, |
12182 | 0 | sha1_hash, |
12183 | 0 | 20 ) == NULL ) |
12184 | 0 | { |
12185 | 0 | libcerror_error_set( |
12186 | 0 | error, |
12187 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
12188 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
12189 | 0 | "%s: unable to set SHA1 hash.", |
12190 | 0 | function ); |
12191 | |
|
12192 | 0 | goto on_error; |
12193 | 0 | } |
12194 | 0 | internal_handle->hash_sections->sha1_hash_set = 1; |
12195 | |
|
12196 | 0 | if( memory_copy( |
12197 | 0 | internal_handle->hash_sections->sha1_digest, |
12198 | 0 | sha1_hash, |
12199 | 0 | 20 ) == NULL ) |
12200 | 0 | { |
12201 | 0 | libcerror_error_set( |
12202 | 0 | error, |
12203 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
12204 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
12205 | 0 | "%s: unable to set SHA1 hash.", |
12206 | 0 | function ); |
12207 | |
|
12208 | 0 | goto on_error; |
12209 | 0 | } |
12210 | 0 | internal_handle->hash_sections->sha1_digest_set = 1; |
12211 | |
|
12212 | 0 | if( libewf_hash_values_parse_sha1_hash( |
12213 | 0 | internal_handle->hash_values, |
12214 | 0 | sha1_hash, |
12215 | 0 | 20, |
12216 | 0 | error ) != 1 ) |
12217 | 0 | { |
12218 | 0 | libcerror_error_set( |
12219 | 0 | error, |
12220 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12221 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
12222 | 0 | "%s: unable to parse SHA1 hash for its value.", |
12223 | 0 | function ); |
12224 | |
|
12225 | 0 | goto on_error; |
12226 | 0 | } |
12227 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12228 | 0 | if( libcthreads_read_write_lock_release_for_write( |
12229 | 0 | internal_handle->read_write_lock, |
12230 | 0 | error ) != 1 ) |
12231 | 0 | { |
12232 | 0 | libcerror_error_set( |
12233 | 0 | error, |
12234 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12235 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
12236 | 0 | "%s: unable to release read/write lock for writing.", |
12237 | 0 | function ); |
12238 | |
|
12239 | 0 | return( -1 ); |
12240 | 0 | } |
12241 | 0 | #endif |
12242 | 0 | return( 1 ); |
12243 | | |
12244 | 0 | on_error: |
12245 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12246 | 0 | libcthreads_read_write_lock_release_for_write( |
12247 | 0 | internal_handle->read_write_lock, |
12248 | 0 | NULL ); |
12249 | 0 | #endif |
12250 | 0 | return( -1 ); |
12251 | 0 | } |
12252 | | |
12253 | | /* Sets the read zero chunk on error |
12254 | | * The chunk is not zeroed if read raw is used |
12255 | | * Returns 1 if successful or -1 on error |
12256 | | */ |
12257 | | int libewf_handle_set_read_zero_chunk_on_error( |
12258 | | libewf_handle_t *handle, |
12259 | | uint8_t zero_on_error, |
12260 | | libcerror_error_t **error ) |
12261 | 0 | { |
12262 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
12263 | 0 | static char *function = "libewf_handle_set_read_zero_chunk_on_error"; |
12264 | |
|
12265 | 0 | if( handle == NULL ) |
12266 | 0 | { |
12267 | 0 | libcerror_error_set( |
12268 | 0 | error, |
12269 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
12270 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
12271 | 0 | "%s: invalid handle.", |
12272 | 0 | function ); |
12273 | |
|
12274 | 0 | return( -1 ); |
12275 | 0 | } |
12276 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
12277 | |
|
12278 | 0 | if( internal_handle->io_handle == NULL ) |
12279 | 0 | { |
12280 | 0 | libcerror_error_set( |
12281 | 0 | error, |
12282 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12283 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
12284 | 0 | "%s: invalid handle - missing IO handle.", |
12285 | 0 | function ); |
12286 | |
|
12287 | 0 | return( -1 ); |
12288 | 0 | } |
12289 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12290 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
12291 | 0 | internal_handle->read_write_lock, |
12292 | 0 | error ) != 1 ) |
12293 | 0 | { |
12294 | 0 | libcerror_error_set( |
12295 | 0 | error, |
12296 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12297 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
12298 | 0 | "%s: unable to grab read/write lock for writing.", |
12299 | 0 | function ); |
12300 | |
|
12301 | 0 | return( -1 ); |
12302 | 0 | } |
12303 | 0 | #endif |
12304 | 0 | internal_handle->io_handle->zero_on_error = zero_on_error; |
12305 | |
|
12306 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12307 | 0 | if( libcthreads_read_write_lock_release_for_write( |
12308 | 0 | internal_handle->read_write_lock, |
12309 | 0 | error ) != 1 ) |
12310 | 0 | { |
12311 | 0 | libcerror_error_set( |
12312 | 0 | error, |
12313 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12314 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
12315 | 0 | "%s: unable to release read/write lock for writing.", |
12316 | 0 | function ); |
12317 | |
|
12318 | 0 | return( -1 ); |
12319 | 0 | } |
12320 | 0 | #endif |
12321 | 0 | return( 1 ); |
12322 | 0 | } |
12323 | | |
12324 | | /* Copies the media values from the source to the destination handle |
12325 | | * Returns 1 if successful or -1 on error |
12326 | | */ |
12327 | | int libewf_handle_copy_media_values( |
12328 | | libewf_handle_t *destination_handle, |
12329 | | libewf_handle_t *source_handle, |
12330 | | libcerror_error_t **error ) |
12331 | 0 | { |
12332 | 0 | libewf_internal_handle_t *internal_destination_handle = NULL; |
12333 | 0 | libewf_internal_handle_t *internal_source_handle = NULL; |
12334 | 0 | static char *function = "libewf_handle_copy_media_values"; |
12335 | |
|
12336 | 0 | if( destination_handle == NULL ) |
12337 | 0 | { |
12338 | 0 | libcerror_error_set( |
12339 | 0 | error, |
12340 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
12341 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
12342 | 0 | "%s: invalid destination handle.", |
12343 | 0 | function ); |
12344 | |
|
12345 | 0 | return( -1 ); |
12346 | 0 | } |
12347 | 0 | if( source_handle == NULL ) |
12348 | 0 | { |
12349 | 0 | libcerror_error_set( |
12350 | 0 | error, |
12351 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
12352 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
12353 | 0 | "%s: invalid source handle.", |
12354 | 0 | function ); |
12355 | |
|
12356 | 0 | return( -1 ); |
12357 | 0 | } |
12358 | 0 | internal_destination_handle = (libewf_internal_handle_t *) destination_handle; |
12359 | 0 | internal_source_handle = (libewf_internal_handle_t *) source_handle; |
12360 | |
|
12361 | 0 | if( internal_source_handle->media_values == NULL ) |
12362 | 0 | { |
12363 | 0 | libcerror_error_set( |
12364 | 0 | error, |
12365 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12366 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
12367 | 0 | "%s: invalid source handle - missing media values.", |
12368 | 0 | function ); |
12369 | |
|
12370 | 0 | return( -1 ); |
12371 | 0 | } |
12372 | 0 | if( internal_destination_handle->media_values == NULL ) |
12373 | 0 | { |
12374 | 0 | libcerror_error_set( |
12375 | 0 | error, |
12376 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12377 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
12378 | 0 | "%s: invalid destination handle - missing media values.", |
12379 | 0 | function ); |
12380 | |
|
12381 | 0 | return( -1 ); |
12382 | 0 | } |
12383 | 0 | if( memory_copy( |
12384 | 0 | internal_destination_handle->media_values, |
12385 | 0 | internal_source_handle->media_values, |
12386 | 0 | sizeof( libewf_media_values_t ) ) == NULL ) |
12387 | 0 | { |
12388 | 0 | libcerror_error_set( |
12389 | 0 | error, |
12390 | 0 | LIBCERROR_ERROR_DOMAIN_MEMORY, |
12391 | 0 | LIBCERROR_MEMORY_ERROR_COPY_FAILED, |
12392 | 0 | "%s: unable to copy media values.", |
12393 | 0 | function ); |
12394 | |
|
12395 | 0 | return( -1 ); |
12396 | 0 | } |
12397 | 0 | return( 1 ); |
12398 | 0 | } |
12399 | | |
12400 | | /* Retrieves the number of acquiry errors |
12401 | | * Returns 1 if successful or -1 on error |
12402 | | */ |
12403 | | int libewf_handle_get_number_of_acquiry_errors( |
12404 | | libewf_handle_t *handle, |
12405 | | uint32_t *number_of_errors, |
12406 | | libcerror_error_t **error ) |
12407 | 0 | { |
12408 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
12409 | 0 | static char *function = "libewf_handle_get_number_of_acquiry_errors"; |
12410 | 0 | int number_of_elements = 0; |
12411 | |
|
12412 | 0 | if( handle == NULL ) |
12413 | 0 | { |
12414 | 0 | libcerror_error_set( |
12415 | 0 | error, |
12416 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
12417 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
12418 | 0 | "%s: invalid handle.", |
12419 | 0 | function ); |
12420 | |
|
12421 | 0 | return( -1 ); |
12422 | 0 | } |
12423 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
12424 | |
|
12425 | 0 | if( number_of_errors == NULL ) |
12426 | 0 | { |
12427 | 0 | libcerror_error_set( |
12428 | 0 | error, |
12429 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
12430 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
12431 | 0 | "%s: invalid number of errors.", |
12432 | 0 | function ); |
12433 | |
|
12434 | 0 | return( -1 ); |
12435 | 0 | } |
12436 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12437 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
12438 | 0 | internal_handle->read_write_lock, |
12439 | 0 | error ) != 1 ) |
12440 | 0 | { |
12441 | 0 | libcerror_error_set( |
12442 | 0 | error, |
12443 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12444 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
12445 | 0 | "%s: unable to grab read/write lock for reading.", |
12446 | 0 | function ); |
12447 | |
|
12448 | 0 | return( -1 ); |
12449 | 0 | } |
12450 | 0 | #endif |
12451 | 0 | if( internal_handle->acquiry_errors != NULL ) |
12452 | 0 | { |
12453 | 0 | if( libcdata_range_list_get_number_of_elements( |
12454 | 0 | internal_handle->acquiry_errors, |
12455 | 0 | &number_of_elements, |
12456 | 0 | error ) != 1 ) |
12457 | 0 | { |
12458 | 0 | libcerror_error_set( |
12459 | 0 | error, |
12460 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12461 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
12462 | 0 | "%s: unable to retrieve number of elements from acquiry errors range list.", |
12463 | 0 | function ); |
12464 | |
|
12465 | 0 | goto on_error; |
12466 | 0 | } |
12467 | 0 | } |
12468 | 0 | if( number_of_elements < 0 ) |
12469 | 0 | { |
12470 | 0 | libcerror_error_set( |
12471 | 0 | error, |
12472 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12473 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
12474 | 0 | "%s: invalid number of elements value out of bounds.", |
12475 | 0 | function ); |
12476 | |
|
12477 | 0 | goto on_error; |
12478 | 0 | } |
12479 | 0 | *number_of_errors = (uint32_t) number_of_elements; |
12480 | |
|
12481 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12482 | 0 | if( libcthreads_read_write_lock_release_for_read( |
12483 | 0 | internal_handle->read_write_lock, |
12484 | 0 | error ) != 1 ) |
12485 | 0 | { |
12486 | 0 | libcerror_error_set( |
12487 | 0 | error, |
12488 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12489 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
12490 | 0 | "%s: unable to release read/write lock for reading.", |
12491 | 0 | function ); |
12492 | |
|
12493 | 0 | return( -1 ); |
12494 | 0 | } |
12495 | 0 | #endif |
12496 | 0 | return( 1 ); |
12497 | | |
12498 | 0 | on_error: |
12499 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12500 | 0 | libcthreads_read_write_lock_release_for_read( |
12501 | 0 | internal_handle->read_write_lock, |
12502 | 0 | NULL ); |
12503 | 0 | #endif |
12504 | 0 | return( -1 ); |
12505 | 0 | } |
12506 | | |
12507 | | /* Retrieves an acquiry error |
12508 | | * Returns 1 if successful or -1 on error |
12509 | | */ |
12510 | | int libewf_handle_get_acquiry_error( |
12511 | | libewf_handle_t *handle, |
12512 | | uint32_t index, |
12513 | | uint64_t *start_sector, |
12514 | | uint64_t *number_of_sectors, |
12515 | | libcerror_error_t **error ) |
12516 | 0 | { |
12517 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
12518 | 0 | static char *function = "libewf_handle_get_acquiry_error"; |
12519 | 0 | intptr_t *value = NULL; |
12520 | 0 | int result = 0; |
12521 | |
|
12522 | 0 | if( handle == NULL ) |
12523 | 0 | { |
12524 | 0 | libcerror_error_set( |
12525 | 0 | error, |
12526 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
12527 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
12528 | 0 | "%s: invalid handle.", |
12529 | 0 | function ); |
12530 | |
|
12531 | 0 | return( -1 ); |
12532 | 0 | } |
12533 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
12534 | |
|
12535 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12536 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
12537 | 0 | internal_handle->read_write_lock, |
12538 | 0 | error ) != 1 ) |
12539 | 0 | { |
12540 | 0 | libcerror_error_set( |
12541 | 0 | error, |
12542 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12543 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
12544 | 0 | "%s: unable to grab read/write lock for reading.", |
12545 | 0 | function ); |
12546 | |
|
12547 | 0 | return( -1 ); |
12548 | 0 | } |
12549 | 0 | #endif |
12550 | 0 | result = libcdata_range_list_get_range_by_index( |
12551 | 0 | internal_handle->acquiry_errors, |
12552 | 0 | (int) index, |
12553 | 0 | start_sector, |
12554 | 0 | number_of_sectors, |
12555 | 0 | &value, |
12556 | 0 | error ); |
12557 | |
|
12558 | 0 | if( result != 1 ) |
12559 | 0 | { |
12560 | 0 | libcerror_error_set( |
12561 | 0 | error, |
12562 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12563 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
12564 | 0 | "%s: unable to retrieve acquiry error: %" PRIu32 ".", |
12565 | 0 | function, |
12566 | 0 | index ); |
12567 | 0 | } |
12568 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12569 | 0 | if( libcthreads_read_write_lock_release_for_read( |
12570 | 0 | internal_handle->read_write_lock, |
12571 | 0 | error ) != 1 ) |
12572 | 0 | { |
12573 | 0 | libcerror_error_set( |
12574 | 0 | error, |
12575 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12576 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
12577 | 0 | "%s: unable to release read/write lock for reading.", |
12578 | 0 | function ); |
12579 | |
|
12580 | 0 | return( -1 ); |
12581 | 0 | } |
12582 | 0 | #endif |
12583 | 0 | return( result ); |
12584 | 0 | } |
12585 | | |
12586 | | /* Append an acquiry error |
12587 | | * Returns 1 if successful or -1 on error |
12588 | | */ |
12589 | | int libewf_handle_append_acquiry_error( |
12590 | | libewf_handle_t *handle, |
12591 | | uint64_t start_sector, |
12592 | | uint64_t number_of_sectors, |
12593 | | libcerror_error_t **error ) |
12594 | 0 | { |
12595 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
12596 | 0 | static char *function = "libewf_handle_append_acquiry_error"; |
12597 | 0 | int result = 0; |
12598 | |
|
12599 | 0 | if( handle == NULL ) |
12600 | 0 | { |
12601 | 0 | libcerror_error_set( |
12602 | 0 | error, |
12603 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
12604 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
12605 | 0 | "%s: invalid handle.", |
12606 | 0 | function ); |
12607 | |
|
12608 | 0 | return( -1 ); |
12609 | 0 | } |
12610 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
12611 | |
|
12612 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12613 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
12614 | 0 | internal_handle->read_write_lock, |
12615 | 0 | error ) != 1 ) |
12616 | 0 | { |
12617 | 0 | libcerror_error_set( |
12618 | 0 | error, |
12619 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12620 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
12621 | 0 | "%s: unable to grab read/write lock for writing.", |
12622 | 0 | function ); |
12623 | |
|
12624 | 0 | return( -1 ); |
12625 | 0 | } |
12626 | 0 | #endif |
12627 | 0 | result = libcdata_range_list_insert_range( |
12628 | 0 | internal_handle->acquiry_errors, |
12629 | 0 | start_sector, |
12630 | 0 | number_of_sectors, |
12631 | 0 | NULL, |
12632 | 0 | NULL, |
12633 | 0 | NULL, |
12634 | 0 | error ); |
12635 | |
|
12636 | 0 | if( result != 1 ) |
12637 | 0 | { |
12638 | 0 | libcerror_error_set( |
12639 | 0 | error, |
12640 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12641 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
12642 | 0 | "%s: unable to insert acquiry error in range list.", |
12643 | 0 | function ); |
12644 | 0 | } |
12645 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12646 | 0 | if( libcthreads_read_write_lock_release_for_write( |
12647 | 0 | internal_handle->read_write_lock, |
12648 | 0 | error ) != 1 ) |
12649 | 0 | { |
12650 | 0 | libcerror_error_set( |
12651 | 0 | error, |
12652 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12653 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
12654 | 0 | "%s: unable to release read/write lock for writing.", |
12655 | 0 | function ); |
12656 | |
|
12657 | 0 | return( -1 ); |
12658 | 0 | } |
12659 | 0 | #endif |
12660 | 0 | return( result ); |
12661 | 0 | } |
12662 | | |
12663 | | /* Retrieves the number of checksum errors |
12664 | | * Returns 1 if successful or -1 on error |
12665 | | */ |
12666 | | int libewf_handle_get_number_of_checksum_errors( |
12667 | | libewf_handle_t *handle, |
12668 | | uint32_t *number_of_errors, |
12669 | | libcerror_error_t **error ) |
12670 | 0 | { |
12671 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
12672 | 0 | static char *function = "libewf_handle_get_number_of_checksum_errors"; |
12673 | 0 | uint32_t number_of_elements = 0; |
12674 | |
|
12675 | 0 | if( handle == NULL ) |
12676 | 0 | { |
12677 | 0 | libcerror_error_set( |
12678 | 0 | error, |
12679 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
12680 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
12681 | 0 | "%s: invalid handle.", |
12682 | 0 | function ); |
12683 | |
|
12684 | 0 | return( -1 ); |
12685 | 0 | } |
12686 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
12687 | |
|
12688 | 0 | if( number_of_errors == NULL ) |
12689 | 0 | { |
12690 | 0 | libcerror_error_set( |
12691 | 0 | error, |
12692 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
12693 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
12694 | 0 | "%s: invalid number of errors.", |
12695 | 0 | function ); |
12696 | |
|
12697 | 0 | return( -1 ); |
12698 | 0 | } |
12699 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12700 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
12701 | 0 | internal_handle->read_write_lock, |
12702 | 0 | error ) != 1 ) |
12703 | 0 | { |
12704 | 0 | libcerror_error_set( |
12705 | 0 | error, |
12706 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12707 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
12708 | 0 | "%s: unable to grab read/write lock for reading.", |
12709 | 0 | function ); |
12710 | |
|
12711 | 0 | return( -1 ); |
12712 | 0 | } |
12713 | 0 | #endif |
12714 | 0 | if( internal_handle->chunk_table != NULL ) |
12715 | 0 | { |
12716 | 0 | if( libewf_chunk_table_get_number_of_checksum_errors( |
12717 | 0 | internal_handle->chunk_table, |
12718 | 0 | &number_of_elements, |
12719 | 0 | error ) != 1 ) |
12720 | 0 | { |
12721 | 0 | libcerror_error_set( |
12722 | 0 | error, |
12723 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12724 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
12725 | 0 | "%s: unable to retrieve number of checksum errors.", |
12726 | 0 | function ); |
12727 | |
|
12728 | 0 | goto on_error; |
12729 | 0 | } |
12730 | 0 | } |
12731 | 0 | *number_of_errors = number_of_elements; |
12732 | |
|
12733 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12734 | 0 | if( libcthreads_read_write_lock_release_for_read( |
12735 | 0 | internal_handle->read_write_lock, |
12736 | 0 | error ) != 1 ) |
12737 | 0 | { |
12738 | 0 | libcerror_error_set( |
12739 | 0 | error, |
12740 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12741 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
12742 | 0 | "%s: unable to release read/write lock for reading.", |
12743 | 0 | function ); |
12744 | |
|
12745 | 0 | return( -1 ); |
12746 | 0 | } |
12747 | 0 | #endif |
12748 | 0 | return( 1 ); |
12749 | | |
12750 | 0 | on_error: |
12751 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12752 | 0 | libcthreads_read_write_lock_release_for_read( |
12753 | 0 | internal_handle->read_write_lock, |
12754 | 0 | NULL ); |
12755 | 0 | #endif |
12756 | 0 | return( -1 ); |
12757 | 0 | } |
12758 | | |
12759 | | /* Retrieves a checksum error |
12760 | | * Returns 1 if successful or -1 on error |
12761 | | */ |
12762 | | int libewf_handle_get_checksum_error( |
12763 | | libewf_handle_t *handle, |
12764 | | uint32_t error_index, |
12765 | | uint64_t *start_sector, |
12766 | | uint64_t *number_of_sectors, |
12767 | | libcerror_error_t **error ) |
12768 | 0 | { |
12769 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
12770 | 0 | static char *function = "libewf_handle_get_checksum_error"; |
12771 | 0 | int result = 0; |
12772 | |
|
12773 | 0 | if( handle == NULL ) |
12774 | 0 | { |
12775 | 0 | libcerror_error_set( |
12776 | 0 | error, |
12777 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
12778 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
12779 | 0 | "%s: invalid handle.", |
12780 | 0 | function ); |
12781 | |
|
12782 | 0 | return( -1 ); |
12783 | 0 | } |
12784 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
12785 | |
|
12786 | 0 | if( internal_handle->chunk_table == NULL ) |
12787 | 0 | { |
12788 | 0 | libcerror_error_set( |
12789 | 0 | error, |
12790 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12791 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
12792 | 0 | "%s: invalid handle - missing chunk table.", |
12793 | 0 | function ); |
12794 | |
|
12795 | 0 | return( -1 ); |
12796 | 0 | } |
12797 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12798 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
12799 | 0 | internal_handle->read_write_lock, |
12800 | 0 | error ) != 1 ) |
12801 | 0 | { |
12802 | 0 | libcerror_error_set( |
12803 | 0 | error, |
12804 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12805 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
12806 | 0 | "%s: unable to grab read/write lock for reading.", |
12807 | 0 | function ); |
12808 | |
|
12809 | 0 | return( -1 ); |
12810 | 0 | } |
12811 | 0 | #endif |
12812 | 0 | result = libewf_chunk_table_get_checksum_error( |
12813 | 0 | internal_handle->chunk_table, |
12814 | 0 | error_index, |
12815 | 0 | start_sector, |
12816 | 0 | number_of_sectors, |
12817 | 0 | error ); |
12818 | |
|
12819 | 0 | if( result != 1 ) |
12820 | 0 | { |
12821 | 0 | libcerror_error_set( |
12822 | 0 | error, |
12823 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12824 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
12825 | 0 | "%s: unable to retrieve checksum error: %" PRIu32 ".", |
12826 | 0 | function, |
12827 | 0 | error_index ); |
12828 | 0 | } |
12829 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12830 | 0 | if( libcthreads_read_write_lock_release_for_read( |
12831 | 0 | internal_handle->read_write_lock, |
12832 | 0 | error ) != 1 ) |
12833 | 0 | { |
12834 | 0 | libcerror_error_set( |
12835 | 0 | error, |
12836 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12837 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
12838 | 0 | "%s: unable to release read/write lock for reading.", |
12839 | 0 | function ); |
12840 | |
|
12841 | 0 | return( -1 ); |
12842 | 0 | } |
12843 | 0 | #endif |
12844 | 0 | return( result ); |
12845 | 0 | } |
12846 | | |
12847 | | /* Appends a checksum error |
12848 | | * Returns 1 if successful or -1 on error |
12849 | | */ |
12850 | | int libewf_handle_append_checksum_error( |
12851 | | libewf_handle_t *handle, |
12852 | | uint64_t start_sector, |
12853 | | uint64_t number_of_sectors, |
12854 | | libcerror_error_t **error ) |
12855 | 0 | { |
12856 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
12857 | 0 | static char *function = "libewf_handle_append_checksum_error"; |
12858 | 0 | int result = 0; |
12859 | |
|
12860 | 0 | if( handle == NULL ) |
12861 | 0 | { |
12862 | 0 | libcerror_error_set( |
12863 | 0 | error, |
12864 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
12865 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
12866 | 0 | "%s: invalid handle.", |
12867 | 0 | function ); |
12868 | |
|
12869 | 0 | return( -1 ); |
12870 | 0 | } |
12871 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
12872 | |
|
12873 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12874 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
12875 | 0 | internal_handle->read_write_lock, |
12876 | 0 | error ) != 1 ) |
12877 | 0 | { |
12878 | 0 | libcerror_error_set( |
12879 | 0 | error, |
12880 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12881 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
12882 | 0 | "%s: unable to grab read/write lock for writing.", |
12883 | 0 | function ); |
12884 | |
|
12885 | 0 | return( -1 ); |
12886 | 0 | } |
12887 | 0 | #endif |
12888 | 0 | result = libewf_chunk_table_append_checksum_error( |
12889 | 0 | internal_handle->chunk_table, |
12890 | 0 | start_sector, |
12891 | 0 | number_of_sectors, |
12892 | 0 | error ); |
12893 | |
|
12894 | 0 | if( result != 1 ) |
12895 | 0 | { |
12896 | 0 | libcerror_error_set( |
12897 | 0 | error, |
12898 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12899 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
12900 | 0 | "%s: unable to append checksum error.", |
12901 | 0 | function ); |
12902 | 0 | } |
12903 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12904 | 0 | if( libcthreads_read_write_lock_release_for_write( |
12905 | 0 | internal_handle->read_write_lock, |
12906 | 0 | error ) != 1 ) |
12907 | 0 | { |
12908 | 0 | libcerror_error_set( |
12909 | 0 | error, |
12910 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12911 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
12912 | 0 | "%s: unable to release read/write lock for writing.", |
12913 | 0 | function ); |
12914 | |
|
12915 | 0 | return( -1 ); |
12916 | 0 | } |
12917 | 0 | #endif |
12918 | 0 | return( result ); |
12919 | 0 | } |
12920 | | |
12921 | | /* Retrieves the number of sessions |
12922 | | * Returns 1 if successful or -1 on error |
12923 | | */ |
12924 | | int libewf_handle_get_number_of_sessions( |
12925 | | libewf_handle_t *handle, |
12926 | | uint32_t *number_of_sessions, |
12927 | | libcerror_error_t **error ) |
12928 | 0 | { |
12929 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
12930 | 0 | static char *function = "libewf_handle_get_number_of_sessions"; |
12931 | 0 | int number_of_entries = 0; |
12932 | |
|
12933 | 0 | if( handle == NULL ) |
12934 | 0 | { |
12935 | 0 | libcerror_error_set( |
12936 | 0 | error, |
12937 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
12938 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
12939 | 0 | "%s: invalid handle.", |
12940 | 0 | function ); |
12941 | |
|
12942 | 0 | return( -1 ); |
12943 | 0 | } |
12944 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
12945 | |
|
12946 | 0 | if( number_of_sessions == NULL ) |
12947 | 0 | { |
12948 | 0 | libcerror_error_set( |
12949 | 0 | error, |
12950 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
12951 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
12952 | 0 | "%s: invalid number of sessions.", |
12953 | 0 | function ); |
12954 | |
|
12955 | 0 | return( -1 ); |
12956 | 0 | } |
12957 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
12958 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
12959 | 0 | internal_handle->read_write_lock, |
12960 | 0 | error ) != 1 ) |
12961 | 0 | { |
12962 | 0 | libcerror_error_set( |
12963 | 0 | error, |
12964 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12965 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
12966 | 0 | "%s: unable to grab read/write lock for reading.", |
12967 | 0 | function ); |
12968 | |
|
12969 | 0 | return( -1 ); |
12970 | 0 | } |
12971 | 0 | #endif |
12972 | 0 | if( internal_handle->sessions != NULL ) |
12973 | 0 | { |
12974 | 0 | if( libcdata_array_get_number_of_entries( |
12975 | 0 | internal_handle->sessions, |
12976 | 0 | &number_of_entries, |
12977 | 0 | error ) != 1 ) |
12978 | 0 | { |
12979 | 0 | libcerror_error_set( |
12980 | 0 | error, |
12981 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12982 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
12983 | 0 | "%s: unable to retrieve number of entries from sessions array.", |
12984 | 0 | function ); |
12985 | |
|
12986 | 0 | goto on_error; |
12987 | 0 | } |
12988 | 0 | } |
12989 | 0 | if( number_of_entries < 0 ) |
12990 | 0 | { |
12991 | 0 | libcerror_error_set( |
12992 | 0 | error, |
12993 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
12994 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
12995 | 0 | "%s: invalid number of entries value out of bounds.", |
12996 | 0 | function ); |
12997 | |
|
12998 | 0 | goto on_error; |
12999 | 0 | } |
13000 | 0 | *number_of_sessions = (uint32_t) number_of_entries; |
13001 | |
|
13002 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13003 | 0 | if( libcthreads_read_write_lock_release_for_read( |
13004 | 0 | internal_handle->read_write_lock, |
13005 | 0 | error ) != 1 ) |
13006 | 0 | { |
13007 | 0 | libcerror_error_set( |
13008 | 0 | error, |
13009 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13010 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13011 | 0 | "%s: unable to release read/write lock for reading.", |
13012 | 0 | function ); |
13013 | |
|
13014 | 0 | return( -1 ); |
13015 | 0 | } |
13016 | 0 | #endif |
13017 | 0 | return( 1 ); |
13018 | | |
13019 | 0 | on_error: |
13020 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13021 | 0 | libcthreads_read_write_lock_release_for_read( |
13022 | 0 | internal_handle->read_write_lock, |
13023 | 0 | NULL ); |
13024 | 0 | #endif |
13025 | 0 | return( -1 ); |
13026 | 0 | } |
13027 | | |
13028 | | /* Retrieves a session |
13029 | | * Returns 1 if successful or -1 on error |
13030 | | */ |
13031 | | int libewf_handle_get_session( |
13032 | | libewf_handle_t *handle, |
13033 | | uint32_t index, |
13034 | | uint64_t *start_sector, |
13035 | | uint64_t *number_of_sectors, |
13036 | | libcerror_error_t **error ) |
13037 | 0 | { |
13038 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
13039 | 0 | static char *function = "libewf_handle_get_session"; |
13040 | 0 | int result = 1; |
13041 | |
|
13042 | 0 | if( handle == NULL ) |
13043 | 0 | { |
13044 | 0 | libcerror_error_set( |
13045 | 0 | error, |
13046 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
13047 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
13048 | 0 | "%s: invalid handle.", |
13049 | 0 | function ); |
13050 | |
|
13051 | 0 | return( -1 ); |
13052 | 0 | } |
13053 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
13054 | |
|
13055 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13056 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
13057 | 0 | internal_handle->read_write_lock, |
13058 | 0 | error ) != 1 ) |
13059 | 0 | { |
13060 | 0 | libcerror_error_set( |
13061 | 0 | error, |
13062 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13063 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13064 | 0 | "%s: unable to grab read/write lock for reading.", |
13065 | 0 | function ); |
13066 | |
|
13067 | 0 | return( -1 ); |
13068 | 0 | } |
13069 | 0 | #endif |
13070 | 0 | if( libewf_sector_range_list_get_range( |
13071 | 0 | internal_handle->sessions, |
13072 | 0 | index, |
13073 | 0 | start_sector, |
13074 | 0 | number_of_sectors, |
13075 | 0 | error ) != 1 ) |
13076 | 0 | { |
13077 | 0 | libcerror_error_set( |
13078 | 0 | error, |
13079 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13080 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
13081 | 0 | "%s: unable to retrieve session: %" PRIu32 " sector range.", |
13082 | 0 | function, |
13083 | 0 | index ); |
13084 | |
|
13085 | 0 | result = -1; |
13086 | 0 | } |
13087 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13088 | 0 | if( libcthreads_read_write_lock_release_for_read( |
13089 | 0 | internal_handle->read_write_lock, |
13090 | 0 | error ) != 1 ) |
13091 | 0 | { |
13092 | 0 | libcerror_error_set( |
13093 | 0 | error, |
13094 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13095 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13096 | 0 | "%s: unable to release read/write lock for reading.", |
13097 | 0 | function ); |
13098 | |
|
13099 | 0 | return( -1 ); |
13100 | 0 | } |
13101 | 0 | #endif |
13102 | 0 | return( result ); |
13103 | 0 | } |
13104 | | |
13105 | | /* Appends a session |
13106 | | * Returns 1 if successful or -1 on error |
13107 | | */ |
13108 | | int libewf_handle_append_session( |
13109 | | libewf_handle_t *handle, |
13110 | | uint64_t start_sector, |
13111 | | uint64_t number_of_sectors, |
13112 | | libcerror_error_t **error ) |
13113 | 0 | { |
13114 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
13115 | 0 | static char *function = "libewf_handle_append_session"; |
13116 | 0 | int result = 1; |
13117 | |
|
13118 | 0 | if( handle == NULL ) |
13119 | 0 | { |
13120 | 0 | libcerror_error_set( |
13121 | 0 | error, |
13122 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
13123 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
13124 | 0 | "%s: invalid handle.", |
13125 | 0 | function ); |
13126 | |
|
13127 | 0 | return( -1 ); |
13128 | 0 | } |
13129 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
13130 | |
|
13131 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13132 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
13133 | 0 | internal_handle->read_write_lock, |
13134 | 0 | error ) != 1 ) |
13135 | 0 | { |
13136 | 0 | libcerror_error_set( |
13137 | 0 | error, |
13138 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13139 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13140 | 0 | "%s: unable to grab read/write lock for writing.", |
13141 | 0 | function ); |
13142 | |
|
13143 | 0 | return( -1 ); |
13144 | 0 | } |
13145 | 0 | #endif |
13146 | 0 | if( libewf_sector_range_list_append_range( |
13147 | 0 | internal_handle->sessions, |
13148 | 0 | start_sector, |
13149 | 0 | number_of_sectors, |
13150 | 0 | error ) != 1 ) |
13151 | 0 | { |
13152 | 0 | libcerror_error_set( |
13153 | 0 | error, |
13154 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13155 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
13156 | 0 | "%s: unable to append session sector range.", |
13157 | 0 | function ); |
13158 | |
|
13159 | 0 | result = -1; |
13160 | 0 | } |
13161 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13162 | 0 | if( libcthreads_read_write_lock_release_for_write( |
13163 | 0 | internal_handle->read_write_lock, |
13164 | 0 | error ) != 1 ) |
13165 | 0 | { |
13166 | 0 | libcerror_error_set( |
13167 | 0 | error, |
13168 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13169 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13170 | 0 | "%s: unable to release read/write lock for writing.", |
13171 | 0 | function ); |
13172 | |
|
13173 | 0 | return( -1 ); |
13174 | 0 | } |
13175 | 0 | #endif |
13176 | 0 | return( result ); |
13177 | 0 | } |
13178 | | |
13179 | | /* Retrieves the number of tracks |
13180 | | * Returns 1 if successful or -1 on error |
13181 | | */ |
13182 | | int libewf_handle_get_number_of_tracks( |
13183 | | libewf_handle_t *handle, |
13184 | | uint32_t *number_of_tracks, |
13185 | | libcerror_error_t **error ) |
13186 | 0 | { |
13187 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
13188 | 0 | static char *function = "libewf_handle_get_number_of_tracks"; |
13189 | 0 | int number_of_entries = 0; |
13190 | |
|
13191 | 0 | if( handle == NULL ) |
13192 | 0 | { |
13193 | 0 | libcerror_error_set( |
13194 | 0 | error, |
13195 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
13196 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
13197 | 0 | "%s: invalid handle.", |
13198 | 0 | function ); |
13199 | |
|
13200 | 0 | return( -1 ); |
13201 | 0 | } |
13202 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
13203 | |
|
13204 | 0 | if( number_of_tracks == NULL ) |
13205 | 0 | { |
13206 | 0 | libcerror_error_set( |
13207 | 0 | error, |
13208 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
13209 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
13210 | 0 | "%s: invalid number of tracks.", |
13211 | 0 | function ); |
13212 | |
|
13213 | 0 | return( -1 ); |
13214 | 0 | } |
13215 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13216 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
13217 | 0 | internal_handle->read_write_lock, |
13218 | 0 | error ) != 1 ) |
13219 | 0 | { |
13220 | 0 | libcerror_error_set( |
13221 | 0 | error, |
13222 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13223 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13224 | 0 | "%s: unable to grab read/write lock for reading.", |
13225 | 0 | function ); |
13226 | |
|
13227 | 0 | return( -1 ); |
13228 | 0 | } |
13229 | 0 | #endif |
13230 | 0 | if( internal_handle->tracks != NULL ) |
13231 | 0 | { |
13232 | 0 | if( libcdata_array_get_number_of_entries( |
13233 | 0 | internal_handle->tracks, |
13234 | 0 | &number_of_entries, |
13235 | 0 | error ) != 1 ) |
13236 | 0 | { |
13237 | 0 | libcerror_error_set( |
13238 | 0 | error, |
13239 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13240 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
13241 | 0 | "%s: unable to retrieve number of entries from tracks array.", |
13242 | 0 | function ); |
13243 | |
|
13244 | 0 | goto on_error; |
13245 | 0 | } |
13246 | 0 | } |
13247 | 0 | if( number_of_entries < 0 ) |
13248 | 0 | { |
13249 | 0 | libcerror_error_set( |
13250 | 0 | error, |
13251 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13252 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
13253 | 0 | "%s: invalid number of entries value out of bounds.", |
13254 | 0 | function ); |
13255 | |
|
13256 | 0 | goto on_error; |
13257 | 0 | } |
13258 | 0 | *number_of_tracks = (uint32_t) number_of_entries; |
13259 | |
|
13260 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13261 | 0 | if( libcthreads_read_write_lock_release_for_read( |
13262 | 0 | internal_handle->read_write_lock, |
13263 | 0 | error ) != 1 ) |
13264 | 0 | { |
13265 | 0 | libcerror_error_set( |
13266 | 0 | error, |
13267 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13268 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13269 | 0 | "%s: unable to release read/write lock for reading.", |
13270 | 0 | function ); |
13271 | |
|
13272 | 0 | return( -1 ); |
13273 | 0 | } |
13274 | 0 | #endif |
13275 | 0 | return( 1 ); |
13276 | | |
13277 | 0 | on_error: |
13278 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13279 | 0 | libcthreads_read_write_lock_release_for_read( |
13280 | 0 | internal_handle->read_write_lock, |
13281 | 0 | NULL ); |
13282 | 0 | #endif |
13283 | 0 | return( -1 ); |
13284 | 0 | } |
13285 | | |
13286 | | /* Retrieves a track |
13287 | | * Returns 1 if successful or -1 on error |
13288 | | */ |
13289 | | int libewf_handle_get_track( |
13290 | | libewf_handle_t *handle, |
13291 | | uint32_t index, |
13292 | | uint64_t *start_sector, |
13293 | | uint64_t *number_of_sectors, |
13294 | | libcerror_error_t **error ) |
13295 | 0 | { |
13296 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
13297 | 0 | static char *function = "libewf_handle_get_track"; |
13298 | 0 | int result = 1; |
13299 | |
|
13300 | 0 | if( handle == NULL ) |
13301 | 0 | { |
13302 | 0 | libcerror_error_set( |
13303 | 0 | error, |
13304 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
13305 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
13306 | 0 | "%s: invalid handle.", |
13307 | 0 | function ); |
13308 | |
|
13309 | 0 | return( -1 ); |
13310 | 0 | } |
13311 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
13312 | |
|
13313 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13314 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
13315 | 0 | internal_handle->read_write_lock, |
13316 | 0 | error ) != 1 ) |
13317 | 0 | { |
13318 | 0 | libcerror_error_set( |
13319 | 0 | error, |
13320 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13321 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13322 | 0 | "%s: unable to grab read/write lock for reading.", |
13323 | 0 | function ); |
13324 | |
|
13325 | 0 | return( -1 ); |
13326 | 0 | } |
13327 | 0 | #endif |
13328 | 0 | if( libewf_sector_range_list_get_range( |
13329 | 0 | internal_handle->tracks, |
13330 | 0 | index, |
13331 | 0 | start_sector, |
13332 | 0 | number_of_sectors, |
13333 | 0 | error ) != 1 ) |
13334 | 0 | { |
13335 | 0 | libcerror_error_set( |
13336 | 0 | error, |
13337 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13338 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
13339 | 0 | "%s: unable to retrieve track: %" PRIu32 " sector range.", |
13340 | 0 | function, |
13341 | 0 | index ); |
13342 | |
|
13343 | 0 | result = -1; |
13344 | 0 | } |
13345 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13346 | 0 | if( libcthreads_read_write_lock_release_for_read( |
13347 | 0 | internal_handle->read_write_lock, |
13348 | 0 | error ) != 1 ) |
13349 | 0 | { |
13350 | 0 | libcerror_error_set( |
13351 | 0 | error, |
13352 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13353 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13354 | 0 | "%s: unable to release read/write lock for reading.", |
13355 | 0 | function ); |
13356 | |
|
13357 | 0 | return( -1 ); |
13358 | 0 | } |
13359 | 0 | #endif |
13360 | 0 | return( result ); |
13361 | 0 | } |
13362 | | |
13363 | | /* Appends a track |
13364 | | * Returns 1 if successful or -1 on error |
13365 | | */ |
13366 | | int libewf_handle_append_track( |
13367 | | libewf_handle_t *handle, |
13368 | | uint64_t start_sector, |
13369 | | uint64_t number_of_sectors, |
13370 | | libcerror_error_t **error ) |
13371 | 0 | { |
13372 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
13373 | 0 | static char *function = "libewf_handle_append_track"; |
13374 | 0 | int result = 1; |
13375 | |
|
13376 | 0 | if( handle == NULL ) |
13377 | 0 | { |
13378 | 0 | libcerror_error_set( |
13379 | 0 | error, |
13380 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
13381 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
13382 | 0 | "%s: invalid handle.", |
13383 | 0 | function ); |
13384 | |
|
13385 | 0 | return( -1 ); |
13386 | 0 | } |
13387 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
13388 | |
|
13389 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13390 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
13391 | 0 | internal_handle->read_write_lock, |
13392 | 0 | error ) != 1 ) |
13393 | 0 | { |
13394 | 0 | libcerror_error_set( |
13395 | 0 | error, |
13396 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13397 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13398 | 0 | "%s: unable to grab read/write lock for writing.", |
13399 | 0 | function ); |
13400 | |
|
13401 | 0 | return( -1 ); |
13402 | 0 | } |
13403 | 0 | #endif |
13404 | 0 | if( libewf_sector_range_list_append_range( |
13405 | 0 | internal_handle->tracks, |
13406 | 0 | start_sector, |
13407 | 0 | number_of_sectors, |
13408 | 0 | error ) != 1 ) |
13409 | 0 | { |
13410 | 0 | libcerror_error_set( |
13411 | 0 | error, |
13412 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13413 | 0 | LIBCERROR_RUNTIME_ERROR_APPEND_FAILED, |
13414 | 0 | "%s: unable to append track sector range.", |
13415 | 0 | function ); |
13416 | |
|
13417 | 0 | result = -1; |
13418 | 0 | } |
13419 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13420 | 0 | if( libcthreads_read_write_lock_release_for_write( |
13421 | 0 | internal_handle->read_write_lock, |
13422 | 0 | error ) != 1 ) |
13423 | 0 | { |
13424 | 0 | libcerror_error_set( |
13425 | 0 | error, |
13426 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13427 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13428 | 0 | "%s: unable to release read/write lock for writing.", |
13429 | 0 | function ); |
13430 | |
|
13431 | 0 | return( -1 ); |
13432 | 0 | } |
13433 | 0 | #endif |
13434 | 0 | return( result ); |
13435 | 0 | } |
13436 | | |
13437 | | /* Retrieves the header codepage |
13438 | | * Returns 1 if successful or -1 on error |
13439 | | */ |
13440 | | int libewf_handle_get_header_codepage( |
13441 | | libewf_handle_t *handle, |
13442 | | int *header_codepage, |
13443 | | libcerror_error_t **error ) |
13444 | 0 | { |
13445 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
13446 | 0 | static char *function = "libewf_handle_get_header_codepage"; |
13447 | |
|
13448 | 0 | if( handle == NULL ) |
13449 | 0 | { |
13450 | 0 | libcerror_error_set( |
13451 | 0 | error, |
13452 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
13453 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
13454 | 0 | "%s: invalid handle.", |
13455 | 0 | function ); |
13456 | |
|
13457 | 0 | return( -1 ); |
13458 | 0 | } |
13459 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
13460 | |
|
13461 | 0 | if( internal_handle->io_handle == NULL ) |
13462 | 0 | { |
13463 | 0 | libcerror_error_set( |
13464 | 0 | error, |
13465 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13466 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
13467 | 0 | "%s: invalid handle - missing IO handle.", |
13468 | 0 | function ); |
13469 | |
|
13470 | 0 | return( -1 ); |
13471 | 0 | } |
13472 | 0 | if( header_codepage == NULL ) |
13473 | 0 | { |
13474 | 0 | libcerror_error_set( |
13475 | 0 | error, |
13476 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
13477 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
13478 | 0 | "%s: invalid header codepage.", |
13479 | 0 | function ); |
13480 | |
|
13481 | 0 | return( -1 ); |
13482 | 0 | } |
13483 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13484 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
13485 | 0 | internal_handle->read_write_lock, |
13486 | 0 | error ) != 1 ) |
13487 | 0 | { |
13488 | 0 | libcerror_error_set( |
13489 | 0 | error, |
13490 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13491 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13492 | 0 | "%s: unable to grab read/write lock for reading.", |
13493 | 0 | function ); |
13494 | |
|
13495 | 0 | return( -1 ); |
13496 | 0 | } |
13497 | 0 | #endif |
13498 | 0 | *header_codepage = internal_handle->io_handle->header_codepage; |
13499 | |
|
13500 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13501 | 0 | if( libcthreads_read_write_lock_release_for_read( |
13502 | 0 | internal_handle->read_write_lock, |
13503 | 0 | error ) != 1 ) |
13504 | 0 | { |
13505 | 0 | libcerror_error_set( |
13506 | 0 | error, |
13507 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13508 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13509 | 0 | "%s: unable to release read/write lock for reading.", |
13510 | 0 | function ); |
13511 | |
|
13512 | 0 | return( -1 ); |
13513 | 0 | } |
13514 | 0 | #endif |
13515 | 0 | return( 1 ); |
13516 | 0 | } |
13517 | | |
13518 | | /* Sets the header codepage |
13519 | | * Returns 1 if successful or -1 on error |
13520 | | */ |
13521 | | int libewf_handle_set_header_codepage( |
13522 | | libewf_handle_t *handle, |
13523 | | int header_codepage, |
13524 | | libcerror_error_t **error ) |
13525 | 0 | { |
13526 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
13527 | 0 | static char *function = "libewf_handle_set_header_codepage"; |
13528 | |
|
13529 | 0 | if( handle == NULL ) |
13530 | 0 | { |
13531 | 0 | libcerror_error_set( |
13532 | 0 | error, |
13533 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
13534 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
13535 | 0 | "%s: invalid handle.", |
13536 | 0 | function ); |
13537 | |
|
13538 | 0 | return( -1 ); |
13539 | 0 | } |
13540 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
13541 | |
|
13542 | 0 | if( internal_handle->io_handle == NULL ) |
13543 | 0 | { |
13544 | 0 | libcerror_error_set( |
13545 | 0 | error, |
13546 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13547 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
13548 | 0 | "%s: invalid handle - missing IO handle.", |
13549 | 0 | function ); |
13550 | |
|
13551 | 0 | return( -1 ); |
13552 | 0 | } |
13553 | 0 | if( ( header_codepage != LIBEWF_CODEPAGE_ASCII ) |
13554 | 0 | && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_874 ) |
13555 | 0 | && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_932 ) |
13556 | 0 | && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_936 ) |
13557 | 0 | && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_1250 ) |
13558 | 0 | && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_1251 ) |
13559 | 0 | && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_1252 ) |
13560 | 0 | && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_1253 ) |
13561 | 0 | && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_1254 ) |
13562 | 0 | && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_1255 ) |
13563 | 0 | && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_1256 ) |
13564 | 0 | && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_1257 ) |
13565 | 0 | && ( header_codepage != LIBEWF_CODEPAGE_WINDOWS_1258 ) ) |
13566 | 0 | { |
13567 | 0 | libcerror_error_set( |
13568 | 0 | error, |
13569 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
13570 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
13571 | 0 | "%s: unsupported header codepage.", |
13572 | 0 | function ); |
13573 | |
|
13574 | 0 | return( -1 ); |
13575 | 0 | } |
13576 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13577 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
13578 | 0 | internal_handle->read_write_lock, |
13579 | 0 | error ) != 1 ) |
13580 | 0 | { |
13581 | 0 | libcerror_error_set( |
13582 | 0 | error, |
13583 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13584 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13585 | 0 | "%s: unable to grab read/write lock for writing.", |
13586 | 0 | function ); |
13587 | |
|
13588 | 0 | return( -1 ); |
13589 | 0 | } |
13590 | 0 | #endif |
13591 | 0 | internal_handle->io_handle->header_codepage = header_codepage; |
13592 | |
|
13593 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13594 | 0 | if( libcthreads_read_write_lock_release_for_write( |
13595 | 0 | internal_handle->read_write_lock, |
13596 | 0 | error ) != 1 ) |
13597 | 0 | { |
13598 | 0 | libcerror_error_set( |
13599 | 0 | error, |
13600 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13601 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13602 | 0 | "%s: unable to release read/write lock for writing.", |
13603 | 0 | function ); |
13604 | |
|
13605 | 0 | return( -1 ); |
13606 | 0 | } |
13607 | 0 | #endif |
13608 | 0 | return( 1 ); |
13609 | 0 | } |
13610 | | |
13611 | | /* Retrieves the header value date format |
13612 | | * Returns 1 if successful or -1 on error |
13613 | | */ |
13614 | | int libewf_handle_get_header_values_date_format( |
13615 | | libewf_handle_t *handle, |
13616 | | int *date_format, |
13617 | | libcerror_error_t **error ) |
13618 | 0 | { |
13619 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
13620 | 0 | static char *function = "libewf_handle_get_header_values_date_format"; |
13621 | |
|
13622 | 0 | if( handle == NULL ) |
13623 | 0 | { |
13624 | 0 | libcerror_error_set( |
13625 | 0 | error, |
13626 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
13627 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
13628 | 0 | "%s: invalid handle.", |
13629 | 0 | function ); |
13630 | |
|
13631 | 0 | return( -1 ); |
13632 | 0 | } |
13633 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
13634 | |
|
13635 | 0 | if( date_format == NULL ) |
13636 | 0 | { |
13637 | 0 | libcerror_error_set( |
13638 | 0 | error, |
13639 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
13640 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
13641 | 0 | "%s: invalid date format.", |
13642 | 0 | function ); |
13643 | |
|
13644 | 0 | return( -1 ); |
13645 | 0 | } |
13646 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13647 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
13648 | 0 | internal_handle->read_write_lock, |
13649 | 0 | error ) != 1 ) |
13650 | 0 | { |
13651 | 0 | libcerror_error_set( |
13652 | 0 | error, |
13653 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13654 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13655 | 0 | "%s: unable to grab read/write lock for reading.", |
13656 | 0 | function ); |
13657 | |
|
13658 | 0 | return( -1 ); |
13659 | 0 | } |
13660 | 0 | #endif |
13661 | 0 | *date_format = internal_handle->date_format; |
13662 | |
|
13663 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13664 | 0 | if( libcthreads_read_write_lock_release_for_read( |
13665 | 0 | internal_handle->read_write_lock, |
13666 | 0 | error ) != 1 ) |
13667 | 0 | { |
13668 | 0 | libcerror_error_set( |
13669 | 0 | error, |
13670 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13671 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13672 | 0 | "%s: unable to release read/write lock for reading.", |
13673 | 0 | function ); |
13674 | |
|
13675 | 0 | return( -1 ); |
13676 | 0 | } |
13677 | 0 | #endif |
13678 | 0 | return( 1 ); |
13679 | 0 | } |
13680 | | |
13681 | | /* Sets the header values date format |
13682 | | * Returns 1 if successful or -1 on error |
13683 | | */ |
13684 | | int libewf_handle_set_header_values_date_format( |
13685 | | libewf_handle_t *handle, |
13686 | | int date_format, |
13687 | | libcerror_error_t **error ) |
13688 | 0 | { |
13689 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
13690 | 0 | static char *function = "libewf_handle_set_header_values_date_format"; |
13691 | |
|
13692 | 0 | if( handle == NULL ) |
13693 | 0 | { |
13694 | 0 | libcerror_error_set( |
13695 | 0 | error, |
13696 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
13697 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
13698 | 0 | "%s: invalid handle.", |
13699 | 0 | function ); |
13700 | |
|
13701 | 0 | return( -1 ); |
13702 | 0 | } |
13703 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
13704 | |
|
13705 | 0 | if( ( date_format != LIBEWF_DATE_FORMAT_CTIME ) |
13706 | 0 | && ( date_format != LIBEWF_DATE_FORMAT_DAYMONTH ) |
13707 | 0 | && ( date_format != LIBEWF_DATE_FORMAT_MONTHDAY ) |
13708 | 0 | && ( date_format != LIBEWF_DATE_FORMAT_ISO8601 ) ) |
13709 | 0 | { |
13710 | 0 | libcerror_error_set( |
13711 | 0 | error, |
13712 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
13713 | 0 | LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, |
13714 | 0 | "%s: unsupported date format.", |
13715 | 0 | function ); |
13716 | |
|
13717 | 0 | return( -1 ); |
13718 | 0 | } |
13719 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13720 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
13721 | 0 | internal_handle->read_write_lock, |
13722 | 0 | error ) != 1 ) |
13723 | 0 | { |
13724 | 0 | libcerror_error_set( |
13725 | 0 | error, |
13726 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13727 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13728 | 0 | "%s: unable to grab read/write lock for writing.", |
13729 | 0 | function ); |
13730 | |
|
13731 | 0 | return( -1 ); |
13732 | 0 | } |
13733 | 0 | #endif |
13734 | 0 | internal_handle->date_format = date_format; |
13735 | |
|
13736 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13737 | 0 | if( libcthreads_read_write_lock_release_for_write( |
13738 | 0 | internal_handle->read_write_lock, |
13739 | 0 | error ) != 1 ) |
13740 | 0 | { |
13741 | 0 | libcerror_error_set( |
13742 | 0 | error, |
13743 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13744 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13745 | 0 | "%s: unable to release read/write lock for writing.", |
13746 | 0 | function ); |
13747 | |
|
13748 | 0 | return( -1 ); |
13749 | 0 | } |
13750 | 0 | #endif |
13751 | 0 | return( 1 ); |
13752 | 0 | } |
13753 | | |
13754 | | /* Retrieves the number of header values |
13755 | | * Returns 1 if successful or -1 on error |
13756 | | */ |
13757 | | int libewf_handle_get_number_of_header_values( |
13758 | | libewf_handle_t *handle, |
13759 | | uint32_t *number_of_values, |
13760 | | libcerror_error_t **error ) |
13761 | 0 | { |
13762 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
13763 | 0 | static char *function = "libewf_handle_get_number_of_header_values"; |
13764 | 0 | int number_of_header_values = 0; |
13765 | |
|
13766 | 0 | if( handle == NULL ) |
13767 | 0 | { |
13768 | 0 | libcerror_error_set( |
13769 | 0 | error, |
13770 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
13771 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
13772 | 0 | "%s: invalid handle.", |
13773 | 0 | function ); |
13774 | |
|
13775 | 0 | return( -1 ); |
13776 | 0 | } |
13777 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
13778 | |
|
13779 | 0 | if( number_of_values == NULL ) |
13780 | 0 | { |
13781 | 0 | libcerror_error_set( |
13782 | 0 | error, |
13783 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
13784 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
13785 | 0 | "%s: invalid number of values.", |
13786 | 0 | function ); |
13787 | |
|
13788 | 0 | return( -1 ); |
13789 | 0 | } |
13790 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13791 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
13792 | 0 | internal_handle->read_write_lock, |
13793 | 0 | error ) != 1 ) |
13794 | 0 | { |
13795 | 0 | libcerror_error_set( |
13796 | 0 | error, |
13797 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13798 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13799 | 0 | "%s: unable to grab read/write lock for reading.", |
13800 | 0 | function ); |
13801 | |
|
13802 | 0 | return( -1 ); |
13803 | 0 | } |
13804 | 0 | #endif |
13805 | 0 | if( internal_handle->header_values != NULL ) |
13806 | 0 | { |
13807 | 0 | if( libfvalue_table_get_number_of_values( |
13808 | 0 | internal_handle->header_values, |
13809 | 0 | &number_of_header_values, |
13810 | 0 | error ) != 1 ) |
13811 | 0 | { |
13812 | 0 | libcerror_error_set( |
13813 | 0 | error, |
13814 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13815 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
13816 | 0 | "%s: unable to retrieve number of header values.", |
13817 | 0 | function ); |
13818 | |
|
13819 | 0 | goto on_error; |
13820 | 0 | } |
13821 | 0 | } |
13822 | 0 | if( number_of_header_values < 0 ) |
13823 | 0 | { |
13824 | 0 | libcerror_error_set( |
13825 | 0 | error, |
13826 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13827 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
13828 | 0 | "%s: invalid number of header values value out of bounds.", |
13829 | 0 | function ); |
13830 | |
|
13831 | 0 | goto on_error; |
13832 | 0 | } |
13833 | 0 | *number_of_values = (uint32_t) number_of_header_values; |
13834 | |
|
13835 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13836 | 0 | if( libcthreads_read_write_lock_release_for_read( |
13837 | 0 | internal_handle->read_write_lock, |
13838 | 0 | error ) != 1 ) |
13839 | 0 | { |
13840 | 0 | libcerror_error_set( |
13841 | 0 | error, |
13842 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13843 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13844 | 0 | "%s: unable to release read/write lock for reading.", |
13845 | 0 | function ); |
13846 | |
|
13847 | 0 | return( -1 ); |
13848 | 0 | } |
13849 | 0 | #endif |
13850 | 0 | return( 1 ); |
13851 | | |
13852 | 0 | on_error: |
13853 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13854 | 0 | libcthreads_read_write_lock_release_for_read( |
13855 | 0 | internal_handle->read_write_lock, |
13856 | 0 | NULL ); |
13857 | 0 | #endif |
13858 | 0 | return( -1 ); |
13859 | 0 | } |
13860 | | |
13861 | | /* Retrieves the size of the value identifier of a specific index |
13862 | | * The identifier size includes the end of string character |
13863 | | * Returns 1 if successful, 0 if no header values are present or -1 on error |
13864 | | */ |
13865 | | int libewf_handle_get_header_value_identifier_size( |
13866 | | libewf_handle_t *handle, |
13867 | | uint32_t index, |
13868 | | size_t *identifier_size, |
13869 | | libcerror_error_t **error ) |
13870 | 0 | { |
13871 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
13872 | 0 | static char *function = "libewf_handle_get_header_value_identifier_size"; |
13873 | 0 | int result = 0; |
13874 | |
|
13875 | 0 | if( handle == NULL ) |
13876 | 0 | { |
13877 | 0 | libcerror_error_set( |
13878 | 0 | error, |
13879 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
13880 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
13881 | 0 | "%s: invalid handle.", |
13882 | 0 | function ); |
13883 | |
|
13884 | 0 | return( -1 ); |
13885 | 0 | } |
13886 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
13887 | |
|
13888 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13889 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
13890 | 0 | internal_handle->read_write_lock, |
13891 | 0 | error ) != 1 ) |
13892 | 0 | { |
13893 | 0 | libcerror_error_set( |
13894 | 0 | error, |
13895 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13896 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13897 | 0 | "%s: unable to grab read/write lock for reading.", |
13898 | 0 | function ); |
13899 | |
|
13900 | 0 | return( -1 ); |
13901 | 0 | } |
13902 | 0 | #endif |
13903 | 0 | if( internal_handle->header_values != NULL ) |
13904 | 0 | { |
13905 | 0 | result = libewf_header_values_get_identifier_size( |
13906 | 0 | internal_handle->header_values, |
13907 | 0 | index, |
13908 | 0 | identifier_size, |
13909 | 0 | error ); |
13910 | |
|
13911 | 0 | if( result == -1 ) |
13912 | 0 | { |
13913 | 0 | libcerror_error_set( |
13914 | 0 | error, |
13915 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13916 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
13917 | 0 | "%s: unable to retrieve header value: %" PRIu32 " identifier size.", |
13918 | 0 | function, |
13919 | 0 | index ); |
13920 | 0 | } |
13921 | 0 | } |
13922 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13923 | 0 | if( libcthreads_read_write_lock_release_for_read( |
13924 | 0 | internal_handle->read_write_lock, |
13925 | 0 | error ) != 1 ) |
13926 | 0 | { |
13927 | 0 | libcerror_error_set( |
13928 | 0 | error, |
13929 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13930 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13931 | 0 | "%s: unable to release read/write lock for reading.", |
13932 | 0 | function ); |
13933 | |
|
13934 | 0 | return( -1 ); |
13935 | 0 | } |
13936 | 0 | #endif |
13937 | 0 | return( result ); |
13938 | 0 | } |
13939 | | |
13940 | | /* Retrieves the header value identifier of a specific index |
13941 | | * The identifier size should include the end of string character |
13942 | | * Returns 1 if successful, 0 if no header values are present or -1 on error |
13943 | | */ |
13944 | | int libewf_handle_get_header_value_identifier( |
13945 | | libewf_handle_t *handle, |
13946 | | uint32_t index, |
13947 | | uint8_t *identifier, |
13948 | | size_t identifier_size, |
13949 | | libcerror_error_t **error ) |
13950 | 0 | { |
13951 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
13952 | 0 | static char *function = "libewf_handle_get_header_value_identifier"; |
13953 | 0 | int result = 0; |
13954 | |
|
13955 | 0 | if( handle == NULL ) |
13956 | 0 | { |
13957 | 0 | libcerror_error_set( |
13958 | 0 | error, |
13959 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
13960 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
13961 | 0 | "%s: invalid handle.", |
13962 | 0 | function ); |
13963 | |
|
13964 | 0 | return( -1 ); |
13965 | 0 | } |
13966 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
13967 | |
|
13968 | 0 | if( identifier == NULL ) |
13969 | 0 | { |
13970 | 0 | libcerror_error_set( |
13971 | 0 | error, |
13972 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
13973 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
13974 | 0 | "%s: invalid identifier.", |
13975 | 0 | function ); |
13976 | |
|
13977 | 0 | return( -1 ); |
13978 | 0 | } |
13979 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
13980 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
13981 | 0 | internal_handle->read_write_lock, |
13982 | 0 | error ) != 1 ) |
13983 | 0 | { |
13984 | 0 | libcerror_error_set( |
13985 | 0 | error, |
13986 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
13987 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
13988 | 0 | "%s: unable to grab read/write lock for reading.", |
13989 | 0 | function ); |
13990 | |
|
13991 | 0 | return( -1 ); |
13992 | 0 | } |
13993 | 0 | #endif |
13994 | 0 | if( internal_handle->header_values != NULL ) |
13995 | 0 | { |
13996 | 0 | result = libewf_header_values_get_identifier( |
13997 | 0 | internal_handle->header_values, |
13998 | 0 | index, |
13999 | 0 | identifier, |
14000 | 0 | identifier_size, |
14001 | 0 | error ); |
14002 | |
|
14003 | 0 | if( result == -1 ) |
14004 | 0 | { |
14005 | 0 | libcerror_error_set( |
14006 | 0 | error, |
14007 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14008 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
14009 | 0 | "%s: unable to retrieve header value: %" PRIu32 " identifier.", |
14010 | 0 | function, |
14011 | 0 | index ); |
14012 | 0 | } |
14013 | 0 | } |
14014 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
14015 | 0 | if( libcthreads_read_write_lock_release_for_read( |
14016 | 0 | internal_handle->read_write_lock, |
14017 | 0 | error ) != 1 ) |
14018 | 0 | { |
14019 | 0 | libcerror_error_set( |
14020 | 0 | error, |
14021 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14022 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14023 | 0 | "%s: unable to release read/write lock for reading.", |
14024 | 0 | function ); |
14025 | |
|
14026 | 0 | return( -1 ); |
14027 | 0 | } |
14028 | 0 | #endif |
14029 | 0 | return( result ); |
14030 | 0 | } |
14031 | | |
14032 | | /* Retrieves the size of the UTF-8 encoded header value of an identifier |
14033 | | * The string size includes the end of string character |
14034 | | * Returns 1 if successful, 0 if not set or -1 on error |
14035 | | */ |
14036 | | int libewf_handle_get_utf8_header_value_size( |
14037 | | libewf_handle_t *handle, |
14038 | | const uint8_t *identifier, |
14039 | | size_t identifier_length, |
14040 | | size_t *utf8_string_size, |
14041 | | libcerror_error_t **error ) |
14042 | 0 | { |
14043 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
14044 | 0 | static char *function = "libewf_handle_get_utf8_header_value_size"; |
14045 | 0 | int result = 0; |
14046 | |
|
14047 | 0 | if( handle == NULL ) |
14048 | 0 | { |
14049 | 0 | libcerror_error_set( |
14050 | 0 | error, |
14051 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
14052 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
14053 | 0 | "%s: invalid handle.", |
14054 | 0 | function ); |
14055 | |
|
14056 | 0 | return( -1 ); |
14057 | 0 | } |
14058 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
14059 | |
|
14060 | 0 | if( utf8_string_size == NULL ) |
14061 | 0 | { |
14062 | 0 | libcerror_error_set( |
14063 | 0 | error, |
14064 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
14065 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
14066 | 0 | "%s: invalid UTF-8 string size.", |
14067 | 0 | function ); |
14068 | |
|
14069 | 0 | return( -1 ); |
14070 | 0 | } |
14071 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
14072 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
14073 | 0 | internal_handle->read_write_lock, |
14074 | 0 | error ) != 1 ) |
14075 | 0 | { |
14076 | 0 | libcerror_error_set( |
14077 | 0 | error, |
14078 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14079 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14080 | 0 | "%s: unable to grab read/write lock for reading.", |
14081 | 0 | function ); |
14082 | |
|
14083 | 0 | return( -1 ); |
14084 | 0 | } |
14085 | 0 | #endif |
14086 | 0 | if( internal_handle->header_values != NULL ) |
14087 | 0 | { |
14088 | 0 | result = libewf_header_values_get_utf8_value_size( |
14089 | 0 | internal_handle->header_values, |
14090 | 0 | identifier, |
14091 | 0 | identifier_length, |
14092 | 0 | internal_handle->date_format, |
14093 | 0 | utf8_string_size, |
14094 | 0 | error ); |
14095 | |
|
14096 | 0 | if( result == -1 ) |
14097 | 0 | { |
14098 | 0 | libcerror_error_set( |
14099 | 0 | error, |
14100 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14101 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
14102 | 0 | "%s: unable to retrieve header value size.", |
14103 | 0 | function ); |
14104 | 0 | } |
14105 | 0 | } |
14106 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
14107 | 0 | if( libcthreads_read_write_lock_release_for_read( |
14108 | 0 | internal_handle->read_write_lock, |
14109 | 0 | error ) != 1 ) |
14110 | 0 | { |
14111 | 0 | libcerror_error_set( |
14112 | 0 | error, |
14113 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14114 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14115 | 0 | "%s: unable to release read/write lock for reading.", |
14116 | 0 | function ); |
14117 | |
|
14118 | 0 | return( -1 ); |
14119 | 0 | } |
14120 | 0 | #endif |
14121 | 0 | return( result ); |
14122 | 0 | } |
14123 | | |
14124 | | /* Retrieves the UTF-8 encoded header value of an identifier |
14125 | | * The string size should include the end of string character |
14126 | | * Returns 1 if successful, 0 if not set or -1 on error |
14127 | | */ |
14128 | | int libewf_handle_get_utf8_header_value( |
14129 | | libewf_handle_t *handle, |
14130 | | const uint8_t *identifier, |
14131 | | size_t identifier_length, |
14132 | | uint8_t *utf8_string, |
14133 | | size_t utf8_string_size, |
14134 | | libcerror_error_t **error ) |
14135 | 0 | { |
14136 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
14137 | 0 | static char *function = "libewf_handle_get_utf8_header_value"; |
14138 | 0 | int result = 0; |
14139 | |
|
14140 | 0 | if( handle == NULL ) |
14141 | 0 | { |
14142 | 0 | libcerror_error_set( |
14143 | 0 | error, |
14144 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
14145 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
14146 | 0 | "%s: invalid handle.", |
14147 | 0 | function ); |
14148 | |
|
14149 | 0 | return( -1 ); |
14150 | 0 | } |
14151 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
14152 | |
|
14153 | 0 | if( utf8_string == NULL ) |
14154 | 0 | { |
14155 | 0 | libcerror_error_set( |
14156 | 0 | error, |
14157 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
14158 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
14159 | 0 | "%s: invalid UTF-8 string.", |
14160 | 0 | function ); |
14161 | |
|
14162 | 0 | return( -1 ); |
14163 | 0 | } |
14164 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
14165 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
14166 | 0 | internal_handle->read_write_lock, |
14167 | 0 | error ) != 1 ) |
14168 | 0 | { |
14169 | 0 | libcerror_error_set( |
14170 | 0 | error, |
14171 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14172 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14173 | 0 | "%s: unable to grab read/write lock for reading.", |
14174 | 0 | function ); |
14175 | |
|
14176 | 0 | return( -1 ); |
14177 | 0 | } |
14178 | 0 | #endif |
14179 | 0 | if( internal_handle->header_values != NULL ) |
14180 | 0 | { |
14181 | 0 | result = libewf_header_values_get_utf8_value( |
14182 | 0 | internal_handle->header_values, |
14183 | 0 | identifier, |
14184 | 0 | identifier_length, |
14185 | 0 | internal_handle->date_format, |
14186 | 0 | utf8_string, |
14187 | 0 | utf8_string_size, |
14188 | 0 | error ); |
14189 | |
|
14190 | 0 | if( result == -1 ) |
14191 | 0 | { |
14192 | 0 | libcerror_error_set( |
14193 | 0 | error, |
14194 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14195 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
14196 | 0 | "%s: unable to retrieve header value.", |
14197 | 0 | function ); |
14198 | 0 | } |
14199 | 0 | } |
14200 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
14201 | 0 | if( libcthreads_read_write_lock_release_for_read( |
14202 | 0 | internal_handle->read_write_lock, |
14203 | 0 | error ) != 1 ) |
14204 | 0 | { |
14205 | 0 | libcerror_error_set( |
14206 | 0 | error, |
14207 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14208 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14209 | 0 | "%s: unable to release read/write lock for reading.", |
14210 | 0 | function ); |
14211 | |
|
14212 | 0 | return( -1 ); |
14213 | 0 | } |
14214 | 0 | #endif |
14215 | 0 | return( result ); |
14216 | 0 | } |
14217 | | |
14218 | | /* Sets the UTF-8 encoded header value specified by the identifier |
14219 | | * Returns 1 if successful or -1 on error |
14220 | | */ |
14221 | | int libewf_handle_set_utf8_header_value( |
14222 | | libewf_handle_t *handle, |
14223 | | const uint8_t *identifier, |
14224 | | size_t identifier_length, |
14225 | | const uint8_t *utf8_string, |
14226 | | size_t utf8_string_length, |
14227 | | libcerror_error_t **error ) |
14228 | 0 | { |
14229 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
14230 | 0 | static char *function = "libewf_handle_set_utf8_header_value"; |
14231 | 0 | int result = 1; |
14232 | |
|
14233 | 0 | if( handle == NULL ) |
14234 | 0 | { |
14235 | 0 | libcerror_error_set( |
14236 | 0 | error, |
14237 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
14238 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
14239 | 0 | "%s: invalid handle.", |
14240 | 0 | function ); |
14241 | |
|
14242 | 0 | return( -1 ); |
14243 | 0 | } |
14244 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
14245 | |
|
14246 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
14247 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
14248 | 0 | internal_handle->read_write_lock, |
14249 | 0 | error ) != 1 ) |
14250 | 0 | { |
14251 | 0 | libcerror_error_set( |
14252 | 0 | error, |
14253 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14254 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14255 | 0 | "%s: unable to grab read/write lock for writing.", |
14256 | 0 | function ); |
14257 | |
|
14258 | 0 | return( -1 ); |
14259 | 0 | } |
14260 | 0 | #endif |
14261 | 0 | if( ( internal_handle->read_io_handle != NULL ) |
14262 | 0 | || ( internal_handle->write_io_handle == NULL ) |
14263 | 0 | || ( internal_handle->write_io_handle->values_initialized != 0 ) ) |
14264 | 0 | { |
14265 | 0 | libcerror_error_set( |
14266 | 0 | error, |
14267 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14268 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14269 | 0 | "%s: header value cannot be changed.", |
14270 | 0 | function ); |
14271 | |
|
14272 | 0 | result = -1; |
14273 | 0 | } |
14274 | 0 | else if( internal_handle->header_values == NULL ) |
14275 | 0 | { |
14276 | 0 | result = libewf_header_values_initialize( |
14277 | 0 | &( internal_handle->header_values ), |
14278 | 0 | error ); |
14279 | |
|
14280 | 0 | if( result != 1 ) |
14281 | 0 | { |
14282 | 0 | libcerror_error_set( |
14283 | 0 | error, |
14284 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14285 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
14286 | 0 | "%s: unable to create header values.", |
14287 | 0 | function ); |
14288 | 0 | } |
14289 | 0 | } |
14290 | 0 | if( result == 1 ) |
14291 | 0 | { |
14292 | 0 | result = libewf_value_table_copy_value_from_utf8_string( |
14293 | 0 | internal_handle->header_values, |
14294 | 0 | identifier, |
14295 | 0 | identifier_length, |
14296 | 0 | utf8_string, |
14297 | 0 | utf8_string_length, |
14298 | 0 | error ); |
14299 | |
|
14300 | 0 | if( result != 1 ) |
14301 | 0 | { |
14302 | 0 | libcerror_error_set( |
14303 | 0 | error, |
14304 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14305 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14306 | 0 | "%s: unable to set header value.", |
14307 | 0 | function ); |
14308 | 0 | } |
14309 | 0 | } |
14310 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
14311 | 0 | if( libcthreads_read_write_lock_release_for_write( |
14312 | 0 | internal_handle->read_write_lock, |
14313 | 0 | error ) != 1 ) |
14314 | 0 | { |
14315 | 0 | libcerror_error_set( |
14316 | 0 | error, |
14317 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14318 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14319 | 0 | "%s: unable to release read/write lock for writing.", |
14320 | 0 | function ); |
14321 | |
|
14322 | 0 | return( -1 ); |
14323 | 0 | } |
14324 | 0 | #endif |
14325 | 0 | return( result ); |
14326 | 0 | } |
14327 | | |
14328 | | /* Retrieves the size of the UTF-16 encoded header value of an identifier |
14329 | | * The string size includes the end of string character |
14330 | | * Returns 1 if successful, 0 if not set or -1 on error |
14331 | | */ |
14332 | | int libewf_handle_get_utf16_header_value_size( |
14333 | | libewf_handle_t *handle, |
14334 | | const uint8_t *identifier, |
14335 | | size_t identifier_length, |
14336 | | size_t *utf16_string_size, |
14337 | | libcerror_error_t **error ) |
14338 | 0 | { |
14339 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
14340 | 0 | static char *function = "libewf_handle_get_utf8_header_value_size"; |
14341 | 0 | int result = 0; |
14342 | |
|
14343 | 0 | if( handle == NULL ) |
14344 | 0 | { |
14345 | 0 | libcerror_error_set( |
14346 | 0 | error, |
14347 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
14348 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
14349 | 0 | "%s: invalid handle.", |
14350 | 0 | function ); |
14351 | |
|
14352 | 0 | return( -1 ); |
14353 | 0 | } |
14354 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
14355 | |
|
14356 | 0 | if( utf16_string_size == NULL ) |
14357 | 0 | { |
14358 | 0 | libcerror_error_set( |
14359 | 0 | error, |
14360 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
14361 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
14362 | 0 | "%s: invalid UTF-16 string size.", |
14363 | 0 | function ); |
14364 | |
|
14365 | 0 | return( -1 ); |
14366 | 0 | } |
14367 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
14368 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
14369 | 0 | internal_handle->read_write_lock, |
14370 | 0 | error ) != 1 ) |
14371 | 0 | { |
14372 | 0 | libcerror_error_set( |
14373 | 0 | error, |
14374 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14375 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14376 | 0 | "%s: unable to grab read/write lock for reading.", |
14377 | 0 | function ); |
14378 | |
|
14379 | 0 | return( -1 ); |
14380 | 0 | } |
14381 | 0 | #endif |
14382 | 0 | if( internal_handle->header_values != NULL ) |
14383 | 0 | { |
14384 | 0 | result = libewf_header_values_get_utf16_value_size( |
14385 | 0 | internal_handle->header_values, |
14386 | 0 | identifier, |
14387 | 0 | identifier_length, |
14388 | 0 | internal_handle->date_format, |
14389 | 0 | utf16_string_size, |
14390 | 0 | error ); |
14391 | |
|
14392 | 0 | if( result == -1 ) |
14393 | 0 | { |
14394 | 0 | libcerror_error_set( |
14395 | 0 | error, |
14396 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14397 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
14398 | 0 | "%s: unable to retrieve header value size.", |
14399 | 0 | function ); |
14400 | 0 | } |
14401 | 0 | } |
14402 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
14403 | 0 | if( libcthreads_read_write_lock_release_for_read( |
14404 | 0 | internal_handle->read_write_lock, |
14405 | 0 | error ) != 1 ) |
14406 | 0 | { |
14407 | 0 | libcerror_error_set( |
14408 | 0 | error, |
14409 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14410 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14411 | 0 | "%s: unable to release read/write lock for reading.", |
14412 | 0 | function ); |
14413 | |
|
14414 | 0 | return( -1 ); |
14415 | 0 | } |
14416 | 0 | #endif |
14417 | 0 | return( result ); |
14418 | 0 | } |
14419 | | |
14420 | | /* Retrieves the UTF-16 encoded header value of an identifier |
14421 | | * The string size should include the end of string character |
14422 | | * Returns 1 if successful, 0 if not set or -1 on error |
14423 | | */ |
14424 | | int libewf_handle_get_utf16_header_value( |
14425 | | libewf_handle_t *handle, |
14426 | | const uint8_t *identifier, |
14427 | | size_t identifier_length, |
14428 | | uint16_t *utf16_string, |
14429 | | size_t utf16_string_size, |
14430 | | libcerror_error_t **error ) |
14431 | 0 | { |
14432 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
14433 | 0 | static char *function = "libewf_handle_get_utf16_header_value"; |
14434 | 0 | int result = 0; |
14435 | |
|
14436 | 0 | if( handle == NULL ) |
14437 | 0 | { |
14438 | 0 | libcerror_error_set( |
14439 | 0 | error, |
14440 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
14441 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
14442 | 0 | "%s: invalid handle.", |
14443 | 0 | function ); |
14444 | |
|
14445 | 0 | return( -1 ); |
14446 | 0 | } |
14447 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
14448 | |
|
14449 | 0 | if( utf16_string == NULL ) |
14450 | 0 | { |
14451 | 0 | libcerror_error_set( |
14452 | 0 | error, |
14453 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
14454 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
14455 | 0 | "%s: invalid UTF-16 string.", |
14456 | 0 | function ); |
14457 | |
|
14458 | 0 | return( -1 ); |
14459 | 0 | } |
14460 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
14461 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
14462 | 0 | internal_handle->read_write_lock, |
14463 | 0 | error ) != 1 ) |
14464 | 0 | { |
14465 | 0 | libcerror_error_set( |
14466 | 0 | error, |
14467 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14468 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14469 | 0 | "%s: unable to grab read/write lock for reading.", |
14470 | 0 | function ); |
14471 | |
|
14472 | 0 | return( -1 ); |
14473 | 0 | } |
14474 | 0 | #endif |
14475 | 0 | if( internal_handle->header_values != NULL ) |
14476 | 0 | { |
14477 | 0 | result = libewf_header_values_get_utf16_value( |
14478 | 0 | internal_handle->header_values, |
14479 | 0 | identifier, |
14480 | 0 | identifier_length, |
14481 | 0 | internal_handle->date_format, |
14482 | 0 | utf16_string, |
14483 | 0 | utf16_string_size, |
14484 | 0 | error ); |
14485 | |
|
14486 | 0 | if( result == -1 ) |
14487 | 0 | { |
14488 | 0 | libcerror_error_set( |
14489 | 0 | error, |
14490 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14491 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
14492 | 0 | "%s: unable to retrieve header value.", |
14493 | 0 | function ); |
14494 | 0 | } |
14495 | 0 | } |
14496 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
14497 | 0 | if( libcthreads_read_write_lock_release_for_read( |
14498 | 0 | internal_handle->read_write_lock, |
14499 | 0 | error ) != 1 ) |
14500 | 0 | { |
14501 | 0 | libcerror_error_set( |
14502 | 0 | error, |
14503 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14504 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14505 | 0 | "%s: unable to release read/write lock for reading.", |
14506 | 0 | function ); |
14507 | |
|
14508 | 0 | return( -1 ); |
14509 | 0 | } |
14510 | 0 | #endif |
14511 | 0 | return( result ); |
14512 | 0 | } |
14513 | | |
14514 | | /* Sets the UTF-16 encoded header value specified by the identifier |
14515 | | * Returns 1 if successful or -1 on error |
14516 | | */ |
14517 | | int libewf_handle_set_utf16_header_value( |
14518 | | libewf_handle_t *handle, |
14519 | | const uint8_t *identifier, |
14520 | | size_t identifier_length, |
14521 | | const uint16_t *utf16_string, |
14522 | | size_t utf16_string_length, |
14523 | | libcerror_error_t **error ) |
14524 | 0 | { |
14525 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
14526 | 0 | static char *function = "libewf_handle_set_utf16_header_value"; |
14527 | 0 | int result = 1; |
14528 | |
|
14529 | 0 | if( handle == NULL ) |
14530 | 0 | { |
14531 | 0 | libcerror_error_set( |
14532 | 0 | error, |
14533 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
14534 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
14535 | 0 | "%s: invalid handle.", |
14536 | 0 | function ); |
14537 | |
|
14538 | 0 | return( -1 ); |
14539 | 0 | } |
14540 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
14541 | |
|
14542 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
14543 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
14544 | 0 | internal_handle->read_write_lock, |
14545 | 0 | error ) != 1 ) |
14546 | 0 | { |
14547 | 0 | libcerror_error_set( |
14548 | 0 | error, |
14549 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14550 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14551 | 0 | "%s: unable to grab read/write lock for writing.", |
14552 | 0 | function ); |
14553 | |
|
14554 | 0 | return( -1 ); |
14555 | 0 | } |
14556 | 0 | #endif |
14557 | 0 | if( ( internal_handle->read_io_handle != NULL ) |
14558 | 0 | || ( internal_handle->write_io_handle == NULL ) |
14559 | 0 | || ( internal_handle->write_io_handle->values_initialized != 0 ) ) |
14560 | 0 | { |
14561 | 0 | libcerror_error_set( |
14562 | 0 | error, |
14563 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14564 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14565 | 0 | "%s: header value cannot be changed.", |
14566 | 0 | function ); |
14567 | |
|
14568 | 0 | result = -1; |
14569 | 0 | } |
14570 | 0 | else if( internal_handle->header_values == NULL ) |
14571 | 0 | { |
14572 | 0 | result = libewf_header_values_initialize( |
14573 | 0 | &( internal_handle->header_values ), |
14574 | 0 | error ); |
14575 | |
|
14576 | 0 | if( result != 1 ) |
14577 | 0 | { |
14578 | 0 | libcerror_error_set( |
14579 | 0 | error, |
14580 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14581 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
14582 | 0 | "%s: unable to create header values.", |
14583 | 0 | function ); |
14584 | 0 | } |
14585 | 0 | } |
14586 | 0 | if( result == 1 ) |
14587 | 0 | { |
14588 | 0 | result = libewf_value_table_copy_value_from_utf16_string( |
14589 | 0 | internal_handle->header_values, |
14590 | 0 | identifier, |
14591 | 0 | identifier_length, |
14592 | 0 | utf16_string, |
14593 | 0 | utf16_string_length, |
14594 | 0 | error ); |
14595 | |
|
14596 | 0 | if( result != 1 ) |
14597 | 0 | { |
14598 | 0 | libcerror_error_set( |
14599 | 0 | error, |
14600 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14601 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14602 | 0 | "%s: unable to set header value.", |
14603 | 0 | function ); |
14604 | 0 | } |
14605 | 0 | } |
14606 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
14607 | 0 | if( libcthreads_read_write_lock_release_for_write( |
14608 | 0 | internal_handle->read_write_lock, |
14609 | 0 | error ) != 1 ) |
14610 | 0 | { |
14611 | 0 | libcerror_error_set( |
14612 | 0 | error, |
14613 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14614 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14615 | 0 | "%s: unable to release read/write lock for writing.", |
14616 | 0 | function ); |
14617 | |
|
14618 | 0 | return( -1 ); |
14619 | 0 | } |
14620 | 0 | #endif |
14621 | 0 | return( result ); |
14622 | 0 | } |
14623 | | |
14624 | | /* Copies the header values from the source to the destination handle |
14625 | | * Returns 1 if successful or -1 on error |
14626 | | */ |
14627 | | int libewf_handle_copy_header_values( |
14628 | | libewf_handle_t *destination_handle, |
14629 | | libewf_handle_t *source_handle, |
14630 | | libcerror_error_t **error ) |
14631 | 0 | { |
14632 | 0 | libewf_internal_handle_t *internal_destination_handle = NULL; |
14633 | 0 | libewf_internal_handle_t *internal_source_handle = NULL; |
14634 | 0 | static char *function = "libewf_handle_copy_header_values"; |
14635 | 0 | int result = 1; |
14636 | |
|
14637 | 0 | if( destination_handle == NULL ) |
14638 | 0 | { |
14639 | 0 | libcerror_error_set( |
14640 | 0 | error, |
14641 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
14642 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
14643 | 0 | "%s: invalid destination handle.", |
14644 | 0 | function ); |
14645 | |
|
14646 | 0 | return( -1 ); |
14647 | 0 | } |
14648 | 0 | if( source_handle == NULL ) |
14649 | 0 | { |
14650 | 0 | libcerror_error_set( |
14651 | 0 | error, |
14652 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
14653 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
14654 | 0 | "%s: invalid source handle.", |
14655 | 0 | function ); |
14656 | |
|
14657 | 0 | return( -1 ); |
14658 | 0 | } |
14659 | 0 | internal_destination_handle = (libewf_internal_handle_t *) destination_handle; |
14660 | 0 | internal_source_handle = (libewf_internal_handle_t *) source_handle; |
14661 | |
|
14662 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
14663 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
14664 | 0 | internal_source_handle->read_write_lock, |
14665 | 0 | error ) != 1 ) |
14666 | 0 | { |
14667 | 0 | libcerror_error_set( |
14668 | 0 | error, |
14669 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14670 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14671 | 0 | "%s: unable to grab read/write lock for reading.", |
14672 | 0 | function ); |
14673 | |
|
14674 | 0 | return( -1 ); |
14675 | 0 | } |
14676 | 0 | #endif |
14677 | 0 | if( internal_source_handle->header_values == NULL ) |
14678 | 0 | { |
14679 | 0 | libcerror_error_set( |
14680 | 0 | error, |
14681 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14682 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
14683 | 0 | "%s: invalid source handle - missing header values.", |
14684 | 0 | function ); |
14685 | |
|
14686 | 0 | result = -1; |
14687 | 0 | } |
14688 | 0 | else |
14689 | 0 | { |
14690 | | /* TODO add destination handle write lock */ |
14691 | 0 | if( internal_destination_handle->header_values == NULL ) |
14692 | 0 | { |
14693 | 0 | if( libewf_header_values_initialize( |
14694 | 0 | &( internal_destination_handle->header_values ), |
14695 | 0 | error ) != 1 ) |
14696 | 0 | { |
14697 | 0 | libcerror_error_set( |
14698 | 0 | error, |
14699 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14700 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
14701 | 0 | "%s: unable to create header values.", |
14702 | 0 | function ); |
14703 | |
|
14704 | 0 | result = -1; |
14705 | 0 | } |
14706 | 0 | } |
14707 | 0 | if( result == 1 ) |
14708 | 0 | { |
14709 | 0 | result = libewf_header_values_copy( |
14710 | 0 | internal_destination_handle->header_values, |
14711 | 0 | internal_source_handle->header_values, |
14712 | 0 | error ); |
14713 | |
|
14714 | 0 | if( result != 1 ) |
14715 | 0 | { |
14716 | 0 | libcerror_error_set( |
14717 | 0 | error, |
14718 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14719 | 0 | LIBCERROR_RUNTIME_ERROR_COPY_FAILED, |
14720 | 0 | "%s: unable to copy header values.", |
14721 | 0 | function ); |
14722 | 0 | } |
14723 | 0 | else |
14724 | 0 | { |
14725 | 0 | internal_destination_handle->header_values_parsed = 1; |
14726 | 0 | } |
14727 | 0 | } |
14728 | 0 | } |
14729 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
14730 | 0 | if( libcthreads_read_write_lock_release_for_read( |
14731 | 0 | internal_source_handle->read_write_lock, |
14732 | 0 | error ) != 1 ) |
14733 | 0 | { |
14734 | 0 | libcerror_error_set( |
14735 | 0 | error, |
14736 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14737 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14738 | 0 | "%s: unable to release read/write lock for reading.", |
14739 | 0 | function ); |
14740 | |
|
14741 | 0 | return( -1 ); |
14742 | 0 | } |
14743 | 0 | #endif |
14744 | 0 | return( result ); |
14745 | 0 | } |
14746 | | |
14747 | | /* Parses the hash values from the hash, digest and/or xhash section |
14748 | | * Returns 1 if successful or -1 on error |
14749 | | */ |
14750 | | int libewf_internal_handle_parse_hash_values( |
14751 | | libewf_internal_handle_t *internal_handle, |
14752 | | libcerror_error_t **error ) |
14753 | 0 | { |
14754 | 0 | static char *function = "libewf_internal_handle_parse_hash_values"; |
14755 | 0 | int result = 1; |
14756 | |
|
14757 | 0 | if( internal_handle == NULL ) |
14758 | 0 | { |
14759 | 0 | libcerror_error_set( |
14760 | 0 | error, |
14761 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
14762 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
14763 | 0 | "%s: invalid handle.", |
14764 | 0 | function ); |
14765 | |
|
14766 | 0 | return( -1 ); |
14767 | 0 | } |
14768 | 0 | if( internal_handle->hash_sections == NULL ) |
14769 | 0 | { |
14770 | 0 | libcerror_error_set( |
14771 | 0 | error, |
14772 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14773 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
14774 | 0 | "%s: invalid handle - missing hash sections.", |
14775 | 0 | function ); |
14776 | |
|
14777 | 0 | return( -1 ); |
14778 | 0 | } |
14779 | 0 | if( internal_handle->hash_values != NULL ) |
14780 | 0 | { |
14781 | 0 | libcerror_error_set( |
14782 | 0 | error, |
14783 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14784 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, |
14785 | 0 | "%s: invalid handle - hash sections already set.", |
14786 | 0 | function ); |
14787 | |
|
14788 | 0 | return( -1 ); |
14789 | 0 | } |
14790 | 0 | if( libewf_hash_values_initialize( |
14791 | 0 | &( internal_handle->hash_values ), |
14792 | 0 | error ) != 1 ) |
14793 | 0 | { |
14794 | 0 | libcerror_error_set( |
14795 | 0 | error, |
14796 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14797 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
14798 | 0 | "%s: unable to create hash values.", |
14799 | 0 | function ); |
14800 | |
|
14801 | 0 | return( -1 ); |
14802 | 0 | } |
14803 | 0 | if( ( internal_handle->hash_sections->md5_hash_set != 0 ) |
14804 | 0 | && ( libewf_hash_values_parse_md5_hash( |
14805 | 0 | internal_handle->hash_values, |
14806 | 0 | internal_handle->hash_sections->md5_hash, |
14807 | 0 | 16, |
14808 | 0 | error ) != 1 ) ) |
14809 | 0 | { |
14810 | 0 | libcerror_error_set( |
14811 | 0 | error, |
14812 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14813 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14814 | 0 | "%s: unable to parse MD5 hash for its value.", |
14815 | 0 | function ); |
14816 | |
|
14817 | 0 | result = -1; |
14818 | 0 | } |
14819 | 0 | else if( ( internal_handle->hash_sections->md5_digest_set != 0 ) |
14820 | 0 | && ( libewf_hash_values_parse_md5_hash( |
14821 | 0 | internal_handle->hash_values, |
14822 | 0 | internal_handle->hash_sections->md5_digest, |
14823 | 0 | 16, |
14824 | 0 | error ) != 1 ) ) |
14825 | 0 | { |
14826 | 0 | libcerror_error_set( |
14827 | 0 | error, |
14828 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14829 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14830 | 0 | "%s: unable to parse MD5 digest for its value.", |
14831 | 0 | function ); |
14832 | |
|
14833 | 0 | result = -1; |
14834 | 0 | } |
14835 | 0 | if( ( internal_handle->hash_sections->sha1_hash_set != 0 ) |
14836 | 0 | && ( libewf_hash_values_parse_sha1_hash( |
14837 | 0 | internal_handle->hash_values, |
14838 | 0 | internal_handle->hash_sections->sha1_hash, |
14839 | 0 | 20, |
14840 | 0 | error ) != 1 ) ) |
14841 | 0 | { |
14842 | 0 | libcerror_error_set( |
14843 | 0 | error, |
14844 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14845 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14846 | 0 | "%s: unable to parse SHA1 hash for its value.", |
14847 | 0 | function ); |
14848 | |
|
14849 | 0 | result = -1; |
14850 | 0 | } |
14851 | 0 | else if( ( internal_handle->hash_sections->sha1_digest_set != 0 ) |
14852 | 0 | && ( libewf_hash_values_parse_sha1_hash( |
14853 | 0 | internal_handle->hash_values, |
14854 | 0 | internal_handle->hash_sections->sha1_digest, |
14855 | 0 | 20, |
14856 | 0 | error ) != 1 ) ) |
14857 | 0 | { |
14858 | 0 | libcerror_error_set( |
14859 | 0 | error, |
14860 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14861 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14862 | 0 | "%s: unable to parse SHA1 digest for its value.", |
14863 | 0 | function ); |
14864 | |
|
14865 | 0 | result = -1; |
14866 | 0 | } |
14867 | 0 | if( ( internal_handle->hash_sections->xhash != NULL ) |
14868 | 0 | && ( libewf_hash_values_parse_xhash( |
14869 | 0 | internal_handle->hash_values, |
14870 | 0 | internal_handle->hash_sections->xhash, |
14871 | 0 | internal_handle->hash_sections->xhash_size, |
14872 | 0 | error ) != 1 ) ) |
14873 | 0 | { |
14874 | 0 | libcerror_error_set( |
14875 | 0 | error, |
14876 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14877 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14878 | 0 | "%s: unable to parse xhash for values.", |
14879 | 0 | function ); |
14880 | |
|
14881 | 0 | result = -1; |
14882 | 0 | } |
14883 | 0 | return( result ); |
14884 | 0 | } |
14885 | | |
14886 | | /* Retrieves the number of hash values |
14887 | | * Returns 1 if successful or -1 on error |
14888 | | */ |
14889 | | int libewf_handle_get_number_of_hash_values( |
14890 | | libewf_handle_t *handle, |
14891 | | uint32_t *number_of_values, |
14892 | | libcerror_error_t **error ) |
14893 | 0 | { |
14894 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
14895 | 0 | static char *function = "libewf_handle_get_number_of_hash_values"; |
14896 | 0 | int number_of_hash_values = 0; |
14897 | |
|
14898 | 0 | if( handle == NULL ) |
14899 | 0 | { |
14900 | 0 | libcerror_error_set( |
14901 | 0 | error, |
14902 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
14903 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
14904 | 0 | "%s: invalid handle.", |
14905 | 0 | function ); |
14906 | |
|
14907 | 0 | return( -1 ); |
14908 | 0 | } |
14909 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
14910 | |
|
14911 | 0 | if( number_of_values == NULL ) |
14912 | 0 | { |
14913 | 0 | libcerror_error_set( |
14914 | 0 | error, |
14915 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
14916 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
14917 | 0 | "%s: invalid number of values.", |
14918 | 0 | function ); |
14919 | |
|
14920 | 0 | return( -1 ); |
14921 | 0 | } |
14922 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
14923 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
14924 | 0 | internal_handle->read_write_lock, |
14925 | 0 | error ) != 1 ) |
14926 | 0 | { |
14927 | 0 | libcerror_error_set( |
14928 | 0 | error, |
14929 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14930 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14931 | 0 | "%s: unable to grab read/write lock for writing.", |
14932 | 0 | function ); |
14933 | |
|
14934 | 0 | return( -1 ); |
14935 | 0 | } |
14936 | 0 | #endif |
14937 | 0 | if( internal_handle->hash_values_parsed == 0 ) |
14938 | 0 | { |
14939 | 0 | if( libewf_internal_handle_parse_hash_values( |
14940 | 0 | internal_handle, |
14941 | 0 | error ) != 1 ) |
14942 | 0 | { |
14943 | 0 | libcerror_error_set( |
14944 | 0 | error, |
14945 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14946 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14947 | 0 | "%s: unable to parse hash values.", |
14948 | 0 | function ); |
14949 | |
|
14950 | 0 | goto on_error; |
14951 | 0 | } |
14952 | 0 | internal_handle->hash_values_parsed = 1; |
14953 | 0 | } |
14954 | 0 | if( internal_handle->hash_values != NULL ) |
14955 | 0 | { |
14956 | 0 | if( libfvalue_table_get_number_of_values( |
14957 | 0 | internal_handle->hash_values, |
14958 | 0 | &number_of_hash_values, |
14959 | 0 | error ) != 1 ) |
14960 | 0 | { |
14961 | 0 | libcerror_error_set( |
14962 | 0 | error, |
14963 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14964 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
14965 | 0 | "%s: unable to retrieve number of hash values.", |
14966 | 0 | function ); |
14967 | |
|
14968 | 0 | goto on_error; |
14969 | 0 | } |
14970 | 0 | } |
14971 | 0 | if( number_of_hash_values < 0 ) |
14972 | 0 | { |
14973 | 0 | libcerror_error_set( |
14974 | 0 | error, |
14975 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14976 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, |
14977 | 0 | "%s: invalid number of hash values value out of bounds.", |
14978 | 0 | function ); |
14979 | |
|
14980 | 0 | goto on_error; |
14981 | 0 | } |
14982 | 0 | *number_of_values = (uint32_t) number_of_hash_values; |
14983 | |
|
14984 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
14985 | 0 | if( libcthreads_read_write_lock_release_for_write( |
14986 | 0 | internal_handle->read_write_lock, |
14987 | 0 | error ) != 1 ) |
14988 | 0 | { |
14989 | 0 | libcerror_error_set( |
14990 | 0 | error, |
14991 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
14992 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
14993 | 0 | "%s: unable to release read/write lock for writing.", |
14994 | 0 | function ); |
14995 | |
|
14996 | 0 | return( -1 ); |
14997 | 0 | } |
14998 | 0 | #endif |
14999 | 0 | return( 1 ); |
15000 | | |
15001 | 0 | on_error: |
15002 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
15003 | 0 | libcthreads_read_write_lock_release_for_write( |
15004 | 0 | internal_handle->read_write_lock, |
15005 | 0 | NULL ); |
15006 | 0 | #endif |
15007 | 0 | return( -1 ); |
15008 | 0 | } |
15009 | | |
15010 | | /* Retrieves the size of the hash value identifier of a specific index |
15011 | | * The identifier size includes the end of string character |
15012 | | * Returns 1 if successful, 0 if if no hash values are present or -1 on error |
15013 | | */ |
15014 | | int libewf_handle_get_hash_value_identifier_size( |
15015 | | libewf_handle_t *handle, |
15016 | | uint32_t index, |
15017 | | size_t *identifier_size, |
15018 | | libcerror_error_t **error ) |
15019 | 0 | { |
15020 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
15021 | 0 | static char *function = "libewf_handle_get_hash_value_identifier_size"; |
15022 | 0 | int result = 0; |
15023 | |
|
15024 | 0 | if( handle == NULL ) |
15025 | 0 | { |
15026 | 0 | libcerror_error_set( |
15027 | 0 | error, |
15028 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
15029 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
15030 | 0 | "%s: invalid handle.", |
15031 | 0 | function ); |
15032 | |
|
15033 | 0 | return( -1 ); |
15034 | 0 | } |
15035 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
15036 | | |
15037 | | /* TODO add write lock */ |
15038 | 0 | if( internal_handle->hash_values_parsed == 0 ) |
15039 | 0 | { |
15040 | 0 | if( libewf_internal_handle_parse_hash_values( |
15041 | 0 | internal_handle, |
15042 | 0 | error ) != 1 ) |
15043 | 0 | { |
15044 | 0 | libcerror_error_set( |
15045 | 0 | error, |
15046 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15047 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15048 | 0 | "%s: unable to parse hash values.", |
15049 | 0 | function ); |
15050 | |
|
15051 | 0 | return( -1 ); |
15052 | 0 | } |
15053 | 0 | internal_handle->hash_values_parsed = 1; |
15054 | 0 | } |
15055 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
15056 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
15057 | 0 | internal_handle->read_write_lock, |
15058 | 0 | error ) != 1 ) |
15059 | 0 | { |
15060 | 0 | libcerror_error_set( |
15061 | 0 | error, |
15062 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15063 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15064 | 0 | "%s: unable to grab read/write lock for reading.", |
15065 | 0 | function ); |
15066 | |
|
15067 | 0 | return( -1 ); |
15068 | 0 | } |
15069 | 0 | #endif |
15070 | 0 | if( internal_handle->hash_values != NULL ) |
15071 | 0 | { |
15072 | 0 | result = libewf_hash_values_get_identifier_size( |
15073 | 0 | internal_handle->hash_values, |
15074 | 0 | index, |
15075 | 0 | identifier_size, |
15076 | 0 | error ); |
15077 | |
|
15078 | 0 | if( result == -1 ) |
15079 | 0 | { |
15080 | 0 | libcerror_error_set( |
15081 | 0 | error, |
15082 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15083 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
15084 | 0 | "%s: unable to retrieve hash value: %" PRIu32 " identifier size.", |
15085 | 0 | function, |
15086 | 0 | index ); |
15087 | 0 | } |
15088 | 0 | } |
15089 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
15090 | 0 | if( libcthreads_read_write_lock_release_for_read( |
15091 | 0 | internal_handle->read_write_lock, |
15092 | 0 | error ) != 1 ) |
15093 | 0 | { |
15094 | 0 | libcerror_error_set( |
15095 | 0 | error, |
15096 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15097 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15098 | 0 | "%s: unable to release read/write lock for reading.", |
15099 | 0 | function ); |
15100 | |
|
15101 | 0 | return( -1 ); |
15102 | 0 | } |
15103 | 0 | #endif |
15104 | 0 | return( result ); |
15105 | 0 | } |
15106 | | |
15107 | | /* Retrieves the hash value identifier of a specific index |
15108 | | * The identifier size should include the end of string character |
15109 | | * Returns 1 if successful, 0 if no hash values are present or -1 on error |
15110 | | */ |
15111 | | int libewf_handle_get_hash_value_identifier( |
15112 | | libewf_handle_t *handle, |
15113 | | uint32_t index, |
15114 | | uint8_t *identifier, |
15115 | | size_t identifier_size, |
15116 | | libcerror_error_t **error ) |
15117 | 0 | { |
15118 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
15119 | 0 | static char *function = "libewf_handle_get_hash_value_identifier"; |
15120 | 0 | int result = 0; |
15121 | |
|
15122 | 0 | if( handle == NULL ) |
15123 | 0 | { |
15124 | 0 | libcerror_error_set( |
15125 | 0 | error, |
15126 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
15127 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
15128 | 0 | "%s: invalid handle.", |
15129 | 0 | function ); |
15130 | |
|
15131 | 0 | return( -1 ); |
15132 | 0 | } |
15133 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
15134 | | |
15135 | | /* TODO add write lock */ |
15136 | 0 | if( internal_handle->hash_values_parsed == 0 ) |
15137 | 0 | { |
15138 | 0 | if( libewf_internal_handle_parse_hash_values( |
15139 | 0 | internal_handle, |
15140 | 0 | error ) != 1 ) |
15141 | 0 | { |
15142 | 0 | libcerror_error_set( |
15143 | 0 | error, |
15144 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15145 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15146 | 0 | "%s: unable to parse hash values.", |
15147 | 0 | function ); |
15148 | |
|
15149 | 0 | return( -1 ); |
15150 | 0 | } |
15151 | 0 | internal_handle->hash_values_parsed = 1; |
15152 | 0 | } |
15153 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
15154 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
15155 | 0 | internal_handle->read_write_lock, |
15156 | 0 | error ) != 1 ) |
15157 | 0 | { |
15158 | 0 | libcerror_error_set( |
15159 | 0 | error, |
15160 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15161 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15162 | 0 | "%s: unable to grab read/write lock for reading.", |
15163 | 0 | function ); |
15164 | |
|
15165 | 0 | return( -1 ); |
15166 | 0 | } |
15167 | 0 | #endif |
15168 | 0 | if( internal_handle->hash_values != NULL ) |
15169 | 0 | { |
15170 | 0 | result = libewf_hash_values_get_identifier( |
15171 | 0 | internal_handle->hash_values, |
15172 | 0 | index, |
15173 | 0 | identifier, |
15174 | 0 | identifier_size, |
15175 | 0 | error ); |
15176 | |
|
15177 | 0 | if( result == -1 ) |
15178 | 0 | { |
15179 | 0 | libcerror_error_set( |
15180 | 0 | error, |
15181 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15182 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
15183 | 0 | "%s: unable to retrieve hash value: %" PRIu32 " identifier.", |
15184 | 0 | function, |
15185 | 0 | index ); |
15186 | 0 | } |
15187 | 0 | } |
15188 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
15189 | 0 | if( libcthreads_read_write_lock_release_for_read( |
15190 | 0 | internal_handle->read_write_lock, |
15191 | 0 | error ) != 1 ) |
15192 | 0 | { |
15193 | 0 | libcerror_error_set( |
15194 | 0 | error, |
15195 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15196 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15197 | 0 | "%s: unable to release read/write lock for reading.", |
15198 | 0 | function ); |
15199 | |
|
15200 | 0 | return( -1 ); |
15201 | 0 | } |
15202 | 0 | #endif |
15203 | 0 | return( result ); |
15204 | 0 | } |
15205 | | |
15206 | | /* Retrieves the size of the UTF-8 encoded hash value of an identifier |
15207 | | * The string size includes the end of string character |
15208 | | * Returns 1 if successful, 0 if not set or -1 on error |
15209 | | */ |
15210 | | int libewf_handle_get_utf8_hash_value_size( |
15211 | | libewf_handle_t *handle, |
15212 | | const uint8_t *identifier, |
15213 | | size_t identifier_length, |
15214 | | size_t *utf8_string_size, |
15215 | | libcerror_error_t **error ) |
15216 | 0 | { |
15217 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
15218 | 0 | static char *function = "libewf_handle_get_utf8_hash_value_size"; |
15219 | 0 | int result = 0; |
15220 | |
|
15221 | 0 | if( handle == NULL ) |
15222 | 0 | { |
15223 | 0 | libcerror_error_set( |
15224 | 0 | error, |
15225 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
15226 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
15227 | 0 | "%s: invalid handle.", |
15228 | 0 | function ); |
15229 | |
|
15230 | 0 | return( -1 ); |
15231 | 0 | } |
15232 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
15233 | | |
15234 | | /* TODO add write lock */ |
15235 | 0 | if( internal_handle->hash_values_parsed == 0 ) |
15236 | 0 | { |
15237 | 0 | if( libewf_internal_handle_parse_hash_values( |
15238 | 0 | internal_handle, |
15239 | 0 | error ) != 1 ) |
15240 | 0 | { |
15241 | 0 | libcerror_error_set( |
15242 | 0 | error, |
15243 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15244 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15245 | 0 | "%s: unable to parse hash values.", |
15246 | 0 | function ); |
15247 | |
|
15248 | 0 | return( -1 ); |
15249 | 0 | } |
15250 | 0 | internal_handle->hash_values_parsed = 1; |
15251 | 0 | } |
15252 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
15253 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
15254 | 0 | internal_handle->read_write_lock, |
15255 | 0 | error ) != 1 ) |
15256 | 0 | { |
15257 | 0 | libcerror_error_set( |
15258 | 0 | error, |
15259 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15260 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15261 | 0 | "%s: unable to grab read/write lock for reading.", |
15262 | 0 | function ); |
15263 | |
|
15264 | 0 | return( -1 ); |
15265 | 0 | } |
15266 | 0 | #endif |
15267 | 0 | if( internal_handle->hash_values != NULL ) |
15268 | 0 | { |
15269 | 0 | result = libewf_value_table_get_utf8_value_size( |
15270 | 0 | internal_handle->hash_values, |
15271 | 0 | identifier, |
15272 | 0 | identifier_length, |
15273 | 0 | utf8_string_size, |
15274 | 0 | error ); |
15275 | |
|
15276 | 0 | if( result == -1 ) |
15277 | 0 | { |
15278 | 0 | libcerror_error_set( |
15279 | 0 | error, |
15280 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15281 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
15282 | 0 | "%s: unable to retrieve hash value size.", |
15283 | 0 | function ); |
15284 | 0 | } |
15285 | 0 | } |
15286 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
15287 | 0 | if( libcthreads_read_write_lock_release_for_read( |
15288 | 0 | internal_handle->read_write_lock, |
15289 | 0 | error ) != 1 ) |
15290 | 0 | { |
15291 | 0 | libcerror_error_set( |
15292 | 0 | error, |
15293 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15294 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15295 | 0 | "%s: unable to release read/write lock for reading.", |
15296 | 0 | function ); |
15297 | |
|
15298 | 0 | return( -1 ); |
15299 | 0 | } |
15300 | 0 | #endif |
15301 | 0 | return( result ); |
15302 | 0 | } |
15303 | | |
15304 | | /* Retrieves the UTF-8 encoded hash value of an identifier |
15305 | | * The string size should include the end of string character |
15306 | | * Returns 1 if successful, 0 if not set or -1 on error |
15307 | | */ |
15308 | | int libewf_handle_get_utf8_hash_value( |
15309 | | libewf_handle_t *handle, |
15310 | | const uint8_t *identifier, |
15311 | | size_t identifier_length, |
15312 | | uint8_t *utf8_string, |
15313 | | size_t utf8_string_size, |
15314 | | libcerror_error_t **error ) |
15315 | 0 | { |
15316 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
15317 | 0 | static char *function = "libewf_handle_get_utf8_hash_value"; |
15318 | 0 | int result = 0; |
15319 | |
|
15320 | 0 | if( handle == NULL ) |
15321 | 0 | { |
15322 | 0 | libcerror_error_set( |
15323 | 0 | error, |
15324 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
15325 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
15326 | 0 | "%s: invalid handle.", |
15327 | 0 | function ); |
15328 | |
|
15329 | 0 | return( -1 ); |
15330 | 0 | } |
15331 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
15332 | | |
15333 | | /* TODO add write lock */ |
15334 | 0 | if( internal_handle->hash_values_parsed == 0 ) |
15335 | 0 | { |
15336 | 0 | if( libewf_internal_handle_parse_hash_values( |
15337 | 0 | internal_handle, |
15338 | 0 | error ) != 1 ) |
15339 | 0 | { |
15340 | 0 | libcerror_error_set( |
15341 | 0 | error, |
15342 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15343 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15344 | 0 | "%s: unable to parse hash values.", |
15345 | 0 | function ); |
15346 | |
|
15347 | 0 | return( -1 ); |
15348 | 0 | } |
15349 | 0 | internal_handle->hash_values_parsed = 1; |
15350 | 0 | } |
15351 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
15352 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
15353 | 0 | internal_handle->read_write_lock, |
15354 | 0 | error ) != 1 ) |
15355 | 0 | { |
15356 | 0 | libcerror_error_set( |
15357 | 0 | error, |
15358 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15359 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15360 | 0 | "%s: unable to grab read/write lock for reading.", |
15361 | 0 | function ); |
15362 | |
|
15363 | 0 | return( -1 ); |
15364 | 0 | } |
15365 | 0 | #endif |
15366 | 0 | if( internal_handle->hash_values != NULL ) |
15367 | 0 | { |
15368 | 0 | result = libewf_value_table_get_utf8_value( |
15369 | 0 | internal_handle->hash_values, |
15370 | 0 | identifier, |
15371 | 0 | identifier_length, |
15372 | 0 | utf8_string, |
15373 | 0 | utf8_string_size, |
15374 | 0 | error ); |
15375 | |
|
15376 | 0 | if( result == -1 ) |
15377 | 0 | { |
15378 | 0 | libcerror_error_set( |
15379 | 0 | error, |
15380 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15381 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
15382 | 0 | "%s: unable to retrieve hash value.", |
15383 | 0 | function ); |
15384 | 0 | } |
15385 | 0 | } |
15386 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
15387 | 0 | if( libcthreads_read_write_lock_release_for_read( |
15388 | 0 | internal_handle->read_write_lock, |
15389 | 0 | error ) != 1 ) |
15390 | 0 | { |
15391 | 0 | libcerror_error_set( |
15392 | 0 | error, |
15393 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15394 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15395 | 0 | "%s: unable to release read/write lock for reading.", |
15396 | 0 | function ); |
15397 | |
|
15398 | 0 | return( -1 ); |
15399 | 0 | } |
15400 | 0 | #endif |
15401 | 0 | return( result ); |
15402 | 0 | } |
15403 | | |
15404 | | /* Sets the UTF-8 encoded hash value specified by the identifier |
15405 | | * Returns 1 if successful or -1 on error |
15406 | | */ |
15407 | | int libewf_handle_set_utf8_hash_value( |
15408 | | libewf_handle_t *handle, |
15409 | | const uint8_t *identifier, |
15410 | | size_t identifier_length, |
15411 | | const uint8_t *utf8_string, |
15412 | | size_t utf8_string_length, |
15413 | | libcerror_error_t **error ) |
15414 | 0 | { |
15415 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
15416 | 0 | static char *function = "libewf_handle_set_utf8_hash_value"; |
15417 | 0 | int result = 1; |
15418 | |
|
15419 | 0 | if( handle == NULL ) |
15420 | 0 | { |
15421 | 0 | libcerror_error_set( |
15422 | 0 | error, |
15423 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
15424 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
15425 | 0 | "%s: invalid handle.", |
15426 | 0 | function ); |
15427 | |
|
15428 | 0 | return( -1 ); |
15429 | 0 | } |
15430 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
15431 | |
|
15432 | 0 | if( internal_handle->io_handle == NULL ) |
15433 | 0 | { |
15434 | 0 | libcerror_error_set( |
15435 | 0 | error, |
15436 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15437 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
15438 | 0 | "%s: invalid handle - missing IO handle.", |
15439 | 0 | function ); |
15440 | |
|
15441 | 0 | return( -1 ); |
15442 | 0 | } |
15443 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
15444 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
15445 | 0 | internal_handle->read_write_lock, |
15446 | 0 | error ) != 1 ) |
15447 | 0 | { |
15448 | 0 | libcerror_error_set( |
15449 | 0 | error, |
15450 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15451 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15452 | 0 | "%s: unable to grab read/write lock for writing.", |
15453 | 0 | function ); |
15454 | |
|
15455 | 0 | return( -1 ); |
15456 | 0 | } |
15457 | 0 | #endif |
15458 | 0 | if( ( ( internal_handle->io_handle->access_flags & LIBEWF_ACCESS_FLAG_READ ) != 0 ) |
15459 | 0 | && ( ( internal_handle->io_handle->access_flags & LIBEWF_ACCESS_FLAG_RESUME ) == 0 ) ) |
15460 | 0 | { |
15461 | 0 | libcerror_error_set( |
15462 | 0 | error, |
15463 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15464 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15465 | 0 | "%s: hash value cannot be changed.", |
15466 | 0 | function ); |
15467 | |
|
15468 | 0 | result = -1; |
15469 | 0 | } |
15470 | 0 | else if( internal_handle->hash_values == NULL ) |
15471 | 0 | { |
15472 | 0 | if( libewf_hash_values_initialize( |
15473 | 0 | &( internal_handle->hash_values ), |
15474 | 0 | error ) != 1 ) |
15475 | 0 | { |
15476 | 0 | libcerror_error_set( |
15477 | 0 | error, |
15478 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15479 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
15480 | 0 | "%s: unable to create hash values.", |
15481 | 0 | function ); |
15482 | |
|
15483 | 0 | result = -1; |
15484 | 0 | } |
15485 | 0 | else |
15486 | 0 | { |
15487 | 0 | internal_handle->hash_values_parsed = 1; |
15488 | 0 | } |
15489 | 0 | } |
15490 | 0 | if( result == 1 ) |
15491 | 0 | { |
15492 | 0 | result = libewf_value_table_copy_value_from_utf8_string( |
15493 | 0 | internal_handle->hash_values, |
15494 | 0 | identifier, |
15495 | 0 | identifier_length, |
15496 | 0 | utf8_string, |
15497 | 0 | utf8_string_length, |
15498 | 0 | error ); |
15499 | |
|
15500 | 0 | if( result != 1 ) |
15501 | 0 | { |
15502 | 0 | libcerror_error_set( |
15503 | 0 | error, |
15504 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15505 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15506 | 0 | "%s: unable to set hash value.", |
15507 | 0 | function ); |
15508 | 0 | } |
15509 | 0 | else if( internal_handle->hash_sections != NULL ) |
15510 | 0 | { |
15511 | 0 | result = libewf_hash_sections_set_digest_from_hash_values( |
15512 | 0 | internal_handle->hash_sections, |
15513 | 0 | identifier, |
15514 | 0 | identifier_length, |
15515 | 0 | internal_handle->hash_values, |
15516 | 0 | error ); |
15517 | |
|
15518 | 0 | if( result != 1 ) |
15519 | 0 | { |
15520 | 0 | libcerror_error_set( |
15521 | 0 | error, |
15522 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15523 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15524 | 0 | "%s: unable to set digest in hash sections.", |
15525 | 0 | function ); |
15526 | 0 | } |
15527 | 0 | } |
15528 | 0 | } |
15529 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
15530 | 0 | if( libcthreads_read_write_lock_release_for_write( |
15531 | 0 | internal_handle->read_write_lock, |
15532 | 0 | error ) != 1 ) |
15533 | 0 | { |
15534 | 0 | libcerror_error_set( |
15535 | 0 | error, |
15536 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15537 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15538 | 0 | "%s: unable to release read/write lock for writing.", |
15539 | 0 | function ); |
15540 | |
|
15541 | 0 | return( -1 ); |
15542 | 0 | } |
15543 | 0 | #endif |
15544 | 0 | return( result ); |
15545 | 0 | } |
15546 | | |
15547 | | /* Retrieves the size of the UTF-16 encoded hash value of an identifier |
15548 | | * The string size includes the end of string character |
15549 | | * Returns 1 if successful, 0 if not set or -1 on error |
15550 | | */ |
15551 | | int libewf_handle_get_utf16_hash_value_size( |
15552 | | libewf_handle_t *handle, |
15553 | | const uint8_t *identifier, |
15554 | | size_t identifier_length, |
15555 | | size_t *utf16_string_size, |
15556 | | libcerror_error_t **error ) |
15557 | 0 | { |
15558 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
15559 | 0 | static char *function = "libewf_handle_get_utf16_hash_value_size"; |
15560 | 0 | int result = 0; |
15561 | |
|
15562 | 0 | if( handle == NULL ) |
15563 | 0 | { |
15564 | 0 | libcerror_error_set( |
15565 | 0 | error, |
15566 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
15567 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
15568 | 0 | "%s: invalid handle.", |
15569 | 0 | function ); |
15570 | |
|
15571 | 0 | return( -1 ); |
15572 | 0 | } |
15573 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
15574 | | |
15575 | | /* TODO add write lock */ |
15576 | 0 | if( internal_handle->hash_values_parsed == 0 ) |
15577 | 0 | { |
15578 | 0 | if( libewf_internal_handle_parse_hash_values( |
15579 | 0 | internal_handle, |
15580 | 0 | error ) != 1 ) |
15581 | 0 | { |
15582 | 0 | libcerror_error_set( |
15583 | 0 | error, |
15584 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15585 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15586 | 0 | "%s: unable to parse hash values.", |
15587 | 0 | function ); |
15588 | |
|
15589 | 0 | return( -1 ); |
15590 | 0 | } |
15591 | 0 | internal_handle->hash_values_parsed = 1; |
15592 | 0 | } |
15593 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
15594 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
15595 | 0 | internal_handle->read_write_lock, |
15596 | 0 | error ) != 1 ) |
15597 | 0 | { |
15598 | 0 | libcerror_error_set( |
15599 | 0 | error, |
15600 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15601 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15602 | 0 | "%s: unable to grab read/write lock for reading.", |
15603 | 0 | function ); |
15604 | |
|
15605 | 0 | return( -1 ); |
15606 | 0 | } |
15607 | 0 | #endif |
15608 | 0 | if( internal_handle->hash_values != NULL ) |
15609 | 0 | { |
15610 | 0 | result = libewf_value_table_get_utf16_value_size( |
15611 | 0 | internal_handle->hash_values, |
15612 | 0 | identifier, |
15613 | 0 | identifier_length, |
15614 | 0 | utf16_string_size, |
15615 | 0 | error ); |
15616 | |
|
15617 | 0 | if( result == -1 ) |
15618 | 0 | { |
15619 | 0 | libcerror_error_set( |
15620 | 0 | error, |
15621 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15622 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
15623 | 0 | "%s: unable to retrieve hash value size.", |
15624 | 0 | function ); |
15625 | 0 | } |
15626 | 0 | } |
15627 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
15628 | 0 | if( libcthreads_read_write_lock_release_for_read( |
15629 | 0 | internal_handle->read_write_lock, |
15630 | 0 | error ) != 1 ) |
15631 | 0 | { |
15632 | 0 | libcerror_error_set( |
15633 | 0 | error, |
15634 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15635 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15636 | 0 | "%s: unable to release read/write lock for reading.", |
15637 | 0 | function ); |
15638 | |
|
15639 | 0 | return( -1 ); |
15640 | 0 | } |
15641 | 0 | #endif |
15642 | 0 | return( result ); |
15643 | 0 | } |
15644 | | |
15645 | | /* Retrieves the UTF-16 encoded hash value of an identifier |
15646 | | * The string size should include the end of string character |
15647 | | * Returns 1 if successful, 0 if not set or -1 on error |
15648 | | */ |
15649 | | int libewf_handle_get_utf16_hash_value( |
15650 | | libewf_handle_t *handle, |
15651 | | const uint8_t *identifier, |
15652 | | size_t identifier_length, |
15653 | | uint16_t *utf16_string, |
15654 | | size_t utf16_string_size, |
15655 | | libcerror_error_t **error ) |
15656 | 0 | { |
15657 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
15658 | 0 | static char *function = "libewf_handle_get_utf16_hash_value"; |
15659 | 0 | int result = 0; |
15660 | |
|
15661 | 0 | if( handle == NULL ) |
15662 | 0 | { |
15663 | 0 | libcerror_error_set( |
15664 | 0 | error, |
15665 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
15666 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
15667 | 0 | "%s: invalid handle.", |
15668 | 0 | function ); |
15669 | |
|
15670 | 0 | return( -1 ); |
15671 | 0 | } |
15672 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
15673 | | |
15674 | | /* TODO add write lock */ |
15675 | 0 | if( internal_handle->hash_values_parsed == 0 ) |
15676 | 0 | { |
15677 | 0 | if( libewf_internal_handle_parse_hash_values( |
15678 | 0 | internal_handle, |
15679 | 0 | error ) != 1 ) |
15680 | 0 | { |
15681 | 0 | libcerror_error_set( |
15682 | 0 | error, |
15683 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15684 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15685 | 0 | "%s: unable to parse hash values.", |
15686 | 0 | function ); |
15687 | |
|
15688 | 0 | return( -1 ); |
15689 | 0 | } |
15690 | 0 | internal_handle->hash_values_parsed = 1; |
15691 | 0 | } |
15692 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
15693 | 0 | if( libcthreads_read_write_lock_grab_for_read( |
15694 | 0 | internal_handle->read_write_lock, |
15695 | 0 | error ) != 1 ) |
15696 | 0 | { |
15697 | 0 | libcerror_error_set( |
15698 | 0 | error, |
15699 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15700 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15701 | 0 | "%s: unable to grab read/write lock for reading.", |
15702 | 0 | function ); |
15703 | |
|
15704 | 0 | return( -1 ); |
15705 | 0 | } |
15706 | 0 | #endif |
15707 | 0 | if( internal_handle->hash_values != NULL ) |
15708 | 0 | { |
15709 | 0 | result = libewf_value_table_get_utf16_value( |
15710 | 0 | internal_handle->hash_values, |
15711 | 0 | identifier, |
15712 | 0 | identifier_length, |
15713 | 0 | utf16_string, |
15714 | 0 | utf16_string_size, |
15715 | 0 | error ); |
15716 | |
|
15717 | 0 | if( result == -1 ) |
15718 | 0 | { |
15719 | 0 | libcerror_error_set( |
15720 | 0 | error, |
15721 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15722 | 0 | LIBCERROR_RUNTIME_ERROR_GET_FAILED, |
15723 | 0 | "%s: unable to retrieve hash value.", |
15724 | 0 | function ); |
15725 | 0 | } |
15726 | 0 | } |
15727 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
15728 | 0 | if( libcthreads_read_write_lock_release_for_read( |
15729 | 0 | internal_handle->read_write_lock, |
15730 | 0 | error ) != 1 ) |
15731 | 0 | { |
15732 | 0 | libcerror_error_set( |
15733 | 0 | error, |
15734 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15735 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15736 | 0 | "%s: unable to release read/write lock for reading.", |
15737 | 0 | function ); |
15738 | |
|
15739 | 0 | return( -1 ); |
15740 | 0 | } |
15741 | 0 | #endif |
15742 | 0 | return( result ); |
15743 | 0 | } |
15744 | | |
15745 | | /* Sets the UTF-16 encoded hash value specified by the identifier |
15746 | | * Returns 1 if successful or -1 on error |
15747 | | */ |
15748 | | int libewf_handle_set_utf16_hash_value( |
15749 | | libewf_handle_t *handle, |
15750 | | const uint8_t *identifier, |
15751 | | size_t identifier_length, |
15752 | | const uint16_t *utf16_string, |
15753 | | size_t utf16_string_length, |
15754 | | libcerror_error_t **error ) |
15755 | 0 | { |
15756 | 0 | libewf_internal_handle_t *internal_handle = NULL; |
15757 | 0 | static char *function = "libewf_handle_set_utf16_hash_value"; |
15758 | 0 | int result = 1; |
15759 | |
|
15760 | 0 | if( handle == NULL ) |
15761 | 0 | { |
15762 | 0 | libcerror_error_set( |
15763 | 0 | error, |
15764 | 0 | LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
15765 | 0 | LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
15766 | 0 | "%s: invalid handle.", |
15767 | 0 | function ); |
15768 | |
|
15769 | 0 | return( -1 ); |
15770 | 0 | } |
15771 | 0 | internal_handle = (libewf_internal_handle_t *) handle; |
15772 | |
|
15773 | 0 | if( internal_handle->io_handle == NULL ) |
15774 | 0 | { |
15775 | 0 | libcerror_error_set( |
15776 | 0 | error, |
15777 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15778 | 0 | LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, |
15779 | 0 | "%s: invalid handle - missing IO handle.", |
15780 | 0 | function ); |
15781 | |
|
15782 | 0 | return( -1 ); |
15783 | 0 | } |
15784 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
15785 | 0 | if( libcthreads_read_write_lock_grab_for_write( |
15786 | 0 | internal_handle->read_write_lock, |
15787 | 0 | error ) != 1 ) |
15788 | 0 | { |
15789 | 0 | libcerror_error_set( |
15790 | 0 | error, |
15791 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15792 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15793 | 0 | "%s: unable to grab read/write lock for writing.", |
15794 | 0 | function ); |
15795 | |
|
15796 | 0 | return( -1 ); |
15797 | 0 | } |
15798 | 0 | #endif |
15799 | 0 | if( ( ( internal_handle->io_handle->access_flags & LIBEWF_ACCESS_FLAG_READ ) != 0 ) |
15800 | 0 | && ( ( internal_handle->io_handle->access_flags & LIBEWF_ACCESS_FLAG_RESUME ) == 0 ) ) |
15801 | 0 | { |
15802 | 0 | libcerror_error_set( |
15803 | 0 | error, |
15804 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15805 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15806 | 0 | "%s: hash value cannot be changed.", |
15807 | 0 | function ); |
15808 | |
|
15809 | 0 | result = -1; |
15810 | 0 | } |
15811 | 0 | else if( internal_handle->hash_values == NULL ) |
15812 | 0 | { |
15813 | 0 | if( libewf_hash_values_initialize( |
15814 | 0 | &( internal_handle->hash_values ), |
15815 | 0 | error ) != 1 ) |
15816 | 0 | { |
15817 | 0 | libcerror_error_set( |
15818 | 0 | error, |
15819 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15820 | 0 | LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, |
15821 | 0 | "%s: unable to create hash values.", |
15822 | 0 | function ); |
15823 | |
|
15824 | 0 | result = -1; |
15825 | 0 | } |
15826 | 0 | else |
15827 | 0 | { |
15828 | 0 | internal_handle->hash_values_parsed = 1; |
15829 | 0 | } |
15830 | 0 | } |
15831 | 0 | if( result == 1 ) |
15832 | 0 | { |
15833 | 0 | result = libewf_value_table_copy_value_from_utf16_string( |
15834 | 0 | internal_handle->hash_values, |
15835 | 0 | identifier, |
15836 | 0 | identifier_length, |
15837 | 0 | utf16_string, |
15838 | 0 | utf16_string_length, |
15839 | 0 | error ); |
15840 | |
|
15841 | 0 | if( result != 1 ) |
15842 | 0 | { |
15843 | 0 | libcerror_error_set( |
15844 | 0 | error, |
15845 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15846 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15847 | 0 | "%s: unable to set hash value.", |
15848 | 0 | function ); |
15849 | 0 | } |
15850 | 0 | else if( internal_handle->hash_sections != NULL ) |
15851 | 0 | { |
15852 | 0 | result = libewf_hash_sections_set_digest_from_hash_values( |
15853 | 0 | internal_handle->hash_sections, |
15854 | 0 | identifier, |
15855 | 0 | identifier_length, |
15856 | 0 | internal_handle->hash_values, |
15857 | 0 | error ); |
15858 | |
|
15859 | 0 | if( result != 1 ) |
15860 | 0 | { |
15861 | 0 | libcerror_error_set( |
15862 | 0 | error, |
15863 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15864 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15865 | 0 | "%s: unable to set digest in hash sections.", |
15866 | 0 | function ); |
15867 | 0 | } |
15868 | 0 | } |
15869 | 0 | } |
15870 | 0 | #if defined( HAVE_LIBEWF_MULTI_THREAD_SUPPORT ) |
15871 | 0 | if( libcthreads_read_write_lock_release_for_write( |
15872 | 0 | internal_handle->read_write_lock, |
15873 | 0 | error ) != 1 ) |
15874 | 0 | { |
15875 | 0 | libcerror_error_set( |
15876 | 0 | error, |
15877 | 0 | LIBCERROR_ERROR_DOMAIN_RUNTIME, |
15878 | 0 | LIBCERROR_RUNTIME_ERROR_SET_FAILED, |
15879 | 0 | "%s: unable to release read/write lock for writing.", |
15880 | 0 | function ); |
15881 | |
|
15882 | 0 | return( -1 ); |
15883 | 0 | } |
15884 | 0 | #endif |
15885 | 0 | return( result ); |
15886 | 0 | } |
15887 | | |