From nobody@FreeBSD.org  Wed Oct  1 02:47:17 2008
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 6DBD8106568D
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  1 Oct 2008 02:47:17 +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 5C32F8FC1A
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  1 Oct 2008 02:47:17 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id m912lGZ1098035
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 1 Oct 2008 02:47:17 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id m912lGv3098034;
	Wed, 1 Oct 2008 02:47:16 GMT
	(envelope-from nobody)
Message-Id: <200810010247.m912lGv3098034@www.freebsd.org>
Date: Wed, 1 Oct 2008 02:47:16 GMT
From: Cyrus Rahman <crahman@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Nanobsd.sh incorrectly calculates partition sizes
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         127759
>Category:       misc
>Synopsis:       [nanobsd] [patch] nanobsd.sh incorrectly calculates partition sizes
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    edwin
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Oct 01 02:50:02 UTC 2008
>Closed-Date:    Tue Jun 23 22:22:38 UTC 2009
>Last-Modified:  Tue Jun 23 22:30:01 UTC 2009
>Originator:     Cyrus Rahman
>Release:        7.1-PRERELEASE
>Organization:
>Environment:
FreeBSD silva.signetica.com 7.1-PRERELEASE FreeBSD 7.1-PRERELEASE #0: Thu Sep 25 23:49:02 MDT 2008     cr@silva.signetica.com:/usr/src/sys/amd64/compile/SIGNETICA  amd64

>Description:
It is possible to ask nanobsd.sh to create a 'data' partition, separate from the system or configuration partitions, and furthermore, by specifying a negative value for its size to request that it use all space unused by those partitions for its own size.

Because the two lines of code that calculate how much space is available for this data partition are written in perl-like syntax, the awk code that does the processing performs the calculation incorrectly.

Furthermore, a comparison later down fails to newfs the partition when the size is negative.

>How-To-Repeat:
Run nanobsd.sh with NANO_DATASIZE set to a negative value.
>Fix:
Apply the attached patch, also listed herein:

