Example #1
0
/* Append a value to the list
 * Creates a new list element
 * Returns 1 if successful or -1 on error
 */
int libewf_list_append_value(
    libewf_list_t *list,
    intptr_t *value,
    liberror_error_t **error )
{
    libewf_list_element_t *list_element = NULL;
    static char *function               = "libewf_list_append_value";

    if( libewf_list_element_initialize(
                &list_element,
                error ) != 1 )
    {
        liberror_error_set(
            error,
            LIBERROR_ERROR_DOMAIN_RUNTIME,
            LIBERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
            "%s: unable to create list element.",
            function );

        goto on_error;
    }
    if( libewf_list_append_element(
                list,
                list_element,
                error ) != 1 )
    {
        liberror_error_set(
            error,
            LIBERROR_ERROR_DOMAIN_RUNTIME,
            LIBERROR_RUNTIME_ERROR_APPEND_FAILED,
            "%s: unable to append element to list.",
            function );

        goto on_error;
    }
    if( libewf_list_element_set_value(
                list_element,
                value,
                error ) != 1 )
    {
        liberror_error_set(
            error,
            LIBERROR_ERROR_DOMAIN_RUNTIME,
            LIBERROR_RUNTIME_ERROR_GET_FAILED,
            "%s: unable to set value of list element.",
            function );

        goto on_error;
    }
    return( 1 );

on_error:
    if( list_element != NULL )
    {
        libewf_list_element_free(
            &list_element,
            NULL,
            NULL );
    }
    return( -1 );
}
Example #2
0
/* Appends a sector
 * Returns 1 if successful, or -1 on error
 */
int libewf_sector_list_append_sector(
     libewf_sector_list_t *sector_list,
     uint64_t first_sector,
     uint64_t number_of_sectors,
     uint8_t merge_ranges,
     libcerror_error_t **error )
{
	libewf_list_element_t *last_list_element      = NULL;
	libewf_list_element_t *list_element           = NULL;
	libewf_list_element_t *remove_element         = NULL;
	libewf_sector_list_value_t *sector_list_value = NULL;
	static char *function                         = "libewf_sector_list_append_sector";
	uint64_t last_range_sector                    = 0;
	uint64_t last_sector                          = 0;
	int create_list_element                       = 0;
	int element_index                             = 0;
	int merge_next_list_element_check             = 0;
	int merge_previous_list_element_check         = 0;

	if( sector_list == NULL )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
		 "%s: invalid sector list.",
		 function );

		return( -1 );
	}
	if( first_sector > (uint64_t) INT64_MAX )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
		 "%s: invalid first sector value exceeds maximum.",
		 function );

		return( -1 );
	}
	if( number_of_sectors > (uint64_t) INT64_MAX )
	{
		libcerror_error_set(
		 error,
		 LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
		 LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
		 "%s: invalid number of sectors value exceeds maximum.",
		 function );

		return( -1 );
	}
	create_list_element = 1;

	/* Check if new range should be merged with an existing range
	 */
	if( merge_ranges == 0 )
	{
		last_list_element = sector_list->last_element;
	}
	else if( sector_list->number_of_elements > 0 )
	{
		last_sector = first_sector + number_of_sectors;

		/* Check the last element first, most often the list will be filled linear 
		 */
		list_element = sector_list->last_element;

		if( list_element == NULL )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
			 "%s: corruption detected for list element: %d.",
			 function,
			 sector_list->number_of_elements - 1 );

			return( -1 );
		}
		if( list_element->value == NULL )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
			 "%s: missing sector list value for list element: %d.",
			 function,
			 sector_list->number_of_elements - 1 );

			return( -1 );
		}
		sector_list_value = (libewf_sector_list_value_t *) list_element->value;

		last_range_sector = sector_list_value->first_sector + sector_list_value->number_of_sectors;

		/* Check if the sector range overlaps at the end of the last sector range
		 */
		if( ( first_sector >= sector_list_value->first_sector )
		 && ( first_sector <= last_range_sector ) )
		{
			if( last_sector > last_range_sector )
			{
				sector_list_value->number_of_sectors += (uint64_t) ( last_sector - last_range_sector );
			}
			create_list_element           = 0;
			merge_next_list_element_check = 1;
		}
		/* Check if the sector range overlaps at the beginning of the last sector range
		 */
		else if( ( last_sector >= sector_list_value->first_sector )
		      && ( last_sector <= last_range_sector ) )
		{
			if( first_sector < sector_list_value->first_sector )
			{
				sector_list_value->first_sector       = first_sector;
				sector_list_value->number_of_sectors += (uint64_t) ( sector_list_value->first_sector - first_sector );
			}
			create_list_element               = 0;
			merge_previous_list_element_check = 1;
		}
		/* Check if the sector range overlaps the last sector range entirely
		 */
		else if( ( first_sector < sector_list_value->first_sector )
		      && ( last_sector > last_range_sector ) )
		{
			sector_list_value->first_sector      = first_sector;
			sector_list_value->number_of_sectors = number_of_sectors;

			create_list_element               = 0;
			merge_previous_list_element_check = 1;
		}
		/* Check if the sector range is beyond the last range
		 */
		else if( last_sector > last_range_sector )
		{
			last_list_element = list_element;
		}
		else if( sector_list->number_of_elements > 1 )
		{
			if( last_sector > ( last_range_sector / 2 ) )
			{
				list_element = list_element->previous_element;

				for( element_index = ( sector_list->number_of_elements - 2 );
				     element_index >= 0;
				     element_index-- )
				{
					if( list_element == NULL )
					{
						libcerror_error_set(
						 error,
						 LIBCERROR_ERROR_DOMAIN_RUNTIME,
						 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
						 "%s: corruption detected for list element: %d.",
						 function,
						 element_index );

						return( -1 );
					}
					if( list_element->value == NULL )
					{
						libcerror_error_set(
						 error,
						 LIBCERROR_ERROR_DOMAIN_RUNTIME,
						 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
						 "%s: missing sector list value for list element: %d.",
						 function,
						 element_index );

						return( -1 );
					}
					sector_list_value = (libewf_sector_list_value_t *) list_element->value;

					last_range_sector = sector_list_value->first_sector + sector_list_value->number_of_sectors;

					/* Check if the sector range overlaps at the end of an existing sector range
					 */
					if( ( first_sector >= sector_list_value->first_sector )
					 && ( first_sector <= last_range_sector ) )
					{
						if( last_sector > last_range_sector )
						{
							sector_list_value->number_of_sectors += (uint64_t) ( last_sector - last_range_sector );
						}
						create_list_element           = 0;
						merge_next_list_element_check = 1;
					}
					/* Check if the sector range overlaps at the beginning of an existing sector range
					 */
					else if( ( last_sector >= sector_list_value->first_sector )
					      && ( last_sector <= last_range_sector ) )
					{
						if( first_sector < sector_list_value->first_sector )
						{
							sector_list_value->first_sector       = first_sector;
							sector_list_value->number_of_sectors += (uint64_t) ( sector_list_value->first_sector - first_sector );
						}
						create_list_element               = 0;
						merge_previous_list_element_check = 1;
					}
					/* Check if the sector range overlaps an existing sector range entirely
					 */
					else if( ( first_sector < sector_list_value->first_sector )
					      && ( last_sector > last_range_sector ) )
					{
						sector_list_value->first_sector      = first_sector;
						sector_list_value->number_of_sectors = number_of_sectors;

						create_list_element               = 0;
						merge_next_list_element_check     = 1;
						merge_previous_list_element_check = 1;
					}
					if( create_list_element == 0 )
					{
						break;
					}
					/* Check if the sector range belongs after the exising sector range
					 */
					if( last_sector > last_range_sector )
					{
						last_list_element = list_element;

						break;
					}
					last_list_element = list_element;
					list_element      = list_element->previous_element;
				}
			}
			else
			{
				list_element = sector_list->first_element;

				for( element_index = 0;
				     element_index < ( sector_list->number_of_elements - 1 );
				     element_index++ )
				{
					if( list_element == NULL )
					{
						libcerror_error_set(
						 error,
						 LIBCERROR_ERROR_DOMAIN_RUNTIME,
						 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
						 "%s: corruption detected for list element: %d.",
						 function,
						 element_index );

						return( -1 );
					}
					if( list_element->value == NULL )
					{
						libcerror_error_set(
						 error,
						 LIBCERROR_ERROR_DOMAIN_RUNTIME,
						 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
						 "%s: missing sector list value for list element: %d.",
						 function,
						 element_index );

						return( -1 );
					}
					sector_list_value = (libewf_sector_list_value_t *) list_element->value;

					last_range_sector = sector_list_value->first_sector + sector_list_value->number_of_sectors;

					/* Check if the sector range overlaps at the end of an existing sector range
					 */
					if( ( first_sector >= sector_list_value->first_sector )
					 && ( first_sector <= last_range_sector ) )
					{
						if( last_sector > last_range_sector )
						{
							sector_list_value->number_of_sectors += (uint64_t) ( last_sector - last_range_sector );
						}
						create_list_element           = 0;
						merge_next_list_element_check = 1;
					}
					/* Check if the sector range overlaps at the beginning of an existing sector range
					 */
					else if( ( last_sector >= sector_list_value->first_sector )
					      && ( last_sector <= last_range_sector ) )
					{
						if( first_sector < sector_list_value->first_sector )
						{
							sector_list_value->first_sector       = first_sector;
							sector_list_value->number_of_sectors += (uint64_t) ( sector_list_value->first_sector - first_sector );
						}
						create_list_element               = 0;
						merge_previous_list_element_check = 1;
					}
					/* Check if the sector range overlaps an existing sector range entirely
					 */
					else if( ( first_sector < sector_list_value->first_sector )
					      && ( last_sector > last_range_sector ) )
					{
						sector_list_value->first_sector      = first_sector;
						sector_list_value->number_of_sectors = number_of_sectors;

						create_list_element               = 0;
						merge_next_list_element_check     = 1;
						merge_previous_list_element_check = 1;
					}
					if( create_list_element == 0 )
					{
						break;
					}
					/* Check if the sector range belongs before the current sector range
					 */
					if( last_sector < last_range_sector )
					{
                                        	last_list_element = list_element->previous_element;

						break;
					}
                                        last_list_element = list_element;
                                        list_element      = list_element->next_element;
				}
			}
		}
		/* Check if the current range should be merged with the previous range
		 */
		if( merge_previous_list_element_check != 0 )
		{
			if( list_element == NULL )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
				 "%s: invalid list element.",
				 function );

				return( -1 );
			}
			if( list_element->previous_element != NULL )
			{
				if( list_element->previous_element->value == NULL )
				{
					libcerror_error_set(
					 error,
					 LIBCERROR_ERROR_DOMAIN_RUNTIME,
					 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
					 "%s: missing sector list value for previous list element.",
					 function );

					return( -1 );
				}
				last_sector = ( (libewf_sector_list_value_t *) list_element->previous_element->value )->first_sector
				            + ( (libewf_sector_list_value_t *) list_element->previous_element->value )->number_of_sectors;

				if( last_sector == sector_list_value->first_sector )
				{
					/* Merge sector range with previous
					 */
					sector_list_value->first_sector       = ( (libewf_sector_list_value_t *) list_element->previous_element->value )->first_sector;
					sector_list_value->number_of_sectors += ( (libewf_sector_list_value_t *) list_element->previous_element->value )->number_of_sectors;

					/* Remove previous list element
					 */
					remove_element = list_element->previous_element;

					if( remove_element == sector_list->first_element )
					{
						sector_list->first_element = remove_element->next_element;
					}
					if( remove_element == sector_list->last_element )
					{
						sector_list->last_element = remove_element->previous_element;
					}
					if( remove_element->next_element != NULL )
					{
						remove_element->next_element->previous_element = remove_element->previous_element;
					}
					if( remove_element->previous_element != NULL )
					{
						remove_element->previous_element->next_element = remove_element->next_element;
					}
					remove_element->next_element     = NULL;
					remove_element->previous_element = NULL;
					sector_list->number_of_elements -= 1;

					if( libewf_list_element_free(
					     &remove_element,
					     (int (*)(intptr_t **, libcerror_error_t **)) &libewf_sector_list_value_free,
					     error ) != 1 )
					{
						libcerror_error_set(
						 error,
						 LIBCERROR_ERROR_DOMAIN_RUNTIME,
						 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
						 "%s: unable to free element: %d.",
						 function,
						 element_index );

						return( -1 );
					}
				}
			}
		}
		/* Check if the current range should be merged with the next range
		 */
		if( merge_next_list_element_check != 0 )
		{
			if( list_element == NULL )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
				 "%s: invalid list element.",
				 function );

				return( -1 );
			}
			if( list_element->next_element != NULL )
			{
				if( list_element->next_element->value == NULL )
				{
					libcerror_error_set(
					 error,
					 LIBCERROR_ERROR_DOMAIN_RUNTIME,
					 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
					 "%s: missing sector list value for next list element.",
					 function );

					return( -1 );
				}
				last_sector = sector_list_value->first_sector + sector_list_value->number_of_sectors;

				if( last_sector == ( (libewf_sector_list_value_t *) list_element->next_element->value )->first_sector )
				{
					/* Merge sector range with next
					 */
					sector_list_value->number_of_sectors += ( (libewf_sector_list_value_t *) list_element->next_element->value )->number_of_sectors;

					/* Remove next list element
					 */
					remove_element = list_element->next_element;

					if( remove_element == sector_list->first_element )
					{
						sector_list->first_element = remove_element->next_element;
					}
					if( remove_element == sector_list->last_element )
					{
						sector_list->last_element = remove_element->previous_element;
					}
					if( remove_element->next_element != NULL )
					{
						remove_element->next_element->previous_element = remove_element->previous_element;
					}
					if( remove_element->previous_element != NULL )
					{
						remove_element->previous_element->next_element = remove_element->next_element;
					}
					remove_element->next_element     = NULL;
					remove_element->previous_element = NULL;
					sector_list->number_of_elements -= 1;

					if( libewf_list_element_free(
					     &remove_element,
					     (int (*)(intptr_t **, libcerror_error_t **)) &libewf_sector_list_value_free,
					     error ) != 1 )
					{
						libcerror_error_set(
						 error,
						 LIBCERROR_ERROR_DOMAIN_RUNTIME,
						 LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED,
						 "%s: unable to free element: %d.",
						 function,
						 element_index );

						return( -1 );
					}
				}
			}
		}
	}
	if( create_list_element != 0 )
	{
		sector_list_value = NULL;

		if( libewf_sector_list_value_initialize(
		     &sector_list_value,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
			 "%s: unable to create sector list value.",
			 function );

			return( -1 );
		}
		if( sector_list_value == NULL )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
			 "%s: missing sector list value.",
			 function );

			return( -1 );
		}
		sector_list_value->first_sector      = first_sector;
		sector_list_value->number_of_sectors = number_of_sectors;

		list_element = NULL;

		if( libewf_list_element_initialize(
		     &list_element,
		     error ) != 1 )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
			 "%s: unable to create list element.",
			 function );

			libewf_sector_list_value_free(
			 &sector_list_value,
			 NULL );

			return( -1 );
		}
		if( list_element == NULL )
		{
			libcerror_error_set(
			 error,
			 LIBCERROR_ERROR_DOMAIN_RUNTIME,
			 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
			 "%s: missing list element.",
			 function );

			libewf_sector_list_value_free(
			 &sector_list_value,
			 NULL );

			return( -1 );
		}
		list_element->value = (intptr_t *) sector_list_value;

		if( sector_list->number_of_elements == 0 )
		{
			if( sector_list->first_element != NULL )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
				 "%s: corruption detected - first element already set.",
				 function );

				libewf_list_element_free(
				 &list_element,
				 (int (*)(intptr_t **, libcerror_error_t **)) &libewf_sector_list_value_free,
				 NULL );

				return( -1 );
			}
			if( sector_list->last_element != NULL )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
				 "%s: corruption detected - last element already set.",
				 function );

				libewf_list_element_free(
				 &list_element,
				 (int (*)(intptr_t **, libcerror_error_t **)) &libewf_sector_list_value_free,
				 NULL );

				return( -1 );
			}
			sector_list->first_element = list_element;
			sector_list->last_element  = list_element;
		}
		else
		{
			if( sector_list->first_element == NULL )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
				 "%s: corruption detected - missing first.",
				 function );

				libewf_list_element_free(
				 &list_element,
				 (int (*)(intptr_t **, libcerror_error_t **)) &libewf_sector_list_value_free,
				 NULL );

				return( -1 );
			}
			if( sector_list->last_element == NULL )
			{
				libcerror_error_set(
				 error,
				 LIBCERROR_ERROR_DOMAIN_RUNTIME,
				 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
				 "%s: corruption detected - missing last.",
				 function );

				libewf_list_element_free(
				 &list_element,
				 (int (*)(intptr_t **, libcerror_error_t **)) &libewf_sector_list_value_free,
				 NULL );

				return( -1 );
			}
			if( last_list_element == NULL )
			{
				sector_list->first_element->previous_element = list_element;
				list_element->next_element                   = sector_list->first_element;

				sector_list->first_element = list_element;
			}
			else
			{
				list_element->previous_element = last_list_element;
				list_element->next_element     = last_list_element->next_element;

				if( last_list_element == sector_list->last_element )
				{
					sector_list->last_element = list_element;
				}
				else if( last_list_element->next_element == NULL )
				{
					libcerror_error_set(
					 error,
					 LIBCERROR_ERROR_DOMAIN_RUNTIME,
					 LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
					 "%s: corruption detected - missing next in last list element.",
					 function );

					return( -1 );
				}
				else
				{
					last_list_element->next_element->previous_element = list_element;
				}
				last_list_element->next_element = list_element;
			}
		}
		sector_list->number_of_elements++;
	}
	return( 1 );
}
Example #3
0
/* Inserts a value to the list
 *
 * Creates a new list element
 *
 * Uses the value_compare_function to determine the order of the entries
 * The value_compare_function should return LIBEWF_LIST_COMPARE_LESS,
 * LIBEWF_LIST_COMPARE_EQUAL, LIBEWF_LIST_COMPARE_GREATER if successful or -1 on error
 *
 * Duplicate entries are allowed by default and inserted after the last duplicate value.
 * Only allowing unique entries can be enforced by setting the flag LIBEWF_LIST_INSERT_FLAG_UNIQUE_ENTRIES
 *
 * Returns 1 if successful, 0 if the list element already exists or -1 on error
 */
int libewf_list_insert_value(
    libewf_list_t *list,
    intptr_t *value,
    int (*value_compare_function)(
        intptr_t *first_value,
        intptr_t *second_value,
        liberror_error_t **error ),
    uint8_t insert_flags,
    liberror_error_t **error )
{
    libewf_list_element_t *list_element = NULL;
    static char *function               = "libewf_list_insert_value";
    int result                          = 0;

    if( libewf_list_element_initialize(
                &list_element,
                error ) != 1 )
    {
        liberror_error_set(
            error,
            LIBERROR_ERROR_DOMAIN_RUNTIME,
            LIBERROR_RUNTIME_ERROR_INITIALIZE_FAILED,
            "%s: unable to create list element.",
            function );

        return( -1 );
    }
    if( libewf_list_element_set_value(
                list_element,
                value,
                error ) != 1 )
    {
        liberror_error_set(
            error,
            LIBERROR_ERROR_DOMAIN_RUNTIME,
            LIBERROR_RUNTIME_ERROR_GET_FAILED,
            "%s: unable to set value of list element.",
            function );

        goto on_error;
    }
    result = libewf_list_insert_element(
                 list,
                 list_element,
                 value_compare_function,
                 insert_flags,
                 error );

    if( result == -1 )
    {
        liberror_error_set(
            error,
            LIBERROR_ERROR_DOMAIN_RUNTIME,
            LIBERROR_RUNTIME_ERROR_APPEND_FAILED,
            "%s: unable to insert element to list.",
            function );

        goto on_error;
    }
    else if( result == 0 )
    {
        if( libewf_list_element_free(
                    &list_element,
                    NULL,
                    error ) != 1 )
        {
            liberror_error_set(
                error,
                LIBERROR_ERROR_DOMAIN_RUNTIME,
                LIBERROR_RUNTIME_ERROR_FINALIZE_FAILED,
                "%s: unable to free list element.",
                function );

            goto on_error;
        }
    }
    return( result );

on_error:
    if( list_element != NULL )
    {
        libewf_list_element_free(
            &list_element,
            NULL,
            NULL );
    }
    return( -1 );
}
Example #4
0
/* 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 );
}