From 05eff6e76c36acc4c7686f38bdca22dd55d7a171 Mon Sep 17 00:00:00 2001 From: Michel Machado Date: Wed, 24 Dec 2014 11:10:21 -0300 Subject: [PATCH] f3probe: suggest f3fix when the drive is fake --- f3fix.c | 4 ---- f3probe.c | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/f3fix.c b/f3fix.c index 50fe5ee..e35f27e 100644 --- a/f3fix.c +++ b/f3fix.c @@ -7,10 +7,6 @@ /* XXX Refactor utils library since f3probe barely uses it. */ #include "utils.h" -/* TODO Modify f3probe to suggest using f3fix when the drive is fake. - * Wait until f3fix is stable to implement this. - */ - /* Argp's global variables. */ const char *argp_program_version = "F3 Fix " F3_STR_VERSION; diff --git a/f3probe.c b/f3probe.c index 5e743f9..82aeca0 100644 --- a/f3probe.c +++ b/f3probe.c @@ -361,6 +361,7 @@ static int test_device(struct args *args) uint64_t write_count, write_time_us; uint64_t reset_count, reset_time_us; const char *final_dev_filename; + uint64_t last_good_sector; dev = args->debug ? create_file_device(args->filename, args->real_size_byte, @@ -435,6 +436,7 @@ static int test_device(struct args *args) printf("\nWARNING: device `%s' moved to `%s' due to the resets\n\n", args->filename, final_dev_filename); + last_good_sector = (real_size_byte >> 9) - 1; fake_type = dev_param_to_type(real_size_byte, announced_size_byte, wrap, block_order); switch (fake_type) { @@ -444,11 +446,18 @@ static int test_device(struct args *args) break; case FKTY_BAD: + printf("Bad news: The device `%s' is damaged\n", + final_dev_filename); + break; + case FKTY_LIMBO: case FKTY_WRAPAROUND: case FKTY_CHAIN: - printf("Bad news: The device `%s' is a counterfeit of type %s\n", - final_dev_filename, fake_type_to_name(fake_type)); + printf("Bad news: The device `%s' is a counterfeit of type %s\n\n" + "You can \"fix\" this device using the following command:\n" + "f3fix --last-sec=%" PRIu64 " %s\n", + final_dev_filename, fake_type_to_name(fake_type), + last_good_sector, final_dev_filename); break; default: @@ -463,7 +472,7 @@ static int test_device(struct args *args) report_order("\t Module:", wrap); report_order("\t Block size:", block_order); assert(block_order >= 9); - report_sector("\tLast good sector:", (real_size_byte >> 9) - 1); + report_sector("\tLast good sector:", last_good_sector); printf("\nProbe time: %.2f seconds\n", time_s); if (args->time_ops) {