From nobody@FreeBSD.org  Tue Aug 31 15:06:39 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id A513010656BD
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 31 Aug 2010 15:06:39 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 899548FC21
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 31 Aug 2010 15:06:39 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o7VF6dZv079126
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 31 Aug 2010 15:06:39 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o7VF6dHI079125;
	Tue, 31 Aug 2010 15:06:39 GMT
	(envelope-from nobody)
Message-Id: <201008311506.o7VF6dHI079125@www.freebsd.org>
Date: Tue, 31 Aug 2010 15:06:39 GMT
From: pluknet <pluknet@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] fix quota(1) output [regression]
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         150151
>Category:       bin
>Synopsis:       [patch] fix quota(1) output [regression]
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    pluknet
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Aug 31 15:10:04 UTC 2010
>Closed-Date:    Thu Jun 30 09:39:51 UTC 2011
>Last-Modified:  Thu Jun 30 09:40:06 UTC 2011
>Originator:     pluknet
>Release:        9-CURRENT as of August '10
>Organization:
>Environment:
FreeBSD 9.0-CURRENT #47: Mon Aug 30 15:58:57 UTC 2010     root@host:/usr/obj/usr/src/sys/CUST amd64
>Description:
After quota64 project merge, quota(1) starts to
1) incorrectly format numbers in -h mode;
2) print incorrect numbers in ordinary (non -h) mode.

The causing changes is in:
1) field expansion resulting in passing too large buffer size to humanize_number(3);
2) some reason resulting in incorrect use of {dbtob() and multiplying} for calculating 1024-k sized blocks from disk blocks.
>How-To-Repeat:
# quota -rg nobody
Raw group quota information for id 65534 on /mnt
block hard limit:     0
block soft limit:     400000
current block count:  8
i-node hard limit:    0
i-node soft limit:    0
current i-node count: 1
block grace time:     1283866029 Tue Sep  7 13:27:09 2010
i-node grace time:    1283861167 Tue Sep  7 12:06:07 2010

Incorrect output:

# quota -gh nobody
Disk quotas for group nobody (gid 65534): 
Filesystem        usage    quota   limit   grace  files   quota  limit   grace
/mnt              4096B  200000K      0B              1       0      0        
# quota -g nobody
Disk quotas for group nobody (gid 65534): 
Filesystem        usage    quota   limit   grace  files   quota  limit   grace
/mnt            4194304  209715200000       0              1       0      0     

>Fix:
The possible and least intrusive change in attach.
It mostly reverts a some part of quota64 project.

Output after patching:

# quota -gh nobody
Disk quotas for group nobody (gid 65534): 
Filesystem        usage    quota   limit   grace  files   quota  limit   grace
/mnt               4.0K     195M      0B              1       0      0        
# quota -g nobody
Disk quotas for group nobody (gid 65534): 
Filesystem        usage    quota   limit   grace  files   quota  limit   grace
/mnt                  4   200000       0              1       0      0        


Patch attached with submission follows:

Index: quota.c
===================================================================
--- quota.c	(revision 211279)
+++ quota.c	(working copy)
@@ -266,7 +266,7 @@
 static void
 prthumanval(int len, u_int64_t bytes)
 {
-	char buf[len + 1];
+	char buf[5];
 
 	humanize_number(buf, sizeof(buf), bytes, "", HN_AUTOSCALE,
 	    HN_B | HN_NOSPACE | HN_DECIMAL);
@@ -356,10 +356,13 @@
 			prthumanval(7, dbtob(qup->dqblk.dqb_bhardlimit));
 		} else {
 			printf(" %7ju%c %7ju %7ju",
-			    dbtob(1024) * (uintmax_t)qup->dqblk.dqb_curblocks,
+			    (uintmax_t)dbtob(qup->dqblk.dqb_curblocks)
+				/ 1024,
 			    (msgb == NULL) ? ' ' : '*',
-			    dbtob(1024) * (uintmax_t)qup->dqblk.dqb_bsoftlimit,
-			    dbtob(1024) * (uintmax_t)qup->dqblk.dqb_bhardlimit);
+			    (uintmax_t)dbtob(qup->dqblk.dqb_bsoftlimit)
+				/ 1024,
+			    (uintmax_t)dbtob(qup->dqblk.dqb_bhardlimit)
+				/ 1024);
 		}
 		if (msgb != NULL)
 			bgrace = timeprt(qup->dqblk.dqb_btime);


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->des 
Responsible-Changed-By: pluknet 
Responsible-Changed-When: Tue Oct 12 13:35:27 UTC 2010 
Responsible-Changed-Why:  
DES would like to look at it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=150151 
State-Changed-From-To: open->closed 
State-Changed-By: pluknet 
State-Changed-When: Thu Jun 30 09:39:16 UTC 2011 
State-Changed-Why:  
Committed with minor modifications. 


