⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libewf_write.c

📁 sleuthit-2.09 一个磁盘的工具集
💻 C
📖 第 1 页 / 共 5 页
字号:
		/* The header2 should be written once		 * the default compression is used		 */		write_count = libewf_section_header2_write( internal_handle, file_descriptor, start_offset, internal_handle->header2, internal_handle->header2_size, EWF_COMPRESSION_DEFAULT );		if( write_count == -1 )		{			LIBEWF_WARNING_PRINT( "libewf_write_headers: unable to write second header2 section.\n" );			return( -1 );		}		if( libewf_section_list_append( section_list, (EWF_CHAR *) "header2", start_offset, ( start_offset + write_count ) ) == NULL )		{			LIBEWF_WARNING_PRINT( "libewf_write_headers: unable to append second header2 section to section list.\n" );			return( -1 );		}		start_offset      += write_count;		total_write_count += write_count;		/* The header should be written once		 * the default compression is used		 */		write_count = libewf_section_header_write( internal_handle, file_descriptor, start_offset, internal_handle->header, header_size, EWF_COMPRESSION_DEFAULT );		if( write_count == -1 )		{			LIBEWF_WARNING_PRINT( "libewf_write_headers: unable to write third header section.\n" );			return( -1 );		}		if( libewf_section_list_append( section_list, (EWF_CHAR *) "header", start_offset, ( start_offset + write_count ) ) == NULL )		{			LIBEWF_WARNING_PRINT( "libewf_write_headers: unable to append third header section to section list.\n" );			return( -1 );		}		start_offset      += write_count;		total_write_count += write_count;	}	return( total_write_count );}/* Write the necessary sections at the start of the segment file * Returns the amount of bytes written, or -1 on error */ssize_t libewf_write_segment_file_start( LIBEWF_INTERNAL_HANDLE *internal_handle, uint16_t segment_number, int file_descriptor, LIBEWF_SECTION_LIST *section_list ){	EWF_FILE_HEADER file_header;	ssize_t total_write_count = 0;	ssize_t write_count       = 0;	if( internal_handle == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_segment_file_start: invalid handle.\n" );		return( -1 );	}	if( section_list == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_segment_file_start: invalid section list.\n" );		return( -1 );	}	if( file_descriptor == -1 )	{		LIBEWF_WARNING_PRINT( "libewf_write_segment_file_start: invalid file descriptor.\n" );		return( -1 );	}	if( segment_number == 0 )	{		LIBEWF_WARNING_PRINT( "libewf_write_segment_file_start: invalid segment number: 0.\n" );		return( -1 );	}	if( libewf_common_memcpy( file_header.signature, evf_file_signature, 8 ) == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_segment_file_start: unable to set data.\n" );		return( -1 );	}	if( libewf_endian_revert_16bit( segment_number, file_header.fields_segment ) != 1 )	{		LIBEWF_WARNING_PRINT( "libewf_write_segment_file_start: unable to revert segment number.\n" );		return( -1 );	}	file_header.fields_start    = 1;	file_header.fields_end[ 0 ] = 0;	file_header.fields_end[ 1 ] = 0;	write_count = ewf_file_header_write( &file_header, file_descriptor );	if( write_count == -1 )	{		LIBEWF_WARNING_PRINT( "libewf_write_segment_file_start: unable to write file header to file.\n" );		return( -1 );	}	total_write_count += write_count;	if( segment_number == 1 )	{		/* Write header section(s)		 */		write_count = libewf_write_headers( internal_handle, file_descriptor, (uint32_t) total_write_count, section_list );		if( write_count == -1 )		{			LIBEWF_WARNING_PRINT( "libewf_write_segment_file_start: unable to write header sections.\n" );			return( -1 );		}		total_write_count += write_count;		if( internal_handle->ewf_format == EWF_FORMAT_S01 )		{			/* Write volume (SMART) section			 */			write_count = libewf_section_volume_s01_write( internal_handle, file_descriptor, (uint32_t) total_write_count );		}		else if( internal_handle->ewf_format == EWF_FORMAT_E01 )		{			/* Write volume section			 */			write_count = libewf_section_volume_e01_write( internal_handle, file_descriptor, (uint32_t) total_write_count );		}		else		{			/* Fail safe			 */			write_count = -1;		}		if( write_count == -1 )		{			LIBEWF_WARNING_PRINT( "libewf_write_segment_file_start: unable to write volume section.\n" );			return( -1 );		}		if( libewf_section_list_append( section_list, (EWF_CHAR *) "volume", (uint32_t) total_write_count, (uint32_t) ( total_write_count + write_count ) ) == NULL )		{			LIBEWF_WARNING_PRINT( "libewf_write_segment_file_start: unable to append volume section to section list.\n" );			return( -1 );		}		total_write_count += write_count;	}	else if( internal_handle->ewf_format == EWF_FORMAT_E01 )	{		/* Write data section		 */		write_count = libewf_section_data_write( internal_handle, file_descriptor, (uint32_t) total_write_count );		if( write_count == -1 )		{			LIBEWF_WARNING_PRINT( "libewf_write_segment_file_start: unable to write data section.\n" );			return( -1 );		}		if( libewf_section_list_append( section_list, (EWF_CHAR *) "data", (uint32_t) total_write_count, (uint32_t) ( total_write_count + write_count ) ) == NULL )		{			LIBEWF_WARNING_PRINT( "libewf_write_segment_file_start: unable to append data section to section list.\n" );			return( -1 );		}		total_write_count += write_count;	}	return( total_write_count );}/* Write the necessary sections before the actual data chunks to file * Returns the amount of bytes written, or -1 on error */ssize_t libewf_write_segment_file_chunks_section_start( LIBEWF_INTERNAL_HANDLE *internal_handle, int file_descriptor, off_t start_offset, uint32_t total_chunk_amount, uint32_t segment_chunk_amount ){	LIBEWF_OFFSET_TABLE *reallocation = NULL;	ssize_t total_write_count         = 0;	ssize_t write_count               = 0;	size_t section_size               = 0;	if( internal_handle == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_segment_file_chunks_section_start: invalid handle.\n" );		return( -1 );	}	if( internal_handle->media == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_segment_file_chunks_section_start: invalid handle - missing subhandle media.\n" );		return( -1 );	}	if( internal_handle->write == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_segment_file_chunks_section_start: invalid handle - missing subhandle write.\n" );		return( -1 );	}	if( internal_handle->offset_table == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_segment_file_chunks_section_start: invalid handle - missing offset table.\n" );		return( -1 );	}	if( file_descriptor == -1 )	{		LIBEWF_WARNING_PRINT( "libewf_write_segment_file_chunks_section_start: invalid file descriptor.\n" );		return( -1 );	}	/* The segment_chunk_amount contain the estimated amount of chunks for this section	 */	if( internal_handle->offset_table->amount < ( total_chunk_amount + segment_chunk_amount ) )	{		reallocation = libewf_offset_table_realloc( internal_handle->offset_table, ( total_chunk_amount + segment_chunk_amount ) );		if( reallocation == NULL )		{			LIBEWF_WARNING_PRINT( "libewf_write_segment_file_chunks_section_start: unable to reallocate offset table.\n" );			return( -1 );		}		internal_handle->offset_table = reallocation;	}	if( ( internal_handle->ewf_format == EWF_FORMAT_S01 )	 || ( internal_handle->format == LIBEWF_FORMAT_ENCASE1 ) )	{		/* Write table section start		 */		write_count = libewf_section_table_write( internal_handle, file_descriptor, start_offset, internal_handle->offset_table, total_chunk_amount, segment_chunk_amount, (EWF_CHAR *) "table", 0 );		if( write_count == -1 )		{			LIBEWF_VERBOSE_PRINT( "libewf_write_segment_file_chunks_section_start: unable to write table section.\n" );			return( -1 );		}		start_offset      += write_count;		total_write_count += write_count;	}	else if( internal_handle->ewf_format == EWF_FORMAT_E01 )	{		section_size = segment_chunk_amount * ( internal_handle->media->chunk_size + EWF_CRC_SIZE );		/* Write sectors section start		 */		write_count = libewf_section_start_write( internal_handle, file_descriptor, (EWF_CHAR *) "sectors", section_size, start_offset );		if( write_count == -1 )		{			LIBEWF_VERBOSE_PRINT( "libewf_write_segment_file_chunks_section_start: unable to write sectors section.\n" );			return( -1 );		}		start_offset      += write_count;		total_write_count += write_count;	}	return( total_write_count );}/* Write a chunk to a segment file (compressed or uncompressed) * Returns the amount of bytes written, or -1 on error */ssize_t libewf_write_segment_file_chunk( LIBEWF_INTERNAL_HANDLE *internal_handle, uint16_t segment_number, int file_descriptor, EWF_CHUNK *chunk_data, off_t start_offset, size_t size, uint32_t chunk ){	LIBEWF_OFFSET_TABLE *reallocation = NULL;	EWF_CRC calculated_crc            = 0;	ssize_t total_write_count         = 0;	ssize_t write_count               = 0;	size_t compressed_data_size       = 0;	size_t data_write_size            = 0;	int8_t compression_level          = 0;	int8_t chunk_cache_used           = 0;	int8_t write_crc                  = 0;	int8_t result                     = 0;	if( internal_handle == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_segment_file_chunk: invalid handle.\n" );		return( -1 );	}	if( internal_handle->media == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_segment_file_chunk: invalid handle - missing subhandle media.\n" );		return( -1 );	}	if( internal_handle->write == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_segment_file_chunk: invalid handle - missing subhandle write.\n" );		return( -1 );	}	if( internal_handle->chunk_cache == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_segment_file_chunk: invalid handle - missing chunk cache.\n" );		return( -1 );	}	if( internal_handle->offset_table == NULL )	{		LIBEWF_WARNING_PRINT( "libewf_write_segment_file_chunk: invalid handle - missing offset table.\n" );		return( -1 );	}	if( file_descriptor == -1 )	{		LIBEWF_WARNING_PRINT( "libewf_write_segment_file_chunk: invalid file descriptor.\n" );		return( -1 );	}	if( chunk_data == internal_handle->chunk_cache->compressed )	{		LIBEWF_WARNING_PRINT( "libewf_write_segment_file_chunk: invalid chunk data buffer - chunk cache compressed cannot be used as chunk data buffer.\n" );		return( -1 );	}	if( internal_handle->offset_table->amount < ( chunk + 1 ) )	{		reallocation = libewf_offset_table_realloc( internal_handle->offset_table, ( chunk + 1 ) );		if( reallocation == NULL )		{			LIBEWF_WARNING_PRINT( "libewf_write_segment_file_chunk: unable to reallocate offset table.\n" );			return( -1 );		}		internal_handle->offset_table = reallocation;	}	/* Swap bytes if necessary	 */	if( ( internal_handle->swap_byte_pairs == 1 ) && ( libewf_endian_swap_byte_pairs( chunk_data, size ) != 1 ) )	{		LIBEWF_WARNING_PRINT( "libewf_write_segment_file_chunk: unable to swap byte pairs.\n" );		return( -1 );	}	/* Update the MD5 hash	 */	if( libewf_md5_update( &internal_handle->md5_context, chunk_data, size ) != 1 )	{		LIBEWF_WARNING_PRINT( "libewf_write_segment_file_chunk: unable to update MD5 context.\n" );		return( -1 );	}	/* Determine the compression level	 */	compression_level = internal_handle->compression_level;	if( compression_level == EWF_COMPRESSION_NONE )	{		if( internal_handle->write->compress_empty_block == 1 )		{			if( libewf_common_test_empty_block( chunk_data, size ) == 1 )			{				compression_level = EWF_COMPRESSION_DEFAULT;			}		}	}	/* The compressed data size contains the maximum allowed buffer size	 */	compressed_data_size = internal_handle->chunk_cache->allocated_size;	if( ( internal_handle->ewf_format == EWF_FORMAT_S01 )	 || ( compression_level != EWF_COMPRESSION_NONE ) )	{		result = ewf_chunk_compress( internal_handle->chunk_cache->compressed, &compressed_data_size, chunk_data, size, compression_level );		/* Check if the compressed buffer was too small		 * and a new compressed data size buffer was passed back		 */		if( ( result == -1 ) && ( compressed_data_size > 0 ) )		{			/* Check if chunk cache passthrough is used			 * if the chunk cache is used as the chunk data buffer			 */			chunk_cache_used = (int8_t) ( chunk_data == internal_handle->chunk_cache->data );			if( libewf_internal_handle_chunk_cache_realloc( internal_handle, compressed_data_size ) == NULL )			{				LIBEWF_WARNING_PRINT( "libewf_write_segment_file_chunk: unable to reallocate chunk cache.\n" );				return( -1 );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -