/* Frees a chunk table * Returns 1 if successful or -1 on error */ int libewf_chunk_table_free( libewf_chunk_table_t **chunk_table, libcerror_error_t **error ) { static char *function = "libewf_chunk_table_free"; int result = 1; if( chunk_table == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid chunk table.", function ); return( -1 ); } if( *chunk_table != NULL ) { if( libcdata_range_list_free( &( ( *chunk_table )->checksum_errors ), NULL, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free checksum errors range list.", function ); result = -1; } memory_free( *chunk_table ); *chunk_table = NULL; } return( result ); }
/* Opens a file for reading * Returns 1 if successful or -1 on error */ int libmsiecf_file_open_read( libmsiecf_internal_file_t *internal_file, libbfio_handle_t *file_io_handle, libcerror_error_t **error ) { static char *function = "libmsiecf_file_open_read"; uint32_t hash_table_offset = 0; if( internal_file == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file.", function ); return( -1 ); } if( internal_file->io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid file - missing IO handle.", function ); return( -1 ); } if( internal_file->directory_array != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: invalid file - directory array already set.", function ); return( -1 ); } if( internal_file->item_array != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: invalid file - item array already set.", function ); return( -1 ); } if( internal_file->recovered_item_array != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: invalid file - recovered item array already set.", function ); return( -1 ); } if( internal_file->unallocated_block_list != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: invalid file - unallocated block list already set.", function ); return( -1 ); } if( libcdata_array_initialize( &( internal_file->directory_array ), 0, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create directory array.", function ); goto on_error; } if( libcdata_array_initialize( &( internal_file->item_array ), 0, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create item array.", function ); goto on_error; } if( libcdata_array_initialize( &( internal_file->recovered_item_array ), 0, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create recovered item array.", function ); goto on_error; } if( libcdata_range_list_initialize( &( internal_file->unallocated_block_list ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_MEMORY, LIBCERROR_MEMORY_ERROR_INSUFFICIENT, "%s: unable to create unallocated data block list.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "Reading file header:\n" ); } #endif if( libmsiecf_io_handle_read_file_header( internal_file->io_handle, file_io_handle, &hash_table_offset, internal_file->directory_array, internal_file->unallocated_block_list, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read file header.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "Reading hash table:\n" ); } #endif if( libmsiecf_io_handle_read_hash_table( internal_file->item_array, internal_file->io_handle, file_io_handle, hash_table_offset, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read hash table.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "Scanning for records:\n" ); } #endif if( libmsiecf_io_handle_read_record_scan( internal_file->item_array, internal_file->recovered_item_array, internal_file->io_handle, file_io_handle, hash_table_offset, internal_file->unallocated_block_list, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to perform record scan.", function ); goto on_error; } return( 1 ); on_error: if( internal_file->unallocated_block_list != NULL ) { libcdata_range_list_free( &( internal_file->unallocated_block_list ), NULL, NULL ); } if( internal_file->recovered_item_array != NULL ) { libcdata_array_free( &( internal_file->recovered_item_array ), (int (*)(intptr_t **, libcerror_error_t **)) &libmsiecf_item_descriptor_free, NULL ); } if( internal_file->item_array != NULL ) { libcdata_array_free( &( internal_file->item_array ), (int (*)(intptr_t **, libcerror_error_t **)) &libmsiecf_item_descriptor_free, NULL ); } if( internal_file->directory_array != NULL ) { libcdata_array_free( &( internal_file->directory_array ), (int (*)(intptr_t **, libcerror_error_t **)) &libmsiecf_directory_descriptor_free, NULL ); } return( -1 ); }
/* Closes a file * Returns 0 if successful or -1 on error */ int libmsiecf_file_close( libmsiecf_file_t *file, libcerror_error_t **error ) { libmsiecf_internal_file_t *internal_file = NULL; static char *function = "libmsiecf_file_close"; int result = 0; if( file == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file.", function ); return( -1 ); } internal_file = (libmsiecf_internal_file_t *) file; if( internal_file->file_io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid file - missing file IO handle.", function ); return( -1 ); } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { if( internal_file->file_io_handle_created_in_library != 0 ) { if( libmsiecf_debug_print_read_offsets( internal_file->file_io_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_PRINT_FAILED, "%s: unable to print the read offsets.", function ); } } } #endif if( internal_file->file_io_handle_opened_in_library != 0 ) { if( libbfio_handle_close( internal_file->file_io_handle, error ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_CLOSE_FAILED, "%s: unable to close file IO handle.", function ); result = -1; } internal_file->file_io_handle_opened_in_library = 0; } if( internal_file->file_io_handle_created_in_library != 0 ) { if( libbfio_handle_free( &( internal_file->file_io_handle ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free file IO handle.", function ); result = -1; } internal_file->file_io_handle_created_in_library = 0; } internal_file->file_io_handle = NULL; if( libmsiecf_io_handle_clear( internal_file->io_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to clear IO handle.", function ); result = -1; } if( internal_file->directory_array != NULL ) { if( libcdata_array_free( &( internal_file->directory_array ), (int (*)(intptr_t **, libcerror_error_t **)) &libmsiecf_directory_descriptor_free, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free directory array.", function ); result = -1; } } if( internal_file->item_array != NULL ) { if( libcdata_array_free( &( internal_file->item_array ), (int (*)(intptr_t **, libcerror_error_t **)) &libmsiecf_item_descriptor_free, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free item array.", function ); result = -1; } } if( internal_file->recovered_item_array != NULL ) { if( libcdata_array_free( &( internal_file->recovered_item_array ), (int (*)(intptr_t **, libcerror_error_t **)) &libmsiecf_item_descriptor_free, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free recovered item array.", function ); result = -1; } } if( internal_file->unallocated_block_list != NULL ) { if( libcdata_range_list_free( &( internal_file->unallocated_block_list ), NULL, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free unallocated block list.", function ); result = -1; } } return( result ); }
/* Opens a file for reading * Returns 1 if successful or -1 on error */ int libolecf_file_open_read( libolecf_internal_file_t *internal_file, libbfio_handle_t *file_io_handle, libcerror_error_t **error ) { libcdata_list_t *directory_entry_list = NULL; static char *function = "libolecf_file_open_read"; uint32_t msat_sector_identifier = 0; uint32_t number_of_msat_sectors = 0; uint32_t number_of_sat_sectors = 0; uint32_t ssat_sector_identifier = 0; uint32_t number_of_ssat_sectors = 0; uint32_t root_directory_sector_identifier = 0; if( internal_file == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file.", function ); return( -1 ); } if( internal_file->io_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_MISSING, "%s: invalid file - missing IO handle.", function ); return( -1 ); } if( internal_file->msat != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: invalid file - MSAT already set.", function ); return( -1 ); } if( internal_file->sat != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: invalid file - SAT already set.", function ); return( -1 ); } if( internal_file->ssat != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: invalid file - SSAT already set.", function ); return( -1 ); } if( internal_file->unallocated_block_list != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: invalid file - unallocated block list already set.", function ); return( -1 ); } if( internal_file->directory_tree_root_node != NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET, "%s: invalid file - directory tree root node already set.", function ); return( -1 ); } if( libolecf_allocation_table_initialize( &( internal_file->msat ), 0, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create MSAT.", function ); goto on_error; } if( libolecf_allocation_table_initialize( &( internal_file->sat ), 0, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create SAT.", function ); goto on_error; } if( libolecf_allocation_table_initialize( &( internal_file->ssat ), 0, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create SSAT.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "Reading file header:\n" ); } #endif if( libolecf_io_handle_read_file_header( internal_file->io_handle, file_io_handle, internal_file->msat, &msat_sector_identifier, &number_of_msat_sectors, &number_of_sat_sectors, &ssat_sector_identifier, &number_of_ssat_sectors, &root_directory_sector_identifier, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read file header.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "Reading master sector allocation table (MSAT):\n" ); } #endif if( libolecf_io_handle_read_msat( internal_file->io_handle, file_io_handle, internal_file->msat, msat_sector_identifier, number_of_msat_sectors, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read MSAT.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "Reading sector allocation table (SAT):\n" ); } #endif if( libolecf_io_handle_read_sat( internal_file->io_handle, file_io_handle, internal_file->msat, internal_file->sat, number_of_sat_sectors, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read SAT.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "Reading short sector allocation table (SSAT):\n" ); } #endif if( libolecf_io_handle_read_ssat( internal_file->io_handle, file_io_handle, internal_file->sat, internal_file->ssat, ssat_sector_identifier, number_of_ssat_sectors, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read SSAT.", function ); goto on_error; } if( libcdata_list_initialize( &directory_entry_list, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create directory entry list.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "Reading directory entries:\n" ); } #endif if( libolecf_io_handle_read_directory_entries( internal_file->io_handle, file_io_handle, internal_file->sat, directory_entry_list, root_directory_sector_identifier, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read directory entries.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libcnotify_verbose != 0 ) { libcnotify_printf( "Creating directory tree:\n" ); } #endif if( libolecf_directory_tree_create( &( internal_file->directory_tree_root_node ), &( internal_file->io_handle->short_sector_stream_start_sector_identifier ), &( internal_file->document_summary_information_directory_entry ), &( internal_file->summary_information_directory_entry ), directory_entry_list, internal_file->io_handle->byte_order, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create directory tree.", function ); goto on_error; } /* The directory entries are no longer managed by the list but by the tree */ if( libcdata_list_free( &directory_entry_list, NULL, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free directory entry list.", function ); goto on_error; } return( 1 ); on_error: if( internal_file->unallocated_block_list != NULL ) { libcdata_range_list_free( &( internal_file->unallocated_block_list ), NULL, NULL ); } if( internal_file->directory_tree_root_node != NULL ) { libcdata_tree_node_free( &( internal_file->directory_tree_root_node ), (int (*)(intptr_t **, libcerror_error_t **)) &libolecf_directory_entry_free, NULL ); } if( directory_entry_list != NULL ) { libcdata_list_free( &directory_entry_list, (int (*)(intptr_t **, libcerror_error_t **)) &libolecf_directory_entry_free, NULL ); } if( internal_file->ssat != NULL ) { libolecf_allocation_table_free( &( internal_file->ssat ), NULL ); } if( internal_file->sat != NULL ) { libolecf_allocation_table_free( &( internal_file->sat ), NULL ); } if( internal_file->msat != NULL ) { libolecf_allocation_table_free( &( internal_file->msat ), NULL ); } return( -1 ); }
/* Tests the libpff_allocation_table_read_file_io_handle function * Returns 1 if successful or 0 if not */ int pff_test_allocation_table_read_file_io_handle( void ) { libbfio_handle_t *file_io_handle = NULL; libcdata_range_list_t *unallocated_block_list = NULL; libcerror_error_t *error = NULL; int result = 0; /* Initialize test */ result = libcdata_range_list_initialize( &unallocated_block_list, &error ); PFF_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); PFF_TEST_ASSERT_IS_NOT_NULL( "unallocated_block_list", unallocated_block_list ); PFF_TEST_ASSERT_IS_NULL( "error", error ); /* Initialize file IO handle */ result = pff_test_open_file_io_handle( &file_io_handle, pff_test_allocation_table_data_32bit, 512, &error ); PFF_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); PFF_TEST_ASSERT_IS_NOT_NULL( "file_io_handle", file_io_handle ); PFF_TEST_ASSERT_IS_NULL( "error", error ); /* Test regular cases */ result = libpff_allocation_table_read_file_io_handle( unallocated_block_list, file_io_handle, 0, LIBPFF_FILE_TYPE_32BIT, &error ); PFF_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); PFF_TEST_ASSERT_IS_NULL( "error", error ); /* Test error cases */ result = libpff_allocation_table_read_file_io_handle( NULL, file_io_handle, 0, LIBPFF_FILE_TYPE_32BIT, &error ); PFF_TEST_ASSERT_EQUAL_INT( "result", result, -1 ); PFF_TEST_ASSERT_IS_NOT_NULL( "error", error ); libcerror_error_free( &error ); result = libpff_allocation_table_read_file_io_handle( unallocated_block_list, NULL, 0, LIBPFF_FILE_TYPE_32BIT, &error ); PFF_TEST_ASSERT_EQUAL_INT( "result", result, -1 ); PFF_TEST_ASSERT_IS_NOT_NULL( "error", error ); libcerror_error_free( &error ); result = libpff_allocation_table_read_file_io_handle( unallocated_block_list, file_io_handle, -1, LIBPFF_FILE_TYPE_32BIT, &error ); PFF_TEST_ASSERT_EQUAL_INT( "result", result, -1 ); PFF_TEST_ASSERT_IS_NOT_NULL( "error", error ); libcerror_error_free( &error ); result = libpff_allocation_table_read_file_io_handle( unallocated_block_list, file_io_handle, 0, 0xff, &error ); PFF_TEST_ASSERT_EQUAL_INT( "result", result, -1 ); PFF_TEST_ASSERT_IS_NOT_NULL( "error", error ); libcerror_error_free( &error ); #if defined( HAVE_PFF_TEST_MEMORY ) /* Test libpff_allocation_table_read_file_io_handle with malloc failing */ pff_test_malloc_attempts_before_fail = 0; result = libpff_allocation_table_read_file_io_handle( unallocated_block_list, file_io_handle, 0, LIBPFF_FILE_TYPE_32BIT, &error ); if( pff_test_malloc_attempts_before_fail != -1 ) { pff_test_malloc_attempts_before_fail = -1; } else { PFF_TEST_ASSERT_EQUAL_INT( "result", result, -1 ); PFF_TEST_ASSERT_IS_NOT_NULL( "error", error ); libcerror_error_free( &error ); } #endif /* defined( HAVE_PFF_TEST_MEMORY ) */ /* Clean up file IO handle */ result = pff_test_close_file_io_handle( &file_io_handle, &error ); PFF_TEST_ASSERT_EQUAL_INT( "result", result, 0 ); PFF_TEST_ASSERT_IS_NULL( "error", error ); /* Clean up */ result = libcdata_range_list_free( &unallocated_block_list, NULL, &error ); PFF_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); PFF_TEST_ASSERT_IS_NULL( "unallocated_block_list", unallocated_block_list ); PFF_TEST_ASSERT_IS_NULL( "error", error ); return( 1 ); on_error: if( error != NULL ) { libcerror_error_free( &error ); } if( file_io_handle != NULL ) { libbfio_handle_free( &file_io_handle, NULL ); } if( unallocated_block_list != NULL ) { libcdata_range_list_free( &unallocated_block_list, NULL, NULL ); } return( 0 ); }
/* Tests the libpff_allocation_table_read_data function * Returns 1 if successful or 0 if not */ int pff_test_allocation_table_read_data( void ) { libcdata_range_list_t *unallocated_block_list = NULL; libcerror_error_t *error = NULL; int result = 0; /* Initialize test */ result = libcdata_range_list_initialize( &unallocated_block_list, &error ); PFF_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); PFF_TEST_ASSERT_IS_NOT_NULL( "unallocated_block_list", unallocated_block_list ); PFF_TEST_ASSERT_IS_NULL( "error", error ); /* Test regular cases */ result = libpff_allocation_table_read_data( unallocated_block_list, pff_test_allocation_table_data_32bit, 512, LIBPFF_FILE_TYPE_32BIT, &error ); PFF_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); PFF_TEST_ASSERT_IS_NULL( "error", error ); result = libpff_allocation_table_read_data( unallocated_block_list, pff_test_allocation_table_data_64bit, 512, LIBPFF_FILE_TYPE_64BIT, &error ); PFF_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); PFF_TEST_ASSERT_IS_NULL( "error", error ); result = libpff_allocation_table_read_data( unallocated_block_list, pff_test_allocation_table_data_64bit_4k_page, 4096, LIBPFF_FILE_TYPE_64BIT_4K_PAGE, &error ); PFF_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); PFF_TEST_ASSERT_IS_NULL( "error", error ); /* Test error cases */ result = libpff_allocation_table_read_data( NULL, pff_test_allocation_table_data_32bit, 512, LIBPFF_FILE_TYPE_32BIT, &error ); PFF_TEST_ASSERT_EQUAL_INT( "result", result, -1 ); PFF_TEST_ASSERT_IS_NOT_NULL( "error", error ); libcerror_error_free( &error ); result = libpff_allocation_table_read_data( unallocated_block_list, NULL, 512, LIBPFF_FILE_TYPE_32BIT, &error ); PFF_TEST_ASSERT_EQUAL_INT( "result", result, -1 ); PFF_TEST_ASSERT_IS_NOT_NULL( "error", error ); libcerror_error_free( &error ); result = libpff_allocation_table_read_data( unallocated_block_list, pff_test_allocation_table_data_32bit, (size_t) SSIZE_MAX + 1, LIBPFF_FILE_TYPE_32BIT, &error ); PFF_TEST_ASSERT_EQUAL_INT( "result", result, -1 ); PFF_TEST_ASSERT_IS_NOT_NULL( "error", error ); libcerror_error_free( &error ); result = libpff_allocation_table_read_data( unallocated_block_list, pff_test_allocation_table_data_32bit, 512, 0xff, &error ); PFF_TEST_ASSERT_EQUAL_INT( "result", result, -1 ); PFF_TEST_ASSERT_IS_NOT_NULL( "error", error ); libcerror_error_free( &error ); result = libpff_allocation_table_read_data( unallocated_block_list, pff_test_allocation_table_data_32bit, 0, LIBPFF_FILE_TYPE_32BIT, &error ); PFF_TEST_ASSERT_EQUAL_INT( "result", result, -1 ); PFF_TEST_ASSERT_IS_NOT_NULL( "error", error ); libcerror_error_free( &error ); /* Clean up */ result = libcdata_range_list_free( &unallocated_block_list, NULL, &error ); PFF_TEST_ASSERT_EQUAL_INT( "result", result, 1 ); PFF_TEST_ASSERT_IS_NULL( "unallocated_block_list", unallocated_block_list ); PFF_TEST_ASSERT_IS_NULL( "error", error ); return( 1 ); on_error: if( error != NULL ) { libcerror_error_free( &error ); } if( unallocated_block_list != NULL ) { libcdata_range_list_free( &unallocated_block_list, NULL, NULL ); } return( 0 ); }