From 4b8db2f2742223a5bc48b22c61a26d0ce1b4a5f6 Mon Sep 17 00:00:00 2001 From: Vreixo Formoso Date: Sat, 29 Dec 2007 17:42:57 +0100 Subject: [PATCH] Report writting progress. --- src/ecma119.c | 17 +++++++++++++++++ src/ecma119.h | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/src/ecma119.c b/src/ecma119.c index 2b8d4eb..9223208 100644 --- a/src/ecma119.c +++ b/src/ecma119.c @@ -656,6 +656,9 @@ void *write_function(void *arg) Ecma119Image *target = (Ecma119Image*)arg; iso_msg_debug(target->image, "Starting image writing..."); + target->bytes_written = (off_t) 0; + target->percent_written = 0; + /* Write System Area, 16 blocks of zeros (ECMA-119, 6.2.1) */ memset(buf, 0, BLOCK_SIZE); for (i = 0; i < 16; ++i) { @@ -960,5 +963,19 @@ int iso_write(Ecma119Image *target, void *buf, size_t count) /* reader cancelled */ return ISO_WRITE_ERROR; } + + target->bytes_written += count; + { + int percent = (target->bytes_written * 100) / target->total_size; + + /* only report in 5% chunks */ + if (percent >= target->percent_written + 5) { + iso_msg_debug(target->image, "Processed %u of %u KB (%d %%)", + (unsigned int) target->bytes_written >> 10, + (unsigned int) target->total_size >> 10, percent); + target->percent_written = percent; + } + } + return ret; } diff --git a/src/ecma119.h b/src/ecma119.h index 4de577e..9f29d18 100644 --- a/src/ecma119.h +++ b/src/ecma119.h @@ -73,6 +73,10 @@ struct ecma119_image off_t total_size; uint32_t vol_space_size; + /* Bytes already written, just for progress notification */ + off_t bytes_written; + int percent_written; + /* * Block being processed, either during image writing or structure * size calculation.