/* Initialize the read IO handle * Returns 1 if successful or -1 on error */ int libewf_read_io_handle_initialize( libewf_read_io_handle_t **read_io_handle, liberror_error_t **error ) { static char *function = "libewf_read_io_handle_initialize"; if( read_io_handle == NULL ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_ARGUMENTS, LIBERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid read IO handle.", function ); return( -1 ); } if( *read_io_handle != NULL ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_RUNTIME, LIBERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: invalid read IO handle value already set.", function ); return( -1 ); } *read_io_handle = memory_allocate_structure( libewf_read_io_handle_t ); if( *read_io_handle == NULL ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_MEMORY, LIBERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create read IO handle.", function ); goto on_error; } if( memory_set( *read_io_handle, 0, sizeof( libewf_read_io_handle_t ) ) == NULL ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_MEMORY, LIBERROR_MEMORY_ERROR_SET_FAILED, "%s: unable to clear read IO handle.", function ); goto on_error; } if( libewf_sector_list_initialize( &( ( *read_io_handle )->checksum_errors ), error ) != 1 ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_RUNTIME, LIBERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create checksum errors sector list.", function ); goto on_error; } ( *read_io_handle )->zero_on_error = 1; return( 1 ); on_error: if( *read_io_handle != NULL ) { memory_free( *read_io_handle ); *read_io_handle = NULL; } return( -1 ); }
/* Clones the sector list * Returns 1 if successful or -1 on error */ int libewf_sector_list_clone( libewf_sector_list_t **destination_sector_list, libewf_sector_list_t *source_sector_list, libcerror_error_t **error ) { libewf_list_element_t *destination_list_element = NULL; libewf_list_element_t *source_list_element = NULL; libewf_sector_list_value_t *destination_value = NULL; static char *function = "libewf_sector_list_clone"; int element_index = 0; if( destination_sector_list == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid destination sector list.", function ); return( -1 ); } if( *destination_sector_list != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: invalid destination sector list value already set.", function ); return( -1 ); } if( source_sector_list == NULL ) { *destination_sector_list = NULL; return( 1 ); } if( libewf_sector_list_initialize( destination_sector_list, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create destination sector list.", function ); goto on_error; } if( *destination_sector_list == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: missing destination sector list.", function ); goto on_error; } source_list_element = source_sector_list->first_element; for( element_index = 0; element_index < source_sector_list->number_of_elements; element_index++ ) { if( source_list_element == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: corruption detected in source sector list element: %d.", function, element_index ); goto on_error; } if( libewf_list_element_initialize( &destination_list_element, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create destination list element: %d.", function, element_index ); goto on_error; } if( libewf_sector_list_value_clone( &destination_value, (libewf_sector_list_value_t *) source_list_element->value, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to clone value of sector list element: %d.", function, element_index ); goto on_error; } if( libewf_list_element_set_value( destination_list_element, (intptr_t *) destination_value, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to set value of destination list element: %d.", function, element_index ); goto on_error; } destination_value = NULL; if( ( *destination_sector_list )->first_element == NULL ) { ( *destination_sector_list )->first_element = destination_list_element; } if( ( *destination_sector_list )->last_element != NULL ) { ( *destination_sector_list )->last_element->next_element = destination_list_element; destination_list_element->previous_element = ( *destination_sector_list )->last_element; } ( *destination_sector_list )->last_element = destination_list_element; ( *destination_sector_list )->number_of_elements += 1; destination_list_element = NULL; source_list_element = source_list_element->next_element; } return( 1 ); on_error: if( destination_value != NULL ) { libewf_sector_list_value_free( &destination_value, NULL ); } if( destination_list_element != NULL ) { libewf_list_element_free( &destination_list_element, (int (*)(intptr_t **, libcerror_error_t **)) &libewf_sector_list_value_free, NULL ); } if( *destination_sector_list != NULL ) { libewf_sector_list_free( destination_sector_list, NULL ); } return( -1 ); }