--- /u/cr/sys/freebsd/nanobsd/nanobsd.sh        2008-09-29 20:59:44.000000000 -0600
+++ nanobsd.sh  2008-09-30 06:12:29.000000000 -0600
@@ -376,8 +376,8 @@
                # Data partition (if any) starts at cylinder boundary.
                if ($7 > 0) {
                        print "p 4 165 " c, dsl * cs
-               } else if ($7 < 0 && $1 > $c) {
-                       print "p 4 165 " c, $1 - $c
+               } else if ($7 < 0 && $1 > c) {
+                       print "p 4 165 " c, $1 - c
                } else if ($1 < c) {
                        print "Disk space overcommitted by", \
                            c - $1, "sectors" > "/dev/stderr"
@@ -432,7 +432,7 @@
        # XXX: fill from where ?
 
        # Create Data slice, if any.
-       if [ $NANO_DATASIZE -gt 0 ] ; then
+       if [ $NANO_DATASIZE -ne 0 ] ; then
                newfs ${NANO_NEWFS} /dev/${MD}s4
                # XXX: fill from where ?
        fi


Patch attached with submission follows:

--- /u/cr/sys/freebsd/nanobsd/nanobsd.sh	2008-09-29 20:59:44.000000000 -0600
+++ nanobsd.sh	2008-09-30 06:12:29.000000000 -0600
@@ -376,8 +376,8 @@
 		# Data partition (if any) starts at cylinder boundary.
 		if ($7 > 0) {
 			print "p 4 165 " c, dsl * cs
-		} else if ($7 < 0 && $1 > $c) {
-			print "p 4 165 " c, $1 - $c
+		} else if ($7 < 0 && $1 > c) {
+			print "p 4 165 " c, $1 - c
 		} else if ($1 < c) {
 			print "Disk space overcommitted by", \
 			    c - $1, "sectors" > "/dev/stderr"
@@ -432,7 +432,7 @@
 	# XXX: fill from where ?
 
 	# Create Data slice, if any.
-	if [ $NANO_DATASIZE -gt 0 ] ; then
+	if [ $NANO_DATASIZE -ne 0 ] ; then
 		newfs ${NANO_NEWFS} /dev/${MD}s4
 		# XXX: fill from where ?
 	fi


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: edwin 
State-Changed-When: Tue Jun 16 12:33:38 UTC 2009 
State-Changed-Why:  
Commited to head, waiting for MFC. 


Responsible-Changed-From-To: freebsd-bugs->edwin 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Tue Jun 16 12:33:38 UTC 2009 
Responsible-Changed-Why:  
I'll handle the MFC. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: misc/127759: commit references a PR
Date: Tue, 16 Jun 2009 12:33:53 +0000 (UTC)

 Author: edwin
 Date: Tue Jun 16 12:33:38 2009
 New Revision: 194288
 URL: http://svn.freebsd.org/changeset/base/194288
 
 Log:
   Fix NanoBSD when the data partition size is defined as a negative
   number.
   
   	It is possible to ask nanobsd.sh to create a 'data' partition,
   	separate from the system or configuration partitions, and
   	furthermore, by specifying a negative value for its size
   	to request that it use all space unused by those partitions
   	for its own size.
   
   	Because the two lines of code that calculate how much space
   	is available for this data partition are written in perl-like
   	syntax, the awk code that does the processing performs the
   	calculation incorrectly.
   	[note - this was already fixed by r174936]
   
   	Furthermore, a comparison later down fails to newfs the
   	partition when the size is negative.
   
   PR:		misc/127759
   Submitted by:	Cyrus Rahman <crahman@gmail.com>
   MFC after:	1 week
 
 Modified:
   head/tools/tools/nanobsd/nanobsd.sh
 
 Modified: head/tools/tools/nanobsd/nanobsd.sh
 ==============================================================================
 --- head/tools/tools/nanobsd/nanobsd.sh	Tue Jun 16 12:14:57 2009	(r194287)
 +++ head/tools/tools/nanobsd/nanobsd.sh	Tue Jun 16 12:33:38 2009	(r194288)
 @@ -474,7 +474,7 @@ create_i386_diskimage ( ) (
  	# XXX: fill from where ?
  
  	# Create Data slice, if any.
 -	if [ $NANO_DATASIZE -gt 0 ] ; then
 +	if [ $NANO_DATASIZE -ne 0 ] ; then
  		newfs ${NANO_NEWFS} /dev/${MD}s4
  		# XXX: fill from where ?
  	fi
 _______________________________________________
 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"
 
State-Changed-From-To: patched->closed 
State-Changed-By: edwin 
State-Changed-When: Tue Jun 23 22:22:19 UTC 2009 
State-Changed-Why:  
MFC to stable/7 done, thank you very much! 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: misc/127759: commit references a PR
Date: Tue, 23 Jun 2009 22:22:34 +0000 (UTC)

 Author: edwin
 Date: Tue Jun 23 22:22:20 2009
 New Revision: 194782
 URL: http://svn.freebsd.org/changeset/base/194782
 
 Log:
   Fix NanoBSD when the data partition size is defined as a negative
   number.
   
         It is possible to ask nanobsd.sh to create a 'data' partition,
         separate from the system or configuration partitions, and
         furthermore, by specifying a negative value for its size
         to request that it use all space unused by those partitions
         for its own size.
   
         Because the two lines of code that calculate how much space
         is available for this data partition are written in perl-like
         syntax, the awk code that does the processing performs the
         calculation incorrectly.
         [note - this was already fixed by r174936]
   
         Furthermore, a comparison later down fails to newfs the
         partition when the size is negative.
   
   PR:           misc/127759
   Submitted by: Cyrus Rahman <crahman@gmail.com>
 
 Modified:
   stable/7/tools/tools/nanobsd/nanobsd.sh   (contents, props changed)
 
 Modified: stable/7/tools/tools/nanobsd/nanobsd.sh
 ==============================================================================
 --- stable/7/tools/tools/nanobsd/nanobsd.sh	Tue Jun 23 22:19:27 2009	(r194781)
 +++ stable/7/tools/tools/nanobsd/nanobsd.sh	Tue Jun 23 22:22:20 2009	(r194782)
 @@ -474,7 +474,7 @@ create_i386_diskimage ( ) (
  	# XXX: fill from where ?
  
  	# Create Data slice, if any.
 -	if [ $NANO_DATASIZE -gt 0 ] ; then
 +	if [ $NANO_DATASIZE -ne 0 ] ; then
  		newfs ${NANO_NEWFS} /dev/${MD}s4
  		# XXX: fill from where ?
  	fi
 _______________________________________________
 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:
