From uspoerlein@gmail.com  Sun Apr 15 18:53:52 2007
Return-Path: <uspoerlein@gmail.com>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id E8A3F16A406
	for <FreeBSD-gnats-submit@freebsd.org>; 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 <FreeBSD-gnats-submit@freebsd.org>; 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 <FreeBSD-gnats-submit@freebsd.org>; 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 <uspoerlein@gmail.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc: phk@freebsd.org
Subject: [PATCH] Slightly improve output of recoverdisk
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         111630
>Category:       bin
>Synopsis:       [patch] Slightly improve output of recoverdisk
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Apr 15 19:00:09 GMT 2007
>Closed-Date:    Mon Apr 23 12:17:54 GMT 2007
>Last-Modified:  Mon Apr 23 12:20:10 GMT 2007
>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:
State-Changed-From-To: open->closed 
State-Changed-By: phk 
State-Changed-When: Mon Apr 23 12:17:43 UTC 2007 
State-Changed-Why:  
committed, thanks 

http://www.freebsd.org/cgi/query-pr.cgi?pr=111630 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/111630: commit references a PR
Date: Mon, 23 Apr 2007 12:17:34 +0000 (UTC)

 phk         2007-04-23 12:17:27 UTC
 
   FreeBSD src repository
 
   Modified files:
     tools/tools/recoverdisk recoverdisk.c 
   Log:
   Improve reporting in recoverdisk a good deal.
   
   Submitted by:   Ulrich Spoerlein <uspoerlein@gmail.com>
   PR:     111630
   
   Revision  Changes    Path
   1.8       +26 -12    src/tools/tools/recoverdisk/recoverdisk.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
