/* Opens the info handle * Returns 1 if successful, 0 if no VSS enabled volume was found or -1 on error */ int info_handle_open_input( info_handle_t *info_handle, const libcstring_system_character_t *filename, libcerror_error_t **error ) { static char *function = "info_handle_open_input"; size_t filename_length = 0; int result = 0; if( info_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid info handle.", function ); return( -1 ); } filename_length = libcstring_system_string_length( filename ); #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) if( libbfio_file_range_set_name_wide( info_handle->input_file_io_handle, filename, filename_length, error ) != 1 ) #else if( libbfio_file_range_set_name( info_handle->input_file_io_handle, filename, filename_length, error ) != 1 ) #endif { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open set file name.", function ); return( -1 ); } if( libbfio_file_range_set( info_handle->input_file_io_handle, info_handle->volume_offset, 0, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open set volume offset.", function ); return( -1 ); } result = libvshadow_check_volume_signature_file_io_handle( info_handle->input_file_io_handle, error ); if( result == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine if volume has a VSS signature.", function ); return( -1 ); } else if( result != 0 ) { if( libvshadow_volume_open_file_io_handle( info_handle->input_volume, info_handle->input_file_io_handle, LIBVSHADOW_OPEN_READ, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open input volume.", function ); return( -1 ); } } return( result ); }
/* Opens a volume * Returns 1 if successful or -1 on error */ int libvshadow_volume_open_wide( libvshadow_volume_t *volume, const wchar_t *filename, int access_flags, libcerror_error_t **error ) { libbfio_handle_t *file_io_handle = NULL; libvshadow_internal_volume_t *internal_volume = NULL; static char *function = "libvshadow_volume_open_wide"; if( volume == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid volume.", function ); return( -1 ); } internal_volume = (libvshadow_internal_volume_t *) volume; if( filename == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid filename.", function ); return( -1 ); } if( ( ( access_flags & LIBVSHADOW_ACCESS_FLAG_READ ) == 0 ) && ( ( access_flags & LIBVSHADOW_ACCESS_FLAG_WRITE ) == 0 ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: unsupported access flags.", function ); return( -1 ); } if( ( access_flags & LIBVSHADOW_ACCESS_FLAG_WRITE ) != 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: write access currently not supported.", function ); return( -1 ); } if( libbfio_file_initialize( &file_io_handle, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to create file IO handle.", function ); goto on_error; } #if defined( HAVE_DEBUG_OUTPUT ) if( libbfio_handle_set_track_offsets_read( file_io_handle, 1, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set track offsets read in file IO handle.", function ); goto on_error; } #endif if( libbfio_file_set_name_wide( file_io_handle, filename, libcstring_wide_string_length( filename ) + 1, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set filename in file IO handle.", function ); goto on_error; } if( libvshadow_volume_open_file_io_handle( volume, file_io_handle, access_flags, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open volume: %ls.", function, filename ); goto on_error; } #if defined( HAVE_LIBVSHADOW_MULTI_THREAD_SUPPORT ) if( libcthreads_read_write_lock_grab_for_write( internal_volume->read_write_lock, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to grab read/write lock for writing.", function ); return( -1 ); } #endif internal_volume->file_io_handle_created_in_library = 1; #if defined( HAVE_LIBVSHADOW_MULTI_THREAD_SUPPORT ) if( libcthreads_read_write_lock_release_for_write( internal_volume->read_write_lock, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to release read/write lock for writing.", function ); return( -1 ); } #endif return( 1 ); on_error: if( file_io_handle != NULL ) { libbfio_handle_free( &file_io_handle, NULL ); } return( -1 ); }