1 /*
2 * Legacy functions
3 *
4 * Copyright (c) 2006-2014, 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
27 #include "libewf_definitions.h"
28 #include "libewf_file_entry.h"
29 #include "libewf_handle.h"
30 #include "libewf_libcerror.h"
31 #include "libewf_libcnotify.h"
32 #include "libewf_metadata.h"
33 #include "libewf_notify.h"
34 #include "libewf_types.h"
35
36 #if !defined( HAVE_LOCAL_LIBEWF )
37
38 /* Returns the flags for reading
39 */
libewf_get_flags_read(void)40 uint8_t libewf_get_flags_read(
41 void )
42 {
43 return( (uint8_t) LIBEWF_ACCESS_FLAG_READ );
44 }
45
46 /* Returns the flags for reading and writing
47 */
libewf_get_flags_read_write(void)48 uint8_t libewf_get_flags_read_write(
49 void )
50 {
51 return( (uint8_t) ( LIBEWF_ACCESS_FLAG_READ | LIBEWF_ACCESS_FLAG_WRITE ) );
52 }
53
54 /* Returns the flags for writing
55 */
libewf_get_flags_write(void)56 uint8_t libewf_get_flags_write(
57 void )
58 {
59 return( (uint8_t) LIBEWF_ACCESS_FLAG_WRITE );
60 }
61
62 /* Returns the flags for resume writing
63 */
libewf_get_flags_write_resume(void)64 uint8_t libewf_get_flags_write_resume(
65 void )
66 {
67 return( (uint8_t) LIBEWF_ACCESS_FLAG_WRITE | LIBEWF_ACCESS_FLAG_RESUME );
68 }
69
70 /* Sets the maximum amount of (concurrent) open file handles
71 * Returns 1 if successful or -1 on error
72 */
libewf_handle_set_maximum_amount_of_open_handles(libewf_handle_t * handle,int maximum_amount_of_open_handles,libcerror_error_t ** error)73 int libewf_handle_set_maximum_amount_of_open_handles(
74 libewf_handle_t *handle,
75 int maximum_amount_of_open_handles,
76 libcerror_error_t **error )
77 {
78 return( libewf_handle_set_maximum_number_of_open_handles(
79 handle,
80 maximum_amount_of_open_handles,
81 error ) );
82 }
83
84 /* Retrieves the segment file size
85 * Returns 1 if successful or -1 on error
86 */
libewf_handle_get_segment_file_size(libewf_handle_t * handle,size64_t * segment_file_size,libcerror_error_t ** error)87 int libewf_handle_get_segment_file_size(
88 libewf_handle_t *handle,
89 size64_t *segment_file_size,
90 libcerror_error_t **error )
91 {
92 return( libewf_handle_get_maximum_segment_size(
93 handle,
94 segment_file_size,
95 error ) );
96 }
97
98 /* Sets the segment file size
99 * Returns 1 if successful or -1 on error
100 */
libewf_handle_set_segment_file_size(libewf_handle_t * handle,size64_t segment_file_size,libcerror_error_t ** error)101 int libewf_handle_set_segment_file_size(
102 libewf_handle_t *handle,
103 size64_t segment_file_size,
104 libcerror_error_t **error )
105 {
106 return( libewf_handle_set_maximum_segment_size(
107 handle,
108 segment_file_size,
109 error ) );
110 }
111
112 /* Retrieves the delta segment file size
113 * Returns 1 if successful or -1 on error
114 */
libewf_handle_get_delta_segment_file_size(libewf_handle_t * handle,size64_t * delta_segment_file_size,libcerror_error_t ** error)115 int libewf_handle_get_delta_segment_file_size(
116 libewf_handle_t *handle,
117 size64_t *delta_segment_file_size,
118 libcerror_error_t **error )
119 {
120 return( libewf_handle_get_maximum_delta_segment_size(
121 handle,
122 delta_segment_file_size,
123 error ) );
124 }
125
126 /* Sets the delta segment file size
127 * Returns 1 if successful or -1 on error
128 */
libewf_handle_set_delta_segment_file_size(libewf_handle_t * handle,size64_t delta_segment_file_size,libcerror_error_t ** error)129 int libewf_handle_set_delta_segment_file_size(
130 libewf_handle_t *handle,
131 size64_t delta_segment_file_size,
132 libcerror_error_t **error )
133 {
134 return( libewf_handle_set_maximum_delta_segment_size(
135 handle,
136 delta_segment_file_size,
137 error ) );
138 }
139
140 /* Retrieves the amount of sectors
141 * Returns 1 if successful or -1 on error
142 */
libewf_handle_get_amount_of_sectors(libewf_handle_t * handle,uint64_t * amount_of_sectors,libcerror_error_t ** error)143 int libewf_handle_get_amount_of_sectors(
144 libewf_handle_t *handle,
145 uint64_t *amount_of_sectors,
146 libcerror_error_t **error )
147 {
148 return( libewf_handle_get_number_of_sectors(
149 handle,
150 amount_of_sectors,
151 error ) );
152 }
153
154 /* Retrieves the amount of chunks written
155 * Returns 1 if successful or -1 on error
156 */
libewf_handle_get_write_amount_of_chunks(libewf_handle_t * handle,uint32_t * amount_of_chunks,libcerror_error_t ** error)157 int libewf_handle_get_write_amount_of_chunks(
158 libewf_handle_t *handle,
159 uint32_t *amount_of_chunks,
160 libcerror_error_t **error )
161 {
162 return( libewf_handle_get_number_of_chunks_written(
163 handle,
164 amount_of_chunks,
165 error ) );
166 }
167
168 /* Sets the read wipe chunk on error
169 * The chunk is not wiped if read raw is used
170 * Returns 1 if successful or -1 on error
171 */
libewf_handle_set_read_wipe_chunk_on_error(libewf_handle_t * handle,uint8_t wipe_on_error,libcerror_error_t ** error)172 int libewf_handle_set_read_wipe_chunk_on_error(
173 libewf_handle_t *handle,
174 uint8_t wipe_on_error,
175 libcerror_error_t **error )
176 {
177 return( libewf_handle_set_read_zero_chunk_on_error(
178 handle,
179 wipe_on_error,
180 error ) );
181 }
182
183 /* Retrieves the amount of acquiry errors
184 * Returns 1 if successful or -1 on error
185 */
libewf_handle_get_amount_of_acquiry_errors(libewf_handle_t * handle,uint32_t * amount_of_errors,libcerror_error_t ** error)186 int libewf_handle_get_amount_of_acquiry_errors(
187 libewf_handle_t *handle,
188 uint32_t *amount_of_errors,
189 libcerror_error_t **error )
190 {
191 return( libewf_handle_get_number_of_acquiry_errors(
192 handle,
193 amount_of_errors,
194 error ) );
195 }
196
197 /* Add an acquiry error
198 * Returns 1 if successful or -1 on error
199 */
libewf_handle_add_acquiry_error(libewf_handle_t * handle,uint64_t start_sector,uint64_t number_of_sectors,libcerror_error_t ** error)200 int libewf_handle_add_acquiry_error(
201 libewf_handle_t *handle,
202 uint64_t start_sector,
203 uint64_t number_of_sectors,
204 libcerror_error_t **error )
205 {
206 return( libewf_handle_append_acquiry_error(
207 handle,
208 start_sector,
209 number_of_sectors,
210 error ) );
211 }
212
213 /* Retrieves the number of CRC errors
214 * Returns 1 if successful or -1 on error
215 */
libewf_handle_get_number_of_crc_errors(libewf_handle_t * handle,uint32_t * number_of_errors,libcerror_error_t ** error)216 int libewf_handle_get_number_of_crc_errors(
217 libewf_handle_t *handle,
218 uint32_t *number_of_errors,
219 libcerror_error_t **error )
220 {
221 return( libewf_handle_get_number_of_checksum_errors(
222 handle,
223 number_of_errors,
224 error ) );
225 }
226
227 /* Retrieves the amount of CRC errors
228 * Returns 1 if successful or -1 on error
229 */
libewf_handle_get_amount_of_crc_errors(libewf_handle_t * handle,uint32_t * amount_of_errors,libcerror_error_t ** error)230 int libewf_handle_get_amount_of_crc_errors(
231 libewf_handle_t *handle,
232 uint32_t *amount_of_errors,
233 libcerror_error_t **error )
234 {
235 return( libewf_handle_get_number_of_checksum_errors(
236 handle,
237 amount_of_errors,
238 error ) );
239 }
240
241 /* Retrieves a CRC error
242 * Returns 1 if successful or -1 on error
243 */
libewf_handle_get_crc_error(libewf_handle_t * handle,uint32_t index,uint64_t * start_sector,uint64_t * number_of_sectors,libcerror_error_t ** error)244 int libewf_handle_get_crc_error(
245 libewf_handle_t *handle,
246 uint32_t index,
247 uint64_t *start_sector,
248 uint64_t *number_of_sectors,
249 libcerror_error_t **error )
250 {
251 return( libewf_handle_get_checksum_error(
252 handle,
253 index,
254 start_sector,
255 number_of_sectors,
256 error ) );
257 }
258
259 /* Add a CRC error
260 * Returns 1 if successful or -1 on error
261 */
libewf_handle_add_crc_error(libewf_handle_t * handle,uint64_t start_sector,uint64_t number_of_sectors,libcerror_error_t ** error)262 int libewf_handle_add_crc_error(
263 libewf_handle_t *handle,
264 uint64_t start_sector,
265 uint64_t number_of_sectors,
266 libcerror_error_t **error )
267 {
268 return( libewf_handle_append_checksum_error(
269 handle,
270 start_sector,
271 number_of_sectors,
272 error ) );
273 }
274
275 /* Retrieves the amount of sessions
276 * Returns 1 if successful or -1 on error
277 */
libewf_handle_get_amount_of_sessions(libewf_handle_t * handle,uint32_t * amount_of_sessions,libcerror_error_t ** error)278 int libewf_handle_get_amount_of_sessions(
279 libewf_handle_t *handle,
280 uint32_t *amount_of_sessions,
281 libcerror_error_t **error )
282 {
283 return( libewf_handle_get_number_of_sessions(
284 handle,
285 amount_of_sessions,
286 error ) );
287 }
288
289 /* Add a session
290 * Returns 1 if successful or -1 on error
291 */
libewf_handle_add_session(libewf_handle_t * handle,uint64_t start_sector,uint64_t number_of_sectors,libcerror_error_t ** error)292 int libewf_handle_add_session(
293 libewf_handle_t *handle,
294 uint64_t start_sector,
295 uint64_t number_of_sectors,
296 libcerror_error_t **error )
297 {
298 return( libewf_handle_append_session(
299 handle,
300 start_sector,
301 number_of_sectors,
302 error ) );
303 }
304
305 /* Retrieves the amount of header values
306 * Returns 1 if successful, 0 if no header values are present or -1 on error
307 */
libewf_handle_get_amount_of_header_values(libewf_handle_t * handle,uint32_t * amount_of_values,libcerror_error_t ** error)308 int libewf_handle_get_amount_of_header_values(
309 libewf_handle_t *handle,
310 uint32_t *amount_of_values,
311 libcerror_error_t **error )
312 {
313 return( libewf_handle_get_number_of_header_values(
314 handle,
315 amount_of_values,
316 error ) );
317 }
318
319 /* Retrieves the size of the UTF-8 encoded header value of an identifier
320 * The value size includes the end of string character
321 * Returns 1 if successful, 0 if value not present or -1 on error
322 */
libewf_handle_get_header_value_size(libewf_handle_t * handle,const uint8_t * identifier,size_t identifier_length,size_t * value_size,libcerror_error_t ** error)323 int libewf_handle_get_header_value_size(
324 libewf_handle_t *handle,
325 const uint8_t *identifier,
326 size_t identifier_length,
327 size_t *value_size,
328 libcerror_error_t **error )
329 {
330 return( libewf_handle_get_utf8_header_value_size(
331 handle,
332 identifier,
333 identifier_length,
334 value_size,
335 error ) );
336 }
337
338 /* Retrieves the UTF-8 encoded header value of an identifier
339 * The value size should include the end of string character
340 * Returns 1 if successful, 0 if value not present or -1 on error
341 */
libewf_handle_get_header_value(libewf_handle_t * handle,const uint8_t * identifier,size_t identifier_length,uint8_t * value,size_t value_size,libcerror_error_t ** error)342 int libewf_handle_get_header_value(
343 libewf_handle_t *handle,
344 const uint8_t *identifier,
345 size_t identifier_length,
346 uint8_t *value,
347 size_t value_size,
348 libcerror_error_t **error )
349 {
350 return( libewf_handle_get_utf8_header_value(
351 handle,
352 identifier,
353 identifier_length,
354 value,
355 value_size,
356 error ) );
357 }
358
359 /* Sets the UTF-8 encoded header value specified by the identifier
360 * Returns 1 if successful or -1 on error
361 */
libewf_handle_set_header_value(libewf_handle_t * handle,const uint8_t * identifier,size_t identifier_length,const uint8_t * value,size_t value_length,libcerror_error_t ** error)362 int libewf_handle_set_header_value(
363 libewf_handle_t *handle,
364 const uint8_t *identifier,
365 size_t identifier_length,
366 const uint8_t *value,
367 size_t value_length,
368 libcerror_error_t **error )
369 {
370 return( libewf_handle_set_utf8_header_value(
371 handle,
372 identifier,
373 identifier_length,
374 value,
375 value_length,
376 error ) );
377 }
378
379 /* Retrieves the amount of hash values
380 * Returns 1 if successful, 0 if no hash values are present or -1 on error
381 */
libewf_handle_get_amount_of_hash_values(libewf_handle_t * handle,uint32_t * amount_of_values,libcerror_error_t ** error)382 int libewf_handle_get_amount_of_hash_values(
383 libewf_handle_t *handle,
384 uint32_t *amount_of_values,
385 libcerror_error_t **error )
386 {
387 return( libewf_handle_get_number_of_hash_values(
388 handle,
389 amount_of_values,
390 error ) );
391 }
392
393 /* Retrieves the size of the UTF-8 encoded hash value of an identifier
394 * The value size includes the end of string character
395 * Returns 1 if successful, 0 if value not present or -1 on error
396 */
libewf_handle_get_hash_value_size(libewf_handle_t * handle,const uint8_t * identifier,size_t identifier_length,size_t * value_size,libcerror_error_t ** error)397 int libewf_handle_get_hash_value_size(
398 libewf_handle_t *handle,
399 const uint8_t *identifier,
400 size_t identifier_length,
401 size_t *value_size,
402 libcerror_error_t **error )
403 {
404 return( libewf_handle_get_utf8_hash_value_size(
405 handle,
406 identifier,
407 identifier_length,
408 value_size,
409 error ) );
410 }
411
412 /* Retrieves the UTF-8 encoded hash value of an identifier
413 * The value size should include the end of string character
414 * Returns 1 if successful, 0 if value not present or -1 on error
415 */
libewf_handle_get_hash_value(libewf_handle_t * handle,const uint8_t * identifier,size_t identifier_length,uint8_t * value,size_t value_size,libcerror_error_t ** error)416 int libewf_handle_get_hash_value(
417 libewf_handle_t *handle,
418 const uint8_t *identifier,
419 size_t identifier_length,
420 uint8_t *value,
421 size_t value_size,
422 libcerror_error_t **error )
423 {
424 return( libewf_handle_get_utf8_hash_value(
425 handle,
426 identifier,
427 identifier_length,
428 value,
429 value_size,
430 error ) );
431 }
432
433 /* Sets the UTF-8 encoded hash value specified by the identifier
434 * Returns 1 if successful or -1 on error
435 */
libewf_handle_set_hash_value(libewf_handle_t * handle,const uint8_t * identifier,size_t identifier_length,const uint8_t * value,size_t value_length,libcerror_error_t ** error)436 int libewf_handle_set_hash_value(
437 libewf_handle_t *handle,
438 const uint8_t *identifier,
439 size_t identifier_length,
440 const uint8_t *value,
441 size_t value_length,
442 libcerror_error_t **error )
443 {
444 return( libewf_handle_set_utf8_hash_value(
445 handle,
446 identifier,
447 identifier_length,
448 value,
449 value_length,
450 error ) );
451 }
452
453 /* Retrieves the amount of sub file entries
454 * Returns 1 if successful or -1 on error
455 */
libewf_file_entry_get_amount_of_sub_file_entries(libewf_file_entry_t * file_entry,int * amount_of_sub_file_entries,libcerror_error_t ** error)456 int libewf_file_entry_get_amount_of_sub_file_entries(
457 libewf_file_entry_t *file_entry,
458 int *amount_of_sub_file_entries,
459 libcerror_error_t **error )
460 {
461 return( libewf_file_entry_get_number_of_sub_file_entries(
462 file_entry,
463 amount_of_sub_file_entries,
464 error ) );
465 }
466
467 /* Retrieves the size of the UTF-8 encoded name from the referenced file entry
468 * The returned size includes the end of string character
469 * Returns 1 if successful or -1 on error
470 */
libewf_file_entry_get_name_size(libewf_file_entry_t * file_entry,size_t * name_size,libcerror_error_t ** error)471 int libewf_file_entry_get_name_size(
472 libewf_file_entry_t *file_entry,
473 size_t *name_size,
474 libcerror_error_t **error )
475 {
476 return( libewf_file_entry_get_utf8_name_size(
477 file_entry,
478 name_size,
479 error ) );
480 }
481
482 /* Retrieves the UTF-8 encoded name value from the referenced file entry
483 * The size should include the end of string character
484 * Returns 1 if successful or -1 on error
485 */
libewf_file_entry_get_name(libewf_file_entry_t * file_entry,uint8_t * name,size_t name_size,libcerror_error_t ** error)486 int libewf_file_entry_get_name(
487 libewf_file_entry_t *file_entry,
488 uint8_t *name,
489 size_t name_size,
490 libcerror_error_t **error )
491 {
492 return( libewf_file_entry_get_utf8_name(
493 file_entry,
494 name,
495 name_size,
496 error ) );
497 }
498
499 #endif
500
501 #if defined( HAVE_V1_API )
502
503 #if !defined( HAVE_LOCAL_LIBEWF )
504
505 /* Sets the notify values
506 */
libewf_set_notify_values(FILE * stream,int verbose)507 void libewf_set_notify_values(
508 FILE *stream,
509 int verbose )
510 {
511 libcerror_error_t *error = NULL;
512 static char *function = "libewf_set_notify_values";
513
514 if( libewf_notify_set_stream(
515 stream,
516 &error ) != 1 )
517 {
518 libcerror_error_set(
519 &error,
520 LIBCERROR_ERROR_DOMAIN_RUNTIME,
521 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
522 "%s: unable to set notify stream.",
523 function );
524
525 libcnotify_print_error_backtrace(
526 error );
527 libcerror_error_free(
528 &error );
529 }
530 libewf_notify_set_verbose(
531 verbose );
532 }
533
534 #endif
535
536 /* Signals the libewf handle to abort its current activity
537 * Returns 1 if successful or -1 on error
538 */
libewf_signal_abort(libewf_handle_t * handle)539 int libewf_signal_abort(
540 libewf_handle_t *handle )
541 {
542 libcerror_error_t *error = NULL;
543 static char *function = "libewf_signal_abort";
544
545 if( libewf_handle_signal_abort(
546 handle,
547 &error ) != 1 )
548 {
549 libcerror_error_set(
550 &error,
551 LIBCERROR_ERROR_DOMAIN_RUNTIME,
552 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
553 "%s: unable to signal abort.",
554 function );
555
556 libcnotify_print_error_backtrace(
557 error );
558 libcerror_error_free(
559 &error );
560
561 return( -1 );
562 }
563 return( 1 );
564 }
565
566 /* Opens a set of EWF file(s)
567 * For reading files should contain all filenames that make up an EWF image
568 * For writing files should contain the base of the filename, extentions like .e01 will be automatically added
569 * Returns a pointer to the new instance of handle, NULL on error
570 */
libewf_open(char * const filenames[],int amount_of_files,uint8_t flags)571 libewf_handle_t *libewf_open(
572 char * const filenames[],
573 int amount_of_files,
574 uint8_t flags )
575 {
576 libcerror_error_t *error = NULL;
577 libewf_handle_t *handle = NULL;
578 static char *function = "libewf_open";
579
580 if( libewf_handle_initialize(
581 &handle,
582 &error ) != 1 )
583 {
584 libcerror_error_set(
585 &error,
586 LIBCERROR_ERROR_DOMAIN_RUNTIME,
587 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
588 "%s: unable to create handle.",
589 function );
590
591 libcnotify_print_error_backtrace(
592 error );
593 libcerror_error_free(
594 &error );
595
596 return( NULL );
597 }
598 if( libewf_handle_open(
599 handle,
600 filenames,
601 amount_of_files,
602 flags,
603 &error ) != 1 )
604 {
605 libcerror_error_set(
606 &error,
607 LIBCERROR_ERROR_DOMAIN_RUNTIME,
608 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
609 "%s: unable to create handle.",
610 function );
611
612 libcnotify_print_error_backtrace(
613 error );
614 libcerror_error_free(
615 &error );
616
617 libewf_handle_free(
618 &handle,
619 NULL );
620
621 return( NULL );
622 }
623 return( handle );
624 }
625
626 #if defined( HAVE_WIDE_CHARACTER_TYPE )
627
628 /* Opens a set of EWF file(s)
629 * For reading files should contain all filenames that make up an EWF image
630 * For writing files should contain the base of the filename, extentions like .e01 will be automatically added
631 * Returns a pointer to the new instance of handle, NULL on error
632 */
libewf_open_wide(wchar_t * const filenames[],int amount_of_files,uint8_t flags)633 libewf_handle_t *libewf_open_wide(
634 wchar_t * const filenames[],
635 int amount_of_files,
636 uint8_t flags )
637 {
638 libcerror_error_t *error = NULL;
639 libewf_handle_t *handle = NULL;
640 static char *function = "libewf_open_wide";
641
642 if( libewf_handle_initialize(
643 &handle,
644 &error ) != 1 )
645 {
646 libcerror_error_set(
647 &error,
648 LIBCERROR_ERROR_DOMAIN_RUNTIME,
649 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
650 "%s: unable to create handle.",
651 function );
652
653 libcnotify_print_error_backtrace(
654 error );
655 libcerror_error_free(
656 &error );
657
658 return( NULL );
659 }
660 if( libewf_handle_open_wide(
661 handle,
662 filenames,
663 amount_of_files,
664 flags,
665 &error ) != 1 )
666 {
667 libcerror_error_set(
668 &error,
669 LIBCERROR_ERROR_DOMAIN_RUNTIME,
670 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
671 "%s: unable to create handle.",
672 function );
673
674 libcnotify_print_error_backtrace(
675 error );
676 libcerror_error_free(
677 &error );
678
679 return( NULL );
680 }
681 return( handle );
682 }
683 #endif
684
685 /* Closes the EWF handle and frees memory used within the handle
686 * Returns 0 if successful or -1 on error
687 */
libewf_close(libewf_handle_t * handle)688 int libewf_close(
689 libewf_handle_t *handle )
690 {
691 libcerror_error_t *error = NULL;
692 static char *function = "libewf_close";
693
694 if( libewf_handle_close(
695 handle,
696 &error ) != 0 )
697 {
698 libcerror_error_set(
699 &error,
700 LIBCERROR_ERROR_DOMAIN_RUNTIME,
701 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
702 "%s: unable to close handle.",
703 function );
704
705 libcnotify_print_error_backtrace(
706 error );
707 libcerror_error_free(
708 &error );
709
710 return( -1 );
711 }
712 if( libewf_handle_free(
713 &handle,
714 &error ) != 1 )
715 {
716 libcerror_error_set(
717 &error,
718 LIBCERROR_ERROR_DOMAIN_RUNTIME,
719 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
720 "%s: unable to free handle.",
721 function );
722
723 libcnotify_print_error_backtrace(
724 error );
725 libcerror_error_free(
726 &error );
727
728 return( -1 );
729 }
730 return( 0 );
731 }
732
733 /* Seeks a certain offset of the media data within the EWF file(s)
734 * It will set the related file offset to the specific chunk offset
735 * Returns the offset if seek is successful or -1 on error
736 */
libewf_seek_offset(libewf_handle_t * handle,off64_t offset)737 off64_t libewf_seek_offset(
738 libewf_handle_t *handle,
739 off64_t offset )
740 {
741 libcerror_error_t *error = NULL;
742 static char *function = "libewf_seek_offset";
743
744 offset = libewf_handle_seek_offset(
745 handle,
746 offset,
747 SEEK_SET,
748 &error );
749
750 if( offset == -1 )
751 {
752 libcerror_error_set(
753 &error,
754 LIBCERROR_ERROR_DOMAIN_IO,
755 LIBCERROR_IO_ERROR_SEEK_FAILED,
756 "%s: unable to seek offset.",
757 function );
758
759 libcnotify_print_error_backtrace(
760 error );
761 libcerror_error_free(
762 &error );
763
764 return( -1 );
765 }
766 return( offset );
767 }
768
769 /* Retrieves the current offset of the media data within the EWF file(s)
770 * Returns the offset if successful or -1 on error
771 */
libewf_get_offset(libewf_handle_t * handle)772 off64_t libewf_get_offset(
773 libewf_handle_t *handle )
774 {
775 libcerror_error_t *error = NULL;
776 static char *function = "libewf_get_offset";
777 off64_t offset = 0;
778
779 if( libewf_handle_get_offset(
780 handle,
781 &offset,
782 &error ) != 1 )
783 {
784 libcerror_error_set(
785 &error,
786 LIBCERROR_ERROR_DOMAIN_RUNTIME,
787 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
788 "%s: unable to retrieve offset.",
789 function );
790
791 libcnotify_print_error_backtrace(
792 error );
793 libcerror_error_free(
794 &error );
795
796 return( -1 );
797 }
798 return( offset );
799 }
800
801 /* Prepares a buffer with chunk data after reading it according to the handle settings
802 * intended for raw read
803 * The buffer size cannot be larger than the chunk size
804 * Returns the resulting chunk size or -1 on error
805 */
libewf_raw_read_prepare_buffer(libewf_handle_t * handle,void * buffer,size_t buffer_size,void * uncompressed_buffer,size_t * uncompressed_buffer_size,int8_t is_compressed,uint32_t chunk_checksum,int8_t read_checksum)806 ssize_t libewf_raw_read_prepare_buffer(
807 libewf_handle_t *handle,
808 void *buffer,
809 size_t buffer_size,
810 void *uncompressed_buffer,
811 size_t *uncompressed_buffer_size,
812 int8_t is_compressed,
813 uint32_t chunk_checksum,
814 int8_t read_checksum )
815 {
816 libcerror_error_t *error = NULL;
817 static char *function = "libewf_raw_read_prepare_buffer";
818 ssize_t chunk_data_size = 0;
819
820 chunk_data_size = libewf_handle_prepare_read_chunk(
821 handle,
822 buffer,
823 buffer_size,
824 uncompressed_buffer,
825 uncompressed_buffer_size,
826 is_compressed,
827 chunk_checksum,
828 read_checksum,
829 &error );
830
831 if( chunk_data_size == -1 )
832 {
833 libcerror_error_set(
834 &error,
835 LIBCERROR_ERROR_DOMAIN_IO,
836 LIBCERROR_IO_ERROR_READ_FAILED,
837 "%s: unable to raw read prepare buffer.",
838 function );
839
840 libcnotify_print_error_backtrace(
841 error );
842 libcerror_error_free(
843 &error );
844
845 return( -1 );
846 }
847 return( chunk_data_size );
848 }
849
850 /* Reads 'raw' data from the current offset into a buffer
851 * size contains the size of the buffer
852 * The function sets the chunk checksum, is compressed and read checksum values
853 * Returns the amount of bytes read or -1 on error
854 */
libewf_raw_read_buffer(libewf_handle_t * handle,void * buffer,size_t buffer_size,int8_t * is_compressed,uint32_t * chunk_checksum,int8_t * read_checksum)855 ssize_t libewf_raw_read_buffer(
856 libewf_handle_t *handle,
857 void *buffer,
858 size_t buffer_size,
859 int8_t *is_compressed,
860 uint32_t *chunk_checksum,
861 int8_t *read_checksum )
862 {
863 uint8_t checksum_buffer[ 4 ];
864
865 libcerror_error_t *error = NULL;
866 static char *function = "libewf_raw_read_buffer";
867 ssize_t read_count = 0;
868
869 read_count = libewf_handle_read_chunk(
870 handle,
871 buffer,
872 buffer_size,
873 is_compressed,
874 checksum_buffer,
875 chunk_checksum,
876 read_checksum,
877 &error );
878
879 if( read_count == -1 )
880 {
881 libcerror_error_set(
882 &error,
883 LIBCERROR_ERROR_DOMAIN_IO,
884 LIBCERROR_IO_ERROR_READ_FAILED,
885 "%s: unable to raw read buffer.",
886 function );
887
888 libcnotify_print_error_backtrace(
889 error );
890 libcerror_error_free(
891 &error );
892
893 return( -1 );
894 }
895 return( read_count );
896 }
897
898 /* Reads media data from the last current into a buffer
899 * Returns the amount of bytes read or -1 on error
900 */
libewf_read_buffer(libewf_handle_t * handle,void * buffer,size_t buffer_size)901 ssize_t libewf_read_buffer(
902 libewf_handle_t *handle,
903 void *buffer,
904 size_t buffer_size )
905 {
906 libcerror_error_t *error = NULL;
907 static char *function = "libewf_read_buffer";
908 ssize_t read_count = 0;
909
910 read_count = libewf_handle_read_buffer(
911 handle,
912 buffer,
913 buffer_size,
914 &error );
915
916 if( read_count == -1 )
917 {
918 libcerror_error_set(
919 &error,
920 LIBCERROR_ERROR_DOMAIN_IO,
921 LIBCERROR_IO_ERROR_READ_FAILED,
922 "%s: unable to read buffer.",
923 function );
924
925 libcnotify_print_error_backtrace(
926 error );
927 libcerror_error_free(
928 &error );
929
930 return( -1 );
931 }
932 return( read_count );
933 }
934
935 /* Reads media data at a specific offset
936 * Returns the amount of bytes read or -1 on error
937 */
libewf_read_random(libewf_handle_t * handle,void * buffer,size_t buffer_size,off64_t offset)938 ssize_t libewf_read_random(
939 libewf_handle_t *handle,
940 void *buffer,
941 size_t buffer_size,
942 off64_t offset )
943 {
944 libcerror_error_t *error = NULL;
945 static char *function = "libewf_read_random";
946 ssize_t read_count = 0;
947
948 read_count = libewf_handle_read_random(
949 handle,
950 buffer,
951 buffer_size,
952 offset,
953 &error );
954
955 if( read_count == -1 )
956 {
957 libcerror_error_set(
958 &error,
959 LIBCERROR_ERROR_DOMAIN_IO,
960 LIBCERROR_IO_ERROR_READ_FAILED,
961 "%s: unable to read random.",
962 function );
963
964 libcnotify_print_error_backtrace(
965 error );
966 libcerror_error_free(
967 &error );
968
969 return( -1 );
970 }
971 return( read_count );
972 }
973
974 /* Prepares a buffer with chunk data before writing according to the handle settings
975 * intended for raw write
976 * The buffer size cannot be larger than the chunk size
977 * The function sets the chunk checksum, is compressed and write checksum values
978 * Returns the resulting chunk size or -1 on error
979 */
libewf_raw_write_prepare_buffer(libewf_handle_t * handle,void * buffer,size_t buffer_size,void * compressed_buffer,size_t * compressed_buffer_size,int8_t * is_compressed,uint32_t * chunk_checksum,int8_t * write_checksum)980 ssize_t libewf_raw_write_prepare_buffer(
981 libewf_handle_t *handle,
982 void *buffer,
983 size_t buffer_size,
984 void *compressed_buffer,
985 size_t *compressed_buffer_size,
986 int8_t *is_compressed,
987 uint32_t *chunk_checksum,
988 int8_t *write_checksum )
989 {
990 libcerror_error_t *error = NULL;
991 static char *function = "libewf_raw_write_prepare_buffer";
992 ssize_t chunk_data_size = 0;
993
994 chunk_data_size = libewf_handle_prepare_write_chunk(
995 handle,
996 buffer,
997 buffer_size,
998 compressed_buffer,
999 compressed_buffer_size,
1000 is_compressed,
1001 chunk_checksum,
1002 write_checksum,
1003 &error );
1004
1005 if( chunk_data_size == -1 )
1006 {
1007 libcerror_error_set(
1008 &error,
1009 LIBCERROR_ERROR_DOMAIN_IO,
1010 LIBCERROR_IO_ERROR_READ_FAILED,
1011 "%s: unable to raw write prepare buffer.",
1012 function );
1013
1014 libcnotify_print_error_backtrace(
1015 error );
1016 libcerror_error_free(
1017 &error );
1018
1019 return( -1 );
1020 }
1021 return( chunk_data_size );
1022 }
1023
1024 /* Writes 'raw' data in EWF format the current offset
1025 * the necessary settings of the write values must have been made
1026 * size contains the size of the data within the buffer while
1027 * data size contains the size of the actual input data
1028 * Will initialize write if necessary
1029 * Returns the amount of input bytes written, 0 when no longer bytes can be written or -1 on error
1030 */
libewf_raw_write_buffer(libewf_handle_t * handle,void * buffer,size_t buffer_size,size_t data_size,int8_t is_compressed,uint32_t chunk_checksum,int8_t write_checksum)1031 ssize_t libewf_raw_write_buffer(
1032 libewf_handle_t *handle,
1033 void *buffer,
1034 size_t buffer_size,
1035 size_t data_size,
1036 int8_t is_compressed,
1037 uint32_t chunk_checksum,
1038 int8_t write_checksum )
1039 {
1040 uint8_t checksum_buffer[ 4 ];
1041
1042 libcerror_error_t *error = NULL;
1043 static char *function = "libewf_raw_write_buffer";
1044 ssize_t write_count = 0;
1045
1046 write_count = libewf_handle_write_chunk(
1047 handle,
1048 buffer,
1049 buffer_size,
1050 data_size,
1051 is_compressed,
1052 checksum_buffer,
1053 chunk_checksum,
1054 write_checksum,
1055 &error );
1056
1057 if( write_count == -1 )
1058 {
1059 libcerror_error_set(
1060 &error,
1061 LIBCERROR_ERROR_DOMAIN_IO,
1062 LIBCERROR_IO_ERROR_READ_FAILED,
1063 "%s: unable to raw write buffer.",
1064 function );
1065
1066 libcnotify_print_error_backtrace(
1067 error );
1068 libcerror_error_free(
1069 &error );
1070
1071 return( -1 );
1072 }
1073 return( write_count );
1074 }
1075
1076 /* Writes data in EWF format at the current offset
1077 * the necessary settings of the write values must have been made
1078 * Will initialize write if necessary
1079 * Returns the amount of input bytes written, 0 when no longer bytes can be written or -1 on error
1080 */
libewf_write_buffer(libewf_handle_t * handle,void * buffer,size_t buffer_size)1081 ssize_t libewf_write_buffer(
1082 libewf_handle_t *handle,
1083 void *buffer,
1084 size_t buffer_size )
1085 {
1086 libcerror_error_t *error = NULL;
1087 static char *function = "libewf_write_buffer";
1088 ssize_t write_count = 0;
1089
1090 write_count = libewf_handle_write_buffer(
1091 handle,
1092 buffer,
1093 buffer_size,
1094 &error );
1095
1096 if( write_count == -1 )
1097 {
1098 libcerror_error_set(
1099 &error,
1100 LIBCERROR_ERROR_DOMAIN_IO,
1101 LIBCERROR_IO_ERROR_READ_FAILED,
1102 "%s: unable to write buffer.",
1103 function );
1104
1105 libcnotify_print_error_backtrace(
1106 error );
1107 libcerror_error_free(
1108 &error );
1109
1110 return( -1 );
1111 }
1112 return( write_count );
1113 }
1114
1115 /* Writes data in EWF format at a specific offset,
1116 * the necessary settings of the write values must have been made
1117 * Will initialize write if necessary
1118 * Returns the amount of input bytes written, 0 when no longer bytes can be written or -1 on error
1119 */
libewf_write_random(libewf_handle_t * handle,void * buffer,size_t buffer_size,off64_t offset)1120 ssize_t libewf_write_random(
1121 libewf_handle_t *handle,
1122 void *buffer,
1123 size_t buffer_size,
1124 off64_t offset )
1125 {
1126 libcerror_error_t *error = NULL;
1127 static char *function = "libewf_write_random";
1128 ssize_t write_count = 0;
1129
1130 write_count = libewf_handle_write_random(
1131 handle,
1132 buffer,
1133 buffer_size,
1134 offset,
1135 &error );
1136
1137 if( write_count == -1 )
1138 {
1139 libcerror_error_set(
1140 &error,
1141 LIBCERROR_ERROR_DOMAIN_IO,
1142 LIBCERROR_IO_ERROR_WRITE_FAILED,
1143 "%s: unable to write random.",
1144 function );
1145
1146 libcnotify_print_error_backtrace(
1147 error );
1148 libcerror_error_free(
1149 &error );
1150
1151 return( -1 );
1152 }
1153 return( write_count );
1154 }
1155
1156 /* Finalizes the write by correcting the EWF the meta data in the segment files
1157 * This function is required after write from stream
1158 * Returns the amount of bytes written or -1 on error
1159 */
libewf_write_finalize(libewf_handle_t * handle)1160 ssize_t libewf_write_finalize(
1161 libewf_handle_t *handle )
1162 {
1163 libcerror_error_t *error = NULL;
1164 static char *function = "libewf_write_finalize";
1165 ssize_t write_count = 0;
1166
1167 write_count = libewf_handle_write_finalize(
1168 handle,
1169 &error );
1170
1171 if( write_count == -1 )
1172 {
1173 libcerror_error_set(
1174 &error,
1175 LIBCERROR_ERROR_DOMAIN_IO,
1176 LIBCERROR_IO_ERROR_WRITE_FAILED,
1177 "%s: unable to finalize write.",
1178 function );
1179
1180 libcnotify_print_error_backtrace(
1181 error );
1182 libcerror_error_free(
1183 &error );
1184
1185 return( -1 );
1186 }
1187 return( write_count );
1188 }
1189
1190 /* Retrieves the segment filename
1191 * The filename size should include the end of string character
1192 * Returns 1 if successful, 0 if value not present or -1 on error
1193 */
libewf_get_segment_filename(libewf_handle_t * handle,char * filename,size_t filename_size)1194 int libewf_get_segment_filename(
1195 libewf_handle_t *handle,
1196 char *filename,
1197 size_t filename_size )
1198 {
1199 libcerror_error_t *error = NULL;
1200 static char *function = "libewf_get_segment_filename";
1201 int result = 0;
1202
1203 result = libewf_handle_get_segment_filename(
1204 handle,
1205 filename,
1206 filename_size,
1207 &error );
1208
1209 if( result == -1 )
1210 {
1211 libcerror_error_set(
1212 &error,
1213 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1214 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1215 "%s: unable to retrieve segment filename.",
1216 function );
1217
1218 libcnotify_print_error_backtrace(
1219 error );
1220 libcerror_error_free(
1221 &error );
1222
1223 return( -1 );
1224 }
1225 return( result );
1226 }
1227
1228 /* Sets the segment file
1229 * Returns 1 if successful or -1 on error
1230 */
libewf_set_segment_filename(libewf_handle_t * handle,const char * filename,size_t filename_length)1231 int libewf_set_segment_filename(
1232 libewf_handle_t *handle,
1233 const char *filename,
1234 size_t filename_length )
1235 {
1236 libcerror_error_t *error = NULL;
1237 static char *function = "libewf_set_segment_filename";
1238
1239 if( libewf_handle_set_segment_filename(
1240 handle,
1241 filename,
1242 filename_length,
1243 &error ) != 1 )
1244 {
1245 libcerror_error_set(
1246 &error,
1247 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1248 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1249 "%s: unable to set segment filename.",
1250 function );
1251
1252 libcnotify_print_error_backtrace(
1253 error );
1254 libcerror_error_free(
1255 &error );
1256
1257 return( -1 );
1258 }
1259 return( 1 );
1260 }
1261
1262 #if defined( HAVE_WIDE_CHARACTER_TYPE )
1263
1264 /* Retrieves the segment filename
1265 * The filename size should include the end of string character
1266 * Returns 1 if successful, 0 if value not present or -1 on error
1267 */
libewf_get_segment_filename_wide(libewf_handle_t * handle,wchar_t * filename,size_t filename_size)1268 int libewf_get_segment_filename_wide(
1269 libewf_handle_t *handle,
1270 wchar_t *filename,
1271 size_t filename_size )
1272 {
1273 libcerror_error_t *error = NULL;
1274 static char *function = "libewf_get_segment_filename_wide";
1275 int result = 0;
1276
1277 result = libewf_handle_get_segment_filename_wide(
1278 handle,
1279 filename,
1280 filename_size,
1281 &error );
1282
1283 if( result == -1 )
1284 {
1285 libcerror_error_set(
1286 &error,
1287 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1288 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1289 "%s: unable to retrieve wide segment filename.",
1290 function );
1291
1292 libcnotify_print_error_backtrace(
1293 error );
1294 libcerror_error_free(
1295 &error );
1296
1297 return( -1 );
1298 }
1299 return( result );
1300 }
1301
1302 /* Sets the segment file
1303 * Returns 1 if successful or -1 on error
1304 */
libewf_set_segment_filename_wide(libewf_handle_t * handle,const wchar_t * filename,size_t filename_length)1305 int libewf_set_segment_filename_wide(
1306 libewf_handle_t *handle,
1307 const wchar_t *filename,
1308 size_t filename_length )
1309 {
1310 libcerror_error_t *error = NULL;
1311 static char *function = "libewf_set_segment_filename_wide";
1312
1313 if( libewf_handle_set_segment_filename_wide(
1314 handle,
1315 filename,
1316 filename_length,
1317 &error ) != 1 )
1318 {
1319 libcerror_error_set(
1320 &error,
1321 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1322 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1323 "%s: unable to set wide segment filename.",
1324 function );
1325
1326 libcnotify_print_error_backtrace(
1327 error );
1328 libcerror_error_free(
1329 &error );
1330
1331 return( -1 );
1332 }
1333 return( 1 );
1334 }
1335
1336 #endif
1337
1338 /* Retrieves the segment file size
1339 * Returns 1 if successful or -1 on error
1340 */
libewf_get_segment_file_size(libewf_handle_t * handle,size64_t * segment_file_size)1341 int libewf_get_segment_file_size(
1342 libewf_handle_t *handle,
1343 size64_t *segment_file_size )
1344 {
1345 libcerror_error_t *error = NULL;
1346 static char *function = "libewf_get_segment_file_size";
1347
1348 if( libewf_handle_get_segment_file_size(
1349 handle,
1350 segment_file_size,
1351 &error ) != 1 )
1352 {
1353 libcerror_error_set(
1354 &error,
1355 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1356 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1357 "%s: unable to retrieve segment file size.",
1358 function );
1359
1360 libcnotify_print_error_backtrace(
1361 error );
1362 libcerror_error_free(
1363 &error );
1364
1365 return( -1 );
1366 }
1367 return( 1 );
1368 }
1369
1370 /* Sets the segment file size
1371 * Returns 1 if successful or -1 on error
1372 */
libewf_set_segment_file_size(libewf_handle_t * handle,size64_t segment_file_size)1373 int libewf_set_segment_file_size(
1374 libewf_handle_t *handle,
1375 size64_t segment_file_size )
1376 {
1377 libcerror_error_t *error = NULL;
1378 static char *function = "libewf_set_segment_file_size";
1379
1380 if( libewf_handle_set_segment_file_size(
1381 handle,
1382 segment_file_size,
1383 &error ) != 1 )
1384 {
1385 libcerror_error_set(
1386 &error,
1387 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1388 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1389 "%s: unable to set segment file size.",
1390 function );
1391
1392 libcnotify_print_error_backtrace(
1393 error );
1394 libcerror_error_free(
1395 &error );
1396
1397 return( -1 );
1398 }
1399 return( 1 );
1400 }
1401
1402 /* Retrieves the delta segment filename
1403 * The filename size should include the end of string character
1404 * Returns 1 if successful, 0 if value not present or -1 on error
1405 */
libewf_get_delta_segment_filename(libewf_handle_t * handle,char * filename,size_t filename_size)1406 int libewf_get_delta_segment_filename(
1407 libewf_handle_t *handle,
1408 char *filename,
1409 size_t filename_size )
1410 {
1411 libcerror_error_t *error = NULL;
1412 static char *function = "libewf_get_delta_segment_filename";
1413 int result = 0;
1414
1415 result = libewf_handle_get_delta_segment_filename(
1416 handle,
1417 filename,
1418 filename_size,
1419 &error );
1420
1421 if( result == -1 )
1422 {
1423 libcerror_error_set(
1424 &error,
1425 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1426 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1427 "%s: unable to retrieve delta segment filename.",
1428 function );
1429
1430 libcnotify_print_error_backtrace(
1431 error );
1432 libcerror_error_free(
1433 &error );
1434
1435 return( -1 );
1436 }
1437 return( result );
1438 }
1439
1440 /* Sets the delta segment file
1441 * Returns 1 if successful or -1 on error
1442 */
libewf_set_delta_segment_filename(libewf_handle_t * handle,const char * filename,size_t filename_length)1443 int libewf_set_delta_segment_filename(
1444 libewf_handle_t *handle,
1445 const char *filename,
1446 size_t filename_length )
1447 {
1448 libcerror_error_t *error = NULL;
1449 static char *function = "libewf_set_delta_segment_filename";
1450
1451 if( libewf_handle_set_delta_segment_filename(
1452 handle,
1453 filename,
1454 filename_length,
1455 &error ) != 1 )
1456 {
1457 libcerror_error_set(
1458 &error,
1459 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1460 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1461 "%s: unable to set delta segment filename.",
1462 function );
1463
1464 libcnotify_print_error_backtrace(
1465 error );
1466 libcerror_error_free(
1467 &error );
1468
1469 return( -1 );
1470 }
1471 return( 1 );
1472 }
1473
1474 #if defined( HAVE_WIDE_CHARACTER_TYPE )
1475
1476 /* Retrieves the delta segment filename
1477 * The filename size should include the end of string character
1478 * Returns 1 if successful, 0 if value not present or -1 on error
1479 */
libewf_get_delta_segment_filename_wide(libewf_handle_t * handle,wchar_t * filename,size_t filename_size)1480 int libewf_get_delta_segment_filename_wide(
1481 libewf_handle_t *handle,
1482 wchar_t *filename,
1483 size_t filename_size )
1484 {
1485 libcerror_error_t *error = NULL;
1486 static char *function = "libewf_get_delta_segment_filename_wide";
1487 int result = 0;
1488
1489 result = libewf_handle_get_delta_segment_filename_wide(
1490 handle,
1491 filename,
1492 filename_size,
1493 &error );
1494
1495 if( result == -1 )
1496 {
1497 libcerror_error_set(
1498 &error,
1499 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1500 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1501 "%s: unable to retrieve wide delta segment filename.",
1502 function );
1503
1504 libcnotify_print_error_backtrace(
1505 error );
1506 libcerror_error_free(
1507 &error );
1508
1509 return( -1 );
1510 }
1511 return( result );
1512 }
1513
1514 /* Sets the delta segment file
1515 * Returns 1 if successful or -1 on error
1516 */
libewf_set_delta_segment_filename_wide(libewf_handle_t * handle,const wchar_t * filename,size_t filename_length)1517 int libewf_set_delta_segment_filename_wide(
1518 libewf_handle_t *handle,
1519 const wchar_t *filename,
1520 size_t filename_length )
1521 {
1522 libcerror_error_t *error = NULL;
1523 static char *function = "libewf_set_delta_segment_filename_wide";
1524
1525 if( libewf_handle_set_delta_segment_filename_wide(
1526 handle,
1527 filename,
1528 filename_length,
1529 &error ) != 1 )
1530 {
1531 libcerror_error_set(
1532 &error,
1533 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1534 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1535 "%s: unable to set wide delta segment filename.",
1536 function );
1537
1538 libcnotify_print_error_backtrace(
1539 error );
1540 libcerror_error_free(
1541 &error );
1542
1543 return( -1 );
1544 }
1545 return( 1 );
1546 }
1547
1548 #endif
1549
1550 /* Retrieves the delta segment file size
1551 * Returns 1 if successful or -1 on error
1552 */
libewf_get_delta_segment_file_size(libewf_handle_t * handle,size64_t * delta_segment_file_size)1553 int libewf_get_delta_segment_file_size(
1554 libewf_handle_t *handle,
1555 size64_t *delta_segment_file_size )
1556 {
1557 libcerror_error_t *error = NULL;
1558 static char *function = "libewf_set_delta_segment_file_size";
1559
1560 if( libewf_handle_get_delta_segment_file_size(
1561 handle,
1562 delta_segment_file_size,
1563 &error ) != 1 )
1564 {
1565 libcerror_error_set(
1566 &error,
1567 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1568 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1569 "%s: unable to retrieve delta segment file size.",
1570 function );
1571
1572 libcnotify_print_error_backtrace(
1573 error );
1574 libcerror_error_free(
1575 &error );
1576
1577 return( -1 );
1578 }
1579 return( 1 );
1580 }
1581
1582 /* Sets the delta segment file size
1583 * Returns 1 if successful or -1 on error
1584 */
libewf_set_delta_segment_file_size(libewf_handle_t * handle,size64_t delta_segment_file_size)1585 int libewf_set_delta_segment_file_size(
1586 libewf_handle_t *handle,
1587 size64_t delta_segment_file_size )
1588 {
1589 libcerror_error_t *error = NULL;
1590 static char *function = "libewf_set_delta_segment_file_size";
1591
1592 if( libewf_handle_set_delta_segment_file_size(
1593 handle,
1594 delta_segment_file_size,
1595 &error ) != 1 )
1596 {
1597 libcerror_error_set(
1598 &error,
1599 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1600 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
1601 "%s: unable to set delta segment file size.",
1602 function );
1603
1604 libcnotify_print_error_backtrace(
1605 error );
1606 libcerror_error_free(
1607 &error );
1608
1609 return( -1 );
1610 }
1611 return( 1 );
1612 }
1613
1614 /* Retrieves the amount of sectors per chunk
1615 * Returns 1 if successful or -1 on error
1616 */
libewf_get_sectors_per_chunk(libewf_handle_t * handle,uint32_t * sectors_per_chunk)1617 int libewf_get_sectors_per_chunk(
1618 libewf_handle_t *handle,
1619 uint32_t *sectors_per_chunk )
1620 {
1621 libcerror_error_t *error = NULL;
1622 static char *function = "libewf_get_sectors_per_chunk";
1623
1624 if( libewf_handle_get_sectors_per_chunk(
1625 handle,
1626 sectors_per_chunk,
1627 &error ) != 1 )
1628 {
1629 libcerror_error_set(
1630 &error,
1631 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1632 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1633 "%s: unable to retrieve the amount of sectors per chunk.",
1634 function );
1635
1636 libcnotify_print_error_backtrace(
1637 error );
1638 libcerror_error_free(
1639 &error );
1640
1641 return( -1 );
1642 }
1643 return( 1 );
1644 }
1645
1646 /* Sets the amount of sectors per chunk
1647 * Returns 1 if successful or -1 on error
1648 */
libewf_set_sectors_per_chunk(libewf_handle_t * handle,uint32_t sectors_per_chunk)1649 int libewf_set_sectors_per_chunk(
1650 libewf_handle_t *handle,
1651 uint32_t sectors_per_chunk )
1652 {
1653 libcerror_error_t *error = NULL;
1654 static char *function = "libewf_set_sectors_per_chunk";
1655
1656 if( libewf_handle_set_sectors_per_chunk(
1657 handle,
1658 sectors_per_chunk,
1659 &error ) != 1 )
1660 {
1661 libcerror_error_set(
1662 &error,
1663 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1664 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1665 "%s: unable to set the amount of sectors per chunk.",
1666 function );
1667
1668 libcnotify_print_error_backtrace(
1669 error );
1670 libcerror_error_free(
1671 &error );
1672
1673 return( -1 );
1674 }
1675 return( 1 );
1676 }
1677
1678 /* Retrieves the amount of bytes per sector
1679 * Returns 1 if successful or -1 on error
1680 */
libewf_get_bytes_per_sector(libewf_handle_t * handle,uint32_t * bytes_per_sector)1681 int libewf_get_bytes_per_sector(
1682 libewf_handle_t *handle,
1683 uint32_t *bytes_per_sector )
1684 {
1685 libcerror_error_t *error = NULL;
1686 static char *function = "libewf_get_bytes_per_sector";
1687
1688 if( libewf_handle_get_bytes_per_sector(
1689 handle,
1690 bytes_per_sector,
1691 &error ) != 1 )
1692 {
1693 libcerror_error_set(
1694 &error,
1695 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1696 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1697 "%s: unable to retrieve the amount of bytes per sector.",
1698 function );
1699
1700 libcnotify_print_error_backtrace(
1701 error );
1702 libcerror_error_free(
1703 &error );
1704
1705 return( -1 );
1706 }
1707 return( 1 );
1708 }
1709
1710 /* Sets the amount of bytes per sector
1711 * Returns 1 if successful or -1 on error
1712 */
libewf_set_bytes_per_sector(libewf_handle_t * handle,uint32_t bytes_per_sector)1713 int libewf_set_bytes_per_sector(
1714 libewf_handle_t *handle,
1715 uint32_t bytes_per_sector )
1716 {
1717 libcerror_error_t *error = NULL;
1718 static char *function = "libewf_set_bytes_per_sector";
1719
1720 if( libewf_handle_set_bytes_per_sector(
1721 handle,
1722 bytes_per_sector,
1723 &error ) != 1 )
1724 {
1725 libcerror_error_set(
1726 &error,
1727 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1728 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1729 "%s: unable to set the amount of bytes per sector.",
1730 function );
1731
1732 libcnotify_print_error_backtrace(
1733 error );
1734 libcerror_error_free(
1735 &error );
1736
1737 return( -1 );
1738 }
1739 return( 1 );
1740 }
1741
1742 /* Retrieves the amount of sectors
1743 * Returns 1 if successful or -1 on error
1744 */
libewf_get_amount_of_sectors(libewf_handle_t * handle,uint32_t * amount_of_sectors)1745 int libewf_get_amount_of_sectors(
1746 libewf_handle_t *handle,
1747 uint32_t *amount_of_sectors )
1748 {
1749 libcerror_error_t *error = NULL;
1750 static char *function = "libewf_get_amount_of_sectors";
1751 uint64_t safe_amount_of_sectors = 0;
1752
1753 if( amount_of_sectors == NULL )
1754 {
1755 libcerror_error_set(
1756 &error,
1757 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
1758 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
1759 "%s: invalid amount of sectors.",
1760 function );
1761
1762 libcnotify_print_error_backtrace(
1763 error );
1764 libcerror_error_free(
1765 &error );
1766
1767 return( -1 );
1768 }
1769 if( libewf_handle_get_amount_of_sectors(
1770 handle,
1771 &safe_amount_of_sectors,
1772 &error ) != 1 )
1773 {
1774 libcerror_error_set(
1775 &error,
1776 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1777 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1778 "%s: unable to retrieve the amount of sectors.",
1779 function );
1780
1781 libcnotify_print_error_backtrace(
1782 error );
1783 libcerror_error_free(
1784 &error );
1785
1786 return( -1 );
1787 }
1788 if( safe_amount_of_sectors > (uint64_t) UINT32_MAX )
1789 {
1790 libcerror_error_set(
1791 &error,
1792 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1793 LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
1794 "%s: invalid amount of sectors value exceeds maximum.",
1795 function );
1796
1797 libcnotify_print_error_backtrace(
1798 error );
1799 libcerror_error_free(
1800 &error );
1801
1802 return( -1 );
1803 }
1804 *amount_of_sectors = (uint32_t) safe_amount_of_sectors;
1805
1806 return( 1 );
1807 }
1808
1809 /* Retrieves the chunk size
1810 * Returns 1 if successful or -1 on error
1811 */
libewf_get_chunk_size(libewf_handle_t * handle,size32_t * chunk_size)1812 int libewf_get_chunk_size(
1813 libewf_handle_t *handle,
1814 size32_t *chunk_size )
1815 {
1816 libcerror_error_t *error = NULL;
1817 static char *function = "libewf_get_chunk_size";
1818
1819 if( libewf_handle_get_chunk_size(
1820 handle,
1821 chunk_size,
1822 &error ) != 1 )
1823 {
1824 libcerror_error_set(
1825 &error,
1826 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1827 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1828 "%s: unable to retrieve the chunk size.",
1829 function );
1830
1831 libcnotify_print_error_backtrace(
1832 error );
1833 libcerror_error_free(
1834 &error );
1835
1836 return( -1 );
1837 }
1838 return( 1 );
1839 }
1840
1841 /* Retrieves the error granularity
1842 * Returns 1 if successful or -1 on error
1843 */
libewf_get_error_granularity(libewf_handle_t * handle,uint32_t * error_granularity)1844 int libewf_get_error_granularity(
1845 libewf_handle_t *handle,
1846 uint32_t *error_granularity )
1847 {
1848 libcerror_error_t *error = NULL;
1849 static char *function = "libewf_get_error_granularity";
1850
1851 if( libewf_handle_get_error_granularity(
1852 handle,
1853 error_granularity,
1854 &error ) != 1 )
1855 {
1856 libcerror_error_set(
1857 &error,
1858 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1859 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1860 "%s: unable to retrieve the error granularity.",
1861 function );
1862
1863 libcnotify_print_error_backtrace(
1864 error );
1865 libcerror_error_free(
1866 &error );
1867
1868 return( -1 );
1869 }
1870 return( 1 );
1871 }
1872
1873 /* Sets the error granularity
1874 * Returns 1 if successful or -1 on error
1875 */
libewf_set_error_granularity(libewf_handle_t * handle,uint32_t error_granularity)1876 int libewf_set_error_granularity(
1877 libewf_handle_t *handle,
1878 uint32_t error_granularity )
1879 {
1880 libcerror_error_t *error = NULL;
1881 static char *function = "libewf_set_error_granularity";
1882
1883 if( libewf_handle_set_error_granularity(
1884 handle,
1885 error_granularity,
1886 &error ) != 1 )
1887 {
1888 libcerror_error_set(
1889 &error,
1890 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1891 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1892 "%s: unable to set the error granularity.",
1893 function );
1894
1895 libcnotify_print_error_backtrace(
1896 error );
1897 libcerror_error_free(
1898 &error );
1899
1900 return( -1 );
1901 }
1902 return( 1 );
1903 }
1904
1905 /* Retrieves the compression values
1906 * Returns 1 if successful or -1 on error
1907 */
libewf_get_compression_values(libewf_handle_t * handle,int8_t * compression_level,uint8_t * compress_empty_block)1908 int libewf_get_compression_values(
1909 libewf_handle_t *handle,
1910 int8_t *compression_level,
1911 uint8_t *compress_empty_block )
1912 {
1913 libcerror_error_t *error = NULL;
1914 static char *function = "libewf_get_compression_values";
1915 uint8_t compression_flags = 0;
1916
1917 if( libewf_handle_get_compression_values(
1918 handle,
1919 compression_level,
1920 &compression_flags,
1921 &error ) != 1 )
1922 {
1923 libcerror_error_set(
1924 &error,
1925 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1926 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1927 "%s: unable to retrieve the compression values.",
1928 function );
1929
1930 libcnotify_print_error_backtrace(
1931 error );
1932 libcerror_error_free(
1933 &error );
1934
1935 return( -1 );
1936 }
1937 if( ( compression_flags & LIBEWF_FLAG_COMPRESS_EMPTY_BLOCK ) == LIBEWF_FLAG_COMPRESS_EMPTY_BLOCK )
1938 {
1939 *compress_empty_block = 1;
1940 }
1941 else
1942 {
1943 *compress_empty_block = 0;
1944 }
1945 return( 1 );
1946 }
1947
1948 /* Sets the compression values
1949 * Returns 1 if successful or -1 on error
1950 */
libewf_set_compression_values(libewf_handle_t * handle,int8_t compression_level,uint8_t compress_empty_block)1951 int libewf_set_compression_values(
1952 libewf_handle_t *handle,
1953 int8_t compression_level,
1954 uint8_t compress_empty_block )
1955 {
1956 libcerror_error_t *error = NULL;
1957 static char *function = "libewf_set_compression_values";
1958 uint8_t compression_flags = 0;
1959
1960 if( compress_empty_block != 0 )
1961 {
1962 compression_flags = LIBEWF_FLAG_COMPRESS_EMPTY_BLOCK;
1963 }
1964 if( libewf_handle_set_compression_values(
1965 handle,
1966 compression_level,
1967 compression_flags,
1968 &error ) != 1 )
1969 {
1970 libcerror_error_set(
1971 &error,
1972 LIBCERROR_ERROR_DOMAIN_RUNTIME,
1973 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
1974 "%s: unable to set the compression values.",
1975 function );
1976
1977 libcnotify_print_error_backtrace(
1978 error );
1979 libcerror_error_free(
1980 &error );
1981
1982 return( -1 );
1983 }
1984 return( 1 );
1985 }
1986
1987 /* Retrieves the size of the contained media data
1988 * Returns 1 if successful or -1 on error
1989 */
libewf_get_media_size(libewf_handle_t * handle,size64_t * media_size)1990 int libewf_get_media_size(
1991 libewf_handle_t *handle,
1992 size64_t *media_size )
1993 {
1994 libcerror_error_t *error = NULL;
1995 static char *function = "libewf_get_media_size";
1996
1997 if( libewf_handle_get_media_size(
1998 handle,
1999 media_size,
2000 &error ) != 1 )
2001 {
2002 libcerror_error_set(
2003 &error,
2004 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2005 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2006 "%s: unable to retrieve the media size.",
2007 function );
2008
2009 libcnotify_print_error_backtrace(
2010 error );
2011 libcerror_error_free(
2012 &error );
2013
2014 return( -1 );
2015 }
2016 return( 1 );
2017 }
2018
2019 /* Sets the media size
2020 * Returns 1 if successful or -1 on error
2021 */
libewf_set_media_size(libewf_handle_t * handle,size64_t media_size)2022 int libewf_set_media_size(
2023 libewf_handle_t *handle,
2024 size64_t media_size )
2025 {
2026 libcerror_error_t *error = NULL;
2027 static char *function = "libewf_set_media_size";
2028
2029 if( libewf_handle_set_media_size(
2030 handle,
2031 media_size,
2032 &error ) != 1 )
2033 {
2034 libcerror_error_set(
2035 &error,
2036 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2037 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2038 "%s: unable to set the media size.",
2039 function );
2040
2041 libcnotify_print_error_backtrace(
2042 error );
2043 libcerror_error_free(
2044 &error );
2045
2046 return( -1 );
2047 }
2048 return( 1 );
2049 }
2050
2051 /* Retrieves the media type value
2052 * Returns 1 if successful or -1 on error
2053 */
libewf_get_media_type(libewf_handle_t * handle,uint8_t * media_type)2054 int libewf_get_media_type(
2055 libewf_handle_t *handle,
2056 uint8_t *media_type )
2057 {
2058 libcerror_error_t *error = NULL;
2059 static char *function = "libewf_get_media_type";
2060
2061 if( libewf_handle_get_media_type(
2062 handle,
2063 media_type,
2064 &error ) != 1 )
2065 {
2066 libcerror_error_set(
2067 &error,
2068 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2069 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2070 "%s: unable to retrieve the media type.",
2071 function );
2072
2073 libcnotify_print_error_backtrace(
2074 error );
2075 libcerror_error_free(
2076 &error );
2077
2078 return( -1 );
2079 }
2080 return( 1 );
2081 }
2082
2083 /* Sets the media type
2084 * Returns 1 if successful or -1 on error
2085 */
libewf_set_media_type(libewf_handle_t * handle,uint8_t media_type)2086 int libewf_set_media_type(
2087 libewf_handle_t *handle,
2088 uint8_t media_type )
2089 {
2090 libcerror_error_t *error = NULL;
2091 static char *function = "libewf_set_media_type";
2092
2093 if( libewf_handle_set_media_type(
2094 handle,
2095 media_type,
2096 &error ) != 1 )
2097 {
2098 libcerror_error_set(
2099 &error,
2100 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2101 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2102 "%s: unable to set the media type.",
2103 function );
2104
2105 libcnotify_print_error_backtrace(
2106 error );
2107 libcerror_error_free(
2108 &error );
2109
2110 return( -1 );
2111 }
2112 return( 1 );
2113 }
2114
2115 /* Retrieves the media flags
2116 * Returns 1 if successful or -1 on error
2117 */
libewf_get_media_flags(libewf_handle_t * handle,uint8_t * media_flags)2118 int libewf_get_media_flags(
2119 libewf_handle_t *handle,
2120 uint8_t *media_flags )
2121 {
2122 libcerror_error_t *error = NULL;
2123 static char *function = "libewf_get_media_flags";
2124
2125 if( libewf_handle_get_media_flags(
2126 handle,
2127 media_flags,
2128 &error ) != 1 )
2129 {
2130 libcerror_error_set(
2131 &error,
2132 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2133 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2134 "%s: unable to retrieve the media flags.",
2135 function );
2136
2137 libcnotify_print_error_backtrace(
2138 error );
2139 libcerror_error_free(
2140 &error );
2141
2142 return( -1 );
2143 }
2144 return( 1 );
2145 }
2146
2147 /* Sets the media flags
2148 * Returns 1 if successful or -1 on error
2149 */
libewf_set_media_flags(libewf_handle_t * handle,uint8_t media_flags)2150 int libewf_set_media_flags(
2151 libewf_handle_t *handle,
2152 uint8_t media_flags )
2153 {
2154 libcerror_error_t *error = NULL;
2155 static char *function = "libewf_set_media_flags";
2156
2157 if( libewf_handle_set_media_flags(
2158 handle,
2159 media_flags,
2160 &error ) != 1 )
2161 {
2162 libcerror_error_set(
2163 &error,
2164 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2165 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2166 "%s: unable to set the media flags.",
2167 function );
2168
2169 libcnotify_print_error_backtrace(
2170 error );
2171 libcerror_error_free(
2172 &error );
2173
2174 return( -1 );
2175 }
2176 return( 1 );
2177 }
2178
2179 /* Retrieves the volume type value
2180 * Returns 1 if successful or -1 on error
2181 */
libewf_get_volume_type(libewf_handle_t * handle,uint8_t * volume_type)2182 int libewf_get_volume_type(
2183 libewf_handle_t *handle,
2184 uint8_t *volume_type )
2185 {
2186 libcerror_error_t *error = NULL;
2187 libewf_internal_handle_t *internal_handle = NULL;
2188 static char *function = "libewf_get_volume_type";
2189
2190 if( handle == NULL )
2191 {
2192 libcerror_error_set(
2193 &error,
2194 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2195 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2196 "%s: invalid handle.",
2197 function );
2198
2199 libcnotify_print_error_backtrace(
2200 error );
2201 libcerror_error_free(
2202 &error );
2203
2204 return( -1 );
2205 }
2206 internal_handle = (libewf_internal_handle_t *) handle;
2207
2208 if( internal_handle->media_values == NULL )
2209 {
2210 libcerror_error_set(
2211 &error,
2212 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2213 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2214 "%s: invalid handle - missing media values.",
2215 function );
2216
2217 libcnotify_print_error_backtrace(
2218 error );
2219 libcerror_error_free(
2220 &error );
2221
2222 return( -1 );
2223 }
2224 if( volume_type == NULL )
2225 {
2226 libcerror_error_set(
2227 &error,
2228 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2229 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2230 "%s: invalid volume type.",
2231 function );
2232
2233 libcnotify_print_error_backtrace(
2234 error );
2235 libcerror_error_free(
2236 &error );
2237
2238 return( -1 );
2239 }
2240 if( ( internal_handle->media_values->media_flags & 0x02 ) == 0 )
2241 {
2242 *volume_type = (int8_t) LIBEWF_VOLUME_TYPE_LOGICAL;
2243 }
2244 else
2245 {
2246 *volume_type = (int8_t) LIBEWF_VOLUME_TYPE_PHYSICAL;
2247 }
2248 return( 1 );
2249 }
2250
2251 /* Sets the volume type
2252 * Returns 1 if successful or -1 on error
2253 */
libewf_set_volume_type(libewf_handle_t * handle,uint8_t volume_type)2254 int libewf_set_volume_type(
2255 libewf_handle_t *handle,
2256 uint8_t volume_type )
2257 {
2258 libcerror_error_t *error = NULL;
2259 libewf_internal_handle_t *internal_handle = NULL;
2260 static char *function = "libewf_set_volume_type";
2261
2262 if( handle == NULL )
2263 {
2264 libcerror_error_set(
2265 &error,
2266 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2267 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2268 "%s: invalid handle.",
2269 function );
2270
2271 libcnotify_print_error_backtrace(
2272 error );
2273 libcerror_error_free(
2274 &error );
2275
2276 return( -1 );
2277 }
2278 internal_handle = (libewf_internal_handle_t *) handle;
2279
2280 if( internal_handle->media_values == NULL )
2281 {
2282 libcerror_error_set(
2283 &error,
2284 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2285 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2286 "%s: invalid handle - missing media values.",
2287 function );
2288
2289 libcnotify_print_error_backtrace(
2290 error );
2291 libcerror_error_free(
2292 &error );
2293
2294 return( -1 );
2295 }
2296 if( ( internal_handle->read_io_handle != NULL )
2297 || ( internal_handle->write_io_handle == NULL )
2298 || ( internal_handle->write_io_handle->values_initialized != 0 ) )
2299 {
2300 libcerror_error_set(
2301 &error,
2302 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2303 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
2304 "%s: volume type cannot be changed.",
2305 function );
2306
2307 libcnotify_print_error_backtrace(
2308 error );
2309 libcerror_error_free(
2310 &error );
2311
2312 return( -1 );
2313 }
2314 if( volume_type == LIBEWF_VOLUME_TYPE_LOGICAL )
2315 {
2316 /* Uses 1-complement of LIBEWF_MEDIA_FLAG_PHYSICAL
2317 */
2318 internal_handle->media_values->media_flags &= ~LIBEWF_MEDIA_FLAG_PHYSICAL;
2319 }
2320 else if( volume_type == LIBEWF_VOLUME_TYPE_PHYSICAL )
2321 {
2322 internal_handle->media_values->media_flags |= LIBEWF_MEDIA_FLAG_PHYSICAL;
2323 }
2324 else
2325 {
2326 libcerror_error_set(
2327 &error,
2328 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2329 LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
2330 "%s: unsupported volume type.",
2331 function );
2332
2333 libcnotify_print_error_backtrace(
2334 error );
2335 libcerror_error_free(
2336 &error );
2337
2338 return( -1 );
2339 }
2340 return( 1 );
2341 }
2342
2343 /* Retrieves the format type value
2344 * Returns 1 if successful or -1 on error
2345 */
libewf_get_format(libewf_handle_t * handle,uint8_t * format)2346 int libewf_get_format(
2347 libewf_handle_t *handle,
2348 uint8_t *format )
2349 {
2350 libcerror_error_t *error = NULL;
2351 static char *function = "libewf_get_format";
2352
2353 if( libewf_handle_get_format(
2354 handle,
2355 format,
2356 &error ) != 1 )
2357 {
2358 libcerror_error_set(
2359 &error,
2360 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2361 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2362 "%s: unable to retrieve the format.",
2363 function );
2364
2365 libcnotify_print_error_backtrace(
2366 error );
2367 libcerror_error_free(
2368 &error );
2369
2370 return( -1 );
2371 }
2372 return( 1 );
2373 }
2374
2375 /* Sets the output format
2376 * Returns 1 if successful or -1 on error
2377 */
libewf_set_format(libewf_handle_t * handle,uint8_t format)2378 int libewf_set_format(
2379 libewf_handle_t *handle,
2380 uint8_t format )
2381 {
2382 libcerror_error_t *error = NULL;
2383 static char *function = "libewf_set_format";
2384
2385 if( libewf_handle_set_format(
2386 handle,
2387 format,
2388 &error ) != 1 )
2389 {
2390 libcerror_error_set(
2391 &error,
2392 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2393 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2394 "%s: unable to set the format.",
2395 function );
2396
2397 libcnotify_print_error_backtrace(
2398 error );
2399 libcerror_error_free(
2400 &error );
2401
2402 return( -1 );
2403 }
2404 return( 1 );
2405 }
2406
2407 /* Retrieves the GUID
2408 * Returns 1 if successful or -1 on error
2409 */
libewf_get_guid(libewf_handle_t * handle,uint8_t * guid,size_t size)2410 int libewf_get_guid(
2411 libewf_handle_t *handle,
2412 uint8_t *guid,
2413 size_t size )
2414 {
2415 libcerror_error_t *error = NULL;
2416 static char *function = "libewf_get_guid";
2417
2418 if( libewf_handle_get_guid(
2419 handle,
2420 guid,
2421 size,
2422 &error ) != 1 )
2423 {
2424 libcerror_error_set(
2425 &error,
2426 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2427 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2428 "%s: unable to retrieve the GUID.",
2429 function );
2430
2431 libcnotify_print_error_backtrace(
2432 error );
2433 libcerror_error_free(
2434 &error );
2435
2436 return( -1 );
2437 }
2438 return( 1 );
2439 }
2440
2441 /* Sets the GUID
2442 * Returns 1 if successful or -1 on error
2443 */
libewf_set_guid(libewf_handle_t * handle,uint8_t * guid,size_t size)2444 int libewf_set_guid(
2445 libewf_handle_t *handle,
2446 uint8_t *guid,
2447 size_t size )
2448 {
2449 libcerror_error_t *error = NULL;
2450 static char *function = "libewf_set_guid";
2451
2452 if( libewf_handle_set_guid(
2453 handle,
2454 guid,
2455 size,
2456 &error ) != 1 )
2457 {
2458 libcerror_error_set(
2459 &error,
2460 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2461 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2462 "%s: unable to set the GUID.",
2463 function );
2464
2465 libcnotify_print_error_backtrace(
2466 error );
2467 libcerror_error_free(
2468 &error );
2469
2470 return( -1 );
2471 }
2472 return( 1 );
2473 }
2474
2475 /* Retrieves the GUID
2476 * Returns 1 if successful or -1 on error
2477 */
libewf_handle_get_guid(libewf_handle_t * handle,uint8_t * guid,size_t size,libcerror_error_t ** error)2478 int libewf_handle_get_guid(
2479 libewf_handle_t *handle,
2480 uint8_t *guid,
2481 size_t size,
2482 libcerror_error_t **error )
2483 {
2484 libewf_internal_handle_t *internal_handle = NULL;
2485 static char *function = "libewf_handle_get_guid";
2486
2487 if( handle == NULL )
2488 {
2489 libcerror_error_set(
2490 error,
2491 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2492 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2493 "%s: invalid handle.",
2494 function );
2495
2496 return( -1 );
2497 }
2498 internal_handle = (libewf_internal_handle_t *) handle;
2499
2500 if( internal_handle->media_values == NULL )
2501 {
2502 libcerror_error_set(
2503 error,
2504 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2505 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2506 "%s: invalid handle - missing media values.",
2507 function );
2508
2509 return( -1 );
2510 }
2511 if( guid == NULL )
2512 {
2513 libcerror_error_set(
2514 error,
2515 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2516 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2517 "%s: invalid GUID.",
2518 function );
2519
2520 return( -1 );
2521 }
2522 if( size < 16 )
2523 {
2524 libcerror_error_set(
2525 error,
2526 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2527 LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
2528 "%s: GUID too small.",
2529 function );
2530
2531 return( -1 );
2532 }
2533 if( memory_copy(
2534 guid,
2535 internal_handle->media_values->guid,
2536 16 ) == NULL )
2537 {
2538 libcerror_error_set(
2539 error,
2540 LIBCERROR_ERROR_DOMAIN_MEMORY,
2541 LIBCERROR_MEMORY_ERROR_COPY_FAILED,
2542 "%s: unable to set GUID.",
2543 function );
2544
2545 return( -1 );
2546 }
2547 return( 1 );
2548 }
2549
2550 /* Sets the GUID
2551 * Returns 1 if successful or -1 on error
2552 */
libewf_handle_set_guid(libewf_handle_t * handle,uint8_t * guid,size_t size,libcerror_error_t ** error)2553 int libewf_handle_set_guid(
2554 libewf_handle_t *handle,
2555 uint8_t *guid,
2556 size_t size,
2557 libcerror_error_t **error )
2558 {
2559 libewf_internal_handle_t *internal_handle = NULL;
2560 static char *function = "libewf_handle_set_guid";
2561
2562 if( handle == NULL )
2563 {
2564 libcerror_error_set(
2565 error,
2566 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2567 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2568 "%s: invalid handle.",
2569 function );
2570
2571 return( -1 );
2572 }
2573 internal_handle = (libewf_internal_handle_t *) handle;
2574
2575 if( internal_handle->media_values == NULL )
2576 {
2577 libcerror_error_set(
2578 error,
2579 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2580 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
2581 "%s: invalid handle - missing media values.",
2582 function );
2583
2584 return( -1 );
2585 }
2586 if( guid == NULL )
2587 {
2588 libcerror_error_set(
2589 error,
2590 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2591 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2592 "%s: invalid GUID.",
2593 function );
2594
2595 return( -1 );
2596 }
2597 if( size < 16 )
2598 {
2599 libcerror_error_set(
2600 error,
2601 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2602 LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL,
2603 "%s: GUID too small.",
2604 function );
2605
2606 return( -1 );
2607 }
2608 if( ( internal_handle->read_io_handle != NULL )
2609 || ( internal_handle->write_io_handle == NULL )
2610 || ( internal_handle->write_io_handle->values_initialized != 0 ) )
2611 {
2612 libcerror_error_set(
2613 error,
2614 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2615 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
2616 "%s: GUID cannot be changed.",
2617 function );
2618
2619 return( -1 );
2620 }
2621 if( memory_copy(
2622 internal_handle->media_values->guid,
2623 guid,
2624 16 ) == NULL )
2625 {
2626 libcerror_error_set(
2627 error,
2628 LIBCERROR_ERROR_DOMAIN_MEMORY,
2629 LIBCERROR_MEMORY_ERROR_COPY_FAILED,
2630 "%s: unable to set GUID.",
2631 function );
2632
2633 return( -1 );
2634 }
2635 return( 1 );
2636 }
2637
2638 /* Retrieves the MD5 hash
2639 * Returns 1 if successful, 0 if value not present or -1 on error
2640 */
libewf_get_md5_hash(libewf_handle_t * handle,uint8_t * md5_hash,size_t size)2641 int libewf_get_md5_hash(
2642 libewf_handle_t *handle,
2643 uint8_t *md5_hash,
2644 size_t size )
2645 {
2646 libcerror_error_t *error = NULL;
2647 static char *function = "libewf_get_md5_hash";
2648
2649 if( libewf_handle_get_md5_hash(
2650 handle,
2651 md5_hash,
2652 size,
2653 &error ) != 1 )
2654 {
2655 libcerror_error_set(
2656 &error,
2657 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2658 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2659 "%s: unable to retrieve the MD5 hash.",
2660 function );
2661
2662 libcnotify_print_error_backtrace(
2663 error );
2664 libcerror_error_free(
2665 &error );
2666
2667 return( -1 );
2668 }
2669 return( 1 );
2670 }
2671
2672 /* Sets the MD5 hash
2673 * Returns 1 if successful or -1 on error
2674 */
libewf_set_md5_hash(libewf_handle_t * handle,uint8_t * md5_hash,size_t size)2675 int libewf_set_md5_hash(
2676 libewf_handle_t *handle,
2677 uint8_t *md5_hash,
2678 size_t size )
2679 {
2680 libcerror_error_t *error = NULL;
2681 static char *function = "libewf_set_md5_hash";
2682
2683 if( libewf_handle_set_md5_hash(
2684 handle,
2685 md5_hash,
2686 size,
2687 &error ) != 1 )
2688 {
2689 libcerror_error_set(
2690 &error,
2691 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2692 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2693 "%s: unable to set the MD5 hash.",
2694 function );
2695
2696 libcnotify_print_error_backtrace(
2697 error );
2698 libcerror_error_free(
2699 &error );
2700
2701 return( -1 );
2702 }
2703 return( 1 );
2704 }
2705
2706 /* Retrieves the SHA1 hash
2707 * Returns 1 if successful, 0 if value not present or -1 on error
2708 */
libewf_get_sha1_hash(libewf_handle_t * handle,uint8_t * sha1_hash,size_t size)2709 int libewf_get_sha1_hash(
2710 libewf_handle_t *handle,
2711 uint8_t *sha1_hash,
2712 size_t size )
2713 {
2714 libcerror_error_t *error = NULL;
2715 static char *function = "libewf_get_sha1_hash";
2716
2717 if( libewf_handle_get_sha1_hash(
2718 handle,
2719 sha1_hash,
2720 size,
2721 &error ) != 1 )
2722 {
2723 libcerror_error_set(
2724 &error,
2725 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2726 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2727 "%s: unable to retrieve the SHA1 hash.",
2728 function );
2729
2730 libcnotify_print_error_backtrace(
2731 error );
2732 libcerror_error_free(
2733 &error );
2734
2735 return( -1 );
2736 }
2737 return( 1 );
2738 }
2739
2740 /* Sets the SHA1 hash
2741 * Returns 1 if successful or -1 on error
2742 */
libewf_set_sha1_hash(libewf_handle_t * handle,uint8_t * sha1_hash,size_t size)2743 int libewf_set_sha1_hash(
2744 libewf_handle_t *handle,
2745 uint8_t *sha1_hash,
2746 size_t size )
2747 {
2748 libcerror_error_t *error = NULL;
2749 static char *function = "libewf_set_sha1_hash";
2750
2751 if( libewf_handle_set_sha1_hash(
2752 handle,
2753 sha1_hash,
2754 size,
2755 &error ) != 1 )
2756 {
2757 libcerror_error_set(
2758 &error,
2759 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2760 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2761 "%s: unable to set the SHA1 hash.",
2762 function );
2763
2764 libcnotify_print_error_backtrace(
2765 error );
2766 libcerror_error_free(
2767 &error );
2768
2769 return( -1 );
2770 }
2771 return( 1 );
2772 }
2773
2774 /* Retrieves the amount of chunks written
2775 * Returns 1 if successful or -1 on error
2776 */
libewf_get_write_amount_of_chunks(libewf_handle_t * handle,uint32_t * amount_of_chunks)2777 int libewf_get_write_amount_of_chunks(
2778 libewf_handle_t *handle,
2779 uint32_t *amount_of_chunks )
2780 {
2781 libcerror_error_t *error = NULL;
2782 static char *function = "libewf_get_write_amount_of_chunks";
2783
2784 if( libewf_handle_get_write_amount_of_chunks(
2785 handle,
2786 amount_of_chunks,
2787 &error ) != 1 )
2788 {
2789 libcerror_error_set(
2790 &error,
2791 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2792 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2793 "%s: unable to retrieve amount of chunks written.",
2794 function );
2795
2796 libcnotify_print_error_backtrace(
2797 error );
2798 libcerror_error_free(
2799 &error );
2800
2801 return( -1 );
2802 }
2803 return( 1 );
2804 }
2805
2806 /* Sets the read wipe chunk on error
2807 * The chunk is not wiped if read raw is used
2808 * Returns 1 if successful or -1 on error
2809 */
libewf_set_read_wipe_chunk_on_error(libewf_handle_t * handle,uint8_t wipe_on_error)2810 int libewf_set_read_wipe_chunk_on_error(
2811 libewf_handle_t *handle,
2812 uint8_t wipe_on_error )
2813 {
2814 libcerror_error_t *error = NULL;
2815 static char *function = "libewf_set_read_wipe_chunk_on_error";
2816
2817 if( libewf_handle_set_read_wipe_chunk_on_error(
2818 handle,
2819 wipe_on_error,
2820 &error ) != 1 )
2821 {
2822 libcerror_error_set(
2823 &error,
2824 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2825 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2826 "%s: unable to set wipe chunk on error during read.",
2827 function );
2828
2829 libcnotify_print_error_backtrace(
2830 error );
2831 libcerror_error_free(
2832 &error );
2833
2834 return( -1 );
2835 }
2836 return( 1 );
2837 }
2838
2839 /* Copies the media values from the source to the destination handle
2840 * Returns 1 if successful or -1 on error
2841 */
libewf_copy_media_values(libewf_handle_t * destination_handle,libewf_handle_t * source_handle)2842 int libewf_copy_media_values(
2843 libewf_handle_t *destination_handle,
2844 libewf_handle_t *source_handle )
2845 {
2846 libcerror_error_t *error = NULL;
2847 static char *function = "libewf_copy_media_values";
2848
2849 if( libewf_handle_copy_media_values(
2850 destination_handle,
2851 source_handle,
2852 &error ) != 1 )
2853 {
2854 libcerror_error_set(
2855 &error,
2856 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2857 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
2858 "%s: unable to copy media values.",
2859 function );
2860
2861 libcnotify_print_error_backtrace(
2862 error );
2863 libcerror_error_free(
2864 &error );
2865
2866 return( -1 );
2867 }
2868 return( 1 );
2869 }
2870
2871 /* Retrieves the amount of acquiry errors
2872 * Returns 1 if successful, 0 if no acquiry errors are present or -1 on error
2873 */
libewf_get_amount_of_acquiry_errors(libewf_handle_t * handle,uint32_t * amount_of_errors)2874 int libewf_get_amount_of_acquiry_errors(
2875 libewf_handle_t *handle,
2876 uint32_t *amount_of_errors )
2877 {
2878 libcerror_error_t *error = NULL;
2879 static char *function = "libewf_get_amount_of_acquiry_errors";
2880
2881 if( libewf_handle_get_amount_of_acquiry_errors(
2882 handle,
2883 amount_of_errors,
2884 &error ) != 1 )
2885 {
2886 libcerror_error_set(
2887 &error,
2888 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2889 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2890 "%s: unable to retrieve the amount of acquiry errors.",
2891 function );
2892
2893 libcnotify_print_error_backtrace(
2894 error );
2895 libcerror_error_free(
2896 &error );
2897
2898 return( -1 );
2899 }
2900 return( 1 );
2901 }
2902
2903 /* Retrieves an acquiry error
2904 * Returns 1 if successful or -1 on error
2905 */
libewf_get_acquiry_error(libewf_handle_t * handle,uint32_t index,off64_t * start_sector,uint32_t * amount_of_sectors)2906 int libewf_get_acquiry_error(
2907 libewf_handle_t *handle,
2908 uint32_t index,
2909 off64_t *start_sector,
2910 uint32_t *amount_of_sectors )
2911 {
2912 libcerror_error_t *error = NULL;
2913 static char *function = "libewf_get_acquiry_error";
2914 uint64_t safe_amount_of_sectors = 0;
2915 int result = 0;
2916
2917 if( amount_of_sectors == NULL )
2918 {
2919 libcerror_error_set(
2920 &error,
2921 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
2922 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
2923 "%s: invalid amount of sectors.",
2924 function );
2925
2926 libcnotify_print_error_backtrace(
2927 error );
2928 libcerror_error_free(
2929 &error );
2930
2931 return( -1 );
2932 }
2933 result = libewf_handle_get_acquiry_error(
2934 handle,
2935 index,
2936 (uint64_t *) start_sector,
2937 &safe_amount_of_sectors,
2938 &error );
2939
2940 if( result == -1 )
2941 {
2942 libcerror_error_set(
2943 &error,
2944 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2945 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
2946 "%s: unable to retrieve acquiry error.",
2947 function );
2948
2949 libcnotify_print_error_backtrace(
2950 error );
2951 libcerror_error_free(
2952 &error );
2953
2954 return( -1 );
2955 }
2956 else if( result != 0 )
2957 {
2958 if( safe_amount_of_sectors > (uint64_t) UINT32_MAX )
2959 {
2960 libcerror_error_set(
2961 &error,
2962 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2963 LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
2964 "%s: invalid amount of sectors value exceeds maximum.",
2965 function );
2966
2967 libcnotify_print_error_backtrace(
2968 error );
2969 libcerror_error_free(
2970 &error );
2971
2972 return( -1 );
2973 }
2974 *amount_of_sectors = (uint32_t) safe_amount_of_sectors;
2975 }
2976 return( result );
2977 }
2978
2979 /* Add an acquiry error
2980 * Returns 1 if successful or -1 on error
2981 */
libewf_add_acquiry_error(libewf_handle_t * handle,off64_t start_sector,uint32_t amount_of_sectors)2982 int libewf_add_acquiry_error(
2983 libewf_handle_t *handle,
2984 off64_t start_sector,
2985 uint32_t amount_of_sectors )
2986 {
2987 libcerror_error_t *error = NULL;
2988 static char *function = "libewf_add_acquiry_error";
2989
2990 if( libewf_handle_add_acquiry_error(
2991 handle,
2992 (uint64_t) start_sector,
2993 (uint64_t) amount_of_sectors,
2994 &error ) != 1 )
2995 {
2996 libcerror_error_set(
2997 &error,
2998 LIBCERROR_ERROR_DOMAIN_RUNTIME,
2999 LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
3000 "%s: unable to add acquiry error.",
3001 function );
3002
3003 libcnotify_print_error_backtrace(
3004 error);
3005 libcerror_error_free(
3006 &error );
3007
3008 return( -1 );
3009 }
3010 return( 1 );
3011 }
3012
3013 /* Retrieves the amount of checksum errors
3014 * Returns 1 if successful or -1 on error
3015 */
libewf_get_amount_of_crc_errors(libewf_handle_t * handle,uint32_t * amount_of_errors)3016 int libewf_get_amount_of_crc_errors(
3017 libewf_handle_t *handle,
3018 uint32_t *amount_of_errors )
3019 {
3020 libcerror_error_t *error = NULL;
3021 static char *function = "libewf_get_amount_of_crc_errors";
3022
3023 if( libewf_handle_get_number_of_checksum_errors(
3024 handle,
3025 amount_of_errors,
3026 &error ) != 1 )
3027 {
3028 libcerror_error_set(
3029 &error,
3030 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3031 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3032 "%s: unable to retrieve the number of checksum errors.",
3033 function );
3034
3035 libcnotify_print_error_backtrace(
3036 error );
3037 libcerror_error_free(
3038 &error );
3039
3040 return( -1 );
3041 }
3042 return( 1 );
3043 }
3044
3045 /* Retrieves a checksum error
3046 * Returns 1 if successful or -1 on error
3047 */
libewf_get_crc_error(libewf_handle_t * handle,uint32_t index,off64_t * start_sector,uint32_t * amount_of_sectors)3048 int libewf_get_crc_error(
3049 libewf_handle_t *handle,
3050 uint32_t index,
3051 off64_t *start_sector,
3052 uint32_t *amount_of_sectors )
3053 {
3054 libcerror_error_t *error = NULL;
3055 static char *function = "libewf_get_crc_error";
3056 uint64_t safe_amount_of_sectors = 0;
3057 int result = 0;
3058
3059 if( amount_of_sectors == NULL )
3060 {
3061 libcerror_error_set(
3062 &error,
3063 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3064 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3065 "%s: invalid amount of sectors.",
3066 function );
3067
3068 libcnotify_print_error_backtrace(
3069 error );
3070 libcerror_error_free(
3071 &error );
3072
3073 return( -1 );
3074 }
3075 result = libewf_handle_get_checksum_error(
3076 handle,
3077 index,
3078 (uint64_t *) start_sector,
3079 &safe_amount_of_sectors,
3080 &error );
3081
3082 if( result == -1 )
3083 {
3084 libcerror_error_set(
3085 &error,
3086 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3087 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3088 "%s: unable to retrieve checksum error.",
3089 function );
3090
3091 libcnotify_print_error_backtrace(
3092 error );
3093 libcerror_error_free(
3094 &error );
3095
3096 return( -1 );
3097 }
3098 else if( result != 0 )
3099 {
3100 if( safe_amount_of_sectors > (uint64_t) UINT32_MAX )
3101 {
3102 libcerror_error_set(
3103 &error,
3104 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3105 LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
3106 "%s: invalid amount of sectors value exceeds maximum.",
3107 function );
3108
3109 libcnotify_print_error_backtrace(
3110 error );
3111 libcerror_error_free(
3112 &error );
3113
3114 return( -1 );
3115 }
3116 *amount_of_sectors = (uint32_t) safe_amount_of_sectors;
3117 }
3118 return( result );
3119 }
3120
3121 /* Add a checksum error
3122 * Returns 1 if successful or -1 on error
3123 */
libewf_add_crc_error(libewf_handle_t * handle,off64_t start_sector,uint32_t amount_of_sectors)3124 int libewf_add_crc_error(
3125 libewf_handle_t *handle,
3126 off64_t start_sector,
3127 uint32_t amount_of_sectors )
3128 {
3129 libcerror_error_t *error = NULL;
3130 static char *function = "libewf_add_crc_error";
3131
3132 if( libewf_handle_append_checksum_error(
3133 handle,
3134 (uint64_t) start_sector,
3135 (uint64_t) amount_of_sectors,
3136 &error ) != 1 )
3137 {
3138 libcerror_error_set(
3139 &error,
3140 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3141 LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
3142 "%s: unable to add checksum error.",
3143 function );
3144
3145 libcnotify_print_error_backtrace(
3146 error);
3147 libcerror_error_free(
3148 &error );
3149
3150 return( -1 );
3151 }
3152 return( 1 );
3153 }
3154
3155 /* Retrieves the amount of sessions
3156 * Returns 1 if successful or -1 on error
3157 */
libewf_get_amount_of_sessions(libewf_handle_t * handle,uint32_t * amount_of_sessions)3158 int libewf_get_amount_of_sessions(
3159 libewf_handle_t *handle,
3160 uint32_t *amount_of_sessions )
3161 {
3162 libcerror_error_t *error = NULL;
3163 static char *function = "libewf_get_amount_of_sessions";
3164
3165 if( libewf_handle_get_amount_of_sessions(
3166 handle,
3167 amount_of_sessions,
3168 &error ) != 1 )
3169 {
3170 libcerror_error_set(
3171 &error,
3172 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3173 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3174 "%s: unable to retrieve the amount of sessions.",
3175 function );
3176
3177 libcnotify_print_error_backtrace(
3178 error );
3179 libcerror_error_free(
3180 &error );
3181
3182 return( -1 );
3183 }
3184 return( 1 );
3185 }
3186
3187 /* Retrieves a session
3188 * Returns 1 if successful or -1 on error
3189 */
libewf_get_session(libewf_handle_t * handle,uint32_t index,off64_t * start_sector,uint32_t * amount_of_sectors)3190 int libewf_get_session(
3191 libewf_handle_t *handle,
3192 uint32_t index,
3193 off64_t *start_sector,
3194 uint32_t *amount_of_sectors )
3195 {
3196 libcerror_error_t *error = NULL;
3197 static char *function = "libewf_get_session";
3198 uint64_t safe_amount_of_sectors = 0;
3199 int result = 0;
3200
3201 if( amount_of_sectors == NULL )
3202 {
3203 libcerror_error_set(
3204 &error,
3205 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3206 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3207 "%s: invalid amount of sectors.",
3208 function );
3209
3210 libcnotify_print_error_backtrace(
3211 error );
3212 libcerror_error_free(
3213 &error );
3214
3215 return( -1 );
3216 }
3217 result = libewf_handle_get_session(
3218 handle,
3219 index,
3220 (uint64_t *) start_sector,
3221 &safe_amount_of_sectors,
3222 &error );
3223
3224 if( result == -1 )
3225 {
3226 libcerror_error_set(
3227 &error,
3228 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3229 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3230 "%s: unable to retrieve session.",
3231 function );
3232
3233 libcnotify_print_error_backtrace(
3234 error );
3235 libcerror_error_free(
3236 &error );
3237
3238 return( -1 );
3239 }
3240 else if( result != 0 )
3241 {
3242 if( safe_amount_of_sectors > (uint64_t) UINT32_MAX )
3243 {
3244 libcerror_error_set(
3245 &error,
3246 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3247 LIBCERROR_RUNTIME_ERROR_VALUE_EXCEEDS_MAXIMUM,
3248 "%s: invalid amount of sectors value exceeds maximum.",
3249 function );
3250
3251 libcnotify_print_error_backtrace(
3252 error );
3253 libcerror_error_free(
3254 &error );
3255
3256 return( -1 );
3257 }
3258 *amount_of_sectors = (uint32_t) safe_amount_of_sectors;
3259 }
3260 return( result );
3261 }
3262
3263 /* Add a session
3264 * Returns 1 if successful or -1 on error
3265 */
libewf_add_session(libewf_handle_t * handle,off64_t start_sector,uint32_t amount_of_sectors)3266 int libewf_add_session(
3267 libewf_handle_t *handle,
3268 off64_t start_sector,
3269 uint32_t amount_of_sectors )
3270 {
3271 libcerror_error_t *error = NULL;
3272 static char *function = "libewf_add_session";
3273
3274 if( libewf_handle_add_session(
3275 handle,
3276 (uint64_t) start_sector,
3277 (uint64_t) amount_of_sectors,
3278 &error ) != 1 )
3279 {
3280 libcerror_error_set(
3281 &error,
3282 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3283 LIBCERROR_RUNTIME_ERROR_APPEND_FAILED,
3284 "%s: unable to add session.",
3285 function );
3286
3287 libcnotify_print_error_backtrace(
3288 error);
3289 libcerror_error_free(
3290 &error );
3291
3292 return( -1 );
3293 }
3294 return( 1 );
3295 }
3296
3297 /* Retrieves the header codepage
3298 * Returns 1 if successful or -1 on error
3299 */
libewf_get_header_codepage(libewf_handle_t * handle,int * header_codepage)3300 int libewf_get_header_codepage(
3301 libewf_handle_t *handle,
3302 int *header_codepage )
3303 {
3304 libcerror_error_t *error = NULL;
3305 static char *function = "libewf_get_header_codepage";
3306
3307 if( libewf_handle_get_header_codepage(
3308 handle,
3309 header_codepage,
3310 &error ) != 1 )
3311 {
3312 libcerror_error_set(
3313 &error,
3314 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3315 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3316 "%s: unable to retrieve the header codepage.",
3317 function );
3318
3319 libcnotify_print_error_backtrace(
3320 error );
3321 libcerror_error_free(
3322 &error );
3323
3324 return( -1 );
3325 }
3326 return( 1 );
3327 }
3328
3329 /* Sets the header codepage
3330 * Returns 1 if successful or -1 on error
3331 */
libewf_set_header_codepage(libewf_handle_t * handle,int header_codepage)3332 int libewf_set_header_codepage(
3333 libewf_handle_t *handle,
3334 int header_codepage )
3335 {
3336 libcerror_error_t *error = NULL;
3337 static char *function = "libewf_set_header_codepage";
3338
3339 if( libewf_handle_set_header_codepage(
3340 handle,
3341 header_codepage,
3342 &error ) != 1 )
3343 {
3344 libcerror_error_set(
3345 &error,
3346 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3347 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3348 "%s: unable to set header codepage.",
3349 function );
3350
3351 libcnotify_print_error_backtrace(
3352 error );
3353 libcerror_error_free(
3354 &error );
3355
3356 return( -1 );
3357 }
3358 return( 1 );
3359 }
3360
3361 /* Retrieves the amount of header values
3362 * Returns 1 if successful, 0 if no header values are present or -1 on error
3363 */
libewf_get_amount_of_header_values(libewf_handle_t * handle,uint32_t * amount_of_values)3364 int libewf_get_amount_of_header_values(
3365 libewf_handle_t *handle,
3366 uint32_t *amount_of_values )
3367 {
3368 libcerror_error_t *error = NULL;
3369 static char *function = "libewf_get_amount_of_header_values";
3370 int result = 0;
3371
3372 result = libewf_handle_get_amount_of_header_values(
3373 handle,
3374 amount_of_values,
3375 &error );
3376
3377 if( result == -1 )
3378 {
3379 libcerror_error_set(
3380 &error,
3381 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3382 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3383 "%s: unable to retrieve the amount of header values.",
3384 function );
3385
3386 libcnotify_print_error_backtrace(
3387 error );
3388 libcerror_error_free(
3389 &error );
3390
3391 return( -1 );
3392 }
3393 return( result );
3394 }
3395
3396 /* Retrieves the header value identifier size specified by its index
3397 * The identifier size includes the end of string character
3398 * Returns 1 if successful, 0 if value not present or -1 on error
3399 */
libewf_get_header_value_identifier_size(libewf_handle_t * handle,uint32_t index,size_t * identifier_size)3400 int libewf_get_header_value_identifier_size(
3401 libewf_handle_t *handle,
3402 uint32_t index,
3403 size_t *identifier_size )
3404 {
3405 libcerror_error_t *error = NULL;
3406 static char *function = "libewf_get_header_value_identifier_size";
3407 int result = 0;
3408
3409 result = libewf_handle_get_header_value_identifier_size(
3410 handle,
3411 index,
3412 identifier_size,
3413 &error );
3414
3415 if( result == -1 )
3416 {
3417 libcerror_error_set(
3418 &error,
3419 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3420 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3421 "%s: unable to retrieve header value identifier size.",
3422 function );
3423
3424 libcnotify_print_error_backtrace(
3425 error );
3426 libcerror_error_free(
3427 &error );
3428 }
3429 return( result );
3430 }
3431
3432 /* Retrieves the header value identifier specified by its index
3433 * The strings are encoded in UTF-8
3434 * The identifier size should include the end of string character
3435 * Returns 1 if successful, 0 if value not present or -1 on error
3436 */
libewf_get_header_value_identifier(libewf_handle_t * handle,uint32_t index,char * identifier,size_t identifier_size)3437 int libewf_get_header_value_identifier(
3438 libewf_handle_t *handle,
3439 uint32_t index,
3440 char *identifier,
3441 size_t identifier_size )
3442 {
3443 libcerror_error_t *error = NULL;
3444 static char *function = "libewf_get_header_value_identifier";
3445 int result = 0;
3446
3447 result = libewf_handle_get_header_value_identifier(
3448 handle,
3449 index,
3450 (uint8_t *) identifier,
3451 identifier_size,
3452 &error );
3453
3454 if( result == -1 )
3455 {
3456 libcerror_error_set(
3457 &error,
3458 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3459 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3460 "%s: unable to retrieve header value identifier.",
3461 function );
3462
3463 libcnotify_print_error_backtrace(
3464 error );
3465 libcerror_error_free(
3466 &error );
3467 }
3468 return( result );
3469 }
3470
3471 /* Retrieves the header value size specified by the identifier
3472 * The value size includes the end of string character
3473 * Returns 1 if successful, 0 if value not present or -1 on error
3474 */
libewf_get_header_value_size(libewf_handle_t * handle,const char * identifier,size_t * value_size)3475 int libewf_get_header_value_size(
3476 libewf_handle_t *handle,
3477 const char *identifier,
3478 size_t *value_size )
3479 {
3480 libcerror_error_t *error = NULL;
3481 static char *function = "libewf_get_header_value_size";
3482 size_t identifier_length = 0;
3483 int result = 0;
3484
3485 if( identifier == NULL )
3486 {
3487 libcerror_error_set(
3488 &error,
3489 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3490 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3491 "%s: invalid indentifier.",
3492 function );
3493
3494 libcnotify_print_error_backtrace(
3495 error );
3496 libcerror_error_free(
3497 &error );
3498
3499 return( -1 );
3500 }
3501 identifier_length = narrow_string_length(
3502 identifier );
3503
3504 result = libewf_handle_get_header_value_size(
3505 handle,
3506 (uint8_t *) identifier,
3507 identifier_length,
3508 value_size,
3509 &error );
3510
3511 if( result == -1 )
3512 {
3513 libcerror_error_set(
3514 &error,
3515 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3516 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3517 "%s: unable to retrieve header value size: %s.",
3518 function,
3519 identifier );
3520
3521 libcnotify_print_error_backtrace(
3522 error );
3523 libcerror_error_free(
3524 &error );
3525 }
3526 return( result );
3527 }
3528
3529 /* Retrieves the header value specified by the identifier
3530 * The strings are encoded in UTF-8
3531 * The value size should include the end of string character
3532 * Returns 1 if successful, 0 if value not present or -1 on error
3533 */
libewf_get_header_value(libewf_handle_t * handle,const char * identifier,char * value,size_t value_size)3534 int libewf_get_header_value(
3535 libewf_handle_t *handle,
3536 const char *identifier,
3537 char *value,
3538 size_t value_size )
3539 {
3540 libcerror_error_t *error = NULL;
3541 static char *function = "libewf_get_header_value";
3542 size_t identifier_length = 0;
3543 int result = 0;
3544
3545 if( identifier == NULL )
3546 {
3547 libcerror_error_set(
3548 &error,
3549 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3550 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3551 "%s: invalid indentifier.",
3552 function );
3553
3554 libcnotify_print_error_backtrace(
3555 error );
3556 libcerror_error_free(
3557 &error );
3558
3559 return( -1 );
3560 }
3561 identifier_length = narrow_string_length(
3562 identifier );
3563
3564 result = libewf_handle_get_header_value(
3565 handle,
3566 (uint8_t *) identifier,
3567 identifier_length,
3568 (uint8_t *) value,
3569 value_size,
3570 &error );
3571
3572 if( result == -1 )
3573 {
3574 libcerror_error_set(
3575 &error,
3576 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3577 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3578 "%s: unable to retrieve header value: %s.",
3579 function,
3580 identifier );
3581
3582 libcnotify_print_error_backtrace(
3583 error );
3584 libcerror_error_free(
3585 &error );
3586
3587 return( -1 );
3588 }
3589 return( result );
3590 }
3591
3592 /* Sets the header value specified by the identifier
3593 * The strings are encoded in UTF-8
3594 * Returns 1 if successful or -1 on error
3595 */
libewf_set_header_value(libewf_handle_t * handle,const char * identifier,const char * value,size_t value_length)3596 int libewf_set_header_value(
3597 libewf_handle_t *handle,
3598 const char *identifier,
3599 const char *value,
3600 size_t value_length )
3601 {
3602 libcerror_error_t *error = NULL;
3603 static char *function = "libewf_set_header_value";
3604 size_t identifier_length = 0;
3605
3606 if( identifier == NULL )
3607 {
3608 libcerror_error_set(
3609 &error,
3610 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3611 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3612 "%s: invalid identifier.",
3613 function );
3614
3615 libcnotify_print_error_backtrace(
3616 error );
3617 libcerror_error_free(
3618 &error );
3619
3620 return( -1 );
3621 }
3622 identifier_length = narrow_string_length(
3623 identifier );
3624
3625 if( libewf_handle_set_header_value(
3626 handle,
3627 (uint8_t *) identifier,
3628 identifier_length,
3629 (uint8_t *) value,
3630 value_length,
3631 &error ) != 1 )
3632 {
3633 libcerror_error_set(
3634 &error,
3635 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3636 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
3637 "%s: unable to set header value: %s.",
3638 function,
3639 identifier );
3640
3641 libcnotify_print_error_backtrace(
3642 error );
3643 libcerror_error_free(
3644 &error );
3645
3646 return( -1 );
3647 }
3648 return( 1 );
3649 }
3650
3651 /* Copies the header values from the source to the destination handle
3652 * Returns 1 if successful or -1 on error
3653 */
libewf_copy_header_values(libewf_handle_t * destination_handle,libewf_handle_t * source_handle)3654 int libewf_copy_header_values(
3655 libewf_handle_t *destination_handle,
3656 libewf_handle_t *source_handle )
3657 {
3658 libcerror_error_t *error = NULL;
3659 static char *function = "libewf_copy_header_values";
3660
3661 if( libewf_handle_copy_header_values(
3662 destination_handle,
3663 source_handle,
3664 &error ) != 1 )
3665 {
3666 libcerror_error_set(
3667 &error,
3668 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3669 LIBCERROR_RUNTIME_ERROR_COPY_FAILED,
3670 "%s: unable to copy header values.",
3671 function );
3672
3673 libcnotify_print_error_backtrace(
3674 error );
3675 libcerror_error_free(
3676 &error );
3677
3678 return( -1 );
3679 }
3680 return( 1 );
3681 }
3682
3683 /* Parses the header values from the xheader, header2 or header section
3684 * Will parse the first available header in order mentioned above
3685 * Returns 1 if successful, 0 if already parsed or -1 on error
3686 */
libewf_parse_header_values(libewf_handle_t * handle,uint8_t date_format)3687 int libewf_parse_header_values(
3688 libewf_handle_t *handle,
3689 uint8_t date_format )
3690 {
3691 libewf_internal_handle_t *internal_handle = NULL;
3692 libcerror_error_t *error = NULL;
3693 static char *function = "libewf_parse_header_values";
3694
3695 if( handle == NULL )
3696 {
3697 libcerror_error_set(
3698 &error,
3699 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3700 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3701 "%s: invalid handle.",
3702 function );
3703
3704 libcnotify_print_error_backtrace(
3705 error );
3706 libcerror_error_free(
3707 &error );
3708
3709 return( -1 );
3710 }
3711 internal_handle = (libewf_internal_handle_t *) handle;
3712
3713 if( ( date_format != LIBEWF_DATE_FORMAT_CTIME )
3714 && ( date_format != LIBEWF_DATE_FORMAT_DAYMONTH )
3715 && ( date_format != LIBEWF_DATE_FORMAT_MONTHDAY )
3716 && ( date_format != LIBEWF_DATE_FORMAT_ISO8601 ) )
3717 {
3718 libcerror_error_set(
3719 &error,
3720 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3721 LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE,
3722 "%s: unsupported date format.",
3723 function );
3724
3725 libcnotify_print_error_backtrace(
3726 error );
3727 libcerror_error_free(
3728 &error );
3729
3730 return( -1 );
3731 }
3732 if( internal_handle->header_values_parsed != 0 )
3733 {
3734 return( 0 );
3735 }
3736 if( libewf_handle_parse_header_values(
3737 internal_handle,
3738 &error ) != 1 )
3739 {
3740 libcerror_error_set(
3741 &error,
3742 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3743 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
3744 "%s: unable to parse header values.",
3745 function );
3746
3747 libcnotify_print_error_backtrace(
3748 error );
3749 libcerror_error_free(
3750 &error );
3751
3752 return( -1 );
3753 }
3754 internal_handle->header_values_parsed = 1;
3755 internal_handle->date_format = date_format;
3756
3757 return( 1 );
3758 }
3759
3760 /* Retrieves the amount of hash values
3761 * Returns 1 if successful or -1 on error
3762 */
libewf_get_amount_of_hash_values(libewf_handle_t * handle,uint32_t * amount_of_values)3763 int libewf_get_amount_of_hash_values(
3764 libewf_handle_t *handle,
3765 uint32_t *amount_of_values )
3766 {
3767 libcerror_error_t *error = NULL;
3768 static char *function = "libewf_get_amount_of_hash_values";
3769
3770 if( libewf_handle_get_amount_of_hash_values(
3771 handle,
3772 amount_of_values,
3773 &error ) != 1 )
3774 {
3775 libcerror_error_set(
3776 &error,
3777 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3778 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3779 "%s: unable to retrieve the amount of hash values.",
3780 function );
3781
3782 libcnotify_print_error_backtrace(
3783 error );
3784 libcerror_error_free(
3785 &error );
3786
3787 return( -1 );
3788 }
3789 return( 1 );
3790 }
3791
3792 /* Retrieves the hash value identifier size specified by its index
3793 * The identifier size includes the end of string character
3794 * Returns 1 if successful, 0 if value not present or -1 on error
3795 */
libewf_get_hash_value_identifier_size(libewf_handle_t * handle,uint32_t index,size_t * identifier_size)3796 int libewf_get_hash_value_identifier_size(
3797 libewf_handle_t *handle,
3798 uint32_t index,
3799 size_t *identifier_size )
3800 {
3801 libcerror_error_t *error = NULL;
3802 static char *function = "libewf_get_hash_value_identifier_size";
3803 int result = 0;
3804
3805 result = libewf_handle_get_hash_value_identifier_size(
3806 handle,
3807 index,
3808 identifier_size,
3809 &error );
3810
3811 if( result == -1 )
3812 {
3813 libcerror_error_set(
3814 &error,
3815 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3816 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3817 "%s: unable to retrieve hash value identifier size.",
3818 function );
3819
3820 libcnotify_print_error_backtrace(
3821 error );
3822 libcerror_error_free(
3823 &error );
3824 }
3825 return( result );
3826 }
3827
3828
3829 /* Retrieves the hash value identifier specified by its index
3830 * The strings are encoded in UTF-8
3831 * The identifier size should include the end of string character
3832 * Returns 1 if successful, 0 if value not present or -1 on error
3833 */
libewf_get_hash_value_identifier(libewf_handle_t * handle,uint32_t index,char * identifier,size_t identifier_size)3834 int libewf_get_hash_value_identifier(
3835 libewf_handle_t *handle,
3836 uint32_t index,
3837 char *identifier,
3838 size_t identifier_size )
3839 {
3840 libcerror_error_t *error = NULL;
3841 static char *function = "libewf_get_hash_value_identifier";
3842 int result = 0;
3843
3844 result = libewf_handle_get_hash_value_identifier(
3845 handle,
3846 index,
3847 (uint8_t *) identifier,
3848 identifier_size,
3849 &error );
3850
3851 if( result == -1 )
3852 {
3853 libcerror_error_set(
3854 &error,
3855 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3856 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3857 "%s: unable to retrieve hash value identifier.",
3858 function );
3859
3860 libcnotify_print_error_backtrace(
3861 error );
3862 libcerror_error_free(
3863 &error );
3864 }
3865 return( result );
3866 }
3867
3868 /* Retrieves the hash value specified by the identifier
3869 * The strings are encoded in UTF-8
3870 * The value size should include the end of string character
3871 * Returns 1 if successful, 0 if value not present or -1 on error
3872 */
libewf_get_hash_value(libewf_handle_t * handle,const char * identifier,char * value,size_t value_size)3873 int libewf_get_hash_value(
3874 libewf_handle_t *handle,
3875 const char *identifier,
3876 char *value,
3877 size_t value_size )
3878 {
3879 libcerror_error_t *error = NULL;
3880 static char *function = "libewf_get_hash_value";
3881 size_t identifier_length = 0;
3882 int result = 0;
3883
3884 if( identifier == NULL )
3885 {
3886 libcerror_error_set(
3887 &error,
3888 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3889 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3890 "%s: invalid indentifier.",
3891 function );
3892
3893 libcnotify_print_error_backtrace(
3894 error );
3895 libcerror_error_free(
3896 &error );
3897
3898 return( -1 );
3899 }
3900 identifier_length = narrow_string_length(
3901 identifier );
3902
3903 result = libewf_handle_get_hash_value(
3904 handle,
3905 (uint8_t *) identifier,
3906 identifier_length,
3907 (uint8_t *) value,
3908 value_size,
3909 &error );
3910
3911 if( result == -1 )
3912 {
3913 libcerror_error_set(
3914 &error,
3915 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3916 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3917 "%s: unable to retrieve hash value: %s.",
3918 function,
3919 identifier );
3920
3921 libcnotify_print_error_backtrace(
3922 error );
3923 libcerror_error_free(
3924 &error );
3925 }
3926 return( result );
3927 }
3928
3929 /* Retrieves the hash value size specified by the identifier
3930 * The value size includes the end of string character
3931 * Returns 1 if successful, 0 if value not present or -1 on error
3932 */
libewf_get_hash_value_size(libewf_handle_t * handle,const char * identifier,size_t * value_size)3933 int libewf_get_hash_value_size(
3934 libewf_handle_t *handle,
3935 const char *identifier,
3936 size_t *value_size )
3937 {
3938 libcerror_error_t *error = NULL;
3939 static char *function = "libewf_get_hash_value_size";
3940 size_t identifier_length = 0;
3941 int result = 0;
3942
3943 if( identifier == NULL )
3944 {
3945 libcerror_error_set(
3946 &error,
3947 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
3948 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
3949 "%s: invalid indentifier.",
3950 function );
3951
3952 libcnotify_print_error_backtrace(
3953 error );
3954 libcerror_error_free(
3955 &error );
3956
3957 return( -1 );
3958 }
3959 identifier_length = narrow_string_length(
3960 identifier );
3961
3962 result = libewf_handle_get_hash_value_size(
3963 handle,
3964 (uint8_t *) identifier,
3965 identifier_length,
3966 value_size,
3967 &error );
3968
3969 if( result == -1 )
3970 {
3971 libcerror_error_set(
3972 &error,
3973 LIBCERROR_ERROR_DOMAIN_RUNTIME,
3974 LIBCERROR_RUNTIME_ERROR_GET_FAILED,
3975 "%s: unable to retrieve hash value size: %s.",
3976 function,
3977 identifier );
3978
3979 libcnotify_print_error_backtrace(
3980 error );
3981 libcerror_error_free(
3982 &error );
3983 }
3984 return( result );
3985 }
3986
3987 /* Sets the hash value specified by the identifier
3988 * The strings are encoded in UTF-8
3989 * Returns 1 if successful or -1 on error
3990 */
libewf_set_hash_value(libewf_handle_t * handle,const char * identifier,const char * value,size_t value_length)3991 int libewf_set_hash_value(
3992 libewf_handle_t *handle,
3993 const char *identifier,
3994 const char *value,
3995 size_t value_length )
3996 {
3997 libcerror_error_t *error = NULL;
3998 static char *function = "libewf_set_hash_value";
3999 size_t identifier_length = 0;
4000
4001 if( identifier == NULL )
4002 {
4003 libcerror_error_set(
4004 &error,
4005 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4006 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4007 "%s: invalid identifier.",
4008 function );
4009
4010 libcnotify_print_error_backtrace(
4011 error );
4012 libcerror_error_free(
4013 &error );
4014
4015 return( -1 );
4016 }
4017 identifier_length = narrow_string_length(
4018 identifier );
4019
4020 if( libewf_handle_set_hash_value(
4021 handle,
4022 (uint8_t *) identifier,
4023 identifier_length,
4024 (uint8_t *) value,
4025 value_length,
4026 &error ) != 1 )
4027 {
4028 libcerror_error_set(
4029 &error,
4030 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4031 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
4032 "%s: unable to set hash value: %s.",
4033 function,
4034 identifier );
4035
4036 libcnotify_print_error_backtrace(
4037 error );
4038 libcerror_error_free(
4039 &error );
4040
4041 return( -1 );
4042 }
4043 return( 1 );
4044 }
4045
4046 /* Parses the hash values from the xhash section
4047 * Returns 1 if successful, 0 if already parsed or -1 on error
4048 */
libewf_parse_hash_values(libewf_handle_t * handle)4049 int libewf_parse_hash_values(
4050 libewf_handle_t *handle )
4051 {
4052 libewf_internal_handle_t *internal_handle = NULL;
4053 libcerror_error_t *error = NULL;
4054 static char *function = "libewf_parse_hash_values";
4055
4056 if( handle == NULL )
4057 {
4058 libcerror_error_set(
4059 &error,
4060 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
4061 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
4062 "%s: invalid handle.",
4063 function );
4064
4065 libcnotify_print_error_backtrace(
4066 error );
4067 libcerror_error_free(
4068 &error );
4069
4070 return( -1 );
4071 }
4072 internal_handle = (libewf_internal_handle_t *) handle;
4073
4074 if( internal_handle->hash_values_parsed != 0 )
4075 {
4076 return( 0 );
4077 }
4078 if( libewf_handle_parse_hash_values(
4079 internal_handle,
4080 &error ) != 1 )
4081 {
4082 libcerror_error_set(
4083 &error,
4084 LIBCERROR_ERROR_DOMAIN_RUNTIME,
4085 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
4086 "%s: unable to parse hash values.",
4087 function );
4088
4089 libcnotify_print_error_backtrace(
4090 error );
4091 libcerror_error_free(
4092 &error );
4093
4094 return( -1 );
4095 }
4096 internal_handle->hash_values_parsed = 1;
4097
4098 return( 1 );
4099 }
4100
4101 #endif
4102
4103