From owner-freebsd-bugs@FreeBSD.ORG Sun Apr 15 19:00:10 2007 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 0B4D916A543 for ; Sun, 15 Apr 2007 19:00:10 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [69.147.83.40]) by mx1.freebsd.org (Postfix) with ESMTP id D84DD13C45A for ; Sun, 15 Apr 2007 19:00:09 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id l3FJ097p054934 for ; Sun, 15 Apr 2007 19:00:09 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id l3FJ09Cn054933; Sun, 15 Apr 2007 19:00:09 GMT (envelope-from gnats) Resent-Date: Sun, 15 Apr 2007 19:00:09 GMT Resent-Message-Id: <200704151900.l3FJ09Cn054933@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Ulrich Spoerlein Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id E8A3F16A406 for ; Sun, 15 Apr 2007 18:53:51 +0000 (UTC) (envelope-from uspoerlein@gmail.com) Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.173]) by mx1.freebsd.org (Postfix) with ESMTP id 541A413C44C for ; Sun, 15 Apr 2007 18:53:51 +0000 (UTC) (envelope-from uspoerlein@gmail.com) Received: by ug-out-1314.google.com with SMTP id 71so793623ugh for ; Sun, 15 Apr 2007 11:53:50 -0700 (PDT) Received: by 10.82.108.9 with SMTP id g9mr2147724buc.1176663229945; Sun, 15 Apr 2007 11:53:49 -0700 (PDT) Received: from roadrunner.q.local ( [85.180.142.223]) by mx.google.com with ESMTP id e8sm126745muf.2007.04.15.11.53.47; Sun, 15 Apr 2007 11:53:49 -0700 (PDT) Received: from roadrunner.q.local (localhost [127.0.0.1]) by roadrunner.q.local (8.13.8/8.13.8) with ESMTP id l3FIrQCg077232; Sun, 15 Apr 2007 20:53:26 +0200 (CEST) (envelope-from q@roadrunner.q.local) Received: (from q@localhost) by roadrunner.q.local (8.13.8/8.13.8/Submit) id l3FIrQrr077231; Sun, 15 Apr 2007 20:53:26 +0200 (CEST) (envelope-from q) Message-Id: <200704151853.l3FIrQrr077231@roadrunner.q.local> Date: Sun, 15 Apr 2007 20:53:26 +0200 (CEST) From: Ulrich Spoerlein To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: phk@FreeBSD.org Subject: bin/111630: [PATCH] Slightly improve output of recoverdisk X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Apr 2007 19:00:10 -0000 >Number: 111630 >Category: bin >Synopsis: [PATCH] Slightly improve output of recoverdisk >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Apr 15 19:00:09 GMT 2007 >Closed-Date: >Last-Modified: >Originator: Ulrich Spoerlein >Release: FreeBSD 6.2-STABLE i386 >Organization: >Environment: >Description: recoverdisk does not display the final update of the status line, this means that it will usually print something like ... 0.9983 % done Completed This is very un-intuitive, the user expects a 100% completed column. And therein lies the second nit. recoverdisk claims to print the percentage done, when in fact it is printing no percentage at all. Multiplying by 100 fixes this trivially. >How-To-Repeat: Create a memory disk, run recoverdisk /dev/md0 # recoverdisk /dev/md0 start size len state done remaining % done 19922944 1048576 248512512 0 19922944 248512512 0.0742188 Completed The attached patch fixes this from printing '0.07 done' to '100% done' # ./recoverdisk /dev/md0 start size len state done remaining % done 267386880 1048576 1048576 0 268435456 0 100.00000 Completed If there are any style issues, please let me know. Thanks. >Fix: --- recoverdisk.c.diff begins here --- Index: recoverdisk.c =================================================================== RCS file: /home/ncvs/src/tools/tools/recoverdisk/recoverdisk.c,v retrieving revision 1.7 diff -u -p -r1.7 recoverdisk.c --- recoverdisk.c 30 May 2006 19:10:18 -0000 1.7 +++ recoverdisk.c 15 Apr 2007 18:46:33 -0000 @@ -56,6 +56,21 @@ static struct lump *lp; static char *wworklist = NULL; static char *rworklist = NULL; + +#define PRINT_HEADER \ + printf("%13s %7s %13s %5s %13s %13s %9s\n", \ + "start", "size", "len", "state", "done", "remaining", "% done") + +#define PRINT_STATUS(start, i, len, state, d, t) \ + printf("\r%13jd %7zu %13jd %5d %13jd %13jd %9.5f", \ + (intmax_t)start, \ + i, \ + (intmax_t)len, \ + state, \ + (intmax_t)d, \ + (intmax_t)(t - d), \ + 100*(double)d/(double)t) + /* Save the worklist if -w was given */ static void save_worklist(void) @@ -138,9 +153,9 @@ main(int argc, char * const argv[]) { int ch; int fdr, fdw; - off_t t, d; + off_t t, d, start, len; size_t i, j; - int error, flags; + int error, flags, state; u_char *buf; u_int sectorsize; time_t t1, t2; @@ -221,13 +236,18 @@ main(int argc, char * const argv[]) signal(SIGINT, sighandler); t1 = 0; - printf("%13s %7s %13s %5s %13s %13s %9s\n", - "start", "size", "len", "state", "done", "remaining", "% done"); + start = len = i = state = 0; + PRINT_HEADER; for (;;) { lp = TAILQ_FIRST(&lumps); if (lp == NULL) break; while (lp->len > 0 && !aborting) { + /* These are only copied for printing stats */ + start = lp->start; + len = lp->len; + state = lp->state; + i = MIN(lp->len, (off_t)bigsize); if (lp->state == 1) i = MIN(lp->len, (off_t)medsize); @@ -235,14 +255,7 @@ main(int argc, char * const argv[]) i = MIN(lp->len, (off_t)minsize); time(&t2); if (t1 != t2 || lp->len < (off_t)bigsize) { - printf("\r%13jd %7zu %13jd %5d %13jd %13jd %.7f", - (intmax_t)lp->start, - i, - (intmax_t)lp->len, - lp->state, - (intmax_t)d, - (intmax_t)(t - d), - (double)d/(double)t); + PRINT_STATUS(start, i, len, state, d, t); t1 = t2; } if (i == 0) { @@ -275,6 +288,7 @@ main(int argc, char * const argv[]) TAILQ_REMOVE(&lumps, lp, list); free(lp); } + PRINT_STATUS(start, i, len, state, d, t); printf("\nCompleted\n"); return (0); } --- recoverdisk.c.diff ends here --- >Release-Note: >Audit-Trail: >Unformatted: