/* Stops the process status information * Returns 1 if successful or -1 on error */ int process_status_stop( process_status_t *process_status, size64_t bytes_total, int status, libcerror_error_t **error ) { libcstring_system_character_t time_string[ 32 ]; static char *function = "process_status_start"; const libcstring_system_character_t *status_string = NULL; time_t seconds_total = 0; if( process_status == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid process status.", function ); return( -1 ); } if( ( status != PROCESS_STATUS_ABORTED ) && ( status != PROCESS_STATUS_COMPLETED ) && ( status != PROCESS_STATUS_FAILED ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: unsupported status.", function ); return( -1 ); } process_status->last_timestamp = time( NULL ); if( ( process_status->output_stream != NULL ) && ( process_status->print_status_information != 0 ) && ( process_status->status_process_string != NULL ) ) { if( status == PROCESS_STATUS_ABORTED ) { status_string = _LIBCSTRING_SYSTEM_STRING( "aborted" ); } else if( status == PROCESS_STATUS_COMPLETED ) { status_string = _LIBCSTRING_SYSTEM_STRING( "completed" ); } else if( status == PROCESS_STATUS_FAILED ) { status_string = _LIBCSTRING_SYSTEM_STRING( "failed" ); } fprintf( process_status->output_stream, "%" PRIs_LIBCSTRING_SYSTEM " %" PRIs_LIBCSTRING_SYSTEM "", process_status->status_process_string, status_string ); if( process_status_get_ctime_string( &( process_status->last_timestamp ), time_string, 32, NULL ) == 1 ) { fprintf( process_status->output_stream, " at: %" PRIs_LIBCSTRING_SYSTEM "\n", time_string ); } else { fprintf( process_status->output_stream, ".\n" ); } if( ( status == PROCESS_STATUS_COMPLETED ) && ( process_status->status_summary_string != NULL ) && ( bytes_total > 0 ) ) { seconds_total = process_status->last_timestamp - process_status->start_timestamp; fprintf( process_status->output_stream, "%" PRIs_LIBCSTRING_SYSTEM ":", process_status->status_summary_string ); process_status_bytes_fprint( process_status->output_stream, bytes_total ); process_status_timestamp_fprint( process_status->output_stream, seconds_total ); process_status_bytes_per_second_fprint( process_status->output_stream, bytes_total, seconds_total ); fprintf( process_status->output_stream, ".\n" ); } } return( 1 ); }
/* Updates the process status information when the total number of bytes is unknown * Returns 1 if successful or -1 on error */ int process_status_update_unknown_total( process_status_t *process_status, size64_t bytes_read, libcerror_error_t **error ) { static char *function = "process_status_update_unknown_total"; time_t seconds_current = 0; time_t timestamp_current = 0; if( process_status == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid process status.", function ); return( -1 ); } if( ( process_status->output_stream != NULL ) && ( process_status->print_status_information != 0 ) && ( process_status->status_update_string != NULL ) ) { timestamp_current = time( NULL ); if( timestamp_current > process_status->last_timestamp ) { /* Update state * - if no status was printed before * - or input has grown > 10 MiB * - or the last update was 30 seconds ago */ if( ( process_status->last_bytes_total == 0 ) || ( bytes_read > ( process_status->last_bytes_total + ( 10 * 1024 * 1024 ) ) ) || ( ( timestamp_current - process_status->last_timestamp ) > 30 ) ) { process_status->last_timestamp = timestamp_current; process_status->last_bytes_total = bytes_read; fprintf( process_status->output_stream, "Status: %" PRIs_LIBCSTRING_SYSTEM "", process_status->status_update_string ); process_status_bytes_fprint( process_status->output_stream, bytes_read ); fprintf( process_status->output_stream, "\n" ); seconds_current = timestamp_current - process_status->start_timestamp; fprintf( process_status->output_stream, " " ); process_status_timestamp_fprint( process_status->output_stream, seconds_current ); process_status_bytes_per_second_fprint( process_status->output_stream, bytes_read, seconds_current ); fprintf( process_status->output_stream, ".\n\n" ); } } } return( 1 ); }
/* Updates the process status information * Returns 1 if successful or -1 on error */ int process_status_update( process_status_t *process_status, size64_t bytes_read, size64_t bytes_total, libcerror_error_t **error ) { static char *function = "process_status_update"; time_t seconds_current = 0; time_t seconds_total = 0; time_t seconds_remaining = 0; time_t timestamp_current = 0; int8_t new_percentage = 0; if( process_status == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid process status.", function ); return( -1 ); } if( ( process_status->output_stream != NULL ) && ( process_status->print_status_information != 0 ) && ( process_status->status_update_string != NULL ) ) { if( ( bytes_total > 0 ) && ( bytes_read > 0 ) ) { new_percentage = (int8_t) ( ( bytes_read * 100 ) / bytes_total ); } /* Estimate the remaining time */ timestamp_current = time( NULL ); if( ( new_percentage > process_status->last_percentage ) && ( timestamp_current > process_status->last_timestamp ) ) { process_status->last_percentage = new_percentage; fprintf( process_status->output_stream, "Status: at %" PRIu8 "%%.\n", new_percentage ); fprintf( process_status->output_stream, " %" PRIs_LIBCSTRING_SYSTEM "", process_status->status_update_string ); process_status_bytes_fprint( process_status->output_stream, bytes_read ); fprintf( process_status->output_stream, " of total" ); process_status_bytes_fprint( process_status->output_stream, bytes_total ); fprintf( process_status->output_stream, ".\n" ); if( ( timestamp_current > process_status->start_timestamp ) && ( new_percentage > 0 ) ) { process_status->last_timestamp = timestamp_current; seconds_current = timestamp_current - process_status->start_timestamp; seconds_total = ( ( seconds_current * 100 ) / new_percentage ); seconds_remaining = seconds_total - seconds_current; /* Negative time means nearly finished */ if( seconds_remaining < 0 ) { seconds_remaining = 0; } fprintf( process_status->output_stream, " completion" ); process_status_timestamp_fprint( process_status->output_stream, seconds_remaining ); process_status_bytes_per_second_fprint( process_status->output_stream, bytes_total, seconds_total ); fprintf( process_status->output_stream, ".\n" ); } fprintf( process_status->output_stream, "\n" ); } } return( 1 ); }
/* Stops the process status information * Returns 1 if successful or -1 on error */ int process_status_stop( process_status_t *process_status, size64_t bytes_total, int status, libcerror_error_t **error ) { libcstring_system_character_t time_string[ 32 ]; static char *function = "process_status_start"; const libcstring_system_character_t *status_string = NULL; int64_t total_number_of_seconds = 0; if( process_status == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid process status.", function ); return( -1 ); } if( ( status != PROCESS_STATUS_ABORTED ) && ( status != PROCESS_STATUS_COMPLETED ) && ( status != PROCESS_STATUS_FAILED ) ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: unsupported status.", function ); return( -1 ); } if( libcdatetime_elements_set_current_time_localtime( process_status->last_time_elements, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set last time elements to current time.", function ); return( -1 ); } if( ( process_status->output_stream != NULL ) && ( process_status->print_status_information != 0 ) && ( process_status->status_process_string != NULL ) ) { if( status == PROCESS_STATUS_ABORTED ) { status_string = _LIBCSTRING_SYSTEM_STRING( "aborted" ); } else if( status == PROCESS_STATUS_COMPLETED ) { status_string = _LIBCSTRING_SYSTEM_STRING( "completed" ); } else if( status == PROCESS_STATUS_FAILED ) { status_string = _LIBCSTRING_SYSTEM_STRING( "failed" ); } fprintf( process_status->output_stream, "%" PRIs_LIBCSTRING_SYSTEM " %" PRIs_LIBCSTRING_SYSTEM "", process_status->status_process_string, status_string ); if( libcdatetime_elements_copy_to_string( process_status->last_time_elements, (uint8_t *) time_string, 32, LIBCDATETIME_STRING_FORMAT_TYPE_CTIME | LIBCDATETIME_STRING_FORMAT_FLAG_DATE_TIME, NULL ) == 1 ) { fprintf( process_status->output_stream, " at: %" PRIs_LIBCSTRING_SYSTEM "\n", time_string ); } else { fprintf( process_status->output_stream, ".\n" ); } if( ( status == PROCESS_STATUS_COMPLETED ) && ( process_status->status_summary_string != NULL ) && ( bytes_total > 0 ) ) { fprintf( process_status->output_stream, "\n" ); if( libcdatetime_elements_get_delta_in_seconds( process_status->last_time_elements, process_status->start_time_elements, &total_number_of_seconds, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine delta between last and start time.", function ); return( -1 ); } fprintf( process_status->output_stream, "%" PRIs_LIBCSTRING_SYSTEM ":", process_status->status_summary_string ); process_status_bytes_fprint( process_status->output_stream, bytes_total ); process_status_timestamp_fprint( process_status->output_stream, total_number_of_seconds ); process_status_bytes_per_second_fprint( process_status->output_stream, bytes_total, total_number_of_seconds ); fprintf( process_status->output_stream, ".\n" ); } } return( 1 ); }
/* Updates the process status information when the total number of bytes is unknown * Returns 1 if successful or -1 on error */ int process_status_update_unknown_total( process_status_t *process_status, size64_t bytes_read, libcerror_error_t **error ) { static char *function = "process_status_update_unknown_total"; int64_t number_of_seconds = 0; if( process_status == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid process status.", function ); return( -1 ); } if( ( process_status->output_stream != NULL ) && ( process_status->print_status_information != 0 ) && ( process_status->status_update_string != NULL ) ) { if( libcdatetime_elements_set_current_time_localtime( process_status->current_time_elements, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set current time elements to current time.", function ); return( -1 ); } if( libcdatetime_elements_get_delta_in_seconds( process_status->current_time_elements, process_status->last_time_elements, &number_of_seconds, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine delta between last and current time.", function ); return( -1 ); } if( number_of_seconds > 3 ) { if( libcdatetime_elements_copy( process_status->last_time_elements, process_status->current_time_elements, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy current time elements to last.", function ); return( -1 ); } if( libcdatetime_elements_get_delta_in_seconds( process_status->last_time_elements, process_status->start_time_elements, &number_of_seconds, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine delta between last and start time.", function ); return( -1 ); } process_status->last_bytes_total = bytes_read; fprintf( process_status->output_stream, "Status: %" PRIs_LIBCSTRING_SYSTEM "", process_status->status_update_string ); process_status_bytes_fprint( process_status->output_stream, bytes_read ); fprintf( process_status->output_stream, "\n" ); fprintf( process_status->output_stream, " " ); process_status_timestamp_fprint( process_status->output_stream, number_of_seconds ); process_status_bytes_per_second_fprint( process_status->output_stream, bytes_read, number_of_seconds ); fprintf( process_status->output_stream, ".\n\n" ); } } return( 1 ); }
/* Updates the process status information * Returns 1 if successful or -1 on error */ int process_status_update( process_status_t *process_status, size64_t bytes_read, size64_t bytes_total, libcerror_error_t **error ) { static char *function = "process_status_update"; int64_t number_of_seconds = 0; int64_t remaining_number_of_seconds = 0; int64_t total_number_of_seconds = 0; int8_t new_percentage = 0; if( process_status == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid process status.", function ); return( -1 ); } if( ( process_status->output_stream != NULL ) && ( process_status->print_status_information != 0 ) && ( process_status->status_update_string != NULL ) ) { if( ( bytes_total > 0 ) && ( bytes_read > 0 ) ) { new_percentage = (int8_t) ( ( bytes_read * 100 ) / bytes_total ); } if( libcdatetime_elements_set_current_time_localtime( process_status->current_time_elements, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_SET_FAILED, "%s: unable to set current time elements to current time.", function ); return( -1 ); } if( libcdatetime_elements_get_delta_in_seconds( process_status->current_time_elements, process_status->last_time_elements, &number_of_seconds, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine delta between last and current time.", function ); return( -1 ); } /* Estimate the remaining time */ if( number_of_seconds > 3 ) { if( libcdatetime_elements_copy( process_status->last_time_elements, process_status->current_time_elements, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_COPY_FAILED, "%s: unable to copy current time elements to last.", function ); return( -1 ); } if( libcdatetime_elements_get_delta_in_seconds( process_status->last_time_elements, process_status->start_time_elements, &number_of_seconds, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to determine delta between last and start time.", function ); return( -1 ); } process_status->last_percentage = new_percentage; fprintf( process_status->output_stream, "Status: at %" PRIu8 "%%.\n", new_percentage ); fprintf( process_status->output_stream, " %" PRIs_LIBCSTRING_SYSTEM "", process_status->status_update_string ); process_status_bytes_fprint( process_status->output_stream, bytes_read ); fprintf( process_status->output_stream, " of total" ); process_status_bytes_fprint( process_status->output_stream, bytes_total ); fprintf( process_status->output_stream, ".\n" ); if( new_percentage > 0 ) { total_number_of_seconds = ( ( number_of_seconds * 100 ) / new_percentage ); remaining_number_of_seconds = total_number_of_seconds - number_of_seconds; /* Negative time means nearly finished */ if( remaining_number_of_seconds < 0 ) { remaining_number_of_seconds = 0; } fprintf( process_status->output_stream, " completion" ); process_status_timestamp_fprint( process_status->output_stream, remaining_number_of_seconds ); process_status_bytes_per_second_fprint( process_status->output_stream, bytes_total, total_number_of_seconds ); fprintf( process_status->output_stream, ".\n" ); } fprintf( process_status->output_stream, "\n" ); } } return( 1 ); }