Responsible-Changed-From-To: des->pluknet 
Responsible-Changed-By: pluknet 
Responsible-Changed-When: Thu Jun 30 09:39:16 UTC 2011 
Responsible-Changed-Why:  
Committed with minor modifications. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/150151: commit references a PR
Date: Thu, 30 Jun 2011 09:20:39 +0000 (UTC)

 Author: pluknet
 Date: Thu Jun 30 09:20:26 2011
 New Revision: 223690
 URL: http://svn.freebsd.org/changeset/base/223690
 
 Log:
   Fix quota(1) output.
   
   - Fix calculation of 1024-byte sized blocks from disk blocks shown when -h
   option isn't specified. It was broken with quota64 integration.
   - In prthumanval(): limit the size of a buffer passed to humanize_number()
   to a width of 5 bytes but allow a shorter length if requested. That's what
   users expect.
   
   PR:		bin/150151
   Reviewed by:	Kirk McKusick
 
 Modified:
   head/usr.bin/quota/quota.c
 
 Modified: head/usr.bin/quota/quota.c
 ==============================================================================
 --- head/usr.bin/quota/quota.c	Thu Jun 30 05:28:10 2011	(r223689)
 +++ head/usr.bin/quota/quota.c	Thu Jun 30 09:20:26 2011	(r223690)
 @@ -264,8 +264,11 @@ prthumanval(int len, u_int64_t bytes)
  {
  	char buf[len + 1];
  
 -	humanize_number(buf, sizeof(buf), bytes, "", HN_AUTOSCALE,
 -	    HN_B | HN_NOSPACE | HN_DECIMAL);
 +	/*
 +	 * Limit the width to 5 bytes as that is what users expect.
 +	 */
 +	humanize_number(buf, sizeof(buf) < 5 ? sizeof(buf) : 5, bytes, "",
 +	    HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
  
  	(void)printf(" %*s", len, buf);
  }
 @@ -352,10 +355,13 @@ showquotas(int type, u_long id, const ch
  			prthumanval(7, dbtob(qup->dqblk.dqb_bhardlimit));
  		} else {
  			printf(" %7ju%c %7ju %7ju",
 -			    dbtob(1024) * (uintmax_t)qup->dqblk.dqb_curblocks,
 +			    (uintmax_t)dbtob(qup->dqblk.dqb_curblocks)
 +				/ 1024,
  			    (msgb == NULL) ? ' ' : '*',
 -			    dbtob(1024) * (uintmax_t)qup->dqblk.dqb_bsoftlimit,
 -			    dbtob(1024) * (uintmax_t)qup->dqblk.dqb_bhardlimit);
 +			    (uintmax_t)dbtob(qup->dqblk.dqb_bsoftlimit)
 +				/ 1024,
 +			    (uintmax_t)dbtob(qup->dqblk.dqb_bhardlimit)
 +				/ 1024);
  		}
  		if (msgb != NULL)
  			bgrace = timeprt(qup->dqblk.dqb_btime);
